diff --git a/LICENSE b/LICENSE index 29f81d812f3e768fa89638d1f72920dbfd1413a8..c9db8b287c9562fe0a649e01414641050ddeae4b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ Apache License - Version 2.0, January 2004 + Version 2.0, January 2024 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION diff --git a/README.en.md b/README.en.md index 37e4cb93c146e66d09d1a3fe82bd44cebf2424b3..e4013df8392571b3805b10fd5a44bb66421762cb 100644 --- a/README.en.md +++ b/README.en.md @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ # test262_sendable #### Description diff --git a/README.md b/README.md index 3462fb7652bc919f7481d2061c649056d05e66e8..8bd8055c06f3d3739a99a3a5ee2f0c36c23c539b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ # test262_sendable #### 介绍 diff --git a/harness/assert.js b/harness/assert.js new file mode 100644 index 0000000000000000000000000000000000000000..c3373464f08dc23a02f57ff43a7241e8e1be2c13 --- /dev/null +++ b/harness/assert.js @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Collection of assertion functions used throughout test262 +defines: [assert] +---*/ + + +function assert(mustBeTrue, message) { + if (mustBeTrue === true) { + return; + } + + if (message === undefined) { + message = 'Expected true but got ' + assert._toString(mustBeTrue); + } + throw new Test262Error(message); +} + +assert._isSameValue = function (a, b) { + if (a === b) { + // Handle +/-0 vs. -/+0 + return a !== 0 || 1 / a === 1 / b; + } + + // Handle NaN vs. NaN + return a !== a && b !== b; +}; + +assert.sameValue = function (actual, expected, message) { + try { + if (assert._isSameValue(actual, expected)) { + return; + } + } catch (error) { + throw new Test262Error(message + ' (_isSameValue operation threw) ' + error); + return; + } + + if (message === undefined) { + message = ''; + } else { + message += ' '; + } + + message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(expected) + '») to be true'; + + throw new Test262Error(message); +}; + +assert.notSameValue = function (actual, unexpected, message) { + if (!assert._isSameValue(actual, unexpected)) { + return; + } + + if (message === undefined) { + message = ''; + } else { + message += ' '; + } + + message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(unexpected) + '») to be false'; + + throw new Test262Error(message); +}; + +assert.throws = function (expectedErrorConstructor, func, message) { + var expectedName, actualName; + if (typeof func !== "function") { + throw new Test262Error('assert.throws requires two arguments: the error constructor ' + + 'and a function to run'); + return; + } + if (message === undefined) { + message = ''; + } else { + message += ' '; + } + + try { + func(); + } catch (thrown) { + if (typeof thrown !== 'object' || thrown === null) { + message += 'Thrown value was not an object!'; + throw new Test262Error(message); + } else if (thrown.constructor !== expectedErrorConstructor) { + expectedName = expectedErrorConstructor.name; + actualName = thrown.constructor.name; + if (expectedName === actualName) { + message += 'Expected a ' + expectedName + ' but got a different error constructor with the same name'; + } else { + message += 'Expected a ' + expectedName + ' but got a ' + actualName; + } + throw new Test262Error(message); + } + return; + } + + message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all'; + throw new Test262Error(message); +}; + +assert._toString = function (value) { + try { + if (value === 0 && 1 / value === -Infinity) { + return '-0'; + } + + return String(value); + } catch (err) { + if (err.name === 'TypeError') { + return Object.prototype.toString.call(value); + } + + throw err; + } +}; diff --git a/harness/assertRelativeDateMs.js b/harness/assertRelativeDateMs.js new file mode 100644 index 0000000000000000000000000000000000000000..eda726eb9fad5e36f6e0695fda942aeb0f00d143 --- /dev/null +++ b/harness/assertRelativeDateMs.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Verify that the given date object's Number representation describes the + correct number of milliseconds since the Unix epoch relative to the local + time zone (as interpreted at the specified date). +defines: [assertRelativeDateMs] +---*/ + +/** + * @param {Date} date + * @param {Number} expectedMs + */ +function assertRelativeDateMs(date, expectedMs) { + var actualMs = date.valueOf(); + var localOffset = date.getTimezoneOffset() * 60000; + + if (actualMs - localOffset !== expectedMs) { + throw new Test262Error( + 'Expected ' + date + ' to be ' + expectedMs + + ' milliseconds from the Unix epoch' + ); + } +} diff --git a/harness/async-gc.js b/harness/async-gc.js new file mode 100644 index 0000000000000000000000000000000000000000..87a4a3e73fdf79349b9f3cde941e0dc60555429e --- /dev/null +++ b/harness/async-gc.js @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Collection of functions used to capture references cleanup from garbage collectors +features: [FinalizationRegistry.prototype.cleanupSome, FinalizationRegistry, Symbol, async-functions] +flags: [non-deterministic] +defines: [asyncGC, asyncGCDeref, resolveAsyncGC] +---*/ + +function asyncGC(...targets) { + var finalizationRegistry = new FinalizationRegistry(() => {}); + var length = targets.length; + + for (let target of targets) { + finalizationRegistry.register(target, 'target'); + target = null; + } + + targets = null; + + return Promise.resolve('tick').then(() => asyncGCDeref()).then(() => { + var names = []; + + // consume iterator to capture names + finalizationRegistry.cleanupSome(name => { names.push(name); }); + + if (!names || names.length != length) { + throw asyncGC.notCollected; + } + }); +} + +asyncGC.notCollected = Symbol('Object was not collected'); + +async function asyncGCDeref() { + var trigger; + + // TODO: Remove this when $262.clearKeptObject becomes documented and required + if ($262.clearKeptObjects) { + trigger = $262.clearKeptObjects(); + } + + await $262.gc(); + + return Promise.resolve(trigger); +} + +function resolveAsyncGC(err) { + if (err === asyncGC.notCollected) { + // Do not fail as GC can't provide necessary resources. + $DONE(); + return; + } + + $DONE(err); +} diff --git a/harness/asyncHelpers.js b/harness/asyncHelpers.js new file mode 100644 index 0000000000000000000000000000000000000000..9f48fa5a50886f89dca9098177858af6a4461a12 --- /dev/null +++ b/harness/asyncHelpers.js @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + A collection of assertion and wrapper functions for testing asynchronous built-ins. +defines: [asyncTest] +---*/ + +function asyncTest(testFunc) { + if (!Object.hasOwn(globalThis, "$DONE")) { + throw new Test262Error("asyncTest called without async flag"); + } + if (typeof testFunc !== "function") { + $DONE(new Test262Error("asyncTest called with non-function argument")); + return; + } + try { + testFunc().then( + function () { + $DONE(); + }, + function (error) { + $DONE(error); + } + ); + } catch (syncError) { + $DONE(syncError); + } +} + +assert.throwsAsync = async function (expectedErrorConstructor, func, message) { + var innerThenable; + if (message === undefined) { + message = ""; + } else { + message += " "; + } + if (typeof func === "function") { + try { + innerThenable = func(); + if ( + innerThenable === null || + typeof innerThenable !== "object" || + typeof innerThenable.then !== "function" + ) { + message += + "Expected to obtain an inner promise that would reject with a" + + expectedErrorConstructor.name + + " but result was not a thenable"; + throw new Test262Error(message); + } + } catch (thrown) { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but an exception was thrown synchronously while obtaining the inner promise"; + throw new Test262Error(message); + } + } else { + message += + "assert.throwsAsync called with an argument that is not a function"; + throw new Test262Error(message); + } + + try { + return innerThenable.then( + function () { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but no exception was thrown at all"; + throw new Test262Error(message); + }, + function (thrown) { + var expectedName, actualName; + if (typeof thrown !== "object" || thrown === null) { + message += "Thrown value was not an object!"; + throw new Test262Error(message); + } else if (thrown.constructor !== expectedErrorConstructor) { + expectedName = expectedErrorConstructor.name; + actualName = thrown.constructor.name; + if (expectedName === actualName) { + message += + "Expected a " + + expectedName + + " but got a different error constructor with the same name"; + } else { + message += + "Expected a " + expectedName + " but got a " + actualName; + } + throw new Test262Error(message); + } + } + ); + } catch (thrown) { + if (typeof thrown !== "object" || thrown === null) { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but innerThenable synchronously threw a value that was not an object "; + } else { + message += + "Expected a " + + expectedErrorConstructor.name + + " to be thrown asynchronously but a " + + thrown.constructor.name + + " was thrown synchronously"; + } + throw new Test262Error(message); + } +}; diff --git a/harness/atomicsHelper.js b/harness/atomicsHelper.js new file mode 100644 index 0000000000000000000000000000000000000000..761fee87c872a2212cf25297fea7764e7ee9931c --- /dev/null +++ b/harness/atomicsHelper.js @@ -0,0 +1,336 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Collection of functions used to interact with Atomics.* operations across agent boundaries. +defines: + - $262.agent.getReportAsync + - $262.agent.getReport + - $262.agent.safeBroadcastAsync + - $262.agent.safeBroadcast + - $262.agent.setTimeout + - $262.agent.tryYield + - $262.agent.trySleep +---*/ + +/** + * @return {String} A report sent from an agent. + */ +{ + // This is only necessary because the original + // $262.agent.getReport API was insufficient. + // + // All runtimes currently have their own + // $262.agent.getReport which is wrong, so we + // will pave over it with a corrected version. + // + // Binding $262.agent is necessary to prevent + // breaking SpiderMonkey's $262.agent.getReport + let getReport = $262.agent.getReport.bind($262.agent); + + $262.agent.getReport = function() { + var r; + while ((r = getReport()) == null) { + $262.agent.sleep(1); + } + return r; + }; + + if (this.setTimeout === undefined) { + (function(that) { + that.setTimeout = function(callback, delay) { + let p = Promise.resolve(); + let start = Date.now(); + let end = start + delay; + function check() { + if ((end - Date.now()) > 0) { + p.then(check); + } + else { + callback(); + } + } + p.then(check); + } + })(this); + } + + $262.agent.setTimeout = setTimeout; + + $262.agent.getReportAsync = function() { + return new Promise(function(resolve) { + (function loop() { + let result = getReport(); + if (!result) { + setTimeout(loop, 1000); + } else { + resolve(result); + } + })(); + }); + }; +} + +/** + * + * Share a given Int32Array or BigInt64Array to all running agents. Ensure that the + * provided TypedArray is a "shared typed array". + * + * NOTE: Migrating all tests to this API is necessary to prevent tests from hanging + * indefinitely when a SAB is sent to a worker but the code in the worker attempts to + * create a non-sharable TypedArray (something that is not Int32Array or BigInt64Array). + * When that scenario occurs, an exception is thrown and the agent worker can no + * longer communicate with any other threads that control the SAB. If the main + * thread happens to be spinning in the $262.agent.waitUntil() while loop, it will never + * meet its termination condition and the test will hang indefinitely. + * + * Because we've defined $262.agent.broadcast(SAB) in + * https://github.com/tc39/test262/blob/HEAD/INTERPRETING.md, there are host implementations + * that assume compatibility, which must be maintained. + * + * + * $262.agent.safeBroadcast(TA) should not be included in + * https://github.com/tc39/test262/blob/HEAD/INTERPRETING.md + * + * + * @param {(Int32Array|BigInt64Array)} typedArray An Int32Array or BigInt64Array with a SharedArrayBuffer + */ +$262.agent.safeBroadcast = function(typedArray) { + let Constructor = Object.getPrototypeOf(typedArray).constructor; + let temp = new Constructor( + new SharedArrayBuffer(Constructor.BYTES_PER_ELEMENT) + ); + try { + // This will never actually wait, but that's fine because we only + // want to ensure that this typedArray CAN be waited on and is shareable. + Atomics.wait(temp, 0, Constructor === Int32Array ? 1 : BigInt(1)); + } catch (error) { + throw new Test262Error(`${Constructor.name} cannot be used as a shared typed array. (${error})`); + } + + $262.agent.broadcast(typedArray.buffer); +}; + +$262.agent.safeBroadcastAsync = async function(ta, index, expected) { + await $262.agent.broadcast(ta.buffer); + await $262.agent.waitUntil(ta, index, expected); + await $262.agent.tryYield(); + return await Atomics.load(ta, index); +}; + + +/** + * With a given Int32Array or BigInt64Array, wait until the expected number of agents have + * reported themselves by calling: + * + * Atomics.add(typedArray, index, 1); + * + * @param {(Int32Array|BigInt64Array)} typedArray An Int32Array or BigInt64Array with a SharedArrayBuffer + * @param {number} index The index of which all agents will report. + * @param {number} expected The number of agents that are expected to report as active. + */ +$262.agent.waitUntil = function(typedArray, index, expected) { + + var agents = 0; + while ((agents = Atomics.load(typedArray, index)) !== expected) { + /* nothing */ + } + assert.sameValue(agents, expected, "Reporting number of 'agents' equals the value of 'expected'"); +}; + +/** + * Timeout values used throughout the Atomics tests. All timeouts are specified in milliseconds. + * + * @property {number} yield Used for `$262.agent.tryYield`. Must not be used in other functions. + * @property {number} small Used when agents will always timeout and `Atomics.wake` is not part + * of the test semantics. Must be larger than `$262.agent.timeouts.yield`. + * @property {number} long Used when some agents may timeout and `Atomics.wake` is called on some + * agents. The agents are required to wait and this needs to be observable + * by the main thread. + * @property {number} huge Used when `Atomics.wake` is called on all waiting agents. The waiting + * must not timeout. The agents are required to wait and this needs to be + * observable by the main thread. All waiting agents must be woken by the + * main thread. + * + * Usage for `$262.agent.timeouts.small`: + * const WAIT_INDEX = 0; + * const RUNNING = 1; + * const TIMEOUT = $262.agent.timeouts.small; + * const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2)); + * + * $262.agent.start(` + * $262.agent.receiveBroadcast(function(sab) { + * const i32a = new Int32Array(sab); + * Atomics.add(i32a, ${RUNNING}, 1); + * + * $262.agent.report(Atomics.wait(i32a, ${WAIT_INDEX}, 0, ${TIMEOUT})); + * + * $262.agent.leaving(); + * }); + * `); + * $262.agent.safeBroadcast(i32a.buffer); + * + * // Wait until the agent was started and then try to yield control to increase + * // the likelihood the agent has called `Atomics.wait` and is now waiting. + * $262.agent.waitUntil(i32a, RUNNING, 1); + * $262.agent.tryYield(); + * + * // The agent is expected to time out. + * assert.sameValue($262.agent.getReport(), "timed-out"); + * + * + * Usage for `$262.agent.timeouts.long`: + * const WAIT_INDEX = 0; + * const RUNNING = 1; + * const NUMAGENT = 2; + * const TIMEOUT = $262.agent.timeouts.long; + * const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2)); + * + * for (let i = 0; i < NUMAGENT; i++) { + * $262.agent.start(` + * $262.agent.receiveBroadcast(function(sab) { + * const i32a = new Int32Array(sab); + * Atomics.add(i32a, ${RUNNING}, 1); + * + * $262.agent.report(Atomics.wait(i32a, ${WAIT_INDEX}, 0, ${TIMEOUT})); + * + * $262.agent.leaving(); + * }); + * `); + * } + * $262.agent.safeBroadcast(i32a.buffer); + * + * // Wait until the agents were started and then try to yield control to increase + * // the likelihood the agents have called `Atomics.wait` and are now waiting. + * $262.agent.waitUntil(i32a, RUNNING, NUMAGENT); + * $262.agent.tryYield(); + * + * // Wake exactly one agent. + * assert.sameValue(Atomics.wake(i32a, WAIT_INDEX, 1), 1); + * + * // When it doesn't matter how many agents were woken at once, a while loop + * // can be used to make the test more resilient against intermittent failures + * // in case even though `tryYield` was called, the agents haven't started to + * // wait. + * // + * // // Repeat until exactly one agent was woken. + * // var woken = 0; + * // while ((woken = Atomics.wake(i32a, WAIT_INDEX, 1)) !== 0) ; + * // assert.sameValue(woken, 1); + * + * // One agent was woken and the other one timed out. + * const reports = [$262.agent.getReport(), $262.agent.getReport()]; + * assert(reports.includes("ok")); + * assert(reports.includes("timed-out")); + * + * + * Usage for `$262.agent.timeouts.huge`: + * const WAIT_INDEX = 0; + * const RUNNING = 1; + * const NUMAGENT = 2; + * const TIMEOUT = $262.agent.timeouts.huge; + * const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2)); + * + * for (let i = 0; i < NUMAGENT; i++) { + * $262.agent.start(` + * $262.agent.receiveBroadcast(function(sab) { + * const i32a = new Int32Array(sab); + * Atomics.add(i32a, ${RUNNING}, 1); + * + * $262.agent.report(Atomics.wait(i32a, ${WAIT_INDEX}, 0, ${TIMEOUT})); + * + * $262.agent.leaving(); + * }); + * `); + * } + * $262.agent.safeBroadcast(i32a.buffer); + * + * // Wait until the agents were started and then try to yield control to increase + * // the likelihood the agents have called `Atomics.wait` and are now waiting. + * $262.agent.waitUntil(i32a, RUNNING, NUMAGENT); + * $262.agent.tryYield(); + * + * // Wake all agents. + * assert.sameValue(Atomics.wake(i32a, WAIT_INDEX), NUMAGENT); + * + * // When it doesn't matter how many agents were woken at once, a while loop + * // can be used to make the test more resilient against intermittent failures + * // in case even though `tryYield` was called, the agents haven't started to + * // wait. + * // + * // // Repeat until all agents were woken. + * // for (var wokenCount = 0; wokenCount < NUMAGENT; ) { + * // var woken = 0; + * // while ((woken = Atomics.wake(i32a, WAIT_INDEX)) !== 0) ; + * // // Maybe perform an action on the woken agents here. + * // wokenCount += woken; + * // } + * + * // All agents were woken and none timeout. + * for (var i = 0; i < NUMAGENT; i++) { + * assert($262.agent.getReport(), "ok"); + * } + */ +$262.agent.timeouts = { + yield: 100, + small: 200, + long: 1000, + huge: 10000, +}; + +/** + * Try to yield control to the agent threads. + * + * Usage: + * const VALUE = 0; + * const RUNNING = 1; + * const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 2)); + * + * $262.agent.start(` + * $262.agent.receiveBroadcast(function(sab) { + * const i32a = new Int32Array(sab); + * Atomics.add(i32a, ${RUNNING}, 1); + * + * Atomics.store(i32a, ${VALUE}, 1); + * + * $262.agent.leaving(); + * }); + * `); + * $262.agent.safeBroadcast(i32a.buffer); + * + * // Wait until agent was started and then try to yield control. + * $262.agent.waitUntil(i32a, RUNNING, 1); + * $262.agent.tryYield(); + * + * // Note: This result is not guaranteed, but should hold in practice most of the time. + * assert.sameValue(Atomics.load(i32a, VALUE), 1); + * + * The default implementation simply waits for `$262.agent.timeouts.yield` milliseconds. + */ +$262.agent.tryYield = function() { + $262.agent.sleep($262.agent.timeouts.yield); +}; + +/** + * Try to sleep the current agent for the given amount of milliseconds. It is acceptable, + * but not encouraged, to ignore this sleep request and directly continue execution. + * + * The default implementation calls `$262.agent.sleep(ms)`. + * + * @param {number} ms Time to sleep in milliseconds. + */ +$262.agent.trySleep = function(ms) { + $262.agent.sleep(ms); +}; diff --git a/harness/byteConversionValues.js b/harness/byteConversionValues.js new file mode 100644 index 0000000000000000000000000000000000000000..e84d7c1e9d76aabe945effdbb02a0abefb73fa99 --- /dev/null +++ b/harness/byteConversionValues.js @@ -0,0 +1,458 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Provide a list for original and expected values for different byte + conversions. + This helper is mostly used on tests for TypedArray and DataView, and each + array from the expected values must match the original values array on every + index containing its original value. +defines: [byteConversionValues] +---*/ +var byteConversionValues = { + values: [ + 127, // 2 ** 7 - 1 + 128, // 2 ** 7 + 32767, // 2 ** 15 - 1 + 32768, // 2 ** 15 + 2147483647, // 2 ** 31 - 1 + 2147483648, // 2 ** 31 + 255, // 2 ** 8 - 1 + 256, // 2 ** 8 + 65535, // 2 ** 16 - 1 + 65536, // 2 ** 16 + 4294967295, // 2 ** 32 - 1 + 4294967296, // 2 ** 32 + 9007199254740991, // 2 ** 53 - 1 + 9007199254740992, // 2 ** 53 + 1.1, + 0.1, + 0.5, + 0.50000001, + 0.6, + 0.7, + undefined, + -1, + -0, + -0.1, + -1.1, + NaN, + -127, // - ( 2 ** 7 - 1 ) + -128, // - ( 2 ** 7 ) + -32767, // - ( 2 ** 15 - 1 ) + -32768, // - ( 2 ** 15 ) + -2147483647, // - ( 2 ** 31 - 1 ) + -2147483648, // - ( 2 ** 31 ) + -255, // - ( 2 ** 8 - 1 ) + -256, // - ( 2 ** 8 ) + -65535, // - ( 2 ** 16 - 1 ) + -65536, // - ( 2 ** 16 ) + -4294967295, // - ( 2 ** 32 - 1 ) + -4294967296, // - ( 2 ** 32 ) + Infinity, + -Infinity, + 0 + ], + + expected: { + Int8: [ + 127, // 127 + -128, // 128 + -1, // 32767 + 0, // 32768 + -1, // 2147483647 + 0, // 2147483648 + -1, // 255 + 0, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 0, // 32768 + 255, // 2147483647 + 0, // 2147483648 + 255, // 255 + 0, // 256 + 255, // 65535 + 0, // 65536 + 255, // 4294967295 + 0, // 4294967296 + 255, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 255, // -1 + 0, // -0 + 0, // -0.1 + 255, // -1.1 + 0, // NaN + 129, // -127 + 128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8Clamped: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 255, // 32768 + 255, // 2147483647 + 255, // 2147483648 + 255, // 255 + 255, // 256 + 255, // 65535 + 255, // 65536 + 255, // 4294967295 + 255, // 4294967296 + 255, // 9007199254740991 + 255, // 9007199254740992 + 1, // 1.1, + 0, // 0.1 + 0, // 0.5 + 1, // 0.50000001, + 1, // 0.6 + 1, // 0.7 + 0, // undefined + 0, // -1 + 0, // -0 + 0, // -0.1 + 0, // -1.1 + 0, // NaN + 0, // -127 + 0, // -128 + 0, // -32767 + 0, // -32768 + 0, // -2147483647 + 0, // -2147483648 + 0, // -255 + 0, // -256 + 0, // -65535 + 0, // -65536 + 0, // -4294967295 + 0, // -4294967296 + 255, // Infinity + 0, // -Infinity + 0 + ], + Int16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + -32768, // 32768 + -1, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + -255, // -255 + -256, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 65535, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 0, // 65536 + 65535, // 4294967295 + 0, // 4294967296 + 65535, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 65535, // -1 + 0, // -0 + 0, // -0.1 + 65535, // -1.1 + 0, // NaN + 65409, // -127 + 65408, // -128 + 32769, // -32767 + 32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 65281, // -255 + 65280, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Int32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + -2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 0, // 4294967296 + 4294967295, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 4294967295, // -1 + 0, // -0 + 0, // -0.1 + 4294967295, // -1.1 + 0, // NaN + 4294967169, // -127 + 4294967168, // -128 + 4294934529, // -32767 + 4294934528, // -32768 + 2147483649, // -2147483647 + 2147483648, // -2147483648 + 4294967041, // -255 + 4294967040, // -256 + 4294901761, // -65535 + 4294901760, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Float32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483648, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967296, // 4294967295 + 4294967296, // 4294967296 + 9007199254740992, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.100000023841858, // 1.1 + 0.10000000149011612, // 0.1 + 0.5, // 0.5 + 0.5, // 0.50000001, + 0.6000000238418579, // 0.6 + 0.699999988079071, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.10000000149011612, // -0.1 + -1.100000023841858, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483648, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967296, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ], + Float64: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 4294967296, // 4294967296 + 9007199254740991, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.1, // 1.1 + 0.1, // 0.1 + 0.5, // 0.5 + 0.50000001, // 0.50000001, + 0.6, // 0.6 + 0.7, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.1, // -0.1 + -1.1, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967295, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ] + } +}; diff --git a/harness/compareArray.js b/harness/compareArray.js new file mode 100644 index 0000000000000000000000000000000000000000..2783698457ef3a5362a0fd2f799df3d7c7bd6fb4 --- /dev/null +++ b/harness/compareArray.js @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Compare the contents of two arrays +defines: [compareArray] +---*/ + +function compareArray(a, b) { + if (b.length !== a.length) { + return false; + } + + for (var i = 0; i < a.length; i++) { + if (!compareArray.isSameValue(b[i], a[i])) { + return false; + } + } + return true; +} + +compareArray.isSameValue = function(a, b) { + if (a === 0 && b === 0) return 1 / a === 1 / b; + if (a !== a && b !== b) return true; + + return a === b; +}; + +compareArray.format = function(arrayLike) { + return `[${[].map.call(arrayLike, String).join(', ')}]`; +}; + +assert.compareArray = function(actual, expected, message) { + message = message === undefined ? '' : message; + + if (typeof message === 'symbol') { + message = message.toString(); + } + + assert(actual != null, `First argument shouldn't be nullish. ${message}`); + assert(expected != null, `Second argument shouldn't be nullish. ${message}`); + var format = compareArray.format; + var result = compareArray(actual, expected); + + // The following prevents actual and expected from being iterated and evaluated + // more than once unless absolutely necessary. + if (!result) { + assert(false, `Expected ${format(actual)} and ${format(expected)} to have the same contents. ${message}`); + } +}; diff --git a/harness/compareIterator.js b/harness/compareIterator.js new file mode 100644 index 0000000000000000000000000000000000000000..d4e3b9a53aaa6e6a39c63d6e7e83a42fb4d77b09 --- /dev/null +++ b/harness/compareIterator.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Compare the values of an iterator with an array of expected values +defines: [assert.compareIterator] +---*/ + +// Example: +// +// function* numbers() { +// yield 1; +// yield 2; +// yield 3; +// } +// +// assert.compareIterator(numbers(), [ +// v => assert.sameValue(v, 1), +// v => assert.sameValue(v, 2), +// v => assert.sameValue(v, 3), +// ]); +// +assert.compareIterator = function(iter, validators, message) { + message = message || ''; + + var i, result; + for (i = 0; i < validators.length; i++) { + result = iter.next(); + assert(!result.done, 'Expected ' + i + ' values(s). Instead iterator only produced ' + (i - 1) + ' value(s). ' + message); + validators[i](result.value); + } + + result = iter.next(); + assert(result.done, 'Expected only ' + i + ' values(s). Instead iterator produced more. ' + message); + assert.sameValue(result.value, undefined, 'Expected value of `undefined` when iterator completes. ' + message); +} diff --git a/harness/dateConstants.js b/harness/dateConstants.js new file mode 100644 index 0000000000000000000000000000000000000000..2eed15ca63a010576eac72b0a95f8f522db726b3 --- /dev/null +++ b/harness/dateConstants.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Collection of date-centric values +defines: + - date_1899_end + - date_1900_start + - date_1969_end + - date_1970_start + - date_1999_end + - date_2000_start + - date_2099_end + - date_2100_start + - start_of_time + - end_of_time +---*/ + +var date_1899_end = -2208988800001; +var date_1900_start = -2208988800000; +var date_1969_end = -1; +var date_1970_start = 0; +var date_1999_end = 946684799999; +var date_2000_start = 946684800000; +var date_2099_end = 4102444799999; +var date_2100_start = 4102444800000; + +var start_of_time = -8.64e15; +var end_of_time = 8.64e15; diff --git a/harness/decimalToHexString.js b/harness/decimalToHexString.js new file mode 100644 index 0000000000000000000000000000000000000000..9840ee589cd3c40ddc29e22a8ff801dbbe93431a --- /dev/null +++ b/harness/decimalToHexString.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Collection of functions used to assert the correctness of various encoding operations. +defines: [decimalToHexString, decimalToPercentHexString] +---*/ + +function decimalToHexString(n) { + var hex = "0123456789ABCDEF"; + n >>>= 0; + var s = ""; + while (n) { + s = hex[n & 0xf] + s; + n >>>= 4; + } + while (s.length < 4) { + s = "0" + s; + } + return s; +} + +function decimalToPercentHexString(n) { + var hex = "0123456789ABCDEF"; + return "%" + hex[(n >> 4) & 0xf] + hex[n & 0xf]; +} diff --git a/harness/deepEqual.js b/harness/deepEqual.js new file mode 100644 index 0000000000000000000000000000000000000000..a2ceeb3d9ccf1b00e1533b9e5dfb45d8d29b217a --- /dev/null +++ b/harness/deepEqual.js @@ -0,0 +1,339 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Compare two values structurally +defines: [assert.deepEqual] +---*/ + +assert.deepEqual = function(actual, expected, message) { + var format = assert.deepEqual.format; + assert( + assert.deepEqual._compare(actual, expected), + `Expected ${format(actual)} to be structurally equal to ${format(expected)}. ${(message || '')}` + ); +}; + +assert.deepEqual.format = function(value, seen) { + switch (typeof value) { + case 'string': + return typeof JSON !== "undefined" ? JSON.stringify(value) : `"${value}"`; + case 'number': + case 'boolean': + case 'symbol': + case 'bigint': + return value.toString(); + case 'undefined': + return 'undefined'; + case 'function': + return `[Function${value.name ? `: ${value.name}` : ''}]`; + case 'object': + if (value === null) return 'null'; + if (value instanceof Date) return `Date "${value.toISOString()}"`; + if (value instanceof RegExp) return value.toString(); + if (!seen) { + seen = { + counter: 0, + map: new Map() + }; + } + + let usage = seen.map.get(value); + if (usage) { + usage.used = true; + return `[Ref: #${usage.id}]`; + } + + usage = { id: ++seen.counter, used: false }; + seen.map.set(value, usage); + + if (typeof Set !== "undefined" && value instanceof Set) { + return `Set {${Array.from(value).map(value => assert.deepEqual.format(value, seen)).join(', ')}}${usage.used ? ` as #${usage.id}` : ''}`; + } + if (typeof Map !== "undefined" && value instanceof Map) { + return `Map {${Array.from(value).map(pair => `${assert.deepEqual.format(pair[0], seen)} => ${assert.deepEqual.format(pair[1], seen)}}`).join(', ')}}${usage.used ? ` as #${usage.id}` : ''}`; + } + if (Array.isArray ? Array.isArray(value) : value instanceof Array) { + return `[${value.map(value => assert.deepEqual.format(value, seen)).join(', ')}]${usage.used ? ` as #${usage.id}` : ''}`; + } + let tag = Symbol.toStringTag in value ? value[Symbol.toStringTag] : 'Object'; + if (tag === 'Object' && Object.getPrototypeOf(value) === null) { + tag = '[Object: null prototype]'; + } + return `${tag ? `${tag} ` : ''}{ ${Object.keys(value).map(key => `${key.toString()}: ${assert.deepEqual.format(value[key], seen)}`).join(', ')} }${usage.used ? ` as #${usage.id}` : ''}`; + default: + return typeof value; + } +}; + +assert.deepEqual._compare = (function () { + var EQUAL = 1; + var NOT_EQUAL = -1; + var UNKNOWN = 0; + + function deepEqual(a, b) { + return compareEquality(a, b) === EQUAL; + } + + function compareEquality(a, b, cache) { + return compareIf(a, b, isOptional, compareOptionality) + || compareIf(a, b, isPrimitiveEquatable, comparePrimitiveEquality) + || compareIf(a, b, isObjectEquatable, compareObjectEquality, cache) + || NOT_EQUAL; + } + + function compareIf(a, b, test, compare, cache) { + return !test(a) + ? !test(b) ? UNKNOWN : NOT_EQUAL + : !test(b) ? NOT_EQUAL : cacheComparison(a, b, compare, cache); + } + + function tryCompareStrictEquality(a, b) { + return a === b ? EQUAL : UNKNOWN; + } + + function tryCompareTypeOfEquality(a, b) { + return typeof a !== typeof b ? NOT_EQUAL : UNKNOWN; + } + + function tryCompareToStringTagEquality(a, b) { + var aTag = Symbol.toStringTag in a ? a[Symbol.toStringTag] : undefined; + var bTag = Symbol.toStringTag in b ? b[Symbol.toStringTag] : undefined; + return aTag !== bTag ? NOT_EQUAL : UNKNOWN; + } + + function isOptional(value) { + return value === undefined + || value === null; + } + + function compareOptionality(a, b) { + return tryCompareStrictEquality(a, b) + || NOT_EQUAL; + } + + function isPrimitiveEquatable(value) { + switch (typeof value) { + case 'string': + case 'number': + case 'bigint': + case 'boolean': + case 'symbol': + return true; + default: + return isBoxed(value); + } + } + + function comparePrimitiveEquality(a, b) { + if (isBoxed(a)) a = a.valueOf(); + if (isBoxed(b)) b = b.valueOf(); + return tryCompareStrictEquality(a, b) + || tryCompareTypeOfEquality(a, b) + || compareIf(a, b, isNaNEquatable, compareNaNEquality) + || NOT_EQUAL; + } + + function isNaNEquatable(value) { + return typeof value === 'number'; + } + + function compareNaNEquality(a, b) { + return isNaN(a) && isNaN(b) ? EQUAL : NOT_EQUAL; + } + + function isObjectEquatable(value) { + return typeof value === 'object'; + } + + function compareObjectEquality(a, b, cache) { + if (!cache) cache = new Map(); + return getCache(cache, a, b) + || setCache(cache, a, b, EQUAL) // consider equal for now + || cacheComparison(a, b, tryCompareStrictEquality, cache) + || cacheComparison(a, b, tryCompareToStringTagEquality, cache) + || compareIf(a, b, isValueOfEquatable, compareValueOfEquality) + || compareIf(a, b, isToStringEquatable, compareToStringEquality) + || compareIf(a, b, isArrayLikeEquatable, compareArrayLikeEquality, cache) + || compareIf(a, b, isStructurallyEquatable, compareStructuralEquality, cache) + || compareIf(a, b, isIterableEquatable, compareIterableEquality, cache) + || cacheComparison(a, b, fail, cache); + } + + function isBoxed(value) { + return value instanceof String + || value instanceof Number + || value instanceof Boolean + || typeof Symbol === 'function' && value instanceof Symbol + || typeof BigInt === 'function' && value instanceof BigInt; + } + + function isValueOfEquatable(value) { + return value instanceof Date; + } + + function compareValueOfEquality(a, b) { + return compareIf(a.valueOf(), b.valueOf(), isPrimitiveEquatable, comparePrimitiveEquality) + || NOT_EQUAL; + } + + function isToStringEquatable(value) { + return value instanceof RegExp; + } + + function compareToStringEquality(a, b) { + return compareIf(a.toString(), b.toString(), isPrimitiveEquatable, comparePrimitiveEquality) + || NOT_EQUAL; + } + + function isArrayLikeEquatable(value) { + return (Array.isArray ? Array.isArray(value) : value instanceof Array) + || (typeof Uint8Array === 'function' && value instanceof Uint8Array) + || (typeof Uint8ClampedArray === 'function' && value instanceof Uint8ClampedArray) + || (typeof Uint16Array === 'function' && value instanceof Uint16Array) + || (typeof Uint32Array === 'function' && value instanceof Uint32Array) + || (typeof Int8Array === 'function' && value instanceof Int8Array) + || (typeof Int16Array === 'function' && value instanceof Int16Array) + || (typeof Int32Array === 'function' && value instanceof Int32Array) + || (typeof Float32Array === 'function' && value instanceof Float32Array) + || (typeof Float64Array === 'function' && value instanceof Float64Array) + || (typeof BigUint64Array === 'function' && value instanceof BigUint64Array) + || (typeof BigInt64Array === 'function' && value instanceof BigInt64Array); + } + + function compareArrayLikeEquality(a, b, cache) { + if (a.length !== b.length) return NOT_EQUAL; + for (var i = 0; i < a.length; i++) { + if (compareEquality(a[i], b[i], cache) === NOT_EQUAL) { + return NOT_EQUAL; + } + } + return EQUAL; + } + + function isStructurallyEquatable(value) { + return !(typeof Promise === 'function' && value instanceof Promise // only comparable by reference + || typeof WeakMap === 'function' && value instanceof WeakMap // only comparable by reference + || typeof WeakSet === 'function' && value instanceof WeakSet // only comparable by reference + || typeof Map === 'function' && value instanceof Map // comparable via @@iterator + || typeof Set === 'function' && value instanceof Set); // comparable via @@iterator + } + + function compareStructuralEquality(a, b, cache) { + var aKeys = []; + for (var key in a) aKeys.push(key); + + var bKeys = []; + for (var key in b) bKeys.push(key); + + if (aKeys.length !== bKeys.length) { + return NOT_EQUAL; + } + + aKeys.sort(); + bKeys.sort(); + + for (var i = 0; i < aKeys.length; i++) { + var aKey = aKeys[i]; + var bKey = bKeys[i]; + if (compareEquality(aKey, bKey, cache) === NOT_EQUAL) { + return NOT_EQUAL; + } + if (compareEquality(a[aKey], b[bKey], cache) === NOT_EQUAL) { + return NOT_EQUAL; + } + } + + return compareIf(a, b, isIterableEquatable, compareIterableEquality, cache) + || EQUAL; + } + + function isIterableEquatable(value) { + return typeof Symbol === 'function' + && typeof value[Symbol.iterator] === 'function'; + } + + function compareIteratorEquality(a, b, cache) { + if (typeof Map === 'function' && a instanceof Map && b instanceof Map || + typeof Set === 'function' && a instanceof Set && b instanceof Set) { + if (a.size !== b.size) return NOT_EQUAL; // exit early if we detect a difference in size + } + + var ar, br; + while (true) { + ar = a.next(); + br = b.next(); + if (ar.done) { + if (br.done) return EQUAL; + if (b.return) b.return(); + return NOT_EQUAL; + } + if (br.done) { + if (a.return) a.return(); + return NOT_EQUAL; + } + if (compareEquality(ar.value, br.value, cache) === NOT_EQUAL) { + if (a.return) a.return(); + if (b.return) b.return(); + return NOT_EQUAL; + } + } + } + + function compareIterableEquality(a, b, cache) { + return compareIteratorEquality(a[Symbol.iterator](), b[Symbol.iterator](), cache); + } + + function cacheComparison(a, b, compare, cache) { + var result = compare(a, b, cache); + if (cache && (result === EQUAL || result === NOT_EQUAL)) { + setCache(cache, a, b, /** @type {EQUAL | NOT_EQUAL} */(result)); + } + return result; + } + + function fail() { + return NOT_EQUAL; + } + + function setCache(cache, left, right, result) { + var otherCache; + + otherCache = cache.get(left); + if (!otherCache) cache.set(left, otherCache = new Map()); + otherCache.set(right, result); + + otherCache = cache.get(right); + if (!otherCache) cache.set(right, otherCache = new Map()); + otherCache.set(left, result); + } + + function getCache(cache, left, right) { + var otherCache; + var result; + + otherCache = cache.get(left); + result = otherCache && otherCache.get(right); + if (result) return result; + + otherCache = cache.get(right); + result = otherCache && otherCache.get(left); + if (result) return result; + + return UNKNOWN; + } + + return deepEqual; +})(); diff --git a/harness/detachArrayBuffer.js b/harness/detachArrayBuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..e69c0cbc2cd8e3ee41541acd371e9b4ea41798fe --- /dev/null +++ b/harness/detachArrayBuffer.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} diff --git a/harness/doneprintHandle.js b/harness/doneprintHandle.js new file mode 100644 index 0000000000000000000000000000000000000000..8c8f589868d07e3e9b55b7f63aea12d06805bc9a --- /dev/null +++ b/harness/doneprintHandle.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | +defines: [$DONE] +---*/ + +function __consolePrintHandle__(msg) { + print(msg); +} + +function $DONE(error) { + if (error) { + if(typeof error === 'object' && error !== null && 'name' in error) { + __consolePrintHandle__('Test262:AsyncTestFailure:' + error.name + ': ' + error.message); + } else { + __consolePrintHandle__('Test262:AsyncTestFailure:Test262Error: ' + String(error)); + } + } else { + __consolePrintHandle__('Test262:AsyncTestComplete'); + } +} diff --git a/harness/features.yml b/harness/features.yml new file mode 100644 index 0000000000000000000000000000000000000000..333af083bed3d9a32cf30d1774972df1669e416b --- /dev/null +++ b/harness/features.yml @@ -0,0 +1,6 @@ +atomicsHelper: [Atomics] +typeCoercion.js: [Symbol.toPrimitive, BigInt] +testAtomics.js: [ArrayBuffer, Atomics, DataView, SharedArrayBuffer, Symbol, TypedArray] +testBigIntTypedArray.js: [BigInt, TypedArray] +testTypedArray.js: [TypedArray] +isConstructor.js: [Reflect.construct] diff --git a/harness/fnGlobalObject.js b/harness/fnGlobalObject.js new file mode 100644 index 0000000000000000000000000000000000000000..370e40c3356609d8fadae9ca4641ec21e9d33a38 --- /dev/null +++ b/harness/fnGlobalObject.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Produce a reliable global object +defines: [fnGlobalObject] +---*/ + +var __globalObject = Function("return this;")(); +function fnGlobalObject() { + return __globalObject; +} diff --git a/harness/hidden-constructors.js b/harness/hidden-constructors.js new file mode 100644 index 0000000000000000000000000000000000000000..7ea8430fe48c4f699d479d73171da854d2d52521 --- /dev/null +++ b/harness/hidden-constructors.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: | + Provides uniform access to built-in constructors that are not exposed to the global object. +defines: + - AsyncArrowFunction + - AsyncFunction + - AsyncGeneratorFunction + - GeneratorFunction +---*/ + +var AsyncArrowFunction = Object.getPrototypeOf(async () => {}).constructor; +var AsyncFunction = Object.getPrototypeOf(async function () {}).constructor; +var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor; +var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor; diff --git a/harness/isConstructor.js b/harness/isConstructor.js new file mode 100644 index 0000000000000000000000000000000000000000..9fad104880935cf1de55f0a6486c82713d64780e --- /dev/null +++ b/harness/isConstructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/harness/nans.js b/harness/nans.js new file mode 100644 index 0000000000000000000000000000000000000000..39f2c57c22e0558b25b1dc1a2b9da8eb9f18bcc9 --- /dev/null +++ b/harness/nans.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + A collection of NaN values produced from expressions that have been observed + to create distinct bit representations on various platforms. These provide a + weak basis for assertions regarding the consistent canonicalization of NaN + values in Array buffers. +defines: [NaNs] +---*/ + +var NaNs = [ + NaN, + Number.NaN, + NaN * 0, + 0/0, + Infinity/Infinity, + -(0/0), + Math.pow(-1, 0.5), + -Math.pow(-1, 0.5), + Number("Not-a-Number"), +]; diff --git a/harness/nativeFunctionMatcher.js b/harness/nativeFunctionMatcher.js new file mode 100644 index 0000000000000000000000000000000000000000..c913005ce30c875be0a0c29b24c91f4137ce988d --- /dev/null +++ b/harness/nativeFunctionMatcher.js @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Assert _NativeFunction_ Syntax +info: | + NativeFunction : + function _NativeFunctionAccessor_ opt _IdentifierName_ opt ( _FormalParameters_ ) { [ native code ] } + NativeFunctionAccessor : + get + set +defines: + - assertToStringOrNativeFunction + - assertNativeFunction + - validateNativeFunctionSource +---*/ + +const validateNativeFunctionSource = function(source) { + // These regexes should be kept up to date with Unicode using `regexpu-core`. + // `/\p{ID_Start}/u` + const UnicodeIDStart = /(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08C7\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\u9FFC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7BF\uA7C2-\uA7CA\uA7F5-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82C[\uDC00-\uDD1E\uDD50-\uDD52\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD838[\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDEC0-\uDEEB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDD\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A])/; + // `/\p{ID_Continue}/u` + const UnicodeIDContinue = /(?:[0-9A-Z_a-z\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05EF-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u07FD\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08C7\u08D3-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u09FE\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B55-\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D81-\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1878\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1ABF\u1AC0\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CD0-\u1CD2\u1CD4-\u1CFA\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\u9FFC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7BF\uA7C2-\uA7CA\uA7F5-\uA827\uA82C\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD27\uDD30-\uDD39\uDE80-\uDEA9\uDEAB\uDEAC\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF50\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD44-\uDD47\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDC9-\uDDCC\uDDCE-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3B-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC5E-\uDC61\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB8\uDEC0-\uDEC9\uDF00-\uDF1A\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDC00-\uDC3A\uDCA0-\uDCE9\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD35\uDD37\uDD38\uDD3B-\uDD43\uDD50-\uDD59\uDDA0-\uDDA7\uDDAA-\uDDD7\uDDDA-\uDDE1\uDDE3\uDDE4\uDE00-\uDE3E\uDE47\uDE50-\uDE99\uDE9D\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD8E\uDD90\uDD91\uDD93-\uDD98\uDDA0-\uDDA9\uDEE0-\uDEF6\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF4F-\uDF87\uDF8F-\uDF9F\uDFE0\uDFE1\uDFE3\uDFE4\uDFF0\uDFF1]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82C[\uDC00-\uDD1E\uDD50-\uDD52\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A\uDD00-\uDD2C\uDD30-\uDD3D\uDD40-\uDD49\uDD4E\uDEC0-\uDEF9]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4B\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD83E[\uDFF0-\uDFF9]|\uD869[\uDC00-\uDEDD\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A]|\uDB40[\uDD00-\uDDEF])/; + // `/\p{Space_Separator}/u` + const UnicodeSpaceSeparator = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/; + + const isNewline = (c) => /[\u000A\u000D\u2028\u2029]/u.test(c); + const isWhitespace = (c) => /[\u0009\u000B\u000C\u0020\u00A0\uFEFF]/u.test(c) || UnicodeSpaceSeparator.test(c); + + let pos = 0; + + const eatWhitespace = () => { + while (pos < source.length) { + const c = source[pos]; + if (isWhitespace(c) || isNewline(c)) { + pos += 1; + continue; + } + + if (c === '/') { + if (source[pos + 1] === '/') { + while (pos < source.length) { + if (isNewline(source[pos])) { + break; + } + pos += 1; + } + continue; + } + if (source[pos + 1] === '*') { + const end = source.indexOf('*/', pos); + if (end === -1) { + throw new SyntaxError(); + } + pos = end + '*/'.length; + continue; + } + } + + break; + } + }; + + const getIdentifier = () => { + eatWhitespace(); + + const start = pos; + let end = pos; + switch (source[end]) { + case '_': + case '$': + end += 1; + break; + default: + if (UnicodeIDStart.test(source[end])) { + end += 1; + break; + } + return null; + } + while (end < source.length) { + const c = source[end]; + switch (c) { + case '_': + case '$': + end += 1; + break; + default: + if (UnicodeIDContinue.test(c)) { + end += 1; + break; + } + return source.slice(start, end); + } + } + return source.slice(start, end); + }; + + const test = (s) => { + eatWhitespace(); + + if (/\w/.test(s)) { + return getIdentifier() === s; + } + return source.slice(pos, pos + s.length) === s; + }; + + const eat = (s) => { + if (test(s)) { + pos += s.length; + return true; + } + return false; + }; + + const eatIdentifier = () => { + const n = getIdentifier(); + if (n !== null) { + pos += n.length; + return true; + } + return false; + }; + + const expect = (s) => { + if (!eat(s)) { + throw new SyntaxError(); + } + }; + + const eatString = () => { + if (source[pos] === '\'' || source[pos] === '"') { + const match = source[pos]; + pos += 1; + while (pos < source.length) { + if (source[pos] === match && source[pos - 1] !== '\\') { + return; + } + if (isNewline(source[pos])) { + throw new SyntaxError(); + } + pos += 1; + } + throw new SyntaxError(); + } + }; + + // "Stumble" through source text until matching character is found. + // Assumes ECMAScript syntax keeps `[]` and `()` balanced. + const stumbleUntil = (c) => { + const match = { + ']': '[', + ')': '(', + }[c]; + let nesting = 1; + while (pos < source.length) { + eatWhitespace(); + eatString(); // Strings may contain unbalanced characters. + if (source[pos] === match) { + nesting += 1; + } else if (source[pos] === c) { + nesting -= 1; + } + pos += 1; + if (nesting === 0) { + return; + } + } + throw new SyntaxError(); + }; + + // function + expect('function'); + + // NativeFunctionAccessor + eat('get') || eat('set'); + + // PropertyName + if (!eatIdentifier() && eat('[')) { + stumbleUntil(']'); + } + + // ( FormalParameters ) + expect('('); + stumbleUntil(')'); + + // { + expect('{'); + + // [native code] + expect('['); + expect('native'); + expect('code'); + expect(']'); + + // } + expect('}'); + + eatWhitespace(); + if (pos !== source.length) { + throw new SyntaxError(); + } +}; + +const assertToStringOrNativeFunction = function(fn, expected) { + const actual = "" + fn; + try { + assert.sameValue(actual, expected); + } catch (unused) { + assertNativeFunction(fn, expected); + } +}; + +const assertNativeFunction = function(fn, special) { + const actual = "" + fn; + try { + validateNativeFunctionSource(actual); + } catch (unused) { + throw new Test262Error('Conforms to NativeFunction Syntax: ' + JSON.stringify(actual) + (special ? ' (' + special + ')' : '')); + } +}; diff --git a/harness/promiseHelper.js b/harness/promiseHelper.js new file mode 100644 index 0000000000000000000000000000000000000000..9750544489e415f9c486880994ef0d26058145b1 --- /dev/null +++ b/harness/promiseHelper.js @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Check that an array contains a numeric sequence starting at 1 + and incrementing by 1 for each entry in the array. Used by + Promise tests to assert the order of execution in deep Promise + resolution pipelines. +defines: [checkSequence, checkSettledPromises] +---*/ + +function checkSequence(arr, message) { + arr.forEach(function(e, i) { + if (e !== (i+1)) { + throw new Test262Error((message ? message : "Steps in unexpected sequence:") + + " '" + arr.join(',') + "'"); + } + }); + + return true; +} + +function checkSettledPromises(settleds, expected, message) { + const prefix = message ? `${message}: ` : ''; + + assert.sameValue(Array.isArray(settleds), true, `${prefix}Settled values is an array`); + + assert.sameValue( + settleds.length, + expected.length, + `${prefix}The settled values has a different length than expected` + ); + + settleds.forEach((settled, i) => { + assert.sameValue( + Object.prototype.hasOwnProperty.call(settled, 'status'), + true, + `${prefix}The settled value has a property status` + ); + + assert.sameValue(settled.status, expected[i].status, `${prefix}status for item ${i}`); + + if (settled.status === 'fulfilled') { + assert.sameValue( + Object.prototype.hasOwnProperty.call(settled, 'value'), + true, + `${prefix}The fulfilled promise has a property named value` + ); + + assert.sameValue( + Object.prototype.hasOwnProperty.call(settled, 'reason'), + false, + `${prefix}The fulfilled promise has no property named reason` + ); + + assert.sameValue(settled.value, expected[i].value, `${prefix}value for item ${i}`); + } else { + assert.sameValue(settled.status, 'rejected', `${prefix}Valid statuses are only fulfilled or rejected`); + + assert.sameValue( + Object.prototype.hasOwnProperty.call(settled, 'value'), + false, + `${prefix}The fulfilled promise has no property named value` + ); + + assert.sameValue( + Object.prototype.hasOwnProperty.call(settled, 'reason'), + true, + `${prefix}The fulfilled promise has a property named reason` + ); + + assert.sameValue(settled.reason, expected[i].reason, `${prefix}Reason value for item ${i}`); + } + }); +} diff --git a/harness/propertyHelper.js b/harness/propertyHelper.js new file mode 100644 index 0000000000000000000000000000000000000000..9c648e44a76357625b28f49d998fb238f9985fe0 --- /dev/null +++ b/harness/propertyHelper.js @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Collection of functions used to safely verify the correctness of + property descriptors. +defines: + - verifyProperty + - verifyEqualTo # deprecated + - verifyWritable # deprecated + - verifyNotWritable # deprecated + - verifyEnumerable # deprecated + - verifyNotEnumerable # deprecated + - verifyConfigurable # deprecated + - verifyNotConfigurable # deprecated + - verifyPrimordialProperty +---*/ + +// @ts-check + +// Capture primordial functions and receiver-uncurried primordial methods that +// are used in verification but might be destroyed *by* that process itself. +var __isArray = Array.isArray; +var __defineProperty = Object.defineProperty; +var __join = Function.prototype.call.bind(Array.prototype.join); +var __push = Function.prototype.call.bind(Array.prototype.push); +var __hasOwnProperty = Function.prototype.call.bind(Object.prototype.hasOwnProperty); +var __propertyIsEnumerable = Function.prototype.call.bind(Object.prototype.propertyIsEnumerable); +var nonIndexNumericPropertyName = Math.pow(2, 32) - 1; + +/** + * @param {object} obj + * @param {string|symbol} name + * @param {PropertyDescriptor|undefined} desc + * @param {object} [options] + * @param {boolean} [options.restore] + */ +function verifyProperty(obj, name, desc, options) { + assert( + arguments.length > 2, + 'verifyProperty should receive at least 3 arguments: obj, name, and descriptor' + ); + + var originalDesc = Object.getOwnPropertyDescriptor(obj, name); + var nameStr = String(name); + + // Allows checking for undefined descriptor if it's explicitly given. + if (desc === undefined) { + assert.sameValue( + originalDesc, + undefined, + "obj['" + nameStr + "'] descriptor should be undefined" + ); + + // desc and originalDesc are both undefined, problem solved; + return true; + } + + assert( + __hasOwnProperty(obj, name), + "obj should have an own property " + nameStr + ); + + assert.notSameValue( + desc, + null, + "The desc argument should be an object or undefined, null" + ); + + assert.sameValue( + typeof desc, + "object", + "The desc argument should be an object or undefined, " + String(desc) + ); + + var names = Object.getOwnPropertyNames(desc); + for (var i = 0; i < names.length; i++) { + assert( + names[i] === "value" || + names[i] === "writable" || + names[i] === "enumerable" || + names[i] === "configurable" || + names[i] === "get" || + names[i] === "set", + "Invalid descriptor field: " + names[i], + ); + } + + var failures = []; + + if (__hasOwnProperty(desc, 'value')) { + if (!isSameValue(desc.value, originalDesc.value)) { + __push(failures, "descriptor value should be " + desc.value); + } + if (!isSameValue(desc.value, obj[name])) { + __push(failures, "object value should be " + desc.value); + } + } + + if (__hasOwnProperty(desc, 'enumerable')) { + if (desc.enumerable !== originalDesc.enumerable || + desc.enumerable !== isEnumerable(obj, name)) { + __push(failures, 'descriptor should ' + (desc.enumerable ? '' : 'not ') + 'be enumerable'); + } + } + + // Operations past this point are potentially destructive! + + if (__hasOwnProperty(desc, 'writable')) { + if (desc.writable !== originalDesc.writable || + desc.writable !== isWritable(obj, name)) { + __push(failures, 'descriptor should ' + (desc.writable ? '' : 'not ') + 'be writable'); + } + } + + if (__hasOwnProperty(desc, 'configurable')) { + if (desc.configurable !== originalDesc.configurable || + desc.configurable !== isConfigurable(obj, name)) { + __push(failures, 'descriptor should ' + (desc.configurable ? '' : 'not ') + 'be configurable'); + } + } + + assert(!failures.length, __join(failures, '; ')); + + if (options && options.restore) { + __defineProperty(obj, name, originalDesc); + } + + return true; +} + +function isConfigurable(obj, name) { + try { + delete obj[name]; + } catch (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("Expected TypeError, got " + e); + } + } + return !__hasOwnProperty(obj, name); +} + +function isEnumerable(obj, name) { + var stringCheck = false; + + if (typeof name === "string") { + for (var x in obj) { + if (x === name) { + stringCheck = true; + break; + } + } + } else { + // skip it if name is not string, works for Symbol names. + stringCheck = true; + } + + return stringCheck && __hasOwnProperty(obj, name) && __propertyIsEnumerable(obj, name); +} + +function isSameValue(a, b) { + if (a === 0 && b === 0) return 1 / a === 1 / b; + if (a !== a && b !== b) return true; + + return a === b; +} + +function isWritable(obj, name, verifyProp, value) { + var unlikelyValue = __isArray(obj) && name === "length" ? + nonIndexNumericPropertyName : + "unlikelyValue"; + var newValue = value || unlikelyValue; + var hadValue = __hasOwnProperty(obj, name); + var oldValue = obj[name]; + var writeSucceeded; + + if (arguments.length < 4 && newValue === oldValue) { + newValue = newValue + "2"; + } + + try { + obj[name] = newValue; + } catch (e) { + if (!(e instanceof TypeError)) { + throw new Test262Error("Expected TypeError, got " + e); + } + } + + writeSucceeded = isSameValue(obj[verifyProp || name], newValue); + + // Revert the change only if it was successful (in other cases, reverting + // is unnecessary and may trigger exceptions for certain property + // configurations) + if (writeSucceeded) { + if (hadValue) { + obj[name] = oldValue; + } else { + delete obj[name]; + } + } + + return writeSucceeded; +} + +/** + * Deprecated; please use `verifyProperty` in new tests. + */ +function verifyEqualTo(obj, name, value) { + if (!isSameValue(obj[name], value)) { + throw new Test262Error("Expected obj[" + String(name) + "] to equal " + value + + ", actually " + obj[name]); + } +} + +/** + * Deprecated; please use `verifyProperty` in new tests. + */ +function verifyWritable(obj, name, verifyProp, value) { + if (!verifyProp) { + assert(Object.getOwnPropertyDescriptor(obj, name).writable, + "Expected obj[" + String(name) + "] to have writable:true."); + } + if (!isWritable(obj, name, verifyProp, value)) { + throw new Test262Error("Expected obj[" + String(name) + "] to be writable, but was not."); + } +} + +/** + * Deprecated; please use `verifyProperty` in new tests. + */ +function verifyNotWritable(obj, name, verifyProp, value) { + if (!verifyProp) { + assert(!Object.getOwnPropertyDescriptor(obj, name).writable, + "Expected obj[" + String(name) + "] to have writable:false."); + } + if (isWritable(obj, name, verifyProp)) { + throw new Test262Error("Expected obj[" + String(name) + "] NOT to be writable, but was."); + } +} + +/** + * Deprecated; please use `verifyProperty` in new tests. + */ +function verifyEnumerable(obj, name) { + assert(Object.getOwnPropertyDescriptor(obj, name).enumerable, + "Expected obj[" + String(name) + "] to have enumerable:true."); + if (!isEnumerable(obj, name)) { + throw new Test262Error("Expected obj[" + String(name) + "] to be enumerable, but was not."); + } +} + +/** + * Deprecated; please use `verifyProperty` in new tests. + */ +function verifyNotEnumerable(obj, name) { + assert(!Object.getOwnPropertyDescriptor(obj, name).enumerable, + "Expected obj[" + String(name) + "] to have enumerable:false."); + if (isEnumerable(obj, name)) { + throw new Test262Error("Expected obj[" + String(name) + "] NOT to be enumerable, but was."); + } +} + +/** + * Deprecated; please use `verifyProperty` in new tests. + */ +function verifyConfigurable(obj, name) { + assert(Object.getOwnPropertyDescriptor(obj, name).configurable, + "Expected obj[" + String(name) + "] to have configurable:true."); + if (!isConfigurable(obj, name)) { + throw new Test262Error("Expected obj[" + String(name) + "] to be configurable, but was not."); + } +} + +/** + * Deprecated; please use `verifyProperty` in new tests. + */ +function verifyNotConfigurable(obj, name) { + assert(!Object.getOwnPropertyDescriptor(obj, name).configurable, + "Expected obj[" + String(name) + "] to have configurable:false."); + if (isConfigurable(obj, name)) { + throw new Test262Error("Expected obj[" + String(name) + "] NOT to be configurable, but was."); + } +} + +/** + * Use this function to verify the properties of a primordial object. + * For non-primordial objects, use verifyProperty. + * See: https://github.com/tc39/how-we-work/blob/main/terminology.md#primordial + */ +var verifyPrimordialProperty = verifyProperty; diff --git a/harness/proxyTrapsHelper.js b/harness/proxyTrapsHelper.js new file mode 100644 index 0000000000000000000000000000000000000000..17daab5abc18e34297b97cf771ee3eb76e214b4b --- /dev/null +++ b/harness/proxyTrapsHelper.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Used to assert the correctness of object behavior in the presence + and context of Proxy objects. +defines: [allowProxyTraps] +---*/ + +function allowProxyTraps(overrides) { + function throwTest262Error(msg) { + return function () { throw new Test262Error(msg); }; + } + if (!overrides) { overrides = {}; } + return { + getPrototypeOf: overrides.getPrototypeOf || throwTest262Error('[[GetPrototypeOf]] trap called'), + setPrototypeOf: overrides.setPrototypeOf || throwTest262Error('[[SetPrototypeOf]] trap called'), + isExtensible: overrides.isExtensible || throwTest262Error('[[IsExtensible]] trap called'), + preventExtensions: overrides.preventExtensions || throwTest262Error('[[PreventExtensions]] trap called'), + getOwnPropertyDescriptor: overrides.getOwnPropertyDescriptor || throwTest262Error('[[GetOwnProperty]] trap called'), + has: overrides.has || throwTest262Error('[[HasProperty]] trap called'), + get: overrides.get || throwTest262Error('[[Get]] trap called'), + set: overrides.set || throwTest262Error('[[Set]] trap called'), + deleteProperty: overrides.deleteProperty || throwTest262Error('[[Delete]] trap called'), + defineProperty: overrides.defineProperty || throwTest262Error('[[DefineOwnProperty]] trap called'), + enumerate: throwTest262Error('[[Enumerate]] trap called: this trap has been removed'), + ownKeys: overrides.ownKeys || throwTest262Error('[[OwnPropertyKeys]] trap called'), + apply: overrides.apply || throwTest262Error('[[Call]] trap called'), + construct: overrides.construct || throwTest262Error('[[Construct]] trap called') + }; +} diff --git a/harness/regExpUtils.js b/harness/regExpUtils.js new file mode 100644 index 0000000000000000000000000000000000000000..4be437e20a784c4461e29122637003738b622389 --- /dev/null +++ b/harness/regExpUtils.js @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Collection of functions used to assert the correctness of RegExp objects. +defines: [buildString, testPropertyEscapes, testPropertyOfStrings, testExtendedCharacterClass, matchValidator] +---*/ + +function buildString(args) { + // Use member expressions rather than destructuring `args` for improved + // compatibility with engines that only implement assignment patterns + // partially or not at all. + const loneCodePoints = args.loneCodePoints; + const ranges = args.ranges; + const CHUNK_SIZE = 10000; + let result = Reflect.apply(String.fromCodePoint, null, loneCodePoints); + for (let i = 0; i < ranges.length; i++) { + const range = ranges[i]; + const start = range[0]; + const end = range[1]; + const codePoints = []; + for (let length = 0, codePoint = start; codePoint <= end; codePoint++) { + codePoints[length++] = codePoint; + if (length === CHUNK_SIZE) { + result += Reflect.apply(String.fromCodePoint, null, codePoints); + codePoints.length = length = 0; + } + } + result += Reflect.apply(String.fromCodePoint, null, codePoints); + } + return result; +} + +function printCodePoint(codePoint) { + const hex = codePoint + .toString(16) + .toUpperCase() + .padStart(6, "0"); + return `U+${hex}`; +} + +function printStringCodePoints(string) { + const buf = []; + for (const symbol of string) { + const formatted = printCodePoint(symbol.codePointAt(0)); + buf.push(formatted); + } + return buf.join(' '); +} + +function testPropertyEscapes(regExp, string, expression) { + if (!regExp.test(string)) { + for (const symbol of string) { + const formatted = printCodePoint(symbol.codePointAt(0)); + assert( + regExp.test(symbol), + `\`${ expression }\` should match ${ formatted } (\`${ symbol }\`)` + ); + } + } +} + +function testPropertyOfStrings(args) { + // Use member expressions rather than destructuring `args` for improved + // compatibility with engines that only implement assignment patterns + // partially or not at all. + const regExp = args.regExp; + const expression = args.expression; + const matchStrings = args.matchStrings; + const nonMatchStrings = args.nonMatchStrings; + const allStrings = matchStrings.join(''); + if (!regExp.test(allStrings)) { + for (const string of matchStrings) { + assert( + regExp.test(string), + `\`${ expression }\` should match ${ string } (${ printStringCodePoints(string) })` + ); + } + } + + const allNonMatchStrings = nonMatchStrings.join(''); + if (regExp.test(allNonMatchStrings)) { + for (const string of nonMatchStrings) { + assert( + !regExp.test(string), + `\`${ expression }\` should not match ${ string } (${ printStringCodePoints(string) })` + ); + } + } +} + +// The exact same logic can be used to test extended character classes +// as enabled through the RegExp `v` flag. This is useful to test not +// just standalone properties of strings, but also string literals, and +// set operations. +const testExtendedCharacterClass = testPropertyOfStrings; + +// Returns a function that validates a RegExp match result. +// +// Example: +// +// var validate = matchValidator(['b'], 1, 'abc'); +// validate(/b/.exec('abc')); +// +function matchValidator(expectedEntries, expectedIndex, expectedInput) { + return function(match) { + assert.compareArray(match, expectedEntries, 'Match entries'); + assert.sameValue(match.index, expectedIndex, 'Match index'); + assert.sameValue(match.input, expectedInput, 'Match input'); + } +} diff --git a/harness/resizableArrayBufferUtils.js b/harness/resizableArrayBufferUtils.js new file mode 100644 index 0000000000000000000000000000000000000000..9dad8ccb83f4c8a2d96d9ef333f16aedc02255a2 --- /dev/null +++ b/harness/resizableArrayBufferUtils.js @@ -0,0 +1,152 @@ +// Copyright 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Collection of helper constants and functions for testing resizable array buffers. +defines: + - floatCtors + - ctors + - MyBigInt64Array + - CreateResizableArrayBuffer + - MayNeedBigInt + - Convert + - ToNumbers + - CreateRabForTest + - CollectValuesAndResize + - TestIterationAndResize +features: [BigInt] +---*/ +// Helper to create subclasses without bombing out when `class` isn't supported +function subClass(type) { + try { + return new Function('return class My' + type + ' extends ' + type + ' {}')(); + } catch (e) {} +} + +const MyUint8Array = subClass('Uint8Array'); +const MyFloat32Array = subClass('Float32Array'); +const MyBigInt64Array = subClass('BigInt64Array'); + +const builtinCtors = [ + Uint8Array, + Int8Array, + Uint16Array, + Int16Array, + Uint32Array, + Int32Array, + Float32Array, + Float64Array, + Uint8ClampedArray, +]; + +// Big(U)int64Array and Float16Array are newer features adding them above unconditionally +// would cause implementations lacking it to fail every test which uses it. +if (typeof Float16Array !== 'undefined') { + builtinCtors.push(Float16Array); +} + +if (typeof BigUint64Array !== 'undefined') { + builtinCtors.push(BigUint64Array); +} + +if (typeof BigInt64Array !== 'undefined') { + builtinCtors.push(BigInt64Array); +} + +const floatCtors = [ + Float32Array, + Float64Array, + MyFloat32Array +]; + +if (typeof Float16Array !== 'undefined') { + floatCtors.push(Float16Array); +} + +const ctors = builtinCtors.concat(MyUint8Array, MyFloat32Array); + +if (typeof MyBigInt64Array !== 'undefined') { + ctors.push(MyBigInt64Array); +} + +function CreateResizableArrayBuffer(byteLength, maxByteLength) { + return new ArrayBuffer(byteLength, { maxByteLength: maxByteLength }); +} + +function Convert(item) { + if (typeof item == 'bigint') { + return Number(item); + } + return item; +} + +function ToNumbers(array) { + let result = []; + for (let i = 0; i < array.length; i++) { + let item = array[i]; + result.push(Convert(item)); + } + return result; +} + +function MayNeedBigInt(ta, n) { + assert.sameValue(typeof n, 'number'); + if ((BigInt64Array !== 'undefined' && ta instanceof BigInt64Array) + || (BigUint64Array !== 'undefined' && ta instanceof BigUint64Array)) { + return BigInt(n); + } + return n; +} + +function CreateRabForTest(ctor) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + return rab; +} + +function CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo) { + if (typeof n == 'bigint') { + values.push(Number(n)); + } else { + values.push(n); + } + if (values.length == resizeAfter) { + rab.resize(resizeTo); + } + return true; +} + +function TestIterationAndResize(iterable, expected, rab, resizeAfter, newByteLength) { + let values = []; + let resized = false; + var arrayValues = false; + + for (let value of iterable) { + if (Array.isArray(value)) { + arrayValues = true; + values.push([ + value[0], + Number(value[1]) + ]); + } else { + values.push(Number(value)); + } + if (!resized && values.length == resizeAfter) { + rab.resize(newByteLength); + resized = true; + } + } + if (!arrayValues) { + assert.compareArray([].concat(values), expected, "TestIterationAndResize: list of iterated values"); + } else { + for (let i = 0; i < expected.length; i++) { + assert.compareArray(values[i], expected[i], "TestIterationAndResize: list of iterated lists of values"); + } + } + assert(resized, "TestIterationAndResize: resize condition should have been hit"); +} diff --git a/harness/sendableBigIntTypedArray.js b/harness/sendableBigIntTypedArray.js new file mode 100644 index 0000000000000000000000000000000000000000..9e7a99bbb9c47cba76f3270462614fcc570e3175 --- /dev/null +++ b/harness/sendableBigIntTypedArray.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var SendableTypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/harness/sendableTypedArray.js b/harness/sendableTypedArray.js new file mode 100644 index 0000000000000000000000000000000000000000..154af65e840c7996ce8753b5d9e8a5a8ee789f22 --- /dev/null +++ b/harness/sendableTypedArray.js @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Collection of functions used to assert the correctness of SendableTypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - SendableTypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %SendableTypedArray% intrinsic constructor function. + */ +var SendableTypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * SendableTypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} diff --git a/harness/sta.js b/harness/sta.js new file mode 100644 index 0000000000000000000000000000000000000000..5634cb9b003b1f2d6a4661bd1398474807371731 --- /dev/null +++ b/harness/sta.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Provides both: + + - An error class to avoid false positives when testing for thrown exceptions + - A function to explicitly throw an exception using the Test262Error class +defines: [Test262Error, $DONOTEVALUATE] +---*/ + + +function Test262Error(message) { + this.message = message || ""; +} + +Test262Error.prototype.toString = function () { + return "Test262Error: " + this.message; +}; + +Test262Error.thrower = function (message) { + throw new Test262Error(message); +}; + +function $DONOTEVALUATE() { + throw "Test262: This statement should not be evaluated."; +} diff --git a/harness/tcoHelper.js b/harness/tcoHelper.js new file mode 100644 index 0000000000000000000000000000000000000000..fafbed857f41a69ddf789d8f035be25f82095d74 --- /dev/null +++ b/harness/tcoHelper.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + This defines the number of consecutive recursive function calls that must be + made in order to prove that stack frames are properly destroyed according to + ES2015 tail call optimization semantics. +defines: [$MAX_ITERATIONS] +---*/ + + + + +var $MAX_ITERATIONS = 100000; diff --git a/harness/temporalHelpers.js b/harness/temporalHelpers.js new file mode 100644 index 0000000000000000000000000000000000000000..c8aee0516f4db5d8a6851120466e920547c3aa2e --- /dev/null +++ b/harness/temporalHelpers.js @@ -0,0 +1,2086 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + This defines helper objects and functions for testing Temporal. +defines: [TemporalHelpers] +features: [Symbol.species, Symbol.iterator, Temporal] +---*/ + +const ASCII_IDENTIFIER = /^[$_a-zA-Z][$_a-zA-Z0-9]*$/u; + +function formatPropertyName(propertyKey, objectName = "") { + switch (typeof propertyKey) { + case "symbol": + if (Symbol.keyFor(propertyKey) !== undefined) { + return `${objectName}[Symbol.for('${Symbol.keyFor(propertyKey)}')]`; + } else if (propertyKey.description.startsWith('Symbol.')) { + return `${objectName}[${propertyKey.description}]`; + } else { + return `${objectName}[Symbol('${propertyKey.description}')]` + } + case "string": + if (propertyKey !== String(Number(propertyKey))) { + if (ASCII_IDENTIFIER.test(propertyKey)) { + return objectName ? `${objectName}.${propertyKey}` : propertyKey; + } + return `${objectName}['${propertyKey.replace(/'/g, "\\'")}']` + } + // fall through + default: + // integer or string integer-index + return `${objectName}[${propertyKey}]`; + } +} + +const SKIP_SYMBOL = Symbol("Skip"); + +var TemporalHelpers = { + /* + * assertDuration(duration, years, ..., nanoseconds[, description]): + * + * Shorthand for asserting that each field of a Temporal.Duration is equal to + * an expected value. + */ + assertDuration(duration, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, description = "") { + assert(duration instanceof Temporal.Duration, `${description} instanceof`); + assert.sameValue(duration.years, years, `${description} years result`); + assert.sameValue(duration.months, months, `${description} months result`); + assert.sameValue(duration.weeks, weeks, `${description} weeks result`); + assert.sameValue(duration.days, days, `${description} days result`); + assert.sameValue(duration.hours, hours, `${description} hours result`); + assert.sameValue(duration.minutes, minutes, `${description} minutes result`); + assert.sameValue(duration.seconds, seconds, `${description} seconds result`); + assert.sameValue(duration.milliseconds, milliseconds, `${description} milliseconds result`); + assert.sameValue(duration.microseconds, microseconds, `${description} microseconds result`); + assert.sameValue(duration.nanoseconds, nanoseconds, `${description} nanoseconds result`); + }, + + /* + * assertDurationsEqual(actual, expected[, description]): + * + * Shorthand for asserting that each field of a Temporal.Duration is equal to + * the corresponding field in another Temporal.Duration. + */ + assertDurationsEqual(actual, expected, description = "") { + assert(expected instanceof Temporal.Duration, `${description} expected value should be a Temporal.Duration`); + TemporalHelpers.assertDuration(actual, expected.years, expected.months, expected.weeks, expected.days, expected.hours, expected.minutes, expected.seconds, expected.milliseconds, expected.microseconds, expected.nanoseconds, description); + }, + + /* + * assertInstantsEqual(actual, expected[, description]): + * + * Shorthand for asserting that two Temporal.Instants are of the correct type + * and equal according to their equals() methods. + */ + assertInstantsEqual(actual, expected, description = "") { + assert(expected instanceof Temporal.Instant, `${description} expected value should be a Temporal.Instant`); + assert(actual instanceof Temporal.Instant, `${description} instanceof`); + assert(actual.equals(expected), `${description} equals method`); + }, + + /* + * assertPlainDate(date, year, ..., nanosecond[, description[, era, eraYear]]): + * + * Shorthand for asserting that each field of a Temporal.PlainDate is equal to + * an expected value. (Except the `calendar` property, since callers may want + * to assert either object equality with an object they put in there, or the + * value of date.calendarId.) + */ + assertPlainDate(date, year, month, monthCode, day, description = "", era = undefined, eraYear = undefined) { + assert(date instanceof Temporal.PlainDate, `${description} instanceof`); + assert.sameValue(date.era, era, `${description} era result`); + assert.sameValue(date.eraYear, eraYear, `${description} eraYear result`); + assert.sameValue(date.year, year, `${description} year result`); + assert.sameValue(date.month, month, `${description} month result`); + assert.sameValue(date.monthCode, monthCode, `${description} monthCode result`); + assert.sameValue(date.day, day, `${description} day result`); + }, + + /* + * assertPlainDateTime(datetime, year, ..., nanosecond[, description[, era, eraYear]]): + * + * Shorthand for asserting that each field of a Temporal.PlainDateTime is + * equal to an expected value. (Except the `calendar` property, since callers + * may want to assert either object equality with an object they put in there, + * or the value of datetime.calendarId.) + */ + assertPlainDateTime(datetime, year, month, monthCode, day, hour, minute, second, millisecond, microsecond, nanosecond, description = "", era = undefined, eraYear = undefined) { + assert(datetime instanceof Temporal.PlainDateTime, `${description} instanceof`); + assert.sameValue(datetime.era, era, `${description} era result`); + assert.sameValue(datetime.eraYear, eraYear, `${description} eraYear result`); + assert.sameValue(datetime.year, year, `${description} year result`); + assert.sameValue(datetime.month, month, `${description} month result`); + assert.sameValue(datetime.monthCode, monthCode, `${description} monthCode result`); + assert.sameValue(datetime.day, day, `${description} day result`); + assert.sameValue(datetime.hour, hour, `${description} hour result`); + assert.sameValue(datetime.minute, minute, `${description} minute result`); + assert.sameValue(datetime.second, second, `${description} second result`); + assert.sameValue(datetime.millisecond, millisecond, `${description} millisecond result`); + assert.sameValue(datetime.microsecond, microsecond, `${description} microsecond result`); + assert.sameValue(datetime.nanosecond, nanosecond, `${description} nanosecond result`); + }, + + /* + * assertPlainDateTimesEqual(actual, expected[, description]): + * + * Shorthand for asserting that two Temporal.PlainDateTimes are of the correct + * type, equal according to their equals() methods, and additionally that + * their calendar internal slots are the same value. + */ + assertPlainDateTimesEqual(actual, expected, description = "") { + assert(expected instanceof Temporal.PlainDateTime, `${description} expected value should be a Temporal.PlainDateTime`); + assert(actual instanceof Temporal.PlainDateTime, `${description} instanceof`); + assert(actual.equals(expected), `${description} equals method`); + assert.sameValue( + actual.getISOFields().calendar, + expected.getISOFields().calendar, + `${description} calendar same value` + ); + }, + + /* + * assertPlainMonthDay(monthDay, monthCode, day[, description [, referenceISOYear]]): + * + * Shorthand for asserting that each field of a Temporal.PlainMonthDay is + * equal to an expected value. (Except the `calendar` property, since callers + * may want to assert either object equality with an object they put in there, + * or the value of monthDay.calendarId().) + */ + assertPlainMonthDay(monthDay, monthCode, day, description = "", referenceISOYear = 1972) { + assert(monthDay instanceof Temporal.PlainMonthDay, `${description} instanceof`); + assert.sameValue(monthDay.monthCode, monthCode, `${description} monthCode result`); + assert.sameValue(monthDay.day, day, `${description} day result`); + assert.sameValue(monthDay.getISOFields().isoYear, referenceISOYear, `${description} referenceISOYear result`); + }, + + /* + * assertPlainTime(time, hour, ..., nanosecond[, description]): + * + * Shorthand for asserting that each field of a Temporal.PlainTime is equal to + * an expected value. + */ + assertPlainTime(time, hour, minute, second, millisecond, microsecond, nanosecond, description = "") { + assert(time instanceof Temporal.PlainTime, `${description} instanceof`); + assert.sameValue(time.hour, hour, `${description} hour result`); + assert.sameValue(time.minute, minute, `${description} minute result`); + assert.sameValue(time.second, second, `${description} second result`); + assert.sameValue(time.millisecond, millisecond, `${description} millisecond result`); + assert.sameValue(time.microsecond, microsecond, `${description} microsecond result`); + assert.sameValue(time.nanosecond, nanosecond, `${description} nanosecond result`); + }, + + /* + * assertPlainTimesEqual(actual, expected[, description]): + * + * Shorthand for asserting that two Temporal.PlainTimes are of the correct + * type and equal according to their equals() methods. + */ + assertPlainTimesEqual(actual, expected, description = "") { + assert(expected instanceof Temporal.PlainTime, `${description} expected value should be a Temporal.PlainTime`); + assert(actual instanceof Temporal.PlainTime, `${description} instanceof`); + assert(actual.equals(expected), `${description} equals method`); + }, + + /* + * assertPlainYearMonth(yearMonth, year, month, monthCode[, description[, era, eraYear, referenceISODay]]): + * + * Shorthand for asserting that each field of a Temporal.PlainYearMonth is + * equal to an expected value. (Except the `calendar` property, since callers + * may want to assert either object equality with an object they put in there, + * or the value of yearMonth.calendarId.) + */ + assertPlainYearMonth(yearMonth, year, month, monthCode, description = "", era = undefined, eraYear = undefined, referenceISODay = 1) { + assert(yearMonth instanceof Temporal.PlainYearMonth, `${description} instanceof`); + assert.sameValue(yearMonth.era, era, `${description} era result`); + assert.sameValue(yearMonth.eraYear, eraYear, `${description} eraYear result`); + assert.sameValue(yearMonth.year, year, `${description} year result`); + assert.sameValue(yearMonth.month, month, `${description} month result`); + assert.sameValue(yearMonth.monthCode, monthCode, `${description} monthCode result`); + assert.sameValue(yearMonth.getISOFields().isoDay, referenceISODay, `${description} referenceISODay result`); + }, + + /* + * assertZonedDateTimesEqual(actual, expected[, description]): + * + * Shorthand for asserting that two Temporal.ZonedDateTimes are of the correct + * type, equal according to their equals() methods, and additionally that + * their time zones and calendar internal slots are the same value. + */ + assertZonedDateTimesEqual(actual, expected, description = "") { + assert(expected instanceof Temporal.ZonedDateTime, `${description} expected value should be a Temporal.ZonedDateTime`); + assert(actual instanceof Temporal.ZonedDateTime, `${description} instanceof`); + assert(actual.equals(expected), `${description} equals method`); + assert.sameValue(actual.timeZone, expected.timeZone, `${description} time zone same value`); + assert.sameValue( + actual.getISOFields().calendar, + expected.getISOFields().calendar, + `${description} calendar same value` + ); + }, + + /* + * assertUnreachable(description): + * + * Helper for asserting that code is not executed. This is useful for + * assertions that methods of user calendars and time zones are not called. + */ + assertUnreachable(description) { + let message = "This code should not be executed"; + if (description) { + message = `${message}: ${description}`; + } + throw new Test262Error(message); + }, + + /* + * checkCalendarDateUntilLargestUnitSingular(func, expectedLargestUnitCalls): + * + * When an options object with a largestUnit property is synthesized inside + * Temporal and passed to user code such as calendar.dateUntil(), the value of + * the largestUnit property should be in the singular form, even if the input + * was given in the plural form. + * (This doesn't apply when the options object is passed through verbatim.) + * + * func(calendar, largestUnit, index) is the operation under test. It's called + * with an instance of a calendar that keeps track of which largestUnit is + * passed to dateUntil(), each key of expectedLargestUnitCalls in turn, and + * the key's numerical index in case the function needs to generate test data + * based on the index. At the end, the actual values passed to dateUntil() are + * compared with the array values of expectedLargestUnitCalls. + */ + checkCalendarDateUntilLargestUnitSingular(func, expectedLargestUnitCalls) { + const actual = []; + + class DateUntilOptionsCalendar extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + + dateUntil(earlier, later, options) { + actual.push(options.largestUnit); + return super.dateUntil(earlier, later, options); + } + + toString() { + return "date-until-options"; + } + } + + const calendar = new DateUntilOptionsCalendar(); + Object.entries(expectedLargestUnitCalls).forEach(([largestUnit, expected], index) => { + func(calendar, largestUnit, index); + assert.compareArray(actual, expected, `largestUnit passed to calendar.dateUntil() for largestUnit ${largestUnit}`); + actual.splice(0); // empty it for the next check + }); + }, + + /* + * checkPlainDateTimeConversionFastPath(func): + * + * ToTemporalDate and ToTemporalTime should both, if given a + * Temporal.PlainDateTime instance, convert to the desired type by reading the + * PlainDateTime's internal slots, rather than calling any getters. + * + * func(datetime, calendar) is the actual operation to test, that must + * internally call the abstract operation ToTemporalDate or ToTemporalTime. + * It is passed a Temporal.PlainDateTime instance, as well as the instance's + * calendar object (so that it doesn't have to call the calendar getter itself + * if it wants to make any assertions about the calendar.) + */ + checkPlainDateTimeConversionFastPath(func, message = "checkPlainDateTimeConversionFastPath") { + const actual = []; + const expected = []; + + const calendar = new Temporal.Calendar("iso8601"); + const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar); + const prototypeDescrs = Object.getOwnPropertyDescriptors(Temporal.PlainDateTime.prototype); + ["year", "month", "monthCode", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond"].forEach((property) => { + Object.defineProperty(datetime, property, { + get() { + actual.push(`get ${formatPropertyName(property)}`); + const value = prototypeDescrs[property].get.call(this); + return { + toString() { + actual.push(`toString ${formatPropertyName(property)}`); + return value.toString(); + }, + valueOf() { + actual.push(`valueOf ${formatPropertyName(property)}`); + return value; + }, + }; + }, + }); + }); + Object.defineProperty(datetime, "calendar", { + get() { + actual.push("get calendar"); + return calendar; + }, + }); + + func(datetime, calendar); + assert.compareArray(actual, expected, `${message}: property getters not called`); + }, + + /* + * Check that an options bag that accepts units written in the singular form, + * also accepts the same units written in the plural form. + * func(unit) should call the method with the appropriate options bag + * containing unit as a value. This will be called twice for each element of + * validSingularUnits, once with singular and once with plural, and the + * results of each pair should be the same (whether a Temporal object or a + * primitive value.) + */ + checkPluralUnitsAccepted(func, validSingularUnits) { + const plurals = { + year: 'years', + month: 'months', + week: 'weeks', + day: 'days', + hour: 'hours', + minute: 'minutes', + second: 'seconds', + millisecond: 'milliseconds', + microsecond: 'microseconds', + nanosecond: 'nanoseconds', + }; + + validSingularUnits.forEach((unit) => { + const singularValue = func(unit); + const pluralValue = func(plurals[unit]); + const desc = `Plural ${plurals[unit]} produces the same result as singular ${unit}`; + if (singularValue instanceof Temporal.Duration) { + TemporalHelpers.assertDurationsEqual(pluralValue, singularValue, desc); + } else if (singularValue instanceof Temporal.Instant) { + TemporalHelpers.assertInstantsEqual(pluralValue, singularValue, desc); + } else if (singularValue instanceof Temporal.PlainDateTime) { + TemporalHelpers.assertPlainDateTimesEqual(pluralValue, singularValue, desc); + } else if (singularValue instanceof Temporal.PlainTime) { + TemporalHelpers.assertPlainTimesEqual(pluralValue, singularValue, desc); + } else if (singularValue instanceof Temporal.ZonedDateTime) { + TemporalHelpers.assertZonedDateTimesEqual(pluralValue, singularValue, desc); + } else { + assert.sameValue(pluralValue, singularValue); + } + }); + }, + + /* + * checkRoundingIncrementOptionWrongType(checkFunc, assertTrueResultFunc, assertObjectResultFunc): + * + * Checks the type handling of the roundingIncrement option. + * checkFunc(roundingIncrement) is a function which takes the value of + * roundingIncrement to test, and calls the method under test with it, + * returning the result. assertTrueResultFunc(result, description) should + * assert that result is the expected result with roundingIncrement: true, and + * assertObjectResultFunc(result, description) should assert that result is + * the expected result with roundingIncrement being an object with a valueOf() + * method. + */ + checkRoundingIncrementOptionWrongType(checkFunc, assertTrueResultFunc, assertObjectResultFunc) { + // null converts to 0, which is out of range + assert.throws(RangeError, () => checkFunc(null), "null"); + // Booleans convert to either 0 or 1, and 1 is allowed + const trueResult = checkFunc(true); + assertTrueResultFunc(trueResult, "true"); + assert.throws(RangeError, () => checkFunc(false), "false"); + // Symbols and BigInts cannot convert to numbers + assert.throws(TypeError, () => checkFunc(Symbol()), "symbol"); + assert.throws(TypeError, () => checkFunc(2n), "bigint"); + + // Objects prefer their valueOf() methods when converting to a number + assert.throws(RangeError, () => checkFunc({}), "plain object"); + + const expected = [ + "get roundingIncrement.valueOf", + "call roundingIncrement.valueOf", + ]; + const actual = []; + const observer = TemporalHelpers.toPrimitiveObserver(actual, 2, "roundingIncrement"); + const objectResult = checkFunc(observer); + assertObjectResultFunc(objectResult, "object with valueOf"); + assert.compareArray(actual, expected, "order of operations"); + }, + + /* + * checkStringOptionWrongType(propertyName, value, checkFunc, assertFunc): + * + * Checks the type handling of a string option, of which there are several in + * Temporal. + * propertyName is the name of the option, and value is the value that + * assertFunc should expect it to have. + * checkFunc(value) is a function which takes the value of the option to test, + * and calls the method under test with it, returning the result. + * assertFunc(result, description) should assert that result is the expected + * result with the option value being an object with a toString() method + * which returns the given value. + */ + checkStringOptionWrongType(propertyName, value, checkFunc, assertFunc) { + // null converts to the string "null", which is an invalid string value + assert.throws(RangeError, () => checkFunc(null), "null"); + // Booleans convert to the strings "true" or "false", which are invalid + assert.throws(RangeError, () => checkFunc(true), "true"); + assert.throws(RangeError, () => checkFunc(false), "false"); + // Symbols cannot convert to strings + assert.throws(TypeError, () => checkFunc(Symbol()), "symbol"); + // Numbers convert to strings which are invalid + assert.throws(RangeError, () => checkFunc(2), "number"); + // BigInts convert to strings which are invalid + assert.throws(RangeError, () => checkFunc(2n), "bigint"); + + // Objects prefer their toString() methods when converting to a string + assert.throws(RangeError, () => checkFunc({}), "plain object"); + + const expected = [ + `get ${propertyName}.toString`, + `call ${propertyName}.toString`, + ]; + const actual = []; + const observer = TemporalHelpers.toPrimitiveObserver(actual, value, propertyName); + const result = checkFunc(observer); + assertFunc(result, "object with toString"); + assert.compareArray(actual, expected, "order of operations"); + }, + + /* + * checkSubclassingIgnored(construct, constructArgs, method, methodArgs, + * resultAssertions): + * + * Methods of Temporal classes that return a new instance of the same class, + * must not take the constructor of a subclass into account, nor the @@species + * property. This helper runs tests to ensure this. + * + * construct(...constructArgs) must yield a valid instance of the Temporal + * class. instance[method](...methodArgs) is the method call under test, which + * must also yield a valid instance of the same Temporal class, not a + * subclass. See below for the individual tests that this runs. + * resultAssertions() is a function that performs additional assertions on the + * instance returned by the method under test. + */ + checkSubclassingIgnored(...args) { + this.checkSubclassConstructorNotObject(...args); + this.checkSubclassConstructorUndefined(...args); + this.checkSubclassConstructorThrows(...args); + this.checkSubclassConstructorNotCalled(...args); + this.checkSubclassSpeciesInvalidResult(...args); + this.checkSubclassSpeciesNotAConstructor(...args); + this.checkSubclassSpeciesNull(...args); + this.checkSubclassSpeciesUndefined(...args); + this.checkSubclassSpeciesThrows(...args); + }, + + /* + * Checks that replacing the 'constructor' property of the instance with + * various primitive values does not affect the returned new instance. + */ + checkSubclassConstructorNotObject(construct, constructArgs, method, methodArgs, resultAssertions) { + function check(value, description) { + const instance = new construct(...constructArgs); + instance.constructor = value; + const result = instance[method](...methodArgs); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype, description); + resultAssertions(result); + } + + check(null, "null"); + check(true, "true"); + check("test", "string"); + check(Symbol(), "Symbol"); + check(7, "number"); + check(7n, "bigint"); + }, + + /* + * Checks that replacing the 'constructor' property of the subclass with + * undefined does not affect the returned new instance. + */ + checkSubclassConstructorUndefined(construct, constructArgs, method, methodArgs, resultAssertions) { + let called = 0; + + class MySubclass extends construct { + constructor() { + ++called; + super(...constructArgs); + } + } + + const instance = new MySubclass(); + assert.sameValue(called, 1); + + MySubclass.prototype.constructor = undefined; + + const result = instance[method](...methodArgs); + assert.sameValue(called, 1); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype); + resultAssertions(result); + }, + + /* + * Checks that making the 'constructor' property of the instance throw when + * called does not affect the returned new instance. + */ + checkSubclassConstructorThrows(construct, constructArgs, method, methodArgs, resultAssertions) { + function CustomError() {} + const instance = new construct(...constructArgs); + Object.defineProperty(instance, "constructor", { + get() { + throw new CustomError(); + } + }); + const result = instance[method](...methodArgs); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype); + resultAssertions(result); + }, + + /* + * Checks that when subclassing, the subclass constructor is not called by + * the method under test. + */ + checkSubclassConstructorNotCalled(construct, constructArgs, method, methodArgs, resultAssertions) { + let called = 0; + + class MySubclass extends construct { + constructor() { + ++called; + super(...constructArgs); + } + } + + const instance = new MySubclass(); + assert.sameValue(called, 1); + + const result = instance[method](...methodArgs); + assert.sameValue(called, 1); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype); + resultAssertions(result); + }, + + /* + * Check that the constructor's @@species property is ignored when it's a + * constructor that returns a non-object value. + */ + checkSubclassSpeciesInvalidResult(construct, constructArgs, method, methodArgs, resultAssertions) { + function check(value, description) { + const instance = new construct(...constructArgs); + instance.constructor = { + [Symbol.species]: function() { + return value; + }, + }; + const result = instance[method](...methodArgs); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype, description); + resultAssertions(result); + } + + check(undefined, "undefined"); + check(null, "null"); + check(true, "true"); + check("test", "string"); + check(Symbol(), "Symbol"); + check(7, "number"); + check(7n, "bigint"); + check({}, "plain object"); + }, + + /* + * Check that the constructor's @@species property is ignored when it's not a + * constructor. + */ + checkSubclassSpeciesNotAConstructor(construct, constructArgs, method, methodArgs, resultAssertions) { + function check(value, description) { + const instance = new construct(...constructArgs); + instance.constructor = { + [Symbol.species]: value, + }; + const result = instance[method](...methodArgs); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype, description); + resultAssertions(result); + } + + check(true, "true"); + check("test", "string"); + check(Symbol(), "Symbol"); + check(7, "number"); + check(7n, "bigint"); + check({}, "plain object"); + }, + + /* + * Check that the constructor's @@species property is ignored when it's null. + */ + checkSubclassSpeciesNull(construct, constructArgs, method, methodArgs, resultAssertions) { + let called = 0; + + class MySubclass extends construct { + constructor() { + ++called; + super(...constructArgs); + } + } + + const instance = new MySubclass(); + assert.sameValue(called, 1); + + MySubclass.prototype.constructor = { + [Symbol.species]: null, + }; + + const result = instance[method](...methodArgs); + assert.sameValue(called, 1); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype); + resultAssertions(result); + }, + + /* + * Check that the constructor's @@species property is ignored when it's + * undefined. + */ + checkSubclassSpeciesUndefined(construct, constructArgs, method, methodArgs, resultAssertions) { + let called = 0; + + class MySubclass extends construct { + constructor() { + ++called; + super(...constructArgs); + } + } + + const instance = new MySubclass(); + assert.sameValue(called, 1); + + MySubclass.prototype.constructor = { + [Symbol.species]: undefined, + }; + + const result = instance[method](...methodArgs); + assert.sameValue(called, 1); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype); + resultAssertions(result); + }, + + /* + * Check that the constructor's @@species property is ignored when it throws, + * i.e. it is not called at all. + */ + checkSubclassSpeciesThrows(construct, constructArgs, method, methodArgs, resultAssertions) { + function CustomError() {} + + const instance = new construct(...constructArgs); + instance.constructor = { + get [Symbol.species]() { + throw new CustomError(); + }, + }; + + const result = instance[method](...methodArgs); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype); + }, + + /* + * checkSubclassingIgnoredStatic(construct, method, methodArgs, resultAssertions): + * + * Static methods of Temporal classes that return a new instance of the class, + * must not use the this-value as a constructor. This helper runs tests to + * ensure this. + * + * construct[method](...methodArgs) is the static method call under test, and + * must yield a valid instance of the Temporal class, not a subclass. See + * below for the individual tests that this runs. + * resultAssertions() is a function that performs additional assertions on the + * instance returned by the method under test. + */ + checkSubclassingIgnoredStatic(...args) { + this.checkStaticInvalidReceiver(...args); + this.checkStaticReceiverNotCalled(...args); + this.checkThisValueNotCalled(...args); + }, + + /* + * Check that calling the static method with a receiver that's not callable, + * still calls the intrinsic constructor. + */ + checkStaticInvalidReceiver(construct, method, methodArgs, resultAssertions) { + function check(value, description) { + const result = construct[method].apply(value, methodArgs); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype); + resultAssertions(result); + } + + check(undefined, "undefined"); + check(null, "null"); + check(true, "true"); + check("test", "string"); + check(Symbol(), "symbol"); + check(7, "number"); + check(7n, "bigint"); + check({}, "Non-callable object"); + }, + + /* + * Check that calling the static method with a receiver that returns a value + * that's not callable, still calls the intrinsic constructor. + */ + checkStaticReceiverNotCalled(construct, method, methodArgs, resultAssertions) { + function check(value, description) { + const receiver = function () { + return value; + }; + const result = construct[method].apply(receiver, methodArgs); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype); + resultAssertions(result); + } + + check(undefined, "undefined"); + check(null, "null"); + check(true, "true"); + check("test", "string"); + check(Symbol(), "symbol"); + check(7, "number"); + check(7n, "bigint"); + check({}, "Non-callable object"); + }, + + /* + * Check that the receiver isn't called. + */ + checkThisValueNotCalled(construct, method, methodArgs, resultAssertions) { + let called = false; + + class MySubclass extends construct { + constructor(...args) { + called = true; + super(...args); + } + } + + const result = MySubclass[method](...methodArgs); + assert.sameValue(called, false); + assert.sameValue(Object.getPrototypeOf(result), construct.prototype); + resultAssertions(result); + }, + + /* + * Check that any iterable returned from a custom time zone's + * getPossibleInstantsFor() method is exhausted. + * The custom time zone object is passed in to func(). + * expected is an array of strings representing the expected calls to the + * getPossibleInstantsFor() method. The PlainDateTimes that it is called with, + * are compared (using their toString() results) with the array. + */ + checkTimeZonePossibleInstantsIterable(func, expected) { + // A custom time zone that returns an iterable instead of an array from its + // getPossibleInstantsFor() method, and for testing purposes skips + // 00:00-01:00 UTC on January 1, 2030, and repeats 00:00-01:00 UTC+1 on + // January 3, 2030. Otherwise identical to the UTC time zone. + class TimeZonePossibleInstantsIterable extends Temporal.TimeZone { + constructor() { + super("UTC"); + this.getPossibleInstantsForCallCount = 0; + this.getPossibleInstantsForCalledWith = []; + this.getPossibleInstantsForReturns = []; + this.iteratorExhausted = []; + } + + toString() { + return "Custom/Iterable"; + } + + getOffsetNanosecondsFor(instant) { + if (Temporal.Instant.compare(instant, "2030-01-01T00:00Z") >= 0 && + Temporal.Instant.compare(instant, "2030-01-03T01:00Z") < 0) { + return 3600_000_000_000; + } else { + return 0; + } + } + + getPossibleInstantsFor(dateTime) { + this.getPossibleInstantsForCallCount++; + this.getPossibleInstantsForCalledWith.push(dateTime); + + // Fake DST transition + let retval = super.getPossibleInstantsFor(dateTime); + if (dateTime.toPlainDate().equals("2030-01-01") && dateTime.hour === 0) { + retval = []; + } else if (dateTime.toPlainDate().equals("2030-01-03") && dateTime.hour === 0) { + retval.push(retval[0].subtract({ hours: 1 })); + } else if (dateTime.year === 2030 && dateTime.month === 1 && dateTime.day >= 1 && dateTime.day <= 2) { + retval[0] = retval[0].subtract({ hours: 1 }); + } + + this.getPossibleInstantsForReturns.push(retval); + this.iteratorExhausted.push(false); + return { + callIndex: this.getPossibleInstantsForCallCount - 1, + timeZone: this, + *[Symbol.iterator]() { + yield* this.timeZone.getPossibleInstantsForReturns[this.callIndex]; + this.timeZone.iteratorExhausted[this.callIndex] = true; + }, + }; + } + } + + const timeZone = new TimeZonePossibleInstantsIterable(); + func(timeZone); + + assert.sameValue(timeZone.getPossibleInstantsForCallCount, expected.length, "getPossibleInstantsFor() method called correct number of times"); + + for (let index = 0; index < expected.length; index++) { + assert.sameValue(timeZone.getPossibleInstantsForCalledWith[index].toString(), expected[index], "getPossibleInstantsFor() called with expected PlainDateTime"); + assert(timeZone.iteratorExhausted[index], "iterated through the whole iterable"); + } + }, + + /* + * Check that any calendar-carrying Temporal object has its [[Calendar]] + * internal slot read by ToTemporalCalendar, and does not fetch the calendar + * by calling getters. + * The custom calendar object is passed in to func() so that it can do its + * own additional assertions involving the calendar if necessary. (Sometimes + * there is nothing to assert as the calendar isn't stored anywhere that can + * be asserted about.) + */ + checkToTemporalCalendarFastPath(func) { + class CalendarFastPathCheck extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + + dateFromFields(...args) { + return super.dateFromFields(...args).withCalendar(this); + } + + monthDayFromFields(...args) { + const { isoYear, isoMonth, isoDay } = super.monthDayFromFields(...args).getISOFields(); + return new Temporal.PlainMonthDay(isoMonth, isoDay, this, isoYear); + } + + yearMonthFromFields(...args) { + const { isoYear, isoMonth, isoDay } = super.yearMonthFromFields(...args).getISOFields(); + return new Temporal.PlainYearMonth(isoYear, isoMonth, this, isoDay); + } + + toString() { + return "fast-path-check"; + } + } + const calendar = new CalendarFastPathCheck(); + + const plainDate = new Temporal.PlainDate(2000, 5, 2, calendar); + const plainDateTime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar); + const plainMonthDay = new Temporal.PlainMonthDay(5, 2, calendar); + const plainYearMonth = new Temporal.PlainYearMonth(2000, 5, calendar); + const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar); + + [plainDate, plainDateTime, plainMonthDay, plainYearMonth, zonedDateTime].forEach((temporalObject) => { + const actual = []; + const expected = []; + + Object.defineProperty(temporalObject, "calendar", { + get() { + actual.push("get calendar"); + return calendar; + }, + }); + + func(temporalObject, calendar); + assert.compareArray(actual, expected, "calendar getter not called"); + }); + }, + + checkToTemporalInstantFastPath(func) { + const actual = []; + const expected = []; + + const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC"); + Object.defineProperty(datetime, 'toString', { + get() { + actual.push("get toString"); + return function (options) { + actual.push("call toString"); + return Temporal.ZonedDateTime.prototype.toString.call(this, options); + }; + }, + }); + + func(datetime); + assert.compareArray(actual, expected, "toString not called"); + }, + + checkToTemporalPlainDateTimeFastPath(func) { + const actual = []; + const expected = []; + + const calendar = new Temporal.Calendar("iso8601"); + const date = new Temporal.PlainDate(2000, 5, 2, calendar); + const prototypeDescrs = Object.getOwnPropertyDescriptors(Temporal.PlainDate.prototype); + ["year", "month", "monthCode", "day"].forEach((property) => { + Object.defineProperty(date, property, { + get() { + actual.push(`get ${formatPropertyName(property)}`); + const value = prototypeDescrs[property].get.call(this); + return TemporalHelpers.toPrimitiveObserver(actual, value, property); + }, + }); + }); + ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"].forEach((property) => { + Object.defineProperty(date, property, { + get() { + actual.push(`get ${formatPropertyName(property)}`); + return undefined; + }, + }); + }); + Object.defineProperty(date, "calendar", { + get() { + actual.push("get calendar"); + return calendar; + }, + }); + + func(date, calendar); + assert.compareArray(actual, expected, "property getters not called"); + }, + + /* + * A custom calendar used in prototype pollution checks. Verifies that the + * fromFields methods are always called with a null-prototype fields object. + */ + calendarCheckFieldsPrototypePollution() { + class CalendarCheckFieldsPrototypePollution extends Temporal.Calendar { + constructor() { + super("iso8601"); + this.dateFromFieldsCallCount = 0; + this.yearMonthFromFieldsCallCount = 0; + this.monthDayFromFieldsCallCount = 0; + } + + // toString must remain "iso8601", so that some methods don't throw due to + // incompatible calendars + + dateFromFields(fields, options = {}) { + this.dateFromFieldsCallCount++; + assert.sameValue(Object.getPrototypeOf(fields), null, "dateFromFields should be called with null-prototype fields object"); + return super.dateFromFields(fields, options); + } + + yearMonthFromFields(fields, options = {}) { + this.yearMonthFromFieldsCallCount++; + assert.sameValue(Object.getPrototypeOf(fields), null, "yearMonthFromFields should be called with null-prototype fields object"); + return super.yearMonthFromFields(fields, options); + } + + monthDayFromFields(fields, options = {}) { + this.monthDayFromFieldsCallCount++; + assert.sameValue(Object.getPrototypeOf(fields), null, "monthDayFromFields should be called with null-prototype fields object"); + return super.monthDayFromFields(fields, options); + } + } + + return new CalendarCheckFieldsPrototypePollution(); + }, + + /* + * A custom calendar used in prototype pollution checks. Verifies that the + * mergeFields() method is always called with null-prototype fields objects. + */ + calendarCheckMergeFieldsPrototypePollution() { + class CalendarCheckMergeFieldsPrototypePollution extends Temporal.Calendar { + constructor() { + super("iso8601"); + this.mergeFieldsCallCount = 0; + } + + toString() { + return "merge-fields-null-proto"; + } + + mergeFields(fields, additionalFields) { + this.mergeFieldsCallCount++; + assert.sameValue(Object.getPrototypeOf(fields), null, "mergeFields should be called with null-prototype fields object (first argument)"); + assert.sameValue(Object.getPrototypeOf(additionalFields), null, "mergeFields should be called with null-prototype fields object (second argument)"); + return super.mergeFields(fields, additionalFields); + } + } + + return new CalendarCheckMergeFieldsPrototypePollution(); + }, + + /* + * A custom calendar used in prototype pollution checks. Verifies that methods + * are always called with a null-prototype options object. + */ + calendarCheckOptionsPrototypePollution() { + class CalendarCheckOptionsPrototypePollution extends Temporal.Calendar { + constructor() { + super("iso8601"); + this.yearMonthFromFieldsCallCount = 0; + this.dateUntilCallCount = 0; + } + + toString() { + return "options-null-proto"; + } + + yearMonthFromFields(fields, options) { + this.yearMonthFromFieldsCallCount++; + assert.sameValue(Object.getPrototypeOf(options), null, "yearMonthFromFields should be called with null-prototype options"); + return super.yearMonthFromFields(fields, options); + } + + dateUntil(one, two, options) { + this.dateUntilCallCount++; + assert.sameValue(Object.getPrototypeOf(options), null, "dateUntil should be called with null-prototype options"); + return super.dateUntil(one, two, options); + } + } + + return new CalendarCheckOptionsPrototypePollution(); + }, + + /* + * A custom calendar that asserts its dateAdd() method is called with the + * options parameter having the value undefined. + */ + calendarDateAddUndefinedOptions() { + class CalendarDateAddUndefinedOptions extends Temporal.Calendar { + constructor() { + super("iso8601"); + this.dateAddCallCount = 0; + } + + toString() { + return "dateadd-undef-options"; + } + + dateAdd(date, duration, options) { + this.dateAddCallCount++; + assert.sameValue(options, undefined, "dateAdd shouldn't be called with options"); + return super.dateAdd(date, duration, options); + } + } + return new CalendarDateAddUndefinedOptions(); + }, + + /* + * A custom calendar that asserts its dateAdd() method is called with a + * PlainDate instance. Optionally, it also asserts that the PlainDate instance + * is the specific object `this.specificPlainDate`, if it is set by the + * calling code. + */ + calendarDateAddPlainDateInstance() { + class CalendarDateAddPlainDateInstance extends Temporal.Calendar { + constructor() { + super("iso8601"); + this.dateAddCallCount = 0; + this.specificPlainDate = undefined; + } + + toString() { + return "dateadd-plain-date-instance"; + } + + dateFromFields(...args) { + return super.dateFromFields(...args).withCalendar(this); + } + + dateAdd(date, duration, options) { + this.dateAddCallCount++; + assert(date instanceof Temporal.PlainDate, "dateAdd() should be called with a PlainDate instance"); + if (this.dateAddCallCount === 1 && this.specificPlainDate) { + assert.sameValue(date, this.specificPlainDate, `dateAdd() should be called first with the specific PlainDate instance ${this.specificPlainDate}`); + } + return super.dateAdd(date, duration, options).withCalendar(this); + } + } + return new CalendarDateAddPlainDateInstance(); + }, + + /* + * A custom calendar that returns @returnValue from its dateUntil() method, + * recording the call in @calls. + */ + calendarDateUntilObservable(calls, returnValue) { + class CalendarDateUntilObservable extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + + dateUntil() { + calls.push("call dateUntil"); + return returnValue; + } + } + + return new CalendarDateUntilObservable(); + }, + + /* + * A custom calendar that returns an iterable instead of an array from its + * fields() method, otherwise identical to the ISO calendar. + */ + calendarFieldsIterable() { + class CalendarFieldsIterable extends Temporal.Calendar { + constructor() { + super("iso8601"); + this.fieldsCallCount = 0; + this.fieldsCalledWith = []; + this.iteratorExhausted = []; + } + + toString() { + return "fields-iterable"; + } + + fields(fieldNames) { + this.fieldsCallCount++; + this.fieldsCalledWith.push(fieldNames.slice()); + this.iteratorExhausted.push(false); + return { + callIndex: this.fieldsCallCount - 1, + calendar: this, + *[Symbol.iterator]() { + yield* this.calendar.fieldsCalledWith[this.callIndex]; + this.calendar.iteratorExhausted[this.callIndex] = true; + }, + }; + } + } + return new CalendarFieldsIterable(); + }, + + /* + * A custom calendar that asserts its ...FromFields() methods are called with + * the options parameter having the value undefined. + */ + calendarFromFieldsUndefinedOptions() { + class CalendarFromFieldsUndefinedOptions extends Temporal.Calendar { + constructor() { + super("iso8601"); + this.dateFromFieldsCallCount = 0; + this.monthDayFromFieldsCallCount = 0; + this.yearMonthFromFieldsCallCount = 0; + } + + toString() { + return "from-fields-undef-options"; + } + + dateFromFields(fields, options) { + this.dateFromFieldsCallCount++; + assert.sameValue(options, undefined, "dateFromFields shouldn't be called with options"); + return super.dateFromFields(fields, options); + } + + yearMonthFromFields(fields, options) { + this.yearMonthFromFieldsCallCount++; + assert.sameValue(options, undefined, "yearMonthFromFields shouldn't be called with options"); + return super.yearMonthFromFields(fields, options); + } + + monthDayFromFields(fields, options) { + this.monthDayFromFieldsCallCount++; + assert.sameValue(options, undefined, "monthDayFromFields shouldn't be called with options"); + return super.monthDayFromFields(fields, options); + } + } + return new CalendarFromFieldsUndefinedOptions(); + }, + + /* + * A custom calendar that modifies the fields object passed in to + * dateFromFields, sabotaging its time properties. + */ + calendarMakeInfinityTime() { + class CalendarMakeInfinityTime extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + + dateFromFields(fields, options) { + const retval = super.dateFromFields(fields, options); + fields.hour = Infinity; + fields.minute = Infinity; + fields.second = Infinity; + fields.millisecond = Infinity; + fields.microsecond = Infinity; + fields.nanosecond = Infinity; + return retval; + } + } + return new CalendarMakeInfinityTime(); + }, + + /* + * A custom calendar that defines getters on the fields object passed into + * dateFromFields that throw, sabotaging its time properties. + */ + calendarMakeInvalidGettersTime() { + class CalendarMakeInvalidGettersTime extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + + dateFromFields(fields, options) { + const retval = super.dateFromFields(fields, options); + const throwingDescriptor = { + get() { + throw new Test262Error("reading a sabotaged time field"); + }, + }; + Object.defineProperties(fields, { + hour: throwingDescriptor, + minute: throwingDescriptor, + second: throwingDescriptor, + millisecond: throwingDescriptor, + microsecond: throwingDescriptor, + nanosecond: throwingDescriptor, + }); + return retval; + } + } + return new CalendarMakeInvalidGettersTime(); + }, + + /* + * A custom calendar whose mergeFields() method returns a proxy object with + * all of its Get and HasProperty operations observable, as well as adding a + * "shouldNotBeCopied": true property. + */ + calendarMergeFieldsGetters() { + class CalendarMergeFieldsGetters extends Temporal.Calendar { + constructor() { + super("iso8601"); + this.mergeFieldsReturnOperations = []; + } + + toString() { + return "merge-fields-getters"; + } + + dateFromFields(fields, options) { + assert.sameValue(fields.shouldNotBeCopied, undefined, "extra fields should not be copied"); + return super.dateFromFields(fields, options); + } + + yearMonthFromFields(fields, options) { + assert.sameValue(fields.shouldNotBeCopied, undefined, "extra fields should not be copied"); + return super.yearMonthFromFields(fields, options); + } + + monthDayFromFields(fields, options) { + assert.sameValue(fields.shouldNotBeCopied, undefined, "extra fields should not be copied"); + return super.monthDayFromFields(fields, options); + } + + mergeFields(fields, additionalFields) { + const retval = super.mergeFields(fields, additionalFields); + retval._calendar = this; + retval.shouldNotBeCopied = true; + return new Proxy(retval, { + get(target, key) { + target._calendar.mergeFieldsReturnOperations.push(`get ${key}`); + const result = target[key]; + if (result === undefined) { + return undefined; + } + return TemporalHelpers.toPrimitiveObserver(target._calendar.mergeFieldsReturnOperations, result, key); + }, + has(target, key) { + target._calendar.mergeFieldsReturnOperations.push(`has ${key}`); + return key in target; + }, + }); + } + } + return new CalendarMergeFieldsGetters(); + }, + + /* + * A custom calendar whose mergeFields() method returns a primitive value, + * given by @primitive, and which records the number of calls made to its + * dateFromFields(), yearMonthFromFields(), and monthDayFromFields() methods. + */ + calendarMergeFieldsReturnsPrimitive(primitive) { + class CalendarMergeFieldsPrimitive extends Temporal.Calendar { + constructor(mergeFieldsReturnValue) { + super("iso8601"); + this._mergeFieldsReturnValue = mergeFieldsReturnValue; + this.dateFromFieldsCallCount = 0; + this.monthDayFromFieldsCallCount = 0; + this.yearMonthFromFieldsCallCount = 0; + } + + toString() { + return "merge-fields-primitive"; + } + + dateFromFields(fields, options) { + this.dateFromFieldsCallCount++; + return super.dateFromFields(fields, options); + } + + yearMonthFromFields(fields, options) { + this.yearMonthFromFieldsCallCount++; + return super.yearMonthFromFields(fields, options); + } + + monthDayFromFields(fields, options) { + this.monthDayFromFieldsCallCount++; + return super.monthDayFromFields(fields, options); + } + + mergeFields() { + return this._mergeFieldsReturnValue; + } + } + return new CalendarMergeFieldsPrimitive(primitive); + }, + + /* + * crossDateLineTimeZone(): + * + * This returns an instance of a custom time zone class that implements one + * single transition where the time zone moves from one side of the + * International Date Line to the other, for the purpose of testing time zone + * calculations without depending on system time zone data. + * + * The transition occurs at epoch second 1325239200 and goes from offset + * -10:00 to +14:00. In other words, the time zone skips the whole calendar + * day of 2011-12-30. This is the same as the real-life transition in the + * Pacific/Apia time zone. + */ + crossDateLineTimeZone() { + const { compare } = Temporal.PlainDateTime; + const skippedDay = new Temporal.PlainDate(2011, 12, 30); + const transitionEpoch = 1325239200_000_000_000n; + const beforeOffset = new Temporal.TimeZone("-10:00"); + const afterOffset = new Temporal.TimeZone("+14:00"); + + class CrossDateLineTimeZone extends Temporal.TimeZone { + constructor() { + super("+14:00"); + } + + getOffsetNanosecondsFor(instant) { + if (instant.epochNanoseconds < transitionEpoch) { + return beforeOffset.getOffsetNanosecondsFor(instant); + } + return afterOffset.getOffsetNanosecondsFor(instant); + } + + getPossibleInstantsFor(datetime) { + const comparison = Temporal.PlainDate.compare(datetime.toPlainDate(), skippedDay); + if (comparison === 0) { + return []; + } + if (comparison < 0) { + return [beforeOffset.getInstantFor(datetime)]; + } + return [afterOffset.getInstantFor(datetime)]; + } + + getPreviousTransition(instant) { + if (instant.epochNanoseconds > transitionEpoch) return new Temporal.Instant(transitionEpoch); + return null; + } + + getNextTransition(instant) { + if (instant.epochNanoseconds < transitionEpoch) return new Temporal.Instant(transitionEpoch); + return null; + } + + toString() { + return "Custom/Date_Line"; + } + } + return new CrossDateLineTimeZone(); + }, + + /* + * observeProperty(calls, object, propertyName, value): + * + * Defines an own property @object.@propertyName with value @value, that + * will log any calls to its accessors to the array @calls. + */ + observeProperty(calls, object, propertyName, value, objectName = "") { + Object.defineProperty(object, propertyName, { + get() { + calls.push(`get ${formatPropertyName(propertyName, objectName)}`); + return value; + }, + set(v) { + calls.push(`set ${formatPropertyName(propertyName, objectName)}`); + } + }); + }, + + /* + * observeMethod(calls, object, propertyName, value): + * + * Defines an own property @object.@propertyName with value @value, that + * will log any calls of @value to the array @calls. + */ + observeMethod(calls, object, propertyName, objectName = "") { + const method = object[propertyName]; + object[propertyName] = function () { + calls.push(`call ${formatPropertyName(propertyName, objectName)}`); + return method.apply(object, arguments); + }; + }, + + /* + * Used for substituteMethod to indicate default behavior instead of a + * substituted value + */ + SUBSTITUTE_SKIP: SKIP_SYMBOL, + + /* + * substituteMethod(object, propertyName, values): + * + * Defines an own property @object.@propertyName that will, for each + * subsequent call to the method previously defined as + * @object.@propertyName: + * - Call the method, if no more values remain + * - Call the method, if the value in @values for the corresponding call + * is SUBSTITUTE_SKIP + * - Otherwise, return the corresponding value in @value + */ + substituteMethod(object, propertyName, values) { + let calls = 0; + const method = object[propertyName]; + object[propertyName] = function () { + if (calls >= values.length) { + return method.apply(object, arguments); + } else if (values[calls] === SKIP_SYMBOL) { + calls++; + return method.apply(object, arguments); + } else { + return values[calls++]; + } + }; + }, + + /* + * calendarObserver: + * A custom calendar that behaves exactly like the ISO 8601 calendar but + * tracks calls to any of its methods, and Get/Has operations on its + * properties, by appending messages to an array. This is for the purpose of + * testing order of operations that are observable from user code. + * objectName is used in the log. + */ + calendarObserver(calls, objectName, methodOverrides = {}) { + function removeExtraHasPropertyChecks(objectName, calls) { + // Inserting the tracking calendar into the return values of methods + // that we chain up into the ISO calendar for, causes extra HasProperty + // checks, which we observe. This removes them so that we don't leak + // implementation details of the helper into the test code. + assert.sameValue(calls.pop(), `has ${objectName}.yearOfWeek`); + assert.sameValue(calls.pop(), `has ${objectName}.yearMonthFromFields`); + assert.sameValue(calls.pop(), `has ${objectName}.year`); + assert.sameValue(calls.pop(), `has ${objectName}.weekOfYear`); + assert.sameValue(calls.pop(), `has ${objectName}.monthsInYear`); + assert.sameValue(calls.pop(), `has ${objectName}.monthDayFromFields`); + assert.sameValue(calls.pop(), `has ${objectName}.monthCode`); + assert.sameValue(calls.pop(), `has ${objectName}.month`); + assert.sameValue(calls.pop(), `has ${objectName}.mergeFields`); + assert.sameValue(calls.pop(), `has ${objectName}.inLeapYear`); + assert.sameValue(calls.pop(), `has ${objectName}.id`); + assert.sameValue(calls.pop(), `has ${objectName}.fields`); + assert.sameValue(calls.pop(), `has ${objectName}.daysInYear`); + assert.sameValue(calls.pop(), `has ${objectName}.daysInWeek`); + assert.sameValue(calls.pop(), `has ${objectName}.daysInMonth`); + assert.sameValue(calls.pop(), `has ${objectName}.dayOfYear`); + assert.sameValue(calls.pop(), `has ${objectName}.dayOfWeek`); + assert.sameValue(calls.pop(), `has ${objectName}.day`); + assert.sameValue(calls.pop(), `has ${objectName}.dateUntil`); + assert.sameValue(calls.pop(), `has ${objectName}.dateFromFields`); + assert.sameValue(calls.pop(), `has ${objectName}.dateAdd`); + } + + const iso8601 = new Temporal.Calendar("iso8601"); + const trackingMethods = { + dateFromFields(...args) { + calls.push(`call ${objectName}.dateFromFields`); + if ('dateFromFields' in methodOverrides) { + const value = methodOverrides.dateFromFields; + return typeof value === "function" ? value(...args) : value; + } + const originalResult = iso8601.dateFromFields(...args); + // Replace the calendar in the result with the call-tracking calendar + const {isoYear, isoMonth, isoDay} = originalResult.getISOFields(); + const result = new Temporal.PlainDate(isoYear, isoMonth, isoDay, this); + removeExtraHasPropertyChecks(objectName, calls); + return result; + }, + yearMonthFromFields(...args) { + calls.push(`call ${objectName}.yearMonthFromFields`); + if ('yearMonthFromFields' in methodOverrides) { + const value = methodOverrides.yearMonthFromFields; + return typeof value === "function" ? value(...args) : value; + } + const originalResult = iso8601.yearMonthFromFields(...args); + // Replace the calendar in the result with the call-tracking calendar + const {isoYear, isoMonth, isoDay} = originalResult.getISOFields(); + const result = new Temporal.PlainYearMonth(isoYear, isoMonth, this, isoDay); + removeExtraHasPropertyChecks(objectName, calls); + return result; + }, + monthDayFromFields(...args) { + calls.push(`call ${objectName}.monthDayFromFields`); + if ('monthDayFromFields' in methodOverrides) { + const value = methodOverrides.monthDayFromFields; + return typeof value === "function" ? value(...args) : value; + } + const originalResult = iso8601.monthDayFromFields(...args); + // Replace the calendar in the result with the call-tracking calendar + const {isoYear, isoMonth, isoDay} = originalResult.getISOFields(); + const result = new Temporal.PlainMonthDay(isoMonth, isoDay, this, isoYear); + removeExtraHasPropertyChecks(objectName, calls); + return result; + }, + dateAdd(...args) { + calls.push(`call ${objectName}.dateAdd`); + if ('dateAdd' in methodOverrides) { + const value = methodOverrides.dateAdd; + return typeof value === "function" ? value(...args) : value; + } + const originalResult = iso8601.dateAdd(...args); + const {isoYear, isoMonth, isoDay} = originalResult.getISOFields(); + const result = new Temporal.PlainDate(isoYear, isoMonth, isoDay, this); + removeExtraHasPropertyChecks(objectName, calls); + return result; + }, + id: "iso8601", + }; + // Automatically generate the other methods that don't need any custom code + [ + "dateUntil", + "day", + "dayOfWeek", + "dayOfYear", + "daysInMonth", + "daysInWeek", + "daysInYear", + "era", + "eraYear", + "fields", + "inLeapYear", + "mergeFields", + "month", + "monthCode", + "monthsInYear", + "toString", + "weekOfYear", + "year", + "yearOfWeek", + ].forEach((methodName) => { + trackingMethods[methodName] = function (...args) { + calls.push(`call ${formatPropertyName(methodName, objectName)}`); + if (methodName in methodOverrides) { + const value = methodOverrides[methodName]; + return typeof value === "function" ? value(...args) : value; + } + return iso8601[methodName](...args); + }; + }); + return new Proxy(trackingMethods, { + get(target, key, receiver) { + const result = Reflect.get(target, key, receiver); + calls.push(`get ${formatPropertyName(key, objectName)}`); + return result; + }, + has(target, key) { + calls.push(`has ${formatPropertyName(key, objectName)}`); + return Reflect.has(target, key); + }, + }); + }, + + /* + * A custom calendar that does not allow any of its methods to be called, for + * the purpose of asserting that a particular operation does not call into + * user code. + */ + calendarThrowEverything() { + class CalendarThrowEverything extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + toString() { + TemporalHelpers.assertUnreachable("toString should not be called"); + } + dateFromFields() { + TemporalHelpers.assertUnreachable("dateFromFields should not be called"); + } + yearMonthFromFields() { + TemporalHelpers.assertUnreachable("yearMonthFromFields should not be called"); + } + monthDayFromFields() { + TemporalHelpers.assertUnreachable("monthDayFromFields should not be called"); + } + dateAdd() { + TemporalHelpers.assertUnreachable("dateAdd should not be called"); + } + dateUntil() { + TemporalHelpers.assertUnreachable("dateUntil should not be called"); + } + era() { + TemporalHelpers.assertUnreachable("era should not be called"); + } + eraYear() { + TemporalHelpers.assertUnreachable("eraYear should not be called"); + } + year() { + TemporalHelpers.assertUnreachable("year should not be called"); + } + month() { + TemporalHelpers.assertUnreachable("month should not be called"); + } + monthCode() { + TemporalHelpers.assertUnreachable("monthCode should not be called"); + } + day() { + TemporalHelpers.assertUnreachable("day should not be called"); + } + fields() { + TemporalHelpers.assertUnreachable("fields should not be called"); + } + mergeFields() { + TemporalHelpers.assertUnreachable("mergeFields should not be called"); + } + } + + return new CalendarThrowEverything(); + }, + + /* + * oneShiftTimeZone(shiftInstant, shiftNanoseconds): + * + * In the case of a spring-forward time zone offset transition (skipped time), + * and disambiguation === 'earlier', BuiltinTimeZoneGetInstantFor subtracts a + * negative number of nanoseconds from a PlainDateTime, which should balance + * with the microseconds field. + * + * This returns an instance of a custom time zone class which skips a length + * of time equal to shiftNanoseconds (a number), at the Temporal.Instant + * shiftInstant. Before shiftInstant, it's identical to UTC, and after + * shiftInstant it's a constant-offset time zone. + * + * It provides a getPossibleInstantsForCalledWith member which is an array + * with the result of calling toString() on any PlainDateTimes passed to + * getPossibleInstantsFor(). + */ + oneShiftTimeZone(shiftInstant, shiftNanoseconds) { + class OneShiftTimeZone extends Temporal.TimeZone { + constructor(shiftInstant, shiftNanoseconds) { + super("+00:00"); + this._shiftInstant = shiftInstant; + this._epoch1 = shiftInstant.epochNanoseconds; + this._epoch2 = this._epoch1 + BigInt(shiftNanoseconds); + this._shiftNanoseconds = shiftNanoseconds; + this._shift = new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, this._shiftNanoseconds); + this.getPossibleInstantsForCalledWith = []; + } + + _isBeforeShift(instant) { + return instant.epochNanoseconds < this._epoch1; + } + + getOffsetNanosecondsFor(instant) { + return this._isBeforeShift(instant) ? 0 : this._shiftNanoseconds; + } + + getPossibleInstantsFor(plainDateTime) { + this.getPossibleInstantsForCalledWith.push(plainDateTime.toString()); + const [instant] = super.getPossibleInstantsFor(plainDateTime); + if (this._shiftNanoseconds > 0) { + if (this._isBeforeShift(instant)) return [instant]; + if (instant.epochNanoseconds < this._epoch2) return []; + return [instant.subtract(this._shift)]; + } + if (instant.epochNanoseconds < this._epoch2) return [instant]; + const shifted = instant.subtract(this._shift); + if (this._isBeforeShift(instant)) return [instant, shifted]; + return [shifted]; + } + + getNextTransition(instant) { + return this._isBeforeShift(instant) ? this._shiftInstant : null; + } + + getPreviousTransition(instant) { + return this._isBeforeShift(instant) ? null : this._shiftInstant; + } + + toString() { + return "Custom/One_Shift"; + } + } + return new OneShiftTimeZone(shiftInstant, shiftNanoseconds); + }, + + /* + * propertyBagObserver(): + * Returns an object that behaves like the given propertyBag but tracks Get + * and Has operations on any of its properties, by appending messages to an + * array. If the value of a property in propertyBag is a primitive, the value + * of the returned object's property will additionally be a + * TemporalHelpers.toPrimitiveObserver that will track calls to its toString + * and valueOf methods in the same array. This is for the purpose of testing + * order of operations that are observable from user code. objectName is used + * in the log. + */ + propertyBagObserver(calls, propertyBag, objectName) { + return new Proxy(propertyBag, { + ownKeys(target) { + calls.push(`ownKeys ${objectName}`); + return Reflect.ownKeys(target); + }, + getOwnPropertyDescriptor(target, key) { + calls.push(`getOwnPropertyDescriptor ${formatPropertyName(key, objectName)}`); + return Reflect.getOwnPropertyDescriptor(target, key); + }, + get(target, key, receiver) { + calls.push(`get ${formatPropertyName(key, objectName)}`); + const result = Reflect.get(target, key, receiver); + if (result === undefined) { + return undefined; + } + if ((result !== null && typeof result === "object") || typeof result === "function") { + return result; + } + return TemporalHelpers.toPrimitiveObserver(calls, result, `${formatPropertyName(key, objectName)}`); + }, + has(target, key) { + calls.push(`has ${formatPropertyName(key, objectName)}`); + return Reflect.has(target, key); + }, + }); + }, + + /* + * specificOffsetTimeZone(): + * + * This returns an instance of a custom time zone class, which returns a + * specific custom value from its getOffsetNanosecondsFrom() method. This is + * for the purpose of testing the validation of what this method returns. + * + * It also returns an empty array from getPossibleInstantsFor(), so as to + * trigger calls to getOffsetNanosecondsFor() when used from the + * BuiltinTimeZoneGetInstantFor operation. + */ + specificOffsetTimeZone(offsetValue) { + class SpecificOffsetTimeZone extends Temporal.TimeZone { + constructor(offsetValue) { + super("UTC"); + this._offsetValue = offsetValue; + } + + getOffsetNanosecondsFor() { + return this._offsetValue; + } + + getPossibleInstantsFor() { + return []; + } + } + return new SpecificOffsetTimeZone(offsetValue); + }, + + /* + * springForwardFallBackTimeZone(): + * + * This returns an instance of a custom time zone class that implements one + * single spring-forward/fall-back transition, for the purpose of testing the + * disambiguation option, without depending on system time zone data. + * + * The spring-forward occurs at epoch second 954669600 (2000-04-02T02:00 + * local) and goes from offset -08:00 to -07:00. + * + * The fall-back occurs at epoch second 972810000 (2000-10-29T02:00 local) and + * goes from offset -07:00 to -08:00. + */ + springForwardFallBackTimeZone() { + const { compare } = Temporal.PlainDateTime; + const springForwardLocal = new Temporal.PlainDateTime(2000, 4, 2, 2); + const springForwardEpoch = 954669600_000_000_000n; + const fallBackLocal = new Temporal.PlainDateTime(2000, 10, 29, 1); + const fallBackEpoch = 972810000_000_000_000n; + const winterOffset = new Temporal.TimeZone('-08:00'); + const summerOffset = new Temporal.TimeZone('-07:00'); + + class SpringForwardFallBackTimeZone extends Temporal.TimeZone { + constructor() { + super("-08:00"); + } + + getOffsetNanosecondsFor(instant) { + if (instant.epochNanoseconds < springForwardEpoch || + instant.epochNanoseconds >= fallBackEpoch) { + return winterOffset.getOffsetNanosecondsFor(instant); + } + return summerOffset.getOffsetNanosecondsFor(instant); + } + + getPossibleInstantsFor(datetime) { + if (compare(datetime, springForwardLocal) >= 0 && compare(datetime, springForwardLocal.add({ hours: 1 })) < 0) { + return []; + } + if (compare(datetime, fallBackLocal) >= 0 && compare(datetime, fallBackLocal.add({ hours: 1 })) < 0) { + return [summerOffset.getInstantFor(datetime), winterOffset.getInstantFor(datetime)]; + } + if (compare(datetime, springForwardLocal) < 0 || compare(datetime, fallBackLocal) >= 0) { + return [winterOffset.getInstantFor(datetime)]; + } + return [summerOffset.getInstantFor(datetime)]; + } + + getPreviousTransition(instant) { + if (instant.epochNanoseconds > fallBackEpoch) return new Temporal.Instant(fallBackEpoch); + if (instant.epochNanoseconds > springForwardEpoch) return new Temporal.Instant(springForwardEpoch); + return null; + } + + getNextTransition(instant) { + if (instant.epochNanoseconds < springForwardEpoch) return new Temporal.Instant(springForwardEpoch); + if (instant.epochNanoseconds < fallBackEpoch) return new Temporal.Instant(fallBackEpoch); + return null; + } + + get id() { + return "Custom/Spring_Fall"; + } + + toString() { + return "Custom/Spring_Fall"; + } + } + return new SpringForwardFallBackTimeZone(); + }, + + /* + * timeZoneObserver: + * A custom calendar that behaves exactly like the UTC time zone but tracks + * calls to any of its methods, and Get/Has operations on its properties, by + * appending messages to an array. This is for the purpose of testing order of + * operations that are observable from user code. objectName is used in the + * log. methodOverrides is an optional object containing properties with the + * same name as Temporal.TimeZone methods. If the property value is a function + * it will be called with the proper arguments instead of the UTC method. + * Otherwise, the property value will be returned directly. + */ + timeZoneObserver(calls, objectName, methodOverrides = {}) { + const utc = new Temporal.TimeZone("UTC"); + const trackingMethods = { + id: "UTC", + }; + // Automatically generate the methods + ["getOffsetNanosecondsFor", "getPossibleInstantsFor", "toString"].forEach((methodName) => { + trackingMethods[methodName] = function (...args) { + calls.push(`call ${formatPropertyName(methodName, objectName)}`); + if (methodName in methodOverrides) { + const value = methodOverrides[methodName]; + return typeof value === "function" ? value(...args) : value; + } + return utc[methodName](...args); + }; + }); + return new Proxy(trackingMethods, { + get(target, key, receiver) { + const result = Reflect.get(target, key, receiver); + calls.push(`get ${formatPropertyName(key, objectName)}`); + return result; + }, + has(target, key) { + calls.push(`has ${formatPropertyName(key, objectName)}`); + return Reflect.has(target, key); + }, + }); + }, + + /* + * Returns an object that will append logs of any Gets or Calls of its valueOf + * or toString properties to the array calls. Both valueOf and toString will + * return the actual primitiveValue. propertyName is used in the log. + */ + toPrimitiveObserver(calls, primitiveValue, propertyName) { + return { + get valueOf() { + calls.push(`get ${propertyName}.valueOf`); + return function () { + calls.push(`call ${propertyName}.valueOf`); + return primitiveValue; + }; + }, + get toString() { + calls.push(`get ${propertyName}.toString`); + return function () { + calls.push(`call ${propertyName}.toString`); + if (primitiveValue === undefined) return undefined; + return primitiveValue.toString(); + }; + }, + }; + }, + + /* + * An object containing further methods that return arrays of ISO strings, for + * testing parsers. + */ + ISO: { + /* + * PlainMonthDay strings that are not valid. + */ + plainMonthDayStringsInvalid() { + return [ + "11-18junk", + ]; + }, + + /* + * PlainMonthDay strings that are valid and that should produce October 1st. + */ + plainMonthDayStringsValid() { + return [ + "10-01", + "1001", + "1965-10-01", + "1976-10-01T152330.1+00:00", + "19761001T15:23:30.1+00:00", + "1976-10-01T15:23:30.1+0000", + "1976-10-01T152330.1+0000", + "19761001T15:23:30.1+0000", + "19761001T152330.1+00:00", + "19761001T152330.1+0000", + "+001976-10-01T152330.1+00:00", + "+0019761001T15:23:30.1+00:00", + "+001976-10-01T15:23:30.1+0000", + "+001976-10-01T152330.1+0000", + "+0019761001T15:23:30.1+0000", + "+0019761001T152330.1+00:00", + "+0019761001T152330.1+0000", + "1976-10-01T15:23:00", + "1976-10-01T15:23", + "1976-10-01T15", + "1976-10-01", + "--10-01", + "--1001", + ]; + }, + + /* + * PlainTime strings that may be mistaken for PlainMonthDay or + * PlainYearMonth strings, and so require a time designator. + */ + plainTimeStringsAmbiguous() { + const ambiguousStrings = [ + "2021-12", // ambiguity between YYYY-MM and HHMM-UU + "2021-12[-12:00]", // ditto, TZ does not disambiguate + "1214", // ambiguity between MMDD and HHMM + "0229", // ditto, including MMDD that doesn't occur every year + "1130", // ditto, including DD that doesn't occur in every month + "12-14", // ambiguity between MM-DD and HH-UU + "12-14[-14:00]", // ditto, TZ does not disambiguate + "202112", // ambiguity between YYYYMM and HHMMSS + "202112[UTC]", // ditto, TZ does not disambiguate + ]; + // Adding a calendar annotation to one of these strings must not cause + // disambiguation in favour of time. + const stringsWithCalendar = ambiguousStrings.map((s) => s + '[u-ca=iso8601]'); + return ambiguousStrings.concat(stringsWithCalendar); + }, + + /* + * PlainTime strings that are of similar form to PlainMonthDay and + * PlainYearMonth strings, but are not ambiguous due to components that + * aren't valid as months or days. + */ + plainTimeStringsUnambiguous() { + return [ + "2021-13", // 13 is not a month + "202113", // ditto + "2021-13[-13:00]", // ditto + "202113[-13:00]", // ditto + "0000-00", // 0 is not a month + "000000", // ditto + "0000-00[UTC]", // ditto + "000000[UTC]", // ditto + "1314", // 13 is not a month + "13-14", // ditto + "1232", // 32 is not a day + "0230", // 30 is not a day in February + "0631", // 31 is not a day in June + "0000", // 0 is neither a month nor a day + "00-00", // ditto + ]; + }, + + /* + * PlainYearMonth-like strings that are not valid. + */ + plainYearMonthStringsInvalid() { + return [ + "2020-13", + ]; + }, + + /* + * PlainYearMonth-like strings that are valid and should produce November + * 1976 in the ISO 8601 calendar. + */ + plainYearMonthStringsValid() { + return [ + "1976-11", + "1976-11-10", + "1976-11-01T09:00:00+00:00", + "1976-11-01T00:00:00+05:00", + "197611", + "+00197611", + "1976-11-18T15:23:30.1\u221202:00", + "1976-11-18T152330.1+00:00", + "19761118T15:23:30.1+00:00", + "1976-11-18T15:23:30.1+0000", + "1976-11-18T152330.1+0000", + "19761118T15:23:30.1+0000", + "19761118T152330.1+00:00", + "19761118T152330.1+0000", + "+001976-11-18T152330.1+00:00", + "+0019761118T15:23:30.1+00:00", + "+001976-11-18T15:23:30.1+0000", + "+001976-11-18T152330.1+0000", + "+0019761118T15:23:30.1+0000", + "+0019761118T152330.1+00:00", + "+0019761118T152330.1+0000", + "1976-11-18T15:23", + "1976-11-18T15", + "1976-11-18", + ]; + }, + + /* + * PlainYearMonth-like strings that are valid and should produce November of + * the ISO year -9999. + */ + plainYearMonthStringsValidNegativeYear() { + return [ + "\u2212009999-11", + ]; + }, + } +}; diff --git a/harness/testAtomics.js b/harness/testAtomics.js new file mode 100644 index 0000000000000000000000000000000000000000..8dd9ff365fa390adbc892bc72e91f77cdd85b9f0 --- /dev/null +++ b/harness/testAtomics.js @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Collection of functions used to assert the correctness of SharedArrayBuffer objects. +defines: + - testWithAtomicsOutOfBoundsIndices + - testWithAtomicsInBoundsIndices + - testWithAtomicsNonViewValues +---*/ + + +/** + * Calls the provided function for a each bad index that should throw a + * RangeError when passed to an Atomics method on a SAB-backed view where + * index 125 is out of range. + * + * @param f - the function to call for each bad index. + */ +function testWithAtomicsOutOfBoundsIndices(f) { + var bad_indices = [ + function(view) { return -1; }, + function(view) { return view.length; }, + function(view) { return view.length * 2; }, + function(view) { return Number.POSITIVE_INFINITY; }, + function(view) { return Number.NEGATIVE_INFINITY; }, + function(view) { return { valueOf: function() { return 125; } }; }, + function(view) { return { toString: function() { return '125'; }, valueOf: false }; }, // non-callable valueOf triggers invocation of toString + ]; + + for (var i = 0; i < bad_indices.length; ++i) { + var IdxGen = bad_indices[i]; + try { + f(IdxGen); + } catch (e) { + e.message += ' (Testing with index gen ' + IdxGen + '.)'; + throw e; + } + } +} + +/** + * Calls the provided function for each good index that should not throw when + * passed to an Atomics method on a SAB-backed view. + * + * The view must have length greater than zero. + * + * @param f - the function to call for each good index. + */ +function testWithAtomicsInBoundsIndices(f) { + // Most of these are eventually coerced to +0 by ToIndex. + var good_indices = [ + function(view) { return 0/-1; }, + function(view) { return '-0'; }, + function(view) { return undefined; }, + function(view) { return NaN; }, + function(view) { return 0.5; }, + function(view) { return '0.5'; }, + function(view) { return -0.9; }, + function(view) { return { password: 'qumquat' }; }, + function(view) { return view.length - 1; }, + function(view) { return { valueOf: function() { return 0; } }; }, + function(view) { return { toString: function() { return '0'; }, valueOf: false }; }, // non-callable valueOf triggers invocation of toString + ]; + + for (var i = 0; i < good_indices.length; ++i) { + var IdxGen = good_indices[i]; + try { + f(IdxGen); + } catch (e) { + e.message += ' (Testing with index gen ' + IdxGen + '.)'; + throw e; + } + } +} + +/** + * Calls the provided function for each value that should throw a TypeError + * when passed to an Atomics method as a view. + * + * @param f - the function to call for each non-view value. + */ + +function testWithAtomicsNonViewValues(f) { + var values = [ + null, + undefined, + true, + false, + new Boolean(true), + 10, + 3.14, + new Number(4), + 'Hi there', + new Date, + /a*utomaton/g, + { password: 'qumquat' }, + new DataView(new ArrayBuffer(10)), + new ArrayBuffer(128), + new SharedArrayBuffer(128), + new Error('Ouch'), + [1,1,2,3,5,8], + function(x) { return -x; }, + Symbol('halleluja'), + // TODO: Proxy? + Object, + Int32Array, + Date, + Math, + Atomics + ]; + + for (var i = 0; i < values.length; ++i) { + var nonView = values[i]; + try { + f(nonView); + } catch (e) { + e.message += ' (Testing with non-view value ' + nonView + '.)'; + throw e; + } + } +} + diff --git a/harness/testBigIntTypedArray.js b/harness/testBigIntTypedArray.js new file mode 100644 index 0000000000000000000000000000000000000000..4956aaa7e35116df7f6d0c5d20392e68477d7a45 --- /dev/null +++ b/harness/testBigIntTypedArray.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/harness/testIntl.js b/harness/testIntl.js new file mode 100644 index 0000000000000000000000000000000000000000..94efe546c30587cf027fbd52d83e243aa03ca7d0 --- /dev/null +++ b/harness/testIntl.js @@ -0,0 +1,2510 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + This file contains shared functions for the tests in the conformance test + suite for the ECMAScript Internationalization API. +author: Norbert Lindenberg +defines: + - testWithIntlConstructors + - taintDataProperty + - taintMethod + - taintProperties + - taintArray + - getLocaleSupportInfo + - getInvalidLanguageTags + - isCanonicalizedStructurallyValidLanguageTag + - getInvalidLocaleArguments + - testOption + - testForUnwantedRegExpChanges + - allCalendars + - allCollations + - allNumberingSystems + - isValidNumberingSystem + - numberingSystemDigits + - allSimpleSanctionedUnits + - testNumberFormat + - getDateTimeComponents + - getDateTimeComponentValues + - isCanonicalizedStructurallyValidTimeZoneName +---*/ +/** + */ + + +/** + * @description Calls the provided function for every service constructor in + * the Intl object. + * @param {Function} f the function to call for each service constructor in + * the Intl object. + * @param {Function} Constructor the constructor object to test with. + */ +function testWithIntlConstructors(f) { + var constructors = ["Collator", "NumberFormat", "DateTimeFormat"]; + + // Optionally supported Intl constructors. + // NB: Intl.Locale isn't an Intl service constructor! + // Intl.DisplayNames cannot be called without type in options. + ["PluralRules", "RelativeTimeFormat", "ListFormat"].forEach(function(constructor) { + if (typeof Intl[constructor] === "function") { + constructors[constructors.length] = constructor; + } + }); + + constructors.forEach(function (constructor) { + var Constructor = Intl[constructor]; + try { + f(Constructor); + } catch (e) { + e.message += " (Testing with " + constructor + ".)"; + throw e; + } + }); +} + + +/** + * Taints a named data property of the given object by installing + * a setter that throws an exception. + * @param {object} obj the object whose data property to taint + * @param {string} property the property to taint + */ +function taintDataProperty(obj, property) { + Object.defineProperty(obj, property, { + set: function(value) { + throw new Test262Error("Client code can adversely affect behavior: setter for " + property + "."); + }, + enumerable: false, + configurable: true + }); +} + + +/** + * Taints a named method of the given object by replacing it with a function + * that throws an exception. + * @param {object} obj the object whose method to taint + * @param {string} property the name of the method to taint + */ +function taintMethod(obj, property) { + Object.defineProperty(obj, property, { + value: function() { + throw new Test262Error("Client code can adversely affect behavior: method " + property + "."); + }, + writable: true, + enumerable: false, + configurable: true + }); +} + + +/** + * Taints the given properties (and similarly named properties) by installing + * setters on Object.prototype that throw exceptions. + * @param {Array} properties an array of property names to taint + */ +function taintProperties(properties) { + properties.forEach(function (property) { + var adaptedProperties = [property, "__" + property, "_" + property, property + "_", property + "__"]; + adaptedProperties.forEach(function (property) { + taintDataProperty(Object.prototype, property); + }); + }); +} + + +/** + * Taints the Array object by creating a setter for the property "0" and + * replacing some key methods with functions that throw exceptions. + */ +function taintArray() { + taintDataProperty(Array.prototype, "0"); + taintMethod(Array.prototype, "indexOf"); + taintMethod(Array.prototype, "join"); + taintMethod(Array.prototype, "push"); + taintMethod(Array.prototype, "slice"); + taintMethod(Array.prototype, "sort"); +} + + +/** + * Gets locale support info for the given constructor object, which must be one + * of Intl constructors. + * @param {object} Constructor the constructor for which to get locale support info + * @param {object} options the options while calling the constructor + * @return {object} locale support info with the following properties: + * supported: array of fully supported language tags + * byFallback: array of language tags that are supported through fallbacks + * unsupported: array of unsupported language tags + */ +function getLocaleSupportInfo(Constructor, options) { + var languages = ["zh", "es", "en", "hi", "ur", "ar", "ja", "pa"]; + var scripts = ["Latn", "Hans", "Deva", "Arab", "Jpan", "Hant", "Guru"]; + var countries = ["CN", "IN", "US", "PK", "JP", "TW", "HK", "SG", "419"]; + + var allTags = []; + var i, j, k; + var language, script, country; + for (i = 0; i < languages.length; i++) { + language = languages[i]; + allTags.push(language); + for (j = 0; j < scripts.length; j++) { + script = scripts[j]; + allTags.push(language + "-" + script); + for (k = 0; k < countries.length; k++) { + country = countries[k]; + allTags.push(language + "-" + script + "-" + country); + } + } + for (k = 0; k < countries.length; k++) { + country = countries[k]; + allTags.push(language + "-" + country); + } + } + + var supported = []; + var byFallback = []; + var unsupported = []; + for (i = 0; i < allTags.length; i++) { + var request = allTags[i]; + var result = new Constructor([request], options).resolvedOptions().locale; + if (request === result) { + supported.push(request); + } else if (request.indexOf(result) === 0) { + byFallback.push(request); + } else { + unsupported.push(request); + } + } + + return { + supported: supported, + byFallback: byFallback, + unsupported: unsupported + }; +} + + +/** + * Returns an array of strings for which IsStructurallyValidLanguageTag() returns false + */ +function getInvalidLanguageTags() { + var invalidLanguageTags = [ + "", // empty tag + "i", // singleton alone + "x", // private use without subtag + "u", // extension singleton in first place + "419", // region code in first place + "u-nu-latn-cu-bob", // extension sequence without language + "hans-cmn-cn", // "hans" could theoretically be a 4-letter language code, + // but those can't be followed by extlang codes. + "cmn-hans-cn-u-u", // duplicate singleton + "cmn-hans-cn-t-u-ca-u", // duplicate singleton + "de-gregory-gregory", // duplicate variant + "*", // language range + "de-*", // language range + "中文", // non-ASCII letters + "en-ß", // non-ASCII letters + "ıd", // non-ASCII letters + "es-Latn-latn", // two scripts + "pl-PL-pl", // two regions + "u-ca-gregory", // extension in first place + "de-1996-1996", // duplicate numeric variant + "pt-u-ca-gregory-u-nu-latn", // duplicate singleton subtag + + // Invalid tags starting with: https://github.com/tc39/ecma402/pull/289 + "no-nyn", // regular grandfathered in BCP47, but invalid in UTS35 + "i-klingon", // irregular grandfathered in BCP47, but invalid in UTS35 + "zh-hak-CN", // language with extlang in BCP47, but invalid in UTS35 + "sgn-ils", // language with extlang in BCP47, but invalid in UTS35 + "x-foo", // privateuse-only in BCP47, but invalid in UTS35 + "x-en-US-12345", // more privateuse-only variants. + "x-12345-12345-en-US", + "x-en-US-12345-12345", + "x-en-u-foo", + "x-en-u-foo-u-bar", + "x-u-foo", + + // underscores in different parts of the language tag + "de_DE", + "DE_de", + "cmn_Hans", + "cmn-hans_cn", + "es_419", + "es-419-u-nu-latn-cu_bob", + "i_klingon", + "cmn-hans-cn-t-ca-u-ca-x_t-u", + "enochian_enochian", + "de-gregory_u-ca-gregory", + + "en\u0000", // null-terminator sequence + " en", // leading whitespace + "en ", // trailing whitespace + "it-IT-Latn", // country before script tag + "de-u", // incomplete Unicode extension sequences + "de-u-", + "de-u-ca-", + "de-u-ca-gregory-", + "si-x", // incomplete private-use tags + "x-", + "x-y-", + ]; + + // make sure the data above is correct + for (var i = 0; i < invalidLanguageTags.length; ++i) { + var invalidTag = invalidLanguageTags[i]; + assert( + !isCanonicalizedStructurallyValidLanguageTag(invalidTag), + "Test data \"" + invalidTag + "\" is a canonicalized and structurally valid language tag." + ); + } + + return invalidLanguageTags; +} + + +/** + * @description Tests whether locale is a String value representing a + * structurally valid and canonicalized BCP 47 language tag, as defined in + * sections 6.2.2 and 6.2.3 of the ECMAScript Internationalization API + * Specification. + * @param {String} locale the string to be tested. + * @result {Boolean} whether the test succeeded. + */ +function isCanonicalizedStructurallyValidLanguageTag(locale) { + + /** + * Regular expression defining Unicode BCP 47 Locale Identifiers. + * + * Spec: https://unicode.org/reports/tr35/#Unicode_locale_identifier + */ + var alpha = "[a-z]", + digit = "[0-9]", + alphanum = "[a-z0-9]", + variant = "(" + alphanum + "{5,8}|(?:" + digit + alphanum + "{3}))", + region = "(" + alpha + "{2}|" + digit + "{3})", + script = "(" + alpha + "{4})", + language = "(" + alpha + "{2,3}|" + alpha + "{5,8})", + privateuse = "(x(-[a-z0-9]{1,8})+)", + singleton = "(" + digit + "|[a-wy-z])", + attribute= "(" + alphanum + "{3,8})", + keyword = "(" + alphanum + alpha + "(-" + alphanum + "{3,8})*)", + unicode_locale_extensions = "(u((-" + keyword + ")+|((-" + attribute + ")+(-" + keyword + ")*)))", + tlang = "(" + language + "(-" + script + ")?(-" + region + ")?(-" + variant + ")*)", + tfield = "(" + alpha + digit + "(-" + alphanum + "{3,8})+)", + transformed_extensions = "(t((-" + tlang + "(-" + tfield + ")*)|(-" + tfield + ")+))", + other_singleton = "(" + digit + "|[a-sv-wy-z])", + other_extensions = "(" + other_singleton + "(-" + alphanum + "{2,8})+)", + extension = "(" + unicode_locale_extensions + "|" + transformed_extensions + "|" + other_extensions + ")", + locale_id = language + "(-" + script + ")?(-" + region + ")?(-" + variant + ")*(-" + extension + ")*(-" + privateuse + ")?", + languageTag = "^(" + locale_id + ")$", + languageTagRE = new RegExp(languageTag, "i"); + + var duplicateSingleton = "-" + singleton + "-(.*-)?\\1(?!" + alphanum + ")", + duplicateSingletonRE = new RegExp(duplicateSingleton, "i"), + duplicateVariant = "(" + alphanum + "{2,8}-)+" + variant + "-(" + alphanum + "{2,8}-)*\\2(?!" + alphanum + ")", + duplicateVariantRE = new RegExp(duplicateVariant, "i"); + + var transformKeyRE = new RegExp("^" + alpha + digit + "$", "i"); + + /** + * Verifies that the given string is a well-formed Unicode BCP 47 Locale Identifier + * with no duplicate variant or singleton subtags. + * + * Spec: ECMAScript Internationalization API Specification, draft, 6.2.2. + */ + function isStructurallyValidLanguageTag(locale) { + if (!languageTagRE.test(locale)) { + return false; + } + locale = locale.split(/-x-/)[0]; + return !duplicateSingletonRE.test(locale) && !duplicateVariantRE.test(locale); + } + + + /** + * Mappings from complete tags to preferred values. + * + * Spec: http://unicode.org/reports/tr35/#Identifiers + * Version: CLDR, version 36.1 + */ + var __tagMappings = { + // property names must be in lower case; values in canonical form + + "art-lojban": "jbo", + "cel-gaulish": "xtg", + "zh-guoyu": "zh", + "zh-hakka": "hak", + "zh-xiang": "hsn", + }; + + + /** + * Mappings from language subtags to preferred values. + * + * Spec: http://unicode.org/reports/tr35/#Identifiers + * Version: CLDR, version 36.1 + */ + var __languageMappings = { + // property names and values must be in canonical case + + "aam": "aas", + "aar": "aa", + "abk": "ab", + "adp": "dz", + "afr": "af", + "aju": "jrb", + "aka": "ak", + "alb": "sq", + "als": "sq", + "amh": "am", + "ara": "ar", + "arb": "ar", + "arg": "an", + "arm": "hy", + "asd": "snz", + "asm": "as", + "aue": "ktz", + "ava": "av", + "ave": "ae", + "aym": "ay", + "ayr": "ay", + "ayx": "nun", + "aze": "az", + "azj": "az", + "bak": "ba", + "bam": "bm", + "baq": "eu", + "bcc": "bal", + "bcl": "bik", + "bel": "be", + "ben": "bn", + "bgm": "bcg", + "bh": "bho", + "bih": "bho", + "bis": "bi", + "bjd": "drl", + "bod": "bo", + "bos": "bs", + "bre": "br", + "bul": "bg", + "bur": "my", + "bxk": "luy", + "bxr": "bua", + "cat": "ca", + "ccq": "rki", + "ces": "cs", + "cha": "ch", + "che": "ce", + "chi": "zh", + "chu": "cu", + "chv": "cv", + "cjr": "mom", + "cka": "cmr", + "cld": "syr", + "cmk": "xch", + "cmn": "zh", + "cor": "kw", + "cos": "co", + "coy": "pij", + "cqu": "quh", + "cre": "cr", + "cwd": "cr", + "cym": "cy", + "cze": "cs", + "dan": "da", + "deu": "de", + "dgo": "doi", + "dhd": "mwr", + "dik": "din", + "diq": "zza", + "dit": "dif", + "div": "dv", + "drh": "mn", + "dut": "nl", + "dzo": "dz", + "ekk": "et", + "ell": "el", + "emk": "man", + "eng": "en", + "epo": "eo", + "esk": "ik", + "est": "et", + "eus": "eu", + "ewe": "ee", + "fao": "fo", + "fas": "fa", + "fat": "ak", + "fij": "fj", + "fin": "fi", + "fra": "fr", + "fre": "fr", + "fry": "fy", + "fuc": "ff", + "ful": "ff", + "gav": "dev", + "gaz": "om", + "gbo": "grb", + "geo": "ka", + "ger": "de", + "gfx": "vaj", + "ggn": "gvr", + "gla": "gd", + "gle": "ga", + "glg": "gl", + "glv": "gv", + "gno": "gon", + "gre": "el", + "grn": "gn", + "gti": "nyc", + "gug": "gn", + "guj": "gu", + "guv": "duz", + "gya": "gba", + "hat": "ht", + "hau": "ha", + "hdn": "hai", + "hea": "hmn", + "heb": "he", + "her": "hz", + "him": "srx", + "hin": "hi", + "hmo": "ho", + "hrr": "jal", + "hrv": "hr", + "hun": "hu", + "hye": "hy", + "ibi": "opa", + "ibo": "ig", + "ice": "is", + "ido": "io", + "iii": "ii", + "ike": "iu", + "iku": "iu", + "ile": "ie", + "ilw": "gal", + "in": "id", + "ina": "ia", + "ind": "id", + "ipk": "ik", + "isl": "is", + "ita": "it", + "iw": "he", + "jav": "jv", + "jeg": "oyb", + "ji": "yi", + "jpn": "ja", + "jw": "jv", + "kal": "kl", + "kan": "kn", + "kas": "ks", + "kat": "ka", + "kau": "kr", + "kaz": "kk", + "kgc": "tdf", + "kgh": "kml", + "khk": "mn", + "khm": "km", + "kik": "ki", + "kin": "rw", + "kir": "ky", + "kmr": "ku", + "knc": "kr", + "kng": "kg", + "knn": "kok", + "koj": "kwv", + "kom": "kv", + "kon": "kg", + "kor": "ko", + "kpv": "kv", + "krm": "bmf", + "ktr": "dtp", + "kua": "kj", + "kur": "ku", + "kvs": "gdj", + "kwq": "yam", + "kxe": "tvd", + "kzj": "dtp", + "kzt": "dtp", + "lao": "lo", + "lat": "la", + "lav": "lv", + "lbk": "bnc", + "lii": "raq", + "lim": "li", + "lin": "ln", + "lit": "lt", + "llo": "ngt", + "lmm": "rmx", + "ltz": "lb", + "lub": "lu", + "lug": "lg", + "lvs": "lv", + "mac": "mk", + "mah": "mh", + "mal": "ml", + "mao": "mi", + "mar": "mr", + "may": "ms", + "meg": "cir", + "mhr": "chm", + "mkd": "mk", + "mlg": "mg", + "mlt": "mt", + "mnk": "man", + "mo": "ro", + "mol": "ro", + "mon": "mn", + "mri": "mi", + "msa": "ms", + "mst": "mry", + "mup": "raj", + "mwj": "vaj", + "mya": "my", + "myd": "aog", + "myt": "mry", + "nad": "xny", + "nau": "na", + "nav": "nv", + "nbl": "nr", + "ncp": "kdz", + "nde": "nd", + "ndo": "ng", + "nep": "ne", + "nld": "nl", + "nno": "nn", + "nns": "nbr", + "nnx": "ngv", + "no": "nb", + "nob": "nb", + "nor": "nb", + "npi": "ne", + "nts": "pij", + "nya": "ny", + "oci": "oc", + "ojg": "oj", + "oji": "oj", + "ori": "or", + "orm": "om", + "ory": "or", + "oss": "os", + "oun": "vaj", + "pan": "pa", + "pbu": "ps", + "pcr": "adx", + "per": "fa", + "pes": "fa", + "pli": "pi", + "plt": "mg", + "pmc": "huw", + "pmu": "phr", + "pnb": "lah", + "pol": "pl", + "por": "pt", + "ppa": "bfy", + "ppr": "lcq", + "pry": "prt", + "pus": "ps", + "puz": "pub", + "que": "qu", + "quz": "qu", + "rmy": "rom", + "roh": "rm", + "ron": "ro", + "rum": "ro", + "run": "rn", + "rus": "ru", + "sag": "sg", + "san": "sa", + "sca": "hle", + "scc": "sr", + "scr": "hr", + "sin": "si", + "skk": "oyb", + "slk": "sk", + "slo": "sk", + "slv": "sl", + "sme": "se", + "smo": "sm", + "sna": "sn", + "snd": "sd", + "som": "so", + "sot": "st", + "spa": "es", + "spy": "kln", + "sqi": "sq", + "src": "sc", + "srd": "sc", + "srp": "sr", + "ssw": "ss", + "sun": "su", + "swa": "sw", + "swe": "sv", + "swh": "sw", + "tah": "ty", + "tam": "ta", + "tat": "tt", + "tdu": "dtp", + "tel": "te", + "tgk": "tg", + "tgl": "fil", + "tha": "th", + "thc": "tpo", + "thx": "oyb", + "tib": "bo", + "tie": "ras", + "tir": "ti", + "tkk": "twm", + "tl": "fil", + "tlw": "weo", + "tmp": "tyj", + "tne": "kak", + "ton": "to", + "tsf": "taj", + "tsn": "tn", + "tso": "ts", + "ttq": "tmh", + "tuk": "tk", + "tur": "tr", + "tw": "ak", + "twi": "ak", + "uig": "ug", + "ukr": "uk", + "umu": "del", + "uok": "ema", + "urd": "ur", + "uzb": "uz", + "uzn": "uz", + "ven": "ve", + "vie": "vi", + "vol": "vo", + "wel": "cy", + "wln": "wa", + "wol": "wo", + "xba": "cax", + "xho": "xh", + "xia": "acn", + "xkh": "waw", + "xpe": "kpe", + "xsj": "suj", + "xsl": "den", + "ybd": "rki", + "ydd": "yi", + "yid": "yi", + "yma": "lrr", + "ymt": "mtm", + "yor": "yo", + "yos": "zom", + "yuu": "yug", + "zai": "zap", + "zha": "za", + "zho": "zh", + "zsm": "ms", + "zul": "zu", + "zyb": "za", + }; + + + /** + * Mappings from region subtags to preferred values. + * + * Spec: http://unicode.org/reports/tr35/#Identifiers + * Version: CLDR, version 36.1 + */ + var __regionMappings = { + // property names and values must be in canonical case + + "004": "AF", + "008": "AL", + "010": "AQ", + "012": "DZ", + "016": "AS", + "020": "AD", + "024": "AO", + "028": "AG", + "031": "AZ", + "032": "AR", + "036": "AU", + "040": "AT", + "044": "BS", + "048": "BH", + "050": "BD", + "051": "AM", + "052": "BB", + "056": "BE", + "060": "BM", + "062": "034", + "064": "BT", + "068": "BO", + "070": "BA", + "072": "BW", + "074": "BV", + "076": "BR", + "084": "BZ", + "086": "IO", + "090": "SB", + "092": "VG", + "096": "BN", + "100": "BG", + "104": "MM", + "108": "BI", + "112": "BY", + "116": "KH", + "120": "CM", + "124": "CA", + "132": "CV", + "136": "KY", + "140": "CF", + "144": "LK", + "148": "TD", + "152": "CL", + "156": "CN", + "158": "TW", + "162": "CX", + "166": "CC", + "170": "CO", + "174": "KM", + "175": "YT", + "178": "CG", + "180": "CD", + "184": "CK", + "188": "CR", + "191": "HR", + "192": "CU", + "196": "CY", + "203": "CZ", + "204": "BJ", + "208": "DK", + "212": "DM", + "214": "DO", + "218": "EC", + "222": "SV", + "226": "GQ", + "230": "ET", + "231": "ET", + "232": "ER", + "233": "EE", + "234": "FO", + "238": "FK", + "239": "GS", + "242": "FJ", + "246": "FI", + "248": "AX", + "249": "FR", + "250": "FR", + "254": "GF", + "258": "PF", + "260": "TF", + "262": "DJ", + "266": "GA", + "268": "GE", + "270": "GM", + "275": "PS", + "276": "DE", + "278": "DE", + "280": "DE", + "288": "GH", + "292": "GI", + "296": "KI", + "300": "GR", + "304": "GL", + "308": "GD", + "312": "GP", + "316": "GU", + "320": "GT", + "324": "GN", + "328": "GY", + "332": "HT", + "334": "HM", + "336": "VA", + "340": "HN", + "344": "HK", + "348": "HU", + "352": "IS", + "356": "IN", + "360": "ID", + "364": "IR", + "368": "IQ", + "372": "IE", + "376": "IL", + "380": "IT", + "384": "CI", + "388": "JM", + "392": "JP", + "398": "KZ", + "400": "JO", + "404": "KE", + "408": "KP", + "410": "KR", + "414": "KW", + "417": "KG", + "418": "LA", + "422": "LB", + "426": "LS", + "428": "LV", + "430": "LR", + "434": "LY", + "438": "LI", + "440": "LT", + "442": "LU", + "446": "MO", + "450": "MG", + "454": "MW", + "458": "MY", + "462": "MV", + "466": "ML", + "470": "MT", + "474": "MQ", + "478": "MR", + "480": "MU", + "484": "MX", + "492": "MC", + "496": "MN", + "498": "MD", + "499": "ME", + "500": "MS", + "504": "MA", + "508": "MZ", + "512": "OM", + "516": "NA", + "520": "NR", + "524": "NP", + "528": "NL", + "531": "CW", + "533": "AW", + "534": "SX", + "535": "BQ", + "540": "NC", + "548": "VU", + "554": "NZ", + "558": "NI", + "562": "NE", + "566": "NG", + "570": "NU", + "574": "NF", + "578": "NO", + "580": "MP", + "581": "UM", + "583": "FM", + "584": "MH", + "585": "PW", + "586": "PK", + "591": "PA", + "598": "PG", + "600": "PY", + "604": "PE", + "608": "PH", + "612": "PN", + "616": "PL", + "620": "PT", + "624": "GW", + "626": "TL", + "630": "PR", + "634": "QA", + "638": "RE", + "642": "RO", + "643": "RU", + "646": "RW", + "652": "BL", + "654": "SH", + "659": "KN", + "660": "AI", + "662": "LC", + "663": "MF", + "666": "PM", + "670": "VC", + "674": "SM", + "678": "ST", + "682": "SA", + "686": "SN", + "688": "RS", + "690": "SC", + "694": "SL", + "702": "SG", + "703": "SK", + "704": "VN", + "705": "SI", + "706": "SO", + "710": "ZA", + "716": "ZW", + "720": "YE", + "724": "ES", + "728": "SS", + "729": "SD", + "732": "EH", + "736": "SD", + "740": "SR", + "744": "SJ", + "748": "SZ", + "752": "SE", + "756": "CH", + "760": "SY", + "762": "TJ", + "764": "TH", + "768": "TG", + "772": "TK", + "776": "TO", + "780": "TT", + "784": "AE", + "788": "TN", + "792": "TR", + "795": "TM", + "796": "TC", + "798": "TV", + "800": "UG", + "804": "UA", + "807": "MK", + "818": "EG", + "826": "GB", + "830": "JE", + "831": "GG", + "832": "JE", + "833": "IM", + "834": "TZ", + "840": "US", + "850": "VI", + "854": "BF", + "858": "UY", + "860": "UZ", + "862": "VE", + "876": "WF", + "882": "WS", + "886": "YE", + "887": "YE", + "891": "RS", + "894": "ZM", + "958": "AA", + "959": "QM", + "960": "QN", + "962": "QP", + "963": "QQ", + "964": "QR", + "965": "QS", + "966": "QT", + "967": "EU", + "968": "QV", + "969": "QW", + "970": "QX", + "971": "QY", + "972": "QZ", + "973": "XA", + "974": "XB", + "975": "XC", + "976": "XD", + "977": "XE", + "978": "XF", + "979": "XG", + "980": "XH", + "981": "XI", + "982": "XJ", + "983": "XK", + "984": "XL", + "985": "XM", + "986": "XN", + "987": "XO", + "988": "XP", + "989": "XQ", + "990": "XR", + "991": "XS", + "992": "XT", + "993": "XU", + "994": "XV", + "995": "XW", + "996": "XX", + "997": "XY", + "998": "XZ", + "999": "ZZ", + "BU": "MM", + "CS": "RS", + "CT": "KI", + "DD": "DE", + "DY": "BJ", + "FQ": "AQ", + "FX": "FR", + "HV": "BF", + "JT": "UM", + "MI": "UM", + "NH": "VU", + "NQ": "AQ", + "PU": "UM", + "PZ": "PA", + "QU": "EU", + "RH": "ZW", + "TP": "TL", + "UK": "GB", + "VD": "VN", + "WK": "UM", + "YD": "YE", + "YU": "RS", + "ZR": "CD", + }; + + + /** + * Complex mappings from language subtags to preferred values. + * + * Spec: http://unicode.org/reports/tr35/#Identifiers + * Version: CLDR, version 36.1 + */ + var __complexLanguageMappings = { + // property names and values must be in canonical case + + "cnr": {language: "sr", region: "ME"}, + "drw": {language: "fa", region: "AF"}, + "hbs": {language: "sr", script: "Latn"}, + "prs": {language: "fa", region: "AF"}, + "sh": {language: "sr", script: "Latn"}, + "swc": {language: "sw", region: "CD"}, + "tnf": {language: "fa", region: "AF"}, + }; + + + /** + * Complex mappings from region subtags to preferred values. + * + * Spec: http://unicode.org/reports/tr35/#Identifiers + * Version: CLDR, version 36.1 + */ + var __complexRegionMappings = { + // property names and values must be in canonical case + + "172": { + default: "RU", + "ab": "GE", + "az": "AZ", + "be": "BY", + "crh": "UA", + "gag": "MD", + "got": "UA", + "hy": "AM", + "ji": "UA", + "ka": "GE", + "kaa": "UZ", + "kk": "KZ", + "ku-Yezi": "GE", + "ky": "KG", + "os": "GE", + "rue": "UA", + "sog": "UZ", + "tg": "TJ", + "tk": "TM", + "tkr": "AZ", + "tly": "AZ", + "ttt": "AZ", + "ug-Cyrl": "KZ", + "uk": "UA", + "und-Armn": "AM", + "und-Chrs": "UZ", + "und-Geor": "GE", + "und-Goth": "UA", + "und-Sogd": "UZ", + "und-Sogo": "UZ", + "und-Yezi": "GE", + "uz": "UZ", + "xco": "UZ", + "xmf": "GE", + }, + "200": { + default: "CZ", + "sk": "SK", + }, + "530": { + default: "CW", + "vic": "SX", + }, + "532": { + default: "CW", + "vic": "SX", + }, + "536": { + default: "SA", + "akk": "IQ", + "ckb": "IQ", + "ku-Arab": "IQ", + "mis": "IQ", + "syr": "IQ", + "und-Hatr": "IQ", + "und-Syrc": "IQ", + "und-Xsux": "IQ", + }, + "582": { + default: "FM", + "mh": "MH", + "pau": "PW", + }, + "810": { + default: "RU", + "ab": "GE", + "az": "AZ", + "be": "BY", + "crh": "UA", + "et": "EE", + "gag": "MD", + "got": "UA", + "hy": "AM", + "ji": "UA", + "ka": "GE", + "kaa": "UZ", + "kk": "KZ", + "ku-Yezi": "GE", + "ky": "KG", + "lt": "LT", + "ltg": "LV", + "lv": "LV", + "os": "GE", + "rue": "UA", + "sgs": "LT", + "sog": "UZ", + "tg": "TJ", + "tk": "TM", + "tkr": "AZ", + "tly": "AZ", + "ttt": "AZ", + "ug-Cyrl": "KZ", + "uk": "UA", + "und-Armn": "AM", + "und-Chrs": "UZ", + "und-Geor": "GE", + "und-Goth": "UA", + "und-Sogd": "UZ", + "und-Sogo": "UZ", + "und-Yezi": "GE", + "uz": "UZ", + "vro": "EE", + "xco": "UZ", + "xmf": "GE", + }, + "890": { + default: "RS", + "bs": "BA", + "hr": "HR", + "mk": "MK", + "sl": "SI", + }, + "AN": { + default: "CW", + "vic": "SX", + }, + "NT": { + default: "SA", + "akk": "IQ", + "ckb": "IQ", + "ku-Arab": "IQ", + "mis": "IQ", + "syr": "IQ", + "und-Hatr": "IQ", + "und-Syrc": "IQ", + "und-Xsux": "IQ", + }, + "PC": { + default: "FM", + "mh": "MH", + "pau": "PW", + }, + "SU": { + default: "RU", + "ab": "GE", + "az": "AZ", + "be": "BY", + "crh": "UA", + "et": "EE", + "gag": "MD", + "got": "UA", + "hy": "AM", + "ji": "UA", + "ka": "GE", + "kaa": "UZ", + "kk": "KZ", + "ku-Yezi": "GE", + "ky": "KG", + "lt": "LT", + "ltg": "LV", + "lv": "LV", + "os": "GE", + "rue": "UA", + "sgs": "LT", + "sog": "UZ", + "tg": "TJ", + "tk": "TM", + "tkr": "AZ", + "tly": "AZ", + "ttt": "AZ", + "ug-Cyrl": "KZ", + "uk": "UA", + "und-Armn": "AM", + "und-Chrs": "UZ", + "und-Geor": "GE", + "und-Goth": "UA", + "und-Sogd": "UZ", + "und-Sogo": "UZ", + "und-Yezi": "GE", + "uz": "UZ", + "vro": "EE", + "xco": "UZ", + "xmf": "GE", + }, + }; + + + /** + * Mappings from variant subtags to preferred values. + * + * Spec: http://unicode.org/reports/tr35/#Identifiers + * Version: CLDR, version 36.1 + */ + var __variantMappings = { + // property names and values must be in canonical case + + "aaland": {type: "region", replacement: "AX"}, + "arevela": {type: "language", replacement: "hy"}, + "arevmda": {type: "language", replacement: "hyw"}, + "heploc": {type: "variant", replacement: "alalc97"}, + "polytoni": {type: "variant", replacement: "polyton"}, + }; + + + /** + * Mappings from Unicode extension subtags to preferred values. + * + * Spec: http://unicode.org/reports/tr35/#Identifiers + * Version: CLDR, version 36.1 + */ + var __unicodeMappings = { + // property names and values must be in canonical case + + "ca": { + "ethiopic-amete-alem": "ethioaa", + "islamicc": "islamic-civil", + }, + "kb": { + "yes": "true", + }, + "kc": { + "yes": "true", + }, + "kh": { + "yes": "true", + }, + "kk": { + "yes": "true", + }, + "kn": { + "yes": "true", + }, + "ks": { + "primary": "level1", + "tertiary": "level3", + }, + "ms": { + "imperial": "uksystem", + }, + "rg": { + "cn11": "cnbj", + "cn12": "cntj", + "cn13": "cnhe", + "cn14": "cnsx", + "cn15": "cnmn", + "cn21": "cnln", + "cn22": "cnjl", + "cn23": "cnhl", + "cn31": "cnsh", + "cn32": "cnjs", + "cn33": "cnzj", + "cn34": "cnah", + "cn35": "cnfj", + "cn36": "cnjx", + "cn37": "cnsd", + "cn41": "cnha", + "cn42": "cnhb", + "cn43": "cnhn", + "cn44": "cngd", + "cn45": "cngx", + "cn46": "cnhi", + "cn50": "cncq", + "cn51": "cnsc", + "cn52": "cngz", + "cn53": "cnyn", + "cn54": "cnxz", + "cn61": "cnsn", + "cn62": "cngs", + "cn63": "cnqh", + "cn64": "cnnx", + "cn65": "cnxj", + "cz10a": "cz110", + "cz10b": "cz111", + "cz10c": "cz112", + "cz10d": "cz113", + "cz10e": "cz114", + "cz10f": "cz115", + "cz611": "cz663", + "cz612": "cz632", + "cz613": "cz633", + "cz614": "cz634", + "cz615": "cz635", + "cz621": "cz641", + "cz622": "cz642", + "cz623": "cz643", + "cz624": "cz644", + "cz626": "cz646", + "cz627": "cz647", + "czjc": "cz31", + "czjm": "cz64", + "czka": "cz41", + "czkr": "cz52", + "czli": "cz51", + "czmo": "cz80", + "czol": "cz71", + "czpa": "cz53", + "czpl": "cz32", + "czpr": "cz10", + "czst": "cz20", + "czus": "cz42", + "czvy": "cz63", + "czzl": "cz72", + "fra": "frges", + "frb": "frnaq", + "frc": "frara", + "frd": "frbfc", + "fre": "frbre", + "frf": "frcvl", + "frg": "frges", + "frh": "frcor", + "fri": "frbfc", + "frj": "fridf", + "frk": "frocc", + "frl": "frnaq", + "frm": "frges", + "frn": "frocc", + "fro": "frhdf", + "frp": "frnor", + "frq": "frnor", + "frr": "frpdl", + "frs": "frhdf", + "frt": "frnaq", + "fru": "frpac", + "frv": "frara", + "laxn": "laxs", + "lud": "lucl", + "lug": "luec", + "lul": "luca", + "mrnkc": "mr13", + "no23": "no50", + "nzn": "nzauk", + "nzs": "nzcan", + "omba": "ombj", + "omsh": "omsj", + "plds": "pl02", + "plkp": "pl04", + "pllb": "pl08", + "plld": "pl10", + "pllu": "pl06", + "plma": "pl12", + "plmz": "pl14", + "plop": "pl16", + "plpd": "pl20", + "plpk": "pl18", + "plpm": "pl22", + "plsk": "pl26", + "plsl": "pl24", + "plwn": "pl28", + "plwp": "pl30", + "plzp": "pl32", + "tteto": "tttob", + "ttrcm": "ttmrc", + "ttwto": "tttob", + "twkhq": "twkhh", + "twtnq": "twtnn", + "twtpq": "twnwt", + "twtxq": "twtxg", + }, + "sd": { + "cn11": "cnbj", + "cn12": "cntj", + "cn13": "cnhe", + "cn14": "cnsx", + "cn15": "cnmn", + "cn21": "cnln", + "cn22": "cnjl", + "cn23": "cnhl", + "cn31": "cnsh", + "cn32": "cnjs", + "cn33": "cnzj", + "cn34": "cnah", + "cn35": "cnfj", + "cn36": "cnjx", + "cn37": "cnsd", + "cn41": "cnha", + "cn42": "cnhb", + "cn43": "cnhn", + "cn44": "cngd", + "cn45": "cngx", + "cn46": "cnhi", + "cn50": "cncq", + "cn51": "cnsc", + "cn52": "cngz", + "cn53": "cnyn", + "cn54": "cnxz", + "cn61": "cnsn", + "cn62": "cngs", + "cn63": "cnqh", + "cn64": "cnnx", + "cn65": "cnxj", + "cz10a": "cz110", + "cz10b": "cz111", + "cz10c": "cz112", + "cz10d": "cz113", + "cz10e": "cz114", + "cz10f": "cz115", + "cz611": "cz663", + "cz612": "cz632", + "cz613": "cz633", + "cz614": "cz634", + "cz615": "cz635", + "cz621": "cz641", + "cz622": "cz642", + "cz623": "cz643", + "cz624": "cz644", + "cz626": "cz646", + "cz627": "cz647", + "czjc": "cz31", + "czjm": "cz64", + "czka": "cz41", + "czkr": "cz52", + "czli": "cz51", + "czmo": "cz80", + "czol": "cz71", + "czpa": "cz53", + "czpl": "cz32", + "czpr": "cz10", + "czst": "cz20", + "czus": "cz42", + "czvy": "cz63", + "czzl": "cz72", + "fra": "frges", + "frb": "frnaq", + "frc": "frara", + "frd": "frbfc", + "fre": "frbre", + "frf": "frcvl", + "frg": "frges", + "frh": "frcor", + "fri": "frbfc", + "frj": "fridf", + "frk": "frocc", + "frl": "frnaq", + "frm": "frges", + "frn": "frocc", + "fro": "frhdf", + "frp": "frnor", + "frq": "frnor", + "frr": "frpdl", + "frs": "frhdf", + "frt": "frnaq", + "fru": "frpac", + "frv": "frara", + "laxn": "laxs", + "lud": "lucl", + "lug": "luec", + "lul": "luca", + "mrnkc": "mr13", + "no23": "no50", + "nzn": "nzauk", + "nzs": "nzcan", + "omba": "ombj", + "omsh": "omsj", + "plds": "pl02", + "plkp": "pl04", + "pllb": "pl08", + "plld": "pl10", + "pllu": "pl06", + "plma": "pl12", + "plmz": "pl14", + "plop": "pl16", + "plpd": "pl20", + "plpk": "pl18", + "plpm": "pl22", + "plsk": "pl26", + "plsl": "pl24", + "plwn": "pl28", + "plwp": "pl30", + "plzp": "pl32", + "tteto": "tttob", + "ttrcm": "ttmrc", + "ttwto": "tttob", + "twkhq": "twkhh", + "twtnq": "twtnn", + "twtpq": "twnwt", + "twtxq": "twtxg", + }, + "tz": { + "aqams": "nzakl", + "cnckg": "cnsha", + "cnhrb": "cnsha", + "cnkhg": "cnurc", + "cuba": "cuhav", + "egypt": "egcai", + "eire": "iedub", + "est": "utcw05", + "gmt0": "gmt", + "hongkong": "hkhkg", + "hst": "utcw10", + "iceland": "isrey", + "iran": "irthr", + "israel": "jeruslm", + "jamaica": "jmkin", + "japan": "jptyo", + "libya": "lytip", + "mst": "utcw07", + "navajo": "usden", + "poland": "plwaw", + "portugal": "ptlis", + "prc": "cnsha", + "roc": "twtpe", + "rok": "krsel", + "turkey": "trist", + "uct": "utc", + "usnavajo": "usden", + "zulu": "utc", + }, + }; + + + /** + * Mappings from Unicode extension subtags to preferred values. + * + * Spec: http://unicode.org/reports/tr35/#Identifiers + * Version: CLDR, version 36.1 + */ + var __transformMappings = { + // property names and values must be in canonical case + + "d0": { + "name": "charname", + }, + "m0": { + "names": "prprname", + }, + }; + + /** + * Canonicalizes the given well-formed BCP 47 language tag, including regularized case of subtags. + * + * Spec: ECMAScript Internationalization API Specification, draft, 6.2.3. + * Spec: RFC 5646, section 4.5. + */ + function canonicalizeLanguageTag(locale) { + + // start with lower case for easier processing, and because most subtags will need to be lower case anyway + locale = locale.toLowerCase(); + + // handle mappings for complete tags + if (__tagMappings.hasOwnProperty(locale)) { + return __tagMappings[locale]; + } + + var subtags = locale.split("-"); + var i = 0; + + // handle standard part: all subtags before first variant or singleton subtag + var language; + var script; + var region; + while (i < subtags.length) { + var subtag = subtags[i]; + if (i === 0) { + language = subtag; + } else if (subtag.length === 2 || subtag.length === 3) { + region = subtag.toUpperCase(); + } else if (subtag.length === 4 && !("0" <= subtag[0] && subtag[0] <= "9")) { + script = subtag[0].toUpperCase() + subtag.substring(1).toLowerCase(); + } else { + break; + } + i++; + } + + if (__languageMappings.hasOwnProperty(language)) { + language = __languageMappings[language]; + } else if (__complexLanguageMappings.hasOwnProperty(language)) { + var mapping = __complexLanguageMappings[language]; + + language = mapping.language; + if (script === undefined && mapping.hasOwnProperty("script")) { + script = mapping.script; + } + if (region === undefined && mapping.hasOwnProperty("region")) { + region = mapping.region; + } + } + + if (region !== undefined) { + if (__regionMappings.hasOwnProperty(region)) { + region = __regionMappings[region]; + } else if (__complexRegionMappings.hasOwnProperty(region)) { + var mapping = __complexRegionMappings[region]; + + var mappingKey = language; + if (script !== undefined) { + mappingKey += "-" + script; + } + + if (mapping.hasOwnProperty(mappingKey)) { + region = mapping[mappingKey]; + } else { + region = mapping.default; + } + } + } + + // handle variants + var variants = []; + while (i < subtags.length && subtags[i].length > 1) { + var variant = subtags[i]; + + if (__variantMappings.hasOwnProperty(variant)) { + var mapping = __variantMappings[variant]; + switch (mapping.type) { + case "language": + language = mapping.replacement; + break; + + case "region": + region = mapping.replacement; + break; + + case "variant": + variants.push(mapping.replacement); + break; + + default: + throw new Error("illegal variant mapping type"); + } + } else { + variants.push(variant); + } + + i += 1; + } + variants.sort(); + + // handle extensions + var extensions = []; + while (i < subtags.length && subtags[i] !== "x") { + var extensionStart = i; + i++; + while (i < subtags.length && subtags[i].length > 1) { + i++; + } + + var extension; + var extensionKey = subtags[extensionStart]; + if (extensionKey === "u") { + var j = extensionStart + 1; + + // skip over leading attributes + while (j < i && subtags[j].length > 2) { + j++; + } + + extension = subtags.slice(extensionStart, j).join("-"); + + while (j < i) { + var keyStart = j; + j++; + + while (j < i && subtags[j].length > 2) { + j++; + } + + var key = subtags[keyStart]; + var value = subtags.slice(keyStart + 1, j).join("-"); + + if (__unicodeMappings.hasOwnProperty(key)) { + var mapping = __unicodeMappings[key]; + if (mapping.hasOwnProperty(value)) { + value = mapping[value]; + } + } + + extension += "-" + key; + if (value !== "" && value !== "true") { + extension += "-" + value; + } + } + } else if (extensionKey === "t") { + var j = extensionStart + 1; + + while (j < i && !transformKeyRE.test(subtags[j])) { + j++; + } + + extension = "t"; + + var transformLanguage = subtags.slice(extensionStart + 1, j).join("-"); + if (transformLanguage !== "") { + extension += "-" + canonicalizeLanguageTag(transformLanguage).toLowerCase(); + } + + while (j < i) { + var keyStart = j; + j++; + + while (j < i && subtags[j].length > 2) { + j++; + } + + var key = subtags[keyStart]; + var value = subtags.slice(keyStart + 1, j).join("-"); + + if (__transformMappings.hasOwnProperty(key)) { + var mapping = __transformMappings[key]; + if (mapping.hasOwnProperty(value)) { + value = mapping[value]; + } + } + + extension += "-" + key + "-" + value; + } + } else { + extension = subtags.slice(extensionStart, i).join("-"); + } + + extensions.push(extension); + } + extensions.sort(); + + // handle private use + var privateUse; + if (i < subtags.length) { + privateUse = subtags.slice(i).join("-"); + } + + // put everything back together + var canonical = language; + if (script !== undefined) { + canonical += "-" + script; + } + if (region !== undefined) { + canonical += "-" + region; + } + if (variants.length > 0) { + canonical += "-" + variants.join("-"); + } + if (extensions.length > 0) { + canonical += "-" + extensions.join("-"); + } + if (privateUse !== undefined) { + if (canonical.length > 0) { + canonical += "-" + privateUse; + } else { + canonical = privateUse; + } + } + + return canonical; + } + + return typeof locale === "string" && isStructurallyValidLanguageTag(locale) && + canonicalizeLanguageTag(locale) === locale; +} + + +/** + * Returns an array of error cases handled by CanonicalizeLocaleList(). + */ +function getInvalidLocaleArguments() { + function CustomError() {} + + var topLevelErrors = [ + // fails ToObject + [null, TypeError], + + // fails Get + [{ get length() { throw new CustomError(); } }, CustomError], + + // fail ToLength + [{ length: Symbol.toPrimitive }, TypeError], + [{ length: { get [Symbol.toPrimitive]() { throw new CustomError(); } } }, CustomError], + [{ length: { [Symbol.toPrimitive]() { throw new CustomError(); } } }, CustomError], + [{ length: { get valueOf() { throw new CustomError(); } } }, CustomError], + [{ length: { valueOf() { throw new CustomError(); } } }, CustomError], + [{ length: { get toString() { throw new CustomError(); } } }, CustomError], + [{ length: { toString() { throw new CustomError(); } } }, CustomError], + + // fail type check + [[undefined], TypeError], + [[null], TypeError], + [[true], TypeError], + [[Symbol.toPrimitive], TypeError], + [[1], TypeError], + [[0.1], TypeError], + [[NaN], TypeError], + ]; + + var invalidLanguageTags = [ + "", // empty tag + "i", // singleton alone + "x", // private use without subtag + "u", // extension singleton in first place + "419", // region code in first place + "u-nu-latn-cu-bob", // extension sequence without language + "hans-cmn-cn", // "hans" could theoretically be a 4-letter language code, + // but those can't be followed by extlang codes. + "abcdefghi", // overlong language + "cmn-hans-cn-u-u", // duplicate singleton + "cmn-hans-cn-t-u-ca-u", // duplicate singleton + "de-gregory-gregory", // duplicate variant + "*", // language range + "de-*", // language range + "中文", // non-ASCII letters + "en-ß", // non-ASCII letters + "ıd" // non-ASCII letters + ]; + + return topLevelErrors.concat( + invalidLanguageTags.map(tag => [tag, RangeError]), + invalidLanguageTags.map(tag => [[tag], RangeError]), + invalidLanguageTags.map(tag => [["en", tag], RangeError]), + ) +} + +/** + * Tests whether the named options property is correctly handled by the given constructor. + * @param {object} Constructor the constructor to test. + * @param {string} property the name of the options property to test. + * @param {string} type the type that values of the property are expected to have + * @param {Array} [values] an array of allowed values for the property. Not needed for boolean. + * @param {any} fallback the fallback value that the property assumes if not provided. + * @param {object} testOptions additional options: + * @param {boolean} isOptional whether support for this property is optional for implementations. + * @param {boolean} noReturn whether the resulting value of the property is not returned. + * @param {boolean} isILD whether the resulting value of the property is implementation and locale dependent. + * @param {object} extra additional option to pass along, properties are value -> {option: value}. + */ +function testOption(Constructor, property, type, values, fallback, testOptions) { + var isOptional = testOptions !== undefined && testOptions.isOptional === true; + var noReturn = testOptions !== undefined && testOptions.noReturn === true; + var isILD = testOptions !== undefined && testOptions.isILD === true; + + function addExtraOptions(options, value, testOptions) { + if (testOptions !== undefined && testOptions.extra !== undefined) { + var extra; + if (value !== undefined && testOptions.extra[value] !== undefined) { + extra = testOptions.extra[value]; + } else if (testOptions.extra.any !== undefined) { + extra = testOptions.extra.any; + } + if (extra !== undefined) { + Object.getOwnPropertyNames(extra).forEach(function (prop) { + options[prop] = extra[prop]; + }); + } + } + } + + var testValues, options, obj, expected, actual, error; + + // test that the specified values are accepted. Also add values that convert to specified values. + if (type === "boolean") { + if (values === undefined) { + values = [true, false]; + } + testValues = values.slice(0); + testValues.push(888); + testValues.push(0); + } else if (type === "string") { + testValues = values.slice(0); + testValues.push({toString: function () { return values[0]; }}); + } + testValues.forEach(function (value) { + options = {}; + options[property] = value; + addExtraOptions(options, value, testOptions); + obj = new Constructor(undefined, options); + if (noReturn) { + if (obj.resolvedOptions().hasOwnProperty(property)) { + throw new Test262Error("Option property " + property + " is returned, but shouldn't be."); + } + } else { + actual = obj.resolvedOptions()[property]; + if (isILD) { + if (actual !== undefined && values.indexOf(actual) === -1) { + throw new Test262Error("Invalid value " + actual + " returned for property " + property + "."); + } + } else { + if (type === "boolean") { + expected = Boolean(value); + } else if (type === "string") { + expected = String(value); + } + if (actual !== expected && !(isOptional && actual === undefined)) { + throw new Test262Error("Option value " + value + " for property " + property + + " was not accepted; got " + actual + " instead."); + } + } + } + }); + + // test that invalid values are rejected + if (type === "string") { + var invalidValues = ["invalidValue", -1, null]; + // assume that we won't have values in caseless scripts + if (values[0].toUpperCase() !== values[0]) { + invalidValues.push(values[0].toUpperCase()); + } else { + invalidValues.push(values[0].toLowerCase()); + } + invalidValues.forEach(function (value) { + options = {}; + options[property] = value; + addExtraOptions(options, value, testOptions); + error = undefined; + try { + obj = new Constructor(undefined, options); + } catch (e) { + error = e; + } + if (error === undefined) { + throw new Test262Error("Invalid option value " + value + " for property " + property + " was not rejected."); + } else if (error.name !== "RangeError") { + throw new Test262Error("Invalid option value " + value + " for property " + property + " was rejected with wrong error " + error.name + "."); + } + }); + } + + // test that fallback value or another valid value is used if no options value is provided + if (!noReturn) { + options = {}; + addExtraOptions(options, undefined, testOptions); + obj = new Constructor(undefined, options); + actual = obj.resolvedOptions()[property]; + if (!(isOptional && actual === undefined)) { + if (fallback !== undefined) { + if (actual !== fallback) { + throw new Test262Error("Option fallback value " + fallback + " for property " + property + + " was not used; got " + actual + " instead."); + } + } else { + if (values.indexOf(actual) === -1 && !(isILD && actual === undefined)) { + throw new Test262Error("Invalid value " + actual + " returned for property " + property + "."); + } + } + } + } +} + + +/** + * Properties of the RegExp constructor that may be affected by use of regular + * expressions, and the default values of these properties. Properties are from + * https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Deprecated_and_obsolete_features#RegExp_Properties + */ +var regExpProperties = ["$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", + "$_", "$*", "$&", "$+", "$`", "$'", + "input", "lastMatch", "lastParen", "leftContext", "rightContext" +]; + +var regExpPropertiesDefaultValues = (function () { + var values = Object.create(null); + (/(?:)/).test(""); + regExpProperties.forEach(function (property) { + values[property] = RegExp[property]; + }); + return values; +}()); + + +/** + * Tests that executing the provided function (which may use regular expressions + * in its implementation) does not create or modify unwanted properties on the + * RegExp constructor. + */ +function testForUnwantedRegExpChanges(testFunc) { + (/(?:)/).test(""); + testFunc(); + regExpProperties.forEach(function (property) { + if (RegExp[property] !== regExpPropertiesDefaultValues[property]) { + throw new Test262Error("RegExp has unexpected property " + property + " with value " + + RegExp[property] + "."); + } + }); +} + + +/** + * Returns an array of all known calendars. + */ +function allCalendars() { + // source: CLDR file common/bcp47/number.xml; version CLDR 39. + // https://github.com/unicode-org/cldr/blob/master/common/bcp47/calendar.xml + return [ + "buddhist", + "chinese", + "coptic", + "dangi", + "ethioaa", + "ethiopic", + "gregory", + "hebrew", + "indian", + "islamic", + "islamic-umalqura", + "islamic-tbla", + "islamic-civil", + "islamic-rgsa", + "iso8601", + "japanese", + "persian", + "roc", + ]; +} + + +/** + * Returns an array of all known collations. + */ +function allCollations() { + // source: CLDR file common/bcp47/collation.xml; version CLDR 39. + // https://github.com/unicode-org/cldr/blob/master/common/bcp47/collation.xml + return [ + "big5han", + "compat", + "dict", + "direct", + "ducet", + "emoji", + "eor", + "gb2312", + "phonebk", + "phonetic", + "pinyin", + "reformed", + "search", + "searchjl", + "standard", + "stroke", + "trad", + "unihan", + "zhuyin", + ]; +} + + +/** + * Returns an array of all known numbering systems. + */ +function allNumberingSystems() { + // source: CLDR file common/bcp47/number.xml; version CLDR 40 & new in Unicode 14.0 + // https://github.com/unicode-org/cldr/blob/master/common/bcp47/number.xml + return [ + "adlm", + "ahom", + "arab", + "arabext", + "armn", + "armnlow", + "bali", + "beng", + "bhks", + "brah", + "cakm", + "cham", + "cyrl", + "deva", + "diak", + "ethi", + "finance", + "fullwide", + "geor", + "gong", + "gonm", + "grek", + "greklow", + "gujr", + "guru", + "hanidays", + "hanidec", + "hans", + "hansfin", + "hant", + "hantfin", + "hebr", + "hmng", + "hmnp", + "java", + "jpan", + "jpanfin", + "jpanyear", + "kali", + "khmr", + "knda", + "lana", + "lanatham", + "laoo", + "latn", + "lepc", + "limb", + "mathbold", + "mathdbl", + "mathmono", + "mathsanb", + "mathsans", + "mlym", + "modi", + "mong", + "mroo", + "mtei", + "mymr", + "mymrshan", + "mymrtlng", + "native", + "newa", + "nkoo", + "olck", + "orya", + "osma", + "rohg", + "roman", + "romanlow", + "saur", + "shrd", + "sind", + "sinh", + "sora", + "sund", + "takr", + "talu", + "taml", + "tamldec", + "tnsa", + "telu", + "thai", + "tirh", + "tibt", + "traditio", + "vaii", + "wara", + "wcho", + ]; +} + + +/** + * Tests whether name is a valid BCP 47 numbering system name + * and not excluded from use in the ECMAScript Internationalization API. + * @param {string} name the name to be tested. + * @return {boolean} whether name is a valid BCP 47 numbering system name and + * allowed for use in the ECMAScript Internationalization API. + */ + +function isValidNumberingSystem(name) { + + var numberingSystems = allNumberingSystems(); + + var excluded = [ + "finance", + "native", + "traditio" + ]; + + + return numberingSystems.indexOf(name) !== -1 && excluded.indexOf(name) === -1; +} + + +/** + * Provides the digits of numbering systems with simple digit mappings, + * as specified in 11.3.2. + */ + +var numberingSystemDigits = { + adlm: "𞥐𞥑𞥒𞥓𞥔𞥕𞥖𞥗𞥘𞥙", + ahom: "𑜰𑜱𑜲𑜳𑜴𑜵𑜶𑜷𑜸𑜹", + arab: "٠١٢٣٤٥٦٧٨٩", + arabext: "۰۱۲۳۴۵۶۷۸۹", + bali: "\u1B50\u1B51\u1B52\u1B53\u1B54\u1B55\u1B56\u1B57\u1B58\u1B59", + beng: "০১২৩৪৫৬৭৮৯", + bhks: "𑱐𑱑𑱒𑱓𑱔𑱕𑱖𑱗𑱘𑱙", + brah: "𑁦𑁧𑁨𑁩𑁪𑁫𑁬𑁭𑁮𑁯", + cakm: "𑄶𑄷𑄸𑄹𑄺𑄻𑄼𑄽𑄾𑄿", + cham: "꩐꩑꩒꩓꩔꩕꩖꩗꩘꩙", + deva: "०१२३४५६७८९", + diak: "𑥐𑥑𑥒𑥓𑥔𑥕𑥖𑥗𑥘𑥙", + fullwide: "0123456789", + gong: "𑶠𑶡𑶢𑶣𑶤𑶥𑶦𑶧𑶨𑶩", + gonm: "𑵐𑵑𑵒𑵓𑵔𑵕𑵖𑵗𑵘𑵙", + gujr: "૦૧૨૩૪૫૬૭૮૯", + guru: "੦੧੨੩੪੫੬੭੮੯", + hanidec: "〇一二三四五六七八九", + hmng: "𖭐𖭑𖭒𖭓𖭔𖭕𖭖𖭗𖭘𖭙", + hmnp: "𞅀𞅁𞅂𞅃𞅄𞅅𞅆𞅇𞅈𞅉", + java: "꧐꧑꧒꧓꧔꧕꧖꧗꧘꧙", + kali: "꤀꤁꤂꤃꤄꤅꤆꤇꤈꤉", + khmr: "០១២៣៤៥៦៧៨៩", + knda: "೦೧೨೩೪೫೬೭೮೯", + lana: "᪀᪁᪂᪃᪄᪅᪆᪇᪈᪉", + lanatham: "᪐᪑᪒᪓᪔᪕᪖᪗᪘᪙", + laoo: "໐໑໒໓໔໕໖໗໘໙", + latn: "0123456789", + lepc: "᱀᱁᱂᱃᱄᱅᱆᱇᱈᱉", + limb: "\u1946\u1947\u1948\u1949\u194A\u194B\u194C\u194D\u194E\u194F", + mathbold: "𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗", + mathdbl: "𝟘𝟙𝟚𝟛𝟜𝟝𝟞𝟟𝟠𝟡", + mathmono: "𝟶𝟷𝟸𝟹𝟺𝟻𝟼𝟽𝟾𝟿", + mathsanb: "𝟬𝟭𝟮𝟯𝟰𝟱𝟲𝟳𝟴𝟵", + mathsans: "𝟢𝟣𝟤𝟥𝟦𝟧𝟨𝟩𝟪𝟫", + mlym: "൦൧൨൩൪൫൬൭൮൯", + modi: "𑙐𑙑𑙒𑙓𑙔𑙕𑙖𑙗𑙘𑙙", + mong: "᠐᠑᠒᠓᠔᠕᠖᠗᠘᠙", + mroo: "𖩠𖩡𖩢𖩣𖩤𖩥𖩦𖩧𖩨𖩩", + mtei: "꯰꯱꯲꯳꯴꯵꯶꯷꯸꯹", + mymr: "၀၁၂၃၄၅၆၇၈၉", + mymrshan: "႐႑႒႓႔႕႖႗႘႙", + mymrtlng: "꧰꧱꧲꧳꧴꧵꧶꧷꧸꧹", + newa: "𑑐𑑑𑑒𑑓𑑔𑑕𑑖𑑗𑑘𑑙", + nkoo: "߀߁߂߃߄߅߆߇߈߉", + olck: "᱐᱑᱒᱓᱔᱕᱖᱗᱘᱙", + orya: "୦୧୨୩୪୫୬୭୮୯", + osma: "𐒠𐒡𐒢𐒣𐒤𐒥𐒦𐒧𐒨𐒩", + rohg: "𐴰𐴱𐴲𐴳𐴴𐴵𐴶𐴷𐴸𐴹", + saur: "꣐꣑꣒꣓꣔꣕꣖꣗꣘꣙", + segment: "🯰🯱🯲🯳🯴🯵🯶🯷🯸🯹", + shrd: "𑇐𑇑𑇒𑇓𑇔𑇕𑇖𑇗𑇘𑇙", + sind: "𑋰𑋱𑋲𑋳𑋴𑋵𑋶𑋷𑋸𑋹", + sinh: "෦෧෨෩෪෫෬෭෮෯", + sora: "𑃰𑃱𑃲𑃳𑃴𑃵𑃶𑃷𑃸𑃹", + sund: "᮰᮱᮲᮳᮴᮵᮶᮷᮸᮹", + takr: "𑛀𑛁𑛂𑛃𑛄𑛅𑛆𑛇𑛈𑛉", + talu: "᧐᧑᧒᧓᧔᧕᧖᧗᧘᧙", + tamldec: "௦௧௨௩௪௫௬௭௮௯", + tnsa: "\u{16AC0}\u{16AC1}\u{16AC2}\u{16AC3}\u{16AC4}\u{16AC5}\u{16AC6}\u{16AC7}\u{16AC8}\u{16AC9}", + telu: "౦౧౨౩౪౫౬౭౮౯", + thai: "๐๑๒๓๔๕๖๗๘๙", + tibt: "༠༡༢༣༤༥༦༧༨༩", + tirh: "𑓐𑓑𑓒𑓓𑓔𑓕𑓖𑓗𑓘𑓙", + vaii: "꘠꘡꘢꘣꘤꘥꘦꘧꘨꘩", + wara: "𑣠𑣡𑣢𑣣𑣤𑣥𑣦𑣧𑣨𑣩", + wcho: "𞋰𞋱𞋲𞋳𞋴𞋵𞋶𞋷𞋸𞋹", +}; + + +/** + * Returns an array of all simple, sanctioned unit identifiers. + */ +function allSimpleSanctionedUnits() { + // https://tc39.es/ecma402/#table-sanctioned-simple-unit-identifiers + return [ + "acre", + "bit", + "byte", + "celsius", + "centimeter", + "day", + "degree", + "fahrenheit", + "fluid-ounce", + "foot", + "gallon", + "gigabit", + "gigabyte", + "gram", + "hectare", + "hour", + "inch", + "kilobit", + "kilobyte", + "kilogram", + "kilometer", + "liter", + "megabit", + "megabyte", + "meter", + "microsecond", + "mile", + "mile-scandinavian", + "milliliter", + "millimeter", + "millisecond", + "minute", + "month", + "nanosecond", + "ounce", + "percent", + "petabyte", + "pound", + "second", + "stone", + "terabit", + "terabyte", + "week", + "yard", + "year", + ]; +} + + +/** + * Tests that number formatting is handled correctly. The function checks that the + * digit sequences in formatted output are as specified, converted to the + * selected numbering system, and embedded in consistent localized patterns. + * @param {Array} locales the locales to be tested. + * @param {Array} numberingSystems the numbering systems to be tested. + * @param {Object} options the options to pass to Intl.NumberFormat. Options + * must include {useGrouping: false}, and must cause 1.1 to be formatted + * pre- and post-decimal digits. + * @param {Object} testData maps input data (in ES5 9.3.1 format) to expected output strings + * in unlocalized format with Western digits. + */ + +function testNumberFormat(locales, numberingSystems, options, testData) { + locales.forEach(function (locale) { + numberingSystems.forEach(function (numbering) { + var digits = numberingSystemDigits[numbering]; + var format = new Intl.NumberFormat([locale + "-u-nu-" + numbering], options); + + function getPatternParts(positive) { + var n = positive ? 1.1 : -1.1; + var formatted = format.format(n); + var oneoneRE = "([^" + digits + "]*)[" + digits + "]+([^" + digits + "]+)[" + digits + "]+([^" + digits + "]*)"; + var match = formatted.match(new RegExp(oneoneRE)); + if (match === null) { + throw new Test262Error("Unexpected formatted " + n + " for " + + format.resolvedOptions().locale + " and options " + + JSON.stringify(options) + ": " + formatted); + } + return match; + } + + function toNumbering(raw) { + return raw.replace(/[0-9]/g, function (digit) { + return digits[digit.charCodeAt(0) - "0".charCodeAt(0)]; + }); + } + + function buildExpected(raw, patternParts) { + var period = raw.indexOf("."); + if (period === -1) { + return patternParts[1] + toNumbering(raw) + patternParts[3]; + } else { + return patternParts[1] + + toNumbering(raw.substring(0, period)) + + patternParts[2] + + toNumbering(raw.substring(period + 1)) + + patternParts[3]; + } + } + + if (format.resolvedOptions().numberingSystem === numbering) { + // figure out prefixes, infixes, suffixes for positive and negative values + var posPatternParts = getPatternParts(true); + var negPatternParts = getPatternParts(false); + + Object.getOwnPropertyNames(testData).forEach(function (input) { + var rawExpected = testData[input]; + var patternParts; + if (rawExpected[0] === "-") { + patternParts = negPatternParts; + rawExpected = rawExpected.substring(1); + } else { + patternParts = posPatternParts; + } + var expected = buildExpected(rawExpected, patternParts); + var actual = format.format(input); + if (actual !== expected) { + throw new Test262Error("Formatted value for " + input + ", " + + format.resolvedOptions().locale + " and options " + + JSON.stringify(options) + " is " + actual + "; expected " + expected + "."); + } + }); + } + }); + }); +} + + +/** + * Return the components of date-time formats. + * @return {Array} an array with all date-time components. + */ + +function getDateTimeComponents() { + return ["weekday", "era", "year", "month", "day", "hour", "minute", "second", "timeZoneName"]; +} + + +/** + * Return the valid values for the given date-time component, as specified + * by the table in section 12.1.1. + * @param {string} component a date-time component. + * @return {Array} an array with the valid values for the component. + */ + +function getDateTimeComponentValues(component) { + + var components = { + weekday: ["narrow", "short", "long"], + era: ["narrow", "short", "long"], + year: ["2-digit", "numeric"], + month: ["2-digit", "numeric", "narrow", "short", "long"], + day: ["2-digit", "numeric"], + hour: ["2-digit", "numeric"], + minute: ["2-digit", "numeric"], + second: ["2-digit", "numeric"], + timeZoneName: ["short", "long"] + }; + + var result = components[component]; + if (result === undefined) { + throw new Test262Error("Internal error: No values defined for date-time component " + component + "."); + } + return result; +} + + +/** + * @description Tests whether timeZone is a String value representing a + * structurally valid and canonicalized time zone name, as defined in + * sections 6.4.1 and 6.4.2 of the ECMAScript Internationalization API + * Specification. + * @param {String} timeZone the string to be tested. + * @result {Boolean} whether the test succeeded. + */ + +function isCanonicalizedStructurallyValidTimeZoneName(timeZone) { + /** + * Regular expression defining IANA Time Zone names. + * + * Spec: IANA Time Zone Database, Theory file + */ + var fileNameComponent = "(?:[A-Za-z_]|\\.(?!\\.?(?:/|$)))[A-Za-z.\\-_]{0,13}"; + var fileName = fileNameComponent + "(?:/" + fileNameComponent + ")*"; + var etcName = "(?:Etc/)?GMT[+-]\\d{1,2}"; + var systemVName = "SystemV/[A-Z]{3}\\d{1,2}(?:[A-Z]{3})?"; + var legacyName = etcName + "|" + systemVName + "|CST6CDT|EST5EDT|MST7MDT|PST8PDT|NZ"; + var zoneNamePattern = new RegExp("^(?:" + fileName + "|" + legacyName + ")$"); + + if (typeof timeZone !== "string") { + return false; + } + // 6.4.2 CanonicalizeTimeZoneName (timeZone), step 3 + if (timeZone === "UTC") { + return true; + } + // 6.4.2 CanonicalizeTimeZoneName (timeZone), step 3 + if (timeZone === "Etc/UTC" || timeZone === "Etc/GMT") { + return false; + } + return zoneNamePattern.test(timeZone); +} diff --git a/harness/testTypedArray.js b/harness/testTypedArray.js new file mode 100644 index 0000000000000000000000000000000000000000..0cc50c9fd50f1e193fdebf3425919218c7914575 --- /dev/null +++ b/harness/testTypedArray.js @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} diff --git a/harness/timer.js b/harness/timer.js new file mode 100644 index 0000000000000000000000000000000000000000..d55f47d4f731512e651a1fb2d0622c34011348c5 --- /dev/null +++ b/harness/timer.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Used in website/scripts/sth.js +defines: [setTimeout] +---*/ +//setTimeout is not available, hence this script was loaded +if (Promise === undefined && this.setTimeout === undefined) { + if(/\$DONE()/.test(code)) + throw new Test262Error("Async test capability is not supported in your test environment"); +} + +if (Promise !== undefined && this.setTimeout === undefined) { + (function(that) { + that.setTimeout = function(callback, delay) { + var p = Promise.resolve(); + var start = Date.now(); + var end = start + delay; + function check(){ + var timeLeft = end - Date.now(); + if(timeLeft > 0) + p.then(check); + else + callback(); + } + p.then(check); + } + })(this); +} diff --git a/harness/typeCoercion.js b/harness/typeCoercion.js new file mode 100644 index 0000000000000000000000000000000000000000..72f79205a01a292e0641400c96004497149a4f44 --- /dev/null +++ b/harness/typeCoercion.js @@ -0,0 +1,463 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Functions to help generate test cases for testing type coercion abstract + operations like ToNumber. +defines: + - testCoercibleToIndexZero + - testCoercibleToIndexOne + - testCoercibleToIndexFromIndex + - testCoercibleToIntegerZero + - testCoercibleToIntegerOne + - testCoercibleToNumberZero + - testCoercibleToNumberNan + - testCoercibleToNumberOne + - testCoercibleToIntegerFromInteger + - testPrimitiveWrappers + - testCoercibleToPrimitiveWithMethod + - testNotCoercibleToIndex + - testNotCoercibleToInteger + - testNotCoercibleToNumber + - testNotCoercibleToPrimitive + - testCoercibleToString + - testNotCoercibleToString + - testCoercibleToBooleanTrue + - testCoercibleToBooleanFalse + - testCoercibleToBigIntZero + - testCoercibleToBigIntOne + - testCoercibleToBigIntFromBigInt + - testNotCoercibleToBigInt +---*/ + +function testCoercibleToIndexZero(test) { + testCoercibleToIntegerZero(test); +} + +function testCoercibleToIndexOne(test) { + testCoercibleToIntegerOne(test); +} + +function testCoercibleToIndexFromIndex(nominalIndex, test) { + assert(Number.isInteger(nominalIndex)); + assert(0 <= nominalIndex && nominalIndex <= 2**53 - 1); + testCoercibleToIntegerFromInteger(nominalIndex, test); +} + +function testCoercibleToIntegerZero(test) { + testCoercibleToNumberZero(test); + + testCoercibleToIntegerFromInteger(0, test); + + // NaN -> +0 + testCoercibleToNumberNan(test); + + // When toString() returns a string that parses to NaN: + test({}); + test([]); +} + +function testCoercibleToIntegerOne(test) { + testCoercibleToNumberOne(test); + + testCoercibleToIntegerFromInteger(1, test); + + // When toString() returns "1" + test([1]); + test(["1"]); +} + +function testCoercibleToNumberZero(test) { + function testPrimitiveValue(value) { + test(value); + // ToPrimitive + testPrimitiveWrappers(value, "number", test); + } + + testPrimitiveValue(null); + testPrimitiveValue(false); + testPrimitiveValue(0); + testPrimitiveValue("0"); +} + +function testCoercibleToNumberNan(test) { + function testPrimitiveValue(value) { + test(value); + // ToPrimitive + testPrimitiveWrappers(value, "number", test); + } + + testPrimitiveValue(undefined); + testPrimitiveValue(NaN); + testPrimitiveValue(""); + testPrimitiveValue("foo"); + testPrimitiveValue("true"); +} + +function testCoercibleToNumberOne(test) { + function testPrimitiveValue(value) { + test(value); + // ToPrimitive + testPrimitiveWrappers(value, "number", test); + } + + testPrimitiveValue(true); + testPrimitiveValue(1); + testPrimitiveValue("1"); +} + +function testCoercibleToIntegerFromInteger(nominalInteger, test) { + assert(Number.isInteger(nominalInteger)); + + function testPrimitiveValue(value) { + test(value); + // ToPrimitive + testPrimitiveWrappers(value, "number", test); + + // Non-primitive values that coerce to the nominal integer: + // toString() returns a string that parsers to a primitive value. + test([value]); + } + + function testPrimitiveNumber(number) { + testPrimitiveValue(number); + // ToNumber: String -> Number + testPrimitiveValue(number.toString()); + } + + testPrimitiveNumber(nominalInteger); + + // ToInteger: floor(abs(number)) + if (nominalInteger >= 0) { + testPrimitiveNumber(nominalInteger + 0.9); + } + if (nominalInteger <= 0) { + testPrimitiveNumber(nominalInteger - 0.9); + } +} + +function testPrimitiveWrappers(primitiveValue, hint, test) { + if (primitiveValue != null) { + // null and undefined result in {} rather than a proper wrapper, + // so skip this case for those values. + test(Object(primitiveValue)); + } + + testCoercibleToPrimitiveWithMethod(hint, function() { + return primitiveValue; + }, test); +} + +function testCoercibleToPrimitiveWithMethod(hint, method, test) { + var methodNames; + if (hint === "number") { + methodNames = ["valueOf", "toString"]; + } else if (hint === "string") { + methodNames = ["toString", "valueOf"]; + } else { + throw new Test262Error(); + } + // precedence order + test({ + [Symbol.toPrimitive]: method, + [methodNames[0]]: function() { throw new Test262Error(); }, + [methodNames[1]]: function() { throw new Test262Error(); }, + }); + test({ + [methodNames[0]]: method, + [methodNames[1]]: function() { throw new Test262Error(); }, + }); + if (hint === "number") { + // The default valueOf returns an object, which is unsuitable. + // The default toString returns a String, which is suitable. + // Therefore this test only works for valueOf falling back to toString. + test({ + // this is toString: + [methodNames[1]]: method, + }); + } + + // GetMethod: if func is undefined or null, return undefined. + test({ + [Symbol.toPrimitive]: undefined, + [methodNames[0]]: method, + [methodNames[1]]: method, + }); + test({ + [Symbol.toPrimitive]: null, + [methodNames[0]]: method, + [methodNames[1]]: method, + }); + + // if methodNames[0] is not callable, fallback to methodNames[1] + test({ + [methodNames[0]]: null, + [methodNames[1]]: method, + }); + test({ + [methodNames[0]]: 1, + [methodNames[1]]: method, + }); + test({ + [methodNames[0]]: {}, + [methodNames[1]]: method, + }); + + // if methodNames[0] returns an object, fallback to methodNames[1] + test({ + [methodNames[0]]: function() { return {}; }, + [methodNames[1]]: method, + }); + test({ + [methodNames[0]]: function() { return Object(1); }, + [methodNames[1]]: method, + }); +} + +function testNotCoercibleToIndex(test) { + function testPrimitiveValue(value) { + test(RangeError, value); + // ToPrimitive + testPrimitiveWrappers(value, "number", function(value) { + test(RangeError, value); + }); + } + + // Let integerIndex be ? ToInteger(value). + testNotCoercibleToInteger(test); + + // If integerIndex < 0, throw a RangeError exception. + testPrimitiveValue(-1); + testPrimitiveValue(-2.5); + testPrimitiveValue("-2.5"); + testPrimitiveValue(-Infinity); + + // Let index be ! ToLength(integerIndex). + // If SameValueZero(integerIndex, index) is false, throw a RangeError exception. + testPrimitiveValue(2 ** 53); + testPrimitiveValue(Infinity); +} + +function testNotCoercibleToInteger(test) { + // ToInteger only throws from ToNumber. + testNotCoercibleToNumber(test); +} + +function testNotCoercibleToNumber(test) { + function testPrimitiveValue(value) { + test(TypeError, value); + // ToPrimitive + testPrimitiveWrappers(value, "number", function(value) { + test(TypeError, value); + }); + } + + // ToNumber: Symbol -> TypeError + testPrimitiveValue(Symbol("1")); + + if (typeof BigInt !== "undefined") { + // ToNumber: BigInt -> TypeError + testPrimitiveValue(BigInt(0)); + } + + // ToPrimitive + testNotCoercibleToPrimitive("number", test); +} + +function testNotCoercibleToPrimitive(hint, test) { + function MyError() {} + + // ToPrimitive: input[@@toPrimitive] is not callable (and non-null) + test(TypeError, {[Symbol.toPrimitive]: 1}); + test(TypeError, {[Symbol.toPrimitive]: {}}); + + // ToPrimitive: input[@@toPrimitive] returns object + test(TypeError, {[Symbol.toPrimitive]: function() { return Object(1); }}); + test(TypeError, {[Symbol.toPrimitive]: function() { return {}; }}); + + // ToPrimitive: input[@@toPrimitive] throws + test(MyError, {[Symbol.toPrimitive]: function() { throw new MyError(); }}); + + // OrdinaryToPrimitive: method throws + testCoercibleToPrimitiveWithMethod(hint, function() { + throw new MyError(); + }, function(value) { + test(MyError, value); + }); + + // OrdinaryToPrimitive: both methods are unsuitable + function testUnsuitableMethod(method) { + test(TypeError, {valueOf:method, toString:method}); + } + // not callable: + testUnsuitableMethod(null); + testUnsuitableMethod(1); + testUnsuitableMethod({}); + // returns object: + testUnsuitableMethod(function() { return Object(1); }); + testUnsuitableMethod(function() { return {}; }); +} + +function testCoercibleToString(test) { + function testPrimitiveValue(value, expectedString) { + test(value, expectedString); + // ToPrimitive + testPrimitiveWrappers(value, "string", function(value) { + test(value, expectedString); + }); + } + + testPrimitiveValue(undefined, "undefined"); + testPrimitiveValue(null, "null"); + testPrimitiveValue(true, "true"); + testPrimitiveValue(false, "false"); + testPrimitiveValue(0, "0"); + testPrimitiveValue(-0, "0"); + testPrimitiveValue(Infinity, "Infinity"); + testPrimitiveValue(-Infinity, "-Infinity"); + testPrimitiveValue(123.456, "123.456"); + testPrimitiveValue(-123.456, "-123.456"); + testPrimitiveValue("", ""); + testPrimitiveValue("foo", "foo"); + + if (typeof BigInt !== "undefined") { + // BigInt -> TypeError + testPrimitiveValue(BigInt(0), "0"); + } + + // toString of a few objects + test([], ""); + test(["foo", "bar"], "foo,bar"); + test({}, "[object Object]"); +} + +function testNotCoercibleToString(test) { + function testPrimitiveValue(value) { + test(TypeError, value); + // ToPrimitive + testPrimitiveWrappers(value, "string", function(value) { + test(TypeError, value); + }); + } + + // Symbol -> TypeError + testPrimitiveValue(Symbol("1")); + + // ToPrimitive + testNotCoercibleToPrimitive("string", test); +} + +function testCoercibleToBooleanTrue(test) { + test(true); + test(1); + test("string"); + test(Symbol("1")); + test({}); +} + +function testCoercibleToBooleanFalse(test) { + test(undefined); + test(null); + test(false); + test(0); + test(-0); + test(NaN); + test(""); +} + +function testCoercibleToBigIntZero(test) { + function testPrimitiveValue(value) { + test(value); + // ToPrimitive + testPrimitiveWrappers(value, "number", test); + } + + testCoercibleToBigIntFromBigInt(BigInt(0), test); + testPrimitiveValue(-BigInt(0)); + testPrimitiveValue("-0"); + testPrimitiveValue(false); + testPrimitiveValue(""); + testPrimitiveValue(" "); + + // toString() returns "" + test([]); + + // toString() returns "0" + test([0]); +} + +function testCoercibleToBigIntOne(test) { + function testPrimitiveValue(value) { + test(value); + // ToPrimitive + testPrimitiveWrappers(value, "number", test); + } + + testCoercibleToBigIntFromBigInt(BigInt(1), test); + testPrimitiveValue(true); + + // toString() returns "1" + test([1]); +} + +function testCoercibleToBigIntFromBigInt(nominalBigInt, test) { + function testPrimitiveValue(value) { + test(value); + // ToPrimitive + testPrimitiveWrappers(value, "number", test); + } + + testPrimitiveValue(nominalBigInt); + testPrimitiveValue(nominalBigInt.toString()); + testPrimitiveValue("0b" + nominalBigInt.toString(2)); + testPrimitiveValue("0o" + nominalBigInt.toString(8)); + testPrimitiveValue("0x" + nominalBigInt.toString(16)); + testPrimitiveValue(" " + nominalBigInt.toString() + " "); + + // toString() returns the decimal string representation + test([nominalBigInt]); + test([nominalBigInt.toString()]); +} + +function testNotCoercibleToBigInt(test) { + function testPrimitiveValue(error, value) { + test(error, value); + // ToPrimitive + testPrimitiveWrappers(value, "number", function(value) { + test(error, value); + }); + } + + // Undefined, Null, Number, Symbol -> TypeError + testPrimitiveValue(TypeError, undefined); + testPrimitiveValue(TypeError, null); + testPrimitiveValue(TypeError, 0); + testPrimitiveValue(TypeError, NaN); + testPrimitiveValue(TypeError, Infinity); + testPrimitiveValue(TypeError, Symbol("1")); + + // when a String parses to NaN -> SyntaxError + function testStringValue(string) { + testPrimitiveValue(SyntaxError, string); + testPrimitiveValue(SyntaxError, " " + string); + testPrimitiveValue(SyntaxError, string + " "); + testPrimitiveValue(SyntaxError, " " + string + " "); + } + testStringValue("a"); + testStringValue("0b2"); + testStringValue("0o8"); + testStringValue("0xg"); + testStringValue("1n"); +} diff --git a/harness/wellKnownIntrinsicObjects.js b/harness/wellKnownIntrinsicObjects.js new file mode 100644 index 0000000000000000000000000000000000000000..3d0b57dc8bdccd21db09964f51311176d3efd25b --- /dev/null +++ b/harness/wellKnownIntrinsicObjects.js @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + An Array of all representable Well-Known Intrinsic Objects +defines: [WellKnownIntrinsicObjects] +---*/ + +const WellKnownIntrinsicObjects = [ + { + name: '%AggregateError%', + source: 'AggregateError', + }, + { + name: '%Array%', + source: 'Array', + }, + { + name: '%ArrayBuffer%', + source: 'ArrayBuffer', + }, + { + name: '%ArrayIteratorPrototype%', + source: 'Object.getPrototypeOf([][Symbol.iterator]())', + }, + { + name: '%AsyncFromSyncIteratorPrototype%', + source: 'undefined', + }, + { + name: '%AsyncFunction%', + source: '(async function() {}).constructor', + }, + { + name: '%AsyncGeneratorFunction%', + source: 'Object.getPrototypeOf(async function * () {})', + }, + { + name: '%AsyncIteratorPrototype%', + source: '((async function * () {})())[Symbol.asyncIterator]()', + }, + { + name: '%Atomics%', + source: 'Atomics', + }, + { + name: '%BigInt%', + source: 'BigInt', + }, + { + name: '%BigInt64Array%', + source: 'BigInt64Array', + }, + { + name: '%BigUint64Array%', + source: 'BigUint64Array', + }, + { + name: '%Boolean%', + source: 'Boolean', + }, + { + name: '%DataView%', + source: 'DataView', + }, + { + name: '%Date%', + source: 'Date', + }, + { + name: '%decodeURI%', + source: 'decodeURI', + }, + { + name: '%decodeURIComponent%', + source: 'decodeURIComponent', + }, + { + name: '%encodeURI%', + source: 'encodeURI', + }, + { + name: '%encodeURIComponent%', + source: 'encodeURIComponent', + }, + { + name: '%Error%', + source: 'Error', + }, + { + name: '%eval%', + source: 'eval', + }, + { + name: '%EvalError%', + source: 'EvalError', + }, + { + name: '%FinalizationRegistry%', + source: 'FinalizationRegistry', + }, + { + name: '%Float32Array%', + source: 'Float32Array', + }, + { + name: '%Float64Array%', + source: 'Float64Array', + }, + { + name: '%ForInIteratorPrototype%', + source: '', + }, + { + name: '%Function%', + source: 'Function', + }, + { + name: '%GeneratorFunction%', + source: 'Object.getPrototypeOf(function * () {})', + }, + { + name: '%Int8Array%', + source: 'Int8Array', + }, + { + name: '%Int16Array%', + source: 'Int16Array', + }, + { + name: '%Int32Array%', + source: 'Int32Array', + }, + { + name: '%isFinite%', + source: 'isFinite', + }, + { + name: '%isNaN%', + source: 'isNaN', + }, + { + name: '%IteratorPrototype%', + source: 'Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]()))', + }, + { + name: '%JSON%', + source: 'JSON', + }, + { + name: '%Map%', + source: 'Map', + }, + { + name: '%MapIteratorPrototype%', + source: 'Object.getPrototypeOf(new Map()[Symbol.iterator]())', + }, + { + name: '%Math%', + source: 'Math', + }, + { + name: '%Number%', + source: 'Number', + }, + { + name: '%Object%', + source: 'Object', + }, + { + name: '%parseFloat%', + source: 'parseFloat', + }, + { + name: '%parseInt%', + source: 'parseInt', + }, + { + name: '%Promise%', + source: 'Promise', + }, + { + name: '%Proxy%', + source: 'Proxy', + }, + { + name: '%RangeError%', + source: 'RangeError', + }, + { + name: '%ReferenceError%', + source: 'ReferenceError', + }, + { + name: '%Reflect%', + source: 'Reflect', + }, + { + name: '%RegExp%', + source: 'RegExp', + }, + { + name: '%RegExpStringIteratorPrototype%', + source: 'RegExp.prototype[Symbol.matchAll]("")', + }, + { + name: '%Set%', + source: 'Set', + }, + { + name: '%SetIteratorPrototype%', + source: 'Object.getPrototypeOf(new Set()[Symbol.iterator]())', + }, + { + name: '%SharedArrayBuffer%', + source: 'SharedArrayBuffer', + }, + { + name: '%String%', + source: 'String', + }, + { + name: '%StringIteratorPrototype%', + source: 'Object.getPrototypeOf(new String()[Symbol.iterator]())', + }, + { + name: '%Symbol%', + source: 'Symbol', + }, + { + name: '%SyntaxError%', + source: 'SyntaxError', + }, + { + name: '%ThrowTypeError%', + source: '(function() { "use strict"; return Object.getOwnPropertyDescriptor(arguments, "callee").get })()', + }, + { + name: '%TypedArray%', + source: 'Object.getPrototypeOf(Uint8Array)', + }, + { + name: '%TypeError%', + source: 'TypeError', + }, + { + name: '%Uint8Array%', + source: 'Uint8Array', + }, + { + name: '%Uint8ClampedArray%', + source: 'Uint8ClampedArray', + }, + { + name: '%Uint16Array%', + source: 'Uint16Array', + }, + { + name: '%Uint32Array%', + source: 'Uint32Array', + }, + { + name: '%URIError%', + source: 'URIError', + }, + { + name: '%WeakMap%', + source: 'WeakMap', + }, + { + name: '%WeakRef%', + source: 'WeakRef', + }, + { + name: '%WeakSet%', + source: 'WeakSet', + }, +]; + +WellKnownIntrinsicObjects.forEach((wkio) => { + var actual; + + try { + actual = new Function("return " + wkio.source)(); + } catch (exception) { + // Nothing to do here. + } + + wkio.value = actual; +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000000000000000000000000000000000000..faa769dd7c7ff09631b9dbf525b1888832728a79 --- /dev/null +++ b/package.json @@ -0,0 +1,31 @@ +{ + "name": "test262", + "version": "5.0.0", + "description": "Test262 tests conformance to the continually maintained draft future ECMAScript standard found at http://tc39.github.io/ecma262/ , together with any Stage 3 or later TC39 proposals.", + "repository": { + "type": "git", + "url": "git+https://github.com/tc39/test262.git" + }, + "license": "BSD", + "bugs": { + "url": "https://github.com/tc39/test262/issues" + }, + "private": true, + "homepage": "https://github.com/tc39/test262#readme", + "devDependencies": { + "esvu": "^1.2.11", + "test262-harness": "^8.0.0" + }, + "scripts": { + "ci": "./tools/scripts/ci_test.sh", + "test": "test262-harness", + "diff": "git diff --diff-filter ACMR --name-only main.. -- test/ && git ls-files --exclude-standard --others -- test/", + "test:diff": "npm run test:diff:v8 && npm run test:diff:spidermonkey && npm run test:diff:chakra && npm run test:diff:javascriptcore", + "test:diff:v8": "test262-harness -t 8 --hostType=d8 --hostPath=v8 $(npm run --silent diff)", + "test:diff:spidermonkey": "test262-harness -t 8 --hostType=jsshell --hostPath=spidermonkey $(npm run --silent diff)", + "test:diff:chakra": "test262-harness -t 8 --hostType=ch --hostPath=chakra $(npm run --silent diff)", + "test:diff:javascriptcore": "test262-harness -t 8 --hostType=jsc --hostPath=javascriptcore $(npm run --silent diff)", + "test:diff:xs": "test262-harness -t 8 --hostType=xs --hostPath=xs $(npm run --silent diff)" + } +} + diff --git a/test/sendable/builtins/ASON/15.12-0-1.js b/test/sendable/builtins/ASON/15.12-0-1.js new file mode 100644 index 0000000000000000000000000000000000000000..5a18e8cc5411062dcbac52429378d313737db11b --- /dev/null +++ b/test/sendable/builtins/ASON/15.12-0-1.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +info: | + This test should be run without any built-ins being added/augmented. + The name JSON must be bound to an object. + 4.2 calls out JSON as one of the built-in objects. +es5id: 15.12-0-1 +description: JSON must be a built-in object +---*/ + +var o = JSON; + +assert.sameValue(typeof(o), "object", 'typeof(o)'); diff --git a/test/sendable/builtins/ASON/15.12-0-2.js b/test/sendable/builtins/ASON/15.12-0-2.js new file mode 100644 index 0000000000000000000000000000000000000000..be97a00743e074ae9d78dcf15bd52bda2b5d83a0 --- /dev/null +++ b/test/sendable/builtins/ASON/15.12-0-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +info: | + This test should be run without any built-ins being added/augmented. + The name JSON must be bound to an object, and must not support [[Construct]]. + step 4 in 11.2.2 should throw a TypeError exception. +es5id: 15.12-0-2 +description: JSON must not support the [[Construct]] method +---*/ + +var o = JSON; +assert.throws(TypeError, function() { + var j = new JSON(); +}); diff --git a/test/sendable/builtins/ASON/15.12-0-3.js b/test/sendable/builtins/ASON/15.12-0-3.js new file mode 100644 index 0000000000000000000000000000000000000000..2de9aba9f998a2406715d21bf9a52449cf781db1 --- /dev/null +++ b/test/sendable/builtins/ASON/15.12-0-3.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +info: | + This test should be run without any built-ins being added/augmented. + The name JSON must be bound to an object, and must not support [[Call]]. + step 5 in 11.2.3 should throw a TypeError exception. +es5id: 15.12-0-3 +description: JSON must not support the [[Call]] method +---*/ + +var o = JSON; +assert.throws(TypeError, function() { + var j = JSON(); +}); diff --git a/test/sendable/builtins/ASON/15.12-0-4.js b/test/sendable/builtins/ASON/15.12-0-4.js new file mode 100644 index 0000000000000000000000000000000000000000..88211d9d301e7110eb0c2a3994c77c476b16f565 --- /dev/null +++ b/test/sendable/builtins/ASON/15.12-0-4.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +info: | + This test should be run without any built-ins being added/augmented. + The last paragraph in section 15 says "every other property described + in this section has the attribute {... [[Enumerable]] : false ...} + unless otherwise specified. This default applies to the properties on + JSON, and we should not be able to enumerate them. +es5id: 15.12-0-4 +description: JSON object's properties must be non enumerable +---*/ + +var o = JSON; +var i = 0; +for (var p in o) { + i++; +} + + +assert.sameValue(i, 0, 'i'); diff --git a/test/sendable/builtins/ASON/Symbol.toStringTag.js b/test/sendable/builtins/ASON/Symbol.toStringTag.js new file mode 100644 index 0000000000000000000000000000000000000000..1f521b04297555ce93973255e9baa88d14aa973a --- /dev/null +++ b/test/sendable/builtins/ASON/Symbol.toStringTag.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +es6id: 24.3.3 +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "JSON". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.toStringTag] +---*/ + +assert.sameValue(JSON[Symbol.toStringTag], 'JSON'); + +verifyNotEnumerable(JSON, Symbol.toStringTag); +verifyNotWritable(JSON, Symbol.toStringTag); +verifyConfigurable(JSON, Symbol.toStringTag); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-0-1.js b/test/sendable/builtins/ASON/parse/15.12.1.1-0-1.js new file mode 100644 index 0000000000000000000000000000000000000000..50dea92ecd01ca5dd4ce2124f95cb0f67dfe4c67 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-0-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-0-1 +description: The JSON lexical grammar treats whitespace as a token seperator +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('12\t\r\n 34'); // should produce a syntax error as whitespace results in two tokens +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-0-2.js b/test/sendable/builtins/ASON/parse/15.12.1.1-0-2.js new file mode 100644 index 0000000000000000000000000000000000000000..17d77b48a5ba13622261b2693ec70dc438d48380 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-0-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-0-2 +description: > + is not valid JSON whitespace as specified by the production + JSONWhitespace. +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u000b1234'); // should produce a syntax error +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-0-3.js b/test/sendable/builtins/ASON/parse/15.12.1.1-0-3.js new file mode 100644 index 0000000000000000000000000000000000000000..4f64dc20b481fa3b6a1a82aad979080ab8c16e8b --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-0-3.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-0-3 +description: > + is not valid JSON whitespace as specified by the production + JSONWhitespace. +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u000c1234'); // should produce a syntax error +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-0-4.js b/test/sendable/builtins/ASON/parse/15.12.1.1-0-4.js new file mode 100644 index 0000000000000000000000000000000000000000..b0a57d78ff0ef9dee6ff42e2bb866361ba41c9cc --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-0-4.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-0-4 +description: > + is not valid JSON whitespace as specified by the production + JSONWhitespace. +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u00a01234'); // should produce a syntax error +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-0-5.js b/test/sendable/builtins/ASON/parse/15.12.1.1-0-5.js new file mode 100644 index 0000000000000000000000000000000000000000..201a22e7703a0dc34fda73b7f129be342a4b90b0 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-0-5.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-0-5 +description: > + is not valid JSON whitespace as specified by the + production JSONWhitespace. +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u200b1234'); // should produce a syntax error +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-0-6.js b/test/sendable/builtins/ASON/parse/15.12.1.1-0-6.js new file mode 100644 index 0000000000000000000000000000000000000000..b5a2e2a7b2f26426f3e1e64f5251f59cc82e9414 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-0-6.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-0-6 +description: > + is not valid JSON whitespace as specified by the production + JSONWhitespace. +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\ufeff1234'); // should produce a syntax error a +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-0-8.js b/test/sendable/builtins/ASON/parse/15.12.1.1-0-8.js new file mode 100644 index 0000000000000000000000000000000000000000..c37e2e39a35a5cd61c64b26c099e2136a1679fb8 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-0-8.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-0-8 +description: > + U+2028 and U+2029 are not valid JSON whitespace as specified by + the production JSONWhitespace. +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u2028\u20291234'); // should produce a syntax error +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-0-9.js b/test/sendable/builtins/ASON/parse/15.12.1.1-0-9.js new file mode 100644 index 0000000000000000000000000000000000000000..6efca79868c5d02b510ee42c01a1b78f117d8bbc --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-0-9.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-0-9 +description: Whitespace characters can appear before/after any JSONtoken +---*/ + +JSON.parseSendable('\t\r \n{\t\r \n' + + '"property"\t\r \n:\t\r \n{\t\r \n}\t\r \n,\t\r \n' + + '"prop2"\t\r \n:\t\r \n' + + '[\t\r \ntrue\t\r \n,\t\r \nnull\t\r \n,123.456\t\r \n]' + + '\t\r \n}\t\r \n'); // should JOSN parse without error diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g1-1.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..5ffb43c42babe75d212d88d409823d8422aaafeb --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g1-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g1-1 +description: The JSON lexical grammar treats as a whitespace character +---*/ + +assert.sameValue(JSON.parseSendable('\t1234'), 1234, ' should be ignored'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('12\t34'); +}, ' should produce a syntax error as whitespace results in two tokens'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g1-2.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..616ce7a920d2114293bad695030b867052f34517 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g1-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g1-2 +description: The JSON lexical grammar treats as a whitespace character +---*/ + +assert.sameValue(JSON.parseSendable('\r1234'), 1234, ' should be ignored'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('12\r34'); +}, ' should produce a syntax error as whitespace results in two tokens'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g1-3.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..10e3d2e66516f44a71db79dac643037868bc23c5 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g1-3.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g1-3 +description: The JSON lexical grammar treats as a whitespace character +---*/ + +assert.sameValue(JSON.parseSendable('\n1234'), 1234, ' should be ignored'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('12\n34'); +}, ' should produce a syntax error as whitespace results in two tokens'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g1-4.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..7036a2c6976cae6af52e570b80a8a4efb6aebdb7 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g1-4.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g1-4 +description: The JSON lexical grammar treats as a whitespace character +---*/ + +assert.sameValue(JSON.parseSendable(' 1234'), 1234, ' should be ignored'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('12 34'); +}, ' should produce a syntax error as whitespace results in two tokens'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g2-1.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..0b267f2b7684ea30bad243b1a62c35ede417c01a --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g2-1.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g2-1 +description: JSONStrings can be written using double quotes +---*/ + +assert.sameValue(JSON.parseSendable('"abc"'), "abc", 'JSON.parseSendable(\'"abc"\')'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g2-2.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..2e668977bc53f8e6155729bfa15b72294831183b --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g2-2.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g2-2 +description: A JSONString may not be delimited by single quotes +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable("'abc'"); +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g2-3.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..e669dcd42a7040b4909f78ba39302beb7e2a1c67 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g2-3.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g2-3 +description: A JSONString may not be delimited by Uncode escaped quotes +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable("\\u0022abc\\u0022"); +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g2-4.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..70b5fb22e094859ef9bc50445bc497a6edb35e9b --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g2-4.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g2-4 +description: A JSONString must both begin and end with double quotes +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('"ab'+"c'"); +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g2-5.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..25e2ad16bd64601e7035af0805042327fec1ab2d --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g2-5.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g2-5 +description: > + A JSONStrings can contain no JSONStringCharacters (Empty + JSONStrings) +---*/ + +assert.sameValue(JSON.parseSendable('""'), "", 'JSON.parseSendable(\'""\')'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g4-1.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..90922377afb417dbbda26f661508dc6ff72c0cea --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g4-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g4-1 +description: > + The JSON lexical grammar does not allow a JSONStringCharacter to + be any of the Unicode characters U+0000 thru U+0007 +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('"\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007"'); // invalid string characters should produce a syntax error +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g4-2.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g4-2.js new file mode 100644 index 0000000000000000000000000000000000000000..3d78b1713bd7ccd64da366ace356aea5a4bb72e8 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g4-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g4-2 +description: > + The JSON lexical grammar does not allow a JSONStringCharacter to + be any of the Unicode characters U+0008 thru U+000F +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('"\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f"'); // invalid string characters should produce a syntax error +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g4-3.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..70666e48bbe9515afea75e39d5483f4725f0e31d --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g4-3.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g4-3 +description: > + The JSON lexical grammar does not allow a JSONStringCharacter to + be any of the Unicode characters U+0010 thru U+0017 +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017"'); // invalid string characters should produce a syntax error +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g4-4.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..15f0fa148ec7a73d0802458a9d99fd7f655b5491 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g4-4.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g4-4 +description: > + The JSON lexical grammar does not allow a JSONStringCharacter to + be any of the Unicode characters U+0018 thru U+001F +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('"\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f"'); // invalid string characters should produce a syntax error +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g5-1.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..7c8956efc0f93ce32ce28f0ba9c457ba4e92455e --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g5-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g5-1 +description: > + The JSON lexical grammar allows Unicode escape sequences in a + JSONString +---*/ + +assert.sameValue(JSON.parseSendable('"\\u0058"'), 'X', 'JSON.parseSendable(\'"\\u0058"\')'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g5-2.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g5-2.js new file mode 100644 index 0000000000000000000000000000000000000000..b0f26a5e5da764dfdb3b0b4634b6444300375204 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g5-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g5-2 +description: > + A JSONStringCharacter UnicodeEscape may not have fewer than 4 hex + characters +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('"\\u005"') +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g5-3.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g5-3.js new file mode 100644 index 0000000000000000000000000000000000000000..39902df1e08b4f5729e3b61bf3ae09bca90a283d --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g5-3.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g5-3 +description: > + A JSONStringCharacter UnicodeEscape may not include any non=hex + characters +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('"\\u0X50"') +}); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g6-1.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-1.js new file mode 100644 index 0000000000000000000000000000000000000000..f6c130536281044f684c5677fbb6b278c319d5e9 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g6-1 +description: > + The JSON lexical grammer allows '/' as a JSONEscapeCharacter after + '' in a JSONString +---*/ + +assert.sameValue(JSON.parseSendable('"\\/"'), '/', 'JSON.parseSendable(\'"\\/"\')'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g6-2.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-2.js new file mode 100644 index 0000000000000000000000000000000000000000..999f68dec57ad2d2a1abbd6e10d6c9c610a7139c --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-2.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g6-2 +description: > + The JSON lexical grammer allows '' as a JSONEscapeCharacter after + '' in a JSONString +---*/ + +assert.sameValue(JSON.parseSendable('"\\\\"'), '\\', 'JSON.parseSendable(\'"\\\\"\')'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g6-3.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-3.js new file mode 100644 index 0000000000000000000000000000000000000000..1121b8279d19b3e60055f8a7834117f95c0ca83e --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-3.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g6-3 +description: > + The JSON lexical grammer allows 'b' as a JSONEscapeCharacter after + '' in a JSONString +---*/ + +assert.sameValue(JSON.parseSendable('"\\b"'), '\b', 'JSON.parseSendable(\'"\\b"\')'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g6-4.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-4.js new file mode 100644 index 0000000000000000000000000000000000000000..ac68e6323274e2f556806c923af50a2c9ac8c945 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-4.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g6-4 +description: > + The JSON lexical grammer allows 'f' as a JSONEscapeCharacter after + '' in a JSONString +---*/ + +assert.sameValue(JSON.parseSendable('"\\f"'), '\f', 'JSON.parseSendable(\'"\\f"\')'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g6-5.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-5.js new file mode 100644 index 0000000000000000000000000000000000000000..12ae29aa064e41763459ee438998aac7b5d1b9b2 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-5.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g6-5 +description: > + The JSON lexical grammer allows 'n' as a JSONEscapeCharacter after + '' in a JSONString +---*/ + +assert.sameValue(JSON.parseSendable('"\\n"'), '\n', 'JSON.parseSendable(\'"\\n"\')'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g6-6.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-6.js new file mode 100644 index 0000000000000000000000000000000000000000..d2af48c9027bcd109883e1f84a173218a6d19760 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-6.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g6-6 +description: > + The JSON lexical grammer allows 'r' as a JSONEscapeCharacter after + '' in a JSONString +---*/ + +assert.sameValue(JSON.parseSendable('"\\r"'), '\r', 'JSON.parseSendable(\'"\\r"\')'); diff --git a/test/sendable/builtins/ASON/parse/15.12.1.1-g6-7.js b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-7.js new file mode 100644 index 0000000000000000000000000000000000000000..2694840cdd4e74628d7cbf99bfb24d4eee7f5482 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.1.1-g6-7.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.1.1-g6-7 +description: > + The JSON lexical grammer allows 't' as a JSONEscapeCharacter after + '' in a JSONString +---*/ + +assert.sameValue(JSON.parseSendable('"\\t"'), '\t', 'JSON.parseSendable(\'"\\t"\')'); diff --git a/test/sendable/builtins/ASON/parse/15.12.2-2-1.js b/test/sendable/builtins/ASON/parse/15.12.2-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..f930df426b41ddd15c579eb879d9e0232760b56f --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.2-2-1.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.2-2-1 +description: > + JSON.parse - parsing an object where property name is a null + character +---*/ + +var nullChars = new Array(); +nullChars[0] = '\"\u0000\"'; +nullChars[1] = '\"\u0001\"'; +nullChars[2] = '\"\u0002\"'; +nullChars[3] = '\"\u0003\"'; +nullChars[4] = '\"\u0004\"'; +nullChars[5] = '\"\u0005\"'; +nullChars[6] = '\"\u0006\"'; +nullChars[7] = '\"\u0007\"'; +nullChars[8] = '\"\u0008\"'; +nullChars[9] = '\"\u0009\"'; +nullChars[10] = '\"\u000A\"'; +nullChars[11] = '\"\u000B\"'; +nullChars[12] = '\"\u000C\"'; +nullChars[13] = '\"\u000D\"'; +nullChars[14] = '\"\u000E\"'; +nullChars[15] = '\"\u000F\"'; +nullChars[16] = '\"\u0010\"'; +nullChars[17] = '\"\u0011\"'; +nullChars[18] = '\"\u0012\"'; +nullChars[19] = '\"\u0013\"'; +nullChars[20] = '\"\u0014\"'; +nullChars[21] = '\"\u0015\"'; +nullChars[22] = '\"\u0016\"'; +nullChars[23] = '\"\u0017\"'; +nullChars[24] = '\"\u0018\"'; +nullChars[25] = '\"\u0019\"'; +nullChars[26] = '\"\u001A\"'; +nullChars[27] = '\"\u001B\"'; +nullChars[28] = '\"\u001C\"'; +nullChars[29] = '\"\u001D\"'; +nullChars[30] = '\"\u001E\"'; +nullChars[31] = '\"\u001F\"'; + +for (var index in nullChars) { + assert.throws(SyntaxError, function() { + var obj = JSON.parseSendable('{ ' + nullChars[index] + ' : "John" } '); + }); +} diff --git a/test/sendable/builtins/ASON/parse/15.12.2-2-10.js b/test/sendable/builtins/ASON/parse/15.12.2-2-10.js new file mode 100644 index 0000000000000000000000000000000000000000..9d6fb44ae110d10361ff90ad6717f65e0b9ad42d --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.2-2-10.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.2-2-10 +description: > + JSON.parse - parsing an object where property value middles with a + null character +---*/ + +var nullChars = new Array(); +nullChars[0] = '\"\u0000\"'; +nullChars[1] = '\"\u0001\"'; +nullChars[2] = '\"\u0002\"'; +nullChars[3] = '\"\u0003\"'; +nullChars[4] = '\"\u0004\"'; +nullChars[5] = '\"\u0005\"'; +nullChars[6] = '\"\u0006\"'; +nullChars[7] = '\"\u0007\"'; +nullChars[8] = '\"\u0008\"'; +nullChars[9] = '\"\u0009\"'; +nullChars[10] = '\"\u000A\"'; +nullChars[11] = '\"\u000B\"'; +nullChars[12] = '\"\u000C\"'; +nullChars[13] = '\"\u000D\"'; +nullChars[14] = '\"\u000E\"'; +nullChars[15] = '\"\u000F\"'; +nullChars[16] = '\"\u0010\"'; +nullChars[17] = '\"\u0011\"'; +nullChars[18] = '\"\u0012\"'; +nullChars[19] = '\"\u0013\"'; +nullChars[20] = '\"\u0014\"'; +nullChars[21] = '\"\u0015\"'; +nullChars[22] = '\"\u0016\"'; +nullChars[23] = '\"\u0017\"'; +nullChars[24] = '\"\u0018\"'; +nullChars[25] = '\"\u0019\"'; +nullChars[26] = '\"\u001A\"'; +nullChars[27] = '\"\u001B\"'; +nullChars[28] = '\"\u001C\"'; +nullChars[29] = '\"\u001D\"'; +nullChars[30] = '\"\u001E\"'; +nullChars[31] = '\"\u001F\"'; + +for (var index in nullChars) { + assert.throws(SyntaxError, function() { + var obj = JSON.parseSendable('{ "name" : ' + "Jo" + nullChars[index] + "hn" + ' } '); + }); +} diff --git a/test/sendable/builtins/ASON/parse/15.12.2-2-2.js b/test/sendable/builtins/ASON/parse/15.12.2-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..c186f556dc7a4eadc67ae645a60fbbccddaf0e6e --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.2-2-2.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.2-2-2 +description: > + JSON.parse - parsing an object where property name starts with a + null character +---*/ + +var nullChars = new Array(); +nullChars[0] = '\"\u0000\"'; +nullChars[1] = '\"\u0001\"'; +nullChars[2] = '\"\u0002\"'; +nullChars[3] = '\"\u0003\"'; +nullChars[4] = '\"\u0004\"'; +nullChars[5] = '\"\u0005\"'; +nullChars[6] = '\"\u0006\"'; +nullChars[7] = '\"\u0007\"'; +nullChars[8] = '\"\u0008\"'; +nullChars[9] = '\"\u0009\"'; +nullChars[10] = '\"\u000A\"'; +nullChars[11] = '\"\u000B\"'; +nullChars[12] = '\"\u000C\"'; +nullChars[13] = '\"\u000D\"'; +nullChars[14] = '\"\u000E\"'; +nullChars[15] = '\"\u000F\"'; +nullChars[16] = '\"\u0010\"'; +nullChars[17] = '\"\u0011\"'; +nullChars[18] = '\"\u0012\"'; +nullChars[19] = '\"\u0013\"'; +nullChars[20] = '\"\u0014\"'; +nullChars[21] = '\"\u0015\"'; +nullChars[22] = '\"\u0016\"'; +nullChars[23] = '\"\u0017\"'; +nullChars[24] = '\"\u0018\"'; +nullChars[25] = '\"\u0019\"'; +nullChars[26] = '\"\u001A\"'; +nullChars[27] = '\"\u001B\"'; +nullChars[28] = '\"\u001C\"'; +nullChars[29] = '\"\u001D\"'; +nullChars[30] = '\"\u001E\"'; +nullChars[31] = '\"\u001F\"'; + +for (var index in nullChars) { + assert.throws(SyntaxError, function() { + var obj = JSON.parseSendable('{ ' + nullChars[index] + "name" + ' : "John" } '); + }); +} diff --git a/test/sendable/builtins/ASON/parse/15.12.2-2-3.js b/test/sendable/builtins/ASON/parse/15.12.2-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..5378050c58d9d03f6a86c1817746612328c5d8c1 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.2-2-3.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.2-2-3 +description: > + JSON.parse - parsing an object where property name ends with a + null character +---*/ + +var nullChars = new Array(); +nullChars[0] = '\"\u0000\"'; +nullChars[1] = '\"\u0001\"'; +nullChars[2] = '\"\u0002\"'; +nullChars[3] = '\"\u0003\"'; +nullChars[4] = '\"\u0004\"'; +nullChars[5] = '\"\u0005\"'; +nullChars[6] = '\"\u0006\"'; +nullChars[7] = '\"\u0007\"'; +nullChars[8] = '\"\u0008\"'; +nullChars[9] = '\"\u0009\"'; +nullChars[10] = '\"\u000A\"'; +nullChars[11] = '\"\u000B\"'; +nullChars[12] = '\"\u000C\"'; +nullChars[13] = '\"\u000D\"'; +nullChars[14] = '\"\u000E\"'; +nullChars[15] = '\"\u000F\"'; +nullChars[16] = '\"\u0010\"'; +nullChars[17] = '\"\u0011\"'; +nullChars[18] = '\"\u0012\"'; +nullChars[19] = '\"\u0013\"'; +nullChars[20] = '\"\u0014\"'; +nullChars[21] = '\"\u0015\"'; +nullChars[22] = '\"\u0016\"'; +nullChars[23] = '\"\u0017\"'; +nullChars[24] = '\"\u0018\"'; +nullChars[25] = '\"\u0019\"'; +nullChars[26] = '\"\u001A\"'; +nullChars[27] = '\"\u001B\"'; +nullChars[28] = '\"\u001C\"'; +nullChars[29] = '\"\u001D\"'; +nullChars[30] = '\"\u001E\"'; +nullChars[31] = '\"\u001F\"'; + +for (var index in nullChars) { + assert.throws(SyntaxError, function() { + var obj = JSON.parseSendable('{' + "name" + nullChars[index] + ' : "John" } '); + }); +} diff --git a/test/sendable/builtins/ASON/parse/15.12.2-2-4.js b/test/sendable/builtins/ASON/parse/15.12.2-2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..b382455ca13b5a56bd78a808ac3f725f498a20f0 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.2-2-4.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.2-2-4 +description: > + JSON.parse - parsing an object where property name starts and ends + with a null character +---*/ + +var nullChars = new Array(); +nullChars[0] = '\"\u0000\"'; +nullChars[1] = '\"\u0001\"'; +nullChars[2] = '\"\u0002\"'; +nullChars[3] = '\"\u0003\"'; +nullChars[4] = '\"\u0004\"'; +nullChars[5] = '\"\u0005\"'; +nullChars[6] = '\"\u0006\"'; +nullChars[7] = '\"\u0007\"'; +nullChars[8] = '\"\u0008\"'; +nullChars[9] = '\"\u0009\"'; +nullChars[10] = '\"\u000A\"'; +nullChars[11] = '\"\u000B\"'; +nullChars[12] = '\"\u000C\"'; +nullChars[13] = '\"\u000D\"'; +nullChars[14] = '\"\u000E\"'; +nullChars[15] = '\"\u000F\"'; +nullChars[16] = '\"\u0010\"'; +nullChars[17] = '\"\u0011\"'; +nullChars[18] = '\"\u0012\"'; +nullChars[19] = '\"\u0013\"'; +nullChars[20] = '\"\u0014\"'; +nullChars[21] = '\"\u0015\"'; +nullChars[22] = '\"\u0016\"'; +nullChars[23] = '\"\u0017\"'; +nullChars[24] = '\"\u0018\"'; +nullChars[25] = '\"\u0019\"'; +nullChars[26] = '\"\u001A\"'; +nullChars[27] = '\"\u001B\"'; +nullChars[28] = '\"\u001C\"'; +nullChars[29] = '\"\u001D\"'; +nullChars[30] = '\"\u001E\"'; +nullChars[31] = '\"\u001F\"'; + +for (var index in nullChars) { + assert.throws(SyntaxError, function() { + var obj = JSON.parseSendable('{' + nullChars[index] + "name" + nullChars[index] + ' : "John" } '); + }); +} diff --git a/test/sendable/builtins/ASON/parse/15.12.2-2-5.js b/test/sendable/builtins/ASON/parse/15.12.2-2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..4364a4757f1b1e7e3482574c67fd9a8c8a7597a0 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.2-2-5.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.2-2-5 +description: > + JSON.parse - parsing an object where property name middles with a + null character +---*/ + +var nullChars = new Array(); +nullChars[0] = '\"\u0000\"'; +nullChars[1] = '\"\u0001\"'; +nullChars[2] = '\"\u0002\"'; +nullChars[3] = '\"\u0003\"'; +nullChars[4] = '\"\u0004\"'; +nullChars[5] = '\"\u0005\"'; +nullChars[6] = '\"\u0006\"'; +nullChars[7] = '\"\u0007\"'; +nullChars[8] = '\"\u0008\"'; +nullChars[9] = '\"\u0009\"'; +nullChars[10] = '\"\u000A\"'; +nullChars[11] = '\"\u000B\"'; +nullChars[12] = '\"\u000C\"'; +nullChars[13] = '\"\u000D\"'; +nullChars[14] = '\"\u000E\"'; +nullChars[15] = '\"\u000F\"'; +nullChars[16] = '\"\u0010\"'; +nullChars[17] = '\"\u0011\"'; +nullChars[18] = '\"\u0012\"'; +nullChars[19] = '\"\u0013\"'; +nullChars[20] = '\"\u0014\"'; +nullChars[21] = '\"\u0015\"'; +nullChars[22] = '\"\u0016\"'; +nullChars[23] = '\"\u0017\"'; +nullChars[24] = '\"\u0018\"'; +nullChars[25] = '\"\u0019\"'; +nullChars[26] = '\"\u001A\"'; +nullChars[27] = '\"\u001B\"'; +nullChars[28] = '\"\u001C\"'; +nullChars[29] = '\"\u001D\"'; +nullChars[30] = '\"\u001E\"'; +nullChars[31] = '\"\u001F\"'; + +for (var index in nullChars) { + assert.throws(SyntaxError, function() { + var obj = JSON.parseSendable('{ ' + "na" + nullChars[index] + "me" + ' : "John" } '); + }); +} diff --git a/test/sendable/builtins/ASON/parse/15.12.2-2-6.js b/test/sendable/builtins/ASON/parse/15.12.2-2-6.js new file mode 100644 index 0000000000000000000000000000000000000000..8cf76e5d294b743682c4aa0b436a076f0cd6ae8c --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.2-2-6.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.2-2-6 +description: > + JSON.parse - parsing an object where property value is a null + character +---*/ + +var nullChars = new Array(); +nullChars[0] = '\"\u0000\"'; +nullChars[1] = '\"\u0001\"'; +nullChars[2] = '\"\u0002\"'; +nullChars[3] = '\"\u0003\"'; +nullChars[4] = '\"\u0004\"'; +nullChars[5] = '\"\u0005\"'; +nullChars[6] = '\"\u0006\"'; +nullChars[7] = '\"\u0007\"'; +nullChars[8] = '\"\u0008\"'; +nullChars[9] = '\"\u0009\"'; +nullChars[10] = '\"\u000A\"'; +nullChars[11] = '\"\u000B\"'; +nullChars[12] = '\"\u000C\"'; +nullChars[13] = '\"\u000D\"'; +nullChars[14] = '\"\u000E\"'; +nullChars[15] = '\"\u000F\"'; +nullChars[16] = '\"\u0010\"'; +nullChars[17] = '\"\u0011\"'; +nullChars[18] = '\"\u0012\"'; +nullChars[19] = '\"\u0013\"'; +nullChars[20] = '\"\u0014\"'; +nullChars[21] = '\"\u0015\"'; +nullChars[22] = '\"\u0016\"'; +nullChars[23] = '\"\u0017\"'; +nullChars[24] = '\"\u0018\"'; +nullChars[25] = '\"\u0019\"'; +nullChars[26] = '\"\u001A\"'; +nullChars[27] = '\"\u001B\"'; +nullChars[28] = '\"\u001C\"'; +nullChars[29] = '\"\u001D\"'; +nullChars[30] = '\"\u001E\"'; +nullChars[31] = '\"\u001F\"'; + +for (var index in nullChars) { + assert.throws(SyntaxError, function() { + var obj = JSON.parseSendable('{ "name" : ' + nullChars[index] + ' } '); + }); +} diff --git a/test/sendable/builtins/ASON/parse/15.12.2-2-7.js b/test/sendable/builtins/ASON/parse/15.12.2-2-7.js new file mode 100644 index 0000000000000000000000000000000000000000..70c8283e19bc0dd7018d126241fd2b9e1f1dce96 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.2-2-7.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.2-2-7 +description: > + JSON.parse - parsing an object where property value starts with a + null character +---*/ + +var nullChars = new Array(); +nullChars[0] = '\"\u0000\"'; +nullChars[1] = '\"\u0001\"'; +nullChars[2] = '\"\u0002\"'; +nullChars[3] = '\"\u0003\"'; +nullChars[4] = '\"\u0004\"'; +nullChars[5] = '\"\u0005\"'; +nullChars[6] = '\"\u0006\"'; +nullChars[7] = '\"\u0007\"'; +nullChars[8] = '\"\u0008\"'; +nullChars[9] = '\"\u0009\"'; +nullChars[10] = '\"\u000A\"'; +nullChars[11] = '\"\u000B\"'; +nullChars[12] = '\"\u000C\"'; +nullChars[13] = '\"\u000D\"'; +nullChars[14] = '\"\u000E\"'; +nullChars[15] = '\"\u000F\"'; +nullChars[16] = '\"\u0010\"'; +nullChars[17] = '\"\u0011\"'; +nullChars[18] = '\"\u0012\"'; +nullChars[19] = '\"\u0013\"'; +nullChars[20] = '\"\u0014\"'; +nullChars[21] = '\"\u0015\"'; +nullChars[22] = '\"\u0016\"'; +nullChars[23] = '\"\u0017\"'; +nullChars[24] = '\"\u0018\"'; +nullChars[25] = '\"\u0019\"'; +nullChars[26] = '\"\u001A\"'; +nullChars[27] = '\"\u001B\"'; +nullChars[28] = '\"\u001C\"'; +nullChars[29] = '\"\u001D\"'; +nullChars[30] = '\"\u001E\"'; +nullChars[31] = '\"\u001F\"'; + +for (var index in nullChars) { + assert.throws(SyntaxError, function() { + var obj = JSON.parseSendable('{ "name" : ' + nullChars[index] + "John" + ' } '); + }); +} diff --git a/test/sendable/builtins/ASON/parse/15.12.2-2-8.js b/test/sendable/builtins/ASON/parse/15.12.2-2-8.js new file mode 100644 index 0000000000000000000000000000000000000000..c3abc56c3d4bba8a33400c3e60d94759f1b63178 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.2-2-8.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.2-2-8 +description: > + JSON.parse - parsing an object where property value ends with a + null character +---*/ + +var nullChars = new Array(); +nullChars[0] = '\"\u0000\"'; +nullChars[1] = '\"\u0001\"'; +nullChars[2] = '\"\u0002\"'; +nullChars[3] = '\"\u0003\"'; +nullChars[4] = '\"\u0004\"'; +nullChars[5] = '\"\u0005\"'; +nullChars[6] = '\"\u0006\"'; +nullChars[7] = '\"\u0007\"'; +nullChars[8] = '\"\u0008\"'; +nullChars[9] = '\"\u0009\"'; +nullChars[10] = '\"\u000A\"'; +nullChars[11] = '\"\u000B\"'; +nullChars[12] = '\"\u000C\"'; +nullChars[13] = '\"\u000D\"'; +nullChars[14] = '\"\u000E\"'; +nullChars[15] = '\"\u000F\"'; +nullChars[16] = '\"\u0010\"'; +nullChars[17] = '\"\u0011\"'; +nullChars[18] = '\"\u0012\"'; +nullChars[19] = '\"\u0013\"'; +nullChars[20] = '\"\u0014\"'; +nullChars[21] = '\"\u0015\"'; +nullChars[22] = '\"\u0016\"'; +nullChars[23] = '\"\u0017\"'; +nullChars[24] = '\"\u0018\"'; +nullChars[25] = '\"\u0019\"'; +nullChars[26] = '\"\u001A\"'; +nullChars[27] = '\"\u001B\"'; +nullChars[28] = '\"\u001C\"'; +nullChars[29] = '\"\u001D\"'; +nullChars[30] = '\"\u001E\"'; +nullChars[31] = '\"\u001F\"'; + +for (var index in nullChars) { + assert.throws(SyntaxError, function() { + var obj = JSON.parseSendable('{ "name" : ' + "John" + nullChars[index] + ' } '); + }); +} diff --git a/test/sendable/builtins/ASON/parse/15.12.2-2-9.js b/test/sendable/builtins/ASON/parse/15.12.2-2-9.js new file mode 100644 index 0000000000000000000000000000000000000000..7a4e6633618951a13aca0f147a2ec6a325e3aa4d --- /dev/null +++ b/test/sendable/builtins/ASON/parse/15.12.2-2-9.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +es5id: 15.12.2-2-9 +description: > + JSON.parse - parsing an object where property value starts and + ends with a null character +---*/ + +var nullChars = new Array(); +nullChars[0] = '\"\u0000\"'; +nullChars[1] = '\"\u0001\"'; +nullChars[2] = '\"\u0002\"'; +nullChars[3] = '\"\u0003\"'; +nullChars[4] = '\"\u0004\"'; +nullChars[5] = '\"\u0005\"'; +nullChars[6] = '\"\u0006\"'; +nullChars[7] = '\"\u0007\"'; +nullChars[8] = '\"\u0008\"'; +nullChars[9] = '\"\u0009\"'; +nullChars[10] = '\"\u000A\"'; +nullChars[11] = '\"\u000B\"'; +nullChars[12] = '\"\u000C\"'; +nullChars[13] = '\"\u000D\"'; +nullChars[14] = '\"\u000E\"'; +nullChars[15] = '\"\u000F\"'; +nullChars[16] = '\"\u0010\"'; +nullChars[17] = '\"\u0011\"'; +nullChars[18] = '\"\u0012\"'; +nullChars[19] = '\"\u0013\"'; +nullChars[20] = '\"\u0014\"'; +nullChars[21] = '\"\u0015\"'; +nullChars[22] = '\"\u0016\"'; +nullChars[23] = '\"\u0017\"'; +nullChars[24] = '\"\u0018\"'; +nullChars[25] = '\"\u0019\"'; +nullChars[26] = '\"\u001A\"'; +nullChars[27] = '\"\u001B\"'; +nullChars[28] = '\"\u001C\"'; +nullChars[29] = '\"\u001D\"'; +nullChars[30] = '\"\u001E\"'; +nullChars[31] = '\"\u001F\"'; + +for (var index in nullChars) { + assert.throws(SyntaxError, function() { + var obj = JSON.parseSendable('{ "name" : ' + nullChars[index] + "John" + nullChars[index] + ' } '); + }); +} diff --git a/test/sendable/builtins/ASON/parse/S15.12.2_A1.js b/test/sendable/builtins/ASON/parse/S15.12.2_A1.js new file mode 100644 index 0000000000000000000000000000000000000000..c3ea45ad889074eb34d51dd880b6c23cd8452fea --- /dev/null +++ b/test/sendable/builtins/ASON/parse/S15.12.2_A1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +info: JSON.parse must create a property with the given property name +es5id: 15.12.2_A1 +description: Tests that JSON.parse treats "__proto__" as a regular property name +---*/ + +var x = JSON.parseSendable('{"__proto__":[]}'); + +assert.sameValue( + Object.getPrototypeOf(x), + Object.prototype, + 'Object.getPrototypeOf("JSON.parseSendable(\'{"__proto__":[]}\')") returns Object.prototype' +); + +assert(Array.isArray(x.__proto__), 'Array.isArray(x.__proto__) must return true'); diff --git a/test/sendable/builtins/ASON/parse/invalid-whitespace.js b/test/sendable/builtins/ASON/parse/invalid-whitespace.js new file mode 100644 index 0000000000000000000000000000000000000000..b65c52f5d033f721cda6f074bcbf07d21353d837 --- /dev/null +++ b/test/sendable/builtins/ASON/parse/invalid-whitespace.js @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-json.parse +es5id: 15.12.1.1-0-7 +description: > + other category z spaces are not valid JSON whitespace as specified + by the production JSONWhitespace. +---*/ + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u16801'); +}, '\\u1680'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u180e1'); +}, '\\u180e'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u20001'); +}, '\\u2000'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u20011'); +}, '\\u2001'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u20021'); +}, '\\u2002'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u20031'); +}, '\\u2003'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u20041'); +}, '\\u2004'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u20051'); +}, '\\u2005'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u20061'); +}, '\\u2006'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u20071'); +}, '\\u2007'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u20081'); +}, '\\u2008'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u20091'); +}, '\\u2009'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u200a1'); +}, '\\u200a'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u202f1'); +}, '\\u202f'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u205f1'); +}, '\\u205f'); + +assert.throws(SyntaxError, function() { + JSON.parseSendable('\u30001'); +}, '\\u3000'); diff --git a/test/sendable/builtins/ASON/stringify/value-bigint-cross-realm.js b/test/sendable/builtins/ASON/stringify/value-bigint-cross-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..123d728f29d6c4ca622271734e75bafbb0c109bc --- /dev/null +++ b/test/sendable/builtins/ASON/stringify/value-bigint-cross-realm.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-serializejsonproperty +description: JSON.stringify called with a BigInt object from another realm +features: [BigInt, cross-realm] +---*/ + +var other = $262.createRealm().global; +var wrapped = other.Object(other.BigInt(100)); + +assert.throws(TypeError, () => JSON.stringify(wrapped), + "cross-realm BigInt object without toJSON method"); + +other.BigInt.prototype.toJSON = function () { return this.toString(); }; + +assert.sameValue(JSON.stringify(wrapped), "\"100\"", + "cross-realm BigInt object with toJSON method"); diff --git a/test/sendable/builtins/ASON/stringify/value-bigint-order.js b/test/sendable/builtins/ASON/stringify/value-bigint-order.js new file mode 100644 index 0000000000000000000000000000000000000000..253986e5069d9bd3efc38283cef72aa84bd121f6 --- /dev/null +++ b/test/sendable/builtins/ASON/stringify/value-bigint-order.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: BigInt stringify order of steps +esid: sec-serializejsonproperty +info: | + Runtime Semantics: SerializeJSONProperty ( key, holder ) + + 2. If Type(value) is Object or BigInt, then + a. Let toJSON be ? GetGetV(value, "toJSON"). + b. If IsCallable(toJSON) is true, then + i. Set value to ? Call(toJSON, value, « key »). + 3. If ReplacerFunction is not undefined, then + a. Set value to ? Call(ReplacerFunction, holder, « key, value »). + 4. If Type(value) is Object, then + [...] + d. Else if value has a [[BigIntData]] internal slot, then + i. Set value to value.[[BigIntData]]. + [...] + 10. If Type(value) is BigInt, throw a TypeError exception +features: [BigInt, arrow-function] +---*/ + +let step; + +function replacer(x, k, v) +{ + assert.sameValue(step++, 1); + assert.sameValue(v, 1n); + return x; +} + +BigInt.prototype.toJSON = function () { assert.sameValue(step++, 0); return 1n; }; + +step = 0; +assert.throws(TypeError, () => JSON.stringify(0n, (k, v) => replacer(2n, k, v))); +assert.sameValue(step, 2); + +step = 0; +assert.throws(TypeError, () => JSON.stringify(0n, (k, v) => replacer(Object(2n), k, v))); +assert.sameValue(step, 2); diff --git a/test/sendable/builtins/ASON/stringify/value-bigint-replacer.js b/test/sendable/builtins/ASON/stringify/value-bigint-replacer.js new file mode 100644 index 0000000000000000000000000000000000000000..3213f22f8e9e1527804d7a1344be2e84c7398e24 --- /dev/null +++ b/test/sendable/builtins/ASON/stringify/value-bigint-replacer.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: JSON serialization of BigInt values with replacer +esid: sec-serializejsonproperty +info: | + Runtime Semantics: SerializeJSONProperty ( key, holder ) + + 3. If ReplacerFunction is not undefined, then + a. Set value to ? Call(ReplacerFunction, holder, « key, value »). +features: [BigInt] +---*/ + +function replacer(k, v) +{ + if (typeof v === "bigint") + return "bigint"; + else + return v; +} + +assert.sameValue(JSON.stringify(0n, replacer), '"bigint"'); +assert.sameValue(JSON.stringify({x: 0n}, replacer), '{"x":"bigint"}'); diff --git a/test/sendable/builtins/ASON/stringify/value-bigint.js b/test/sendable/builtins/ASON/stringify/value-bigint.js new file mode 100644 index 0000000000000000000000000000000000000000..1170ebe057b50444471afe3e6262c3ad369f479f --- /dev/null +++ b/test/sendable/builtins/ASON/stringify/value-bigint.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: JSON serialization of BigInt values +esid: pending +features: [BigInt] +---*/ + +assert.throws(TypeError, () => JSON.stringify(0n)); +assert.throws(TypeError, () => JSON.stringify(Object(0n))); +assert.throws(TypeError, () => JSON.stringify({x: 0n})); diff --git a/test/sendable/builtins/ASON/stringify/value-string-escape-unicode.js b/test/sendable/builtins/ASON/stringify/value-string-escape-unicode.js new file mode 100644 index 0000000000000000000000000000000000000000..67d77a18d463b71933470f3d500bb0f5d40aab46 --- /dev/null +++ b/test/sendable/builtins/ASON/stringify/value-string-escape-unicode.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-quotejsonstring +description: > + JSON.stringify strings containing surrogate code units +features: [well-formed-json-stringify] +---*/ + +assert.sameValue(JSON.stringify("\uD834"), '"\\ud834"', + 'JSON.stringify("\\uD834")'); +assert.sameValue(JSON.stringify("\uDF06"), '"\\udf06"', + 'JSON.stringify("\\uDF06")'); + +assert.sameValue(JSON.stringify("\uD834\uDF06"), '"𝌆"', + 'JSON.stringify("\\uD834\\uDF06")'); +assert.sameValue(JSON.stringify("\uD834\uD834\uDF06\uD834"), '"\\ud834𝌆\\ud834"', + 'JSON.stringify("\\uD834\\uD834\\uDF06\\uD834")'); +assert.sameValue(JSON.stringify("\uD834\uD834\uDF06\uDF06"), '"\\ud834𝌆\\udf06"', + 'JSON.stringify("\\uD834\\uD834\\uDF06\\uDF06")'); +assert.sameValue(JSON.stringify("\uDF06\uD834\uDF06\uD834"), '"\\udf06𝌆\\ud834"', + 'JSON.stringify("\\uDF06\\uD834\\uDF06\\uD834")'); +assert.sameValue(JSON.stringify("\uDF06\uD834\uDF06\uDF06"), '"\\udf06𝌆\\udf06"', + 'JSON.stringify("\\uDF06\\uD834\\uDF06\\uDF06")'); + +assert.sameValue(JSON.stringify("\uDF06\uD834"), '"\\udf06\\ud834"', + 'JSON.stringify("\\uDF06\\uD834")'); +assert.sameValue(JSON.stringify("\uD834\uDF06\uD834\uD834"), '"𝌆\\ud834\\ud834"', + 'JSON.stringify("\\uD834\\uDF06\\uD834\\uD834")'); +assert.sameValue(JSON.stringify("\uD834\uDF06\uD834\uDF06"), '"𝌆𝌆"', + 'JSON.stringify("\\uD834\\uDF06\\uD834\\uDF06")'); +assert.sameValue(JSON.stringify("\uDF06\uDF06\uD834\uD834"), '"\\udf06\\udf06\\ud834\\ud834"', + 'JSON.stringify("\\uDF06\\uDF06\\uD834\\uD834")'); +assert.sameValue(JSON.stringify("\uDF06\uDF06\uD834\uDF06"), '"\\udf06\\udf06𝌆"', + 'JSON.stringify("\\uDF06\\uDF06\\uD834\\uDF06")'); diff --git a/test/sendable/builtins/Array/15.4.5-1.js b/test/sendable/builtins/Array/15.4.5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..6db446cd41d928f5936545a0150e7a02cb84b523 --- /dev/null +++ b/test/sendable/builtins/Array/15.4.5-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +es5id: 15.4.5-1 +description: Array instances have [[Class]] set to 'Array' +---*/ + +var a = []; +var s = Object.prototype.toString.call(a); +assert.sameValue(s, '[object Array]', 'The value of s is expected to be "[object Array]"'); diff --git a/test/sendable/builtins/Array/15.4.5.1-5-1.js b/test/sendable/builtins/Array/15.4.5.1-5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..587cfcac961f326f294d4d3ca4666386f6646fa6 --- /dev/null +++ b/test/sendable/builtins/Array/15.4.5.1-5-1.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +es5id: 15.4.5.1-5-1 +description: > + Defining a property named 4294967295 (2**32-1)(not an array + element) +---*/ + +var a = []; +a[4294967295] = "not an array element"; +assert.sameValue(a[4294967295], "not an array element", 'The value of a[4294967295] is expected to be "not an array element"'); diff --git a/test/sendable/builtins/Array/15.4.5.1-5-2.js b/test/sendable/builtins/Array/15.4.5.1-5-2.js new file mode 100644 index 0000000000000000000000000000000000000000..5c891e23bddb9924c0ea4dc0dbe581a0dd1b59ca --- /dev/null +++ b/test/sendable/builtins/Array/15.4.5.1-5-2.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +es5id: 15.4.5.1-5-2 +description: > + Defining a property named 4294967295 (2**32-1) doesn't change + length of the array +---*/ + +var a = [0, 1, 2]; +a[4294967295] = "not an array element"; +assert.sameValue(a.length, 3, 'The value of a.length is expected to be 3'); diff --git a/test/sendable/builtins/Array/S15.4.1_A1.1_T1.js b/test/sendable/builtins/Array/S15.4.1_A1.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..09d90b299acde27ba4710322d38dfa6ad71eabb6 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.1_A1.1_T1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The [[Prototype]] property of the newly constructed object + is set to the original Array prototype object, the one that + is the initial value of Array.prototype +es5id: 15.4.1_A1.1_T1 +description: > + Create new property of Array.prototype. When new Array object has + this property +---*/ + +SendableArray.prototype.myproperty = 42; +var x = SendableArray(); +assert.sameValue(x.myproperty, 42, 'The value of x.myproperty is expected to be 42'); +assert.sameValue( + Object.prototype.hasOwnProperty.call(x, 'myproperty'), + false, + 'Object.prototype.hasOwnProperty.call(SendableArray(), "myproperty") must return false' +); diff --git a/test/sendable/builtins/Array/S15.4.1_A1.1_T2.js b/test/sendable/builtins/Array/S15.4.1_A1.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..51e04777f0501977cdf996d6b9afdb83e7c1beed --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.1_A1.1_T2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The [[Prototype]] property of the newly constructed object + is set to the original Array prototype object, the one that + is the initial value of Array.prototype +es5id: 15.4.1_A1.1_T2 +description: Array.prototype.toString = Object.prototype.toString +---*/ + +SendableArray.prototype.toString = Object.prototype.toString; +var x = SendableArray(); +assert.sameValue(x.toString(), "[object SendableArray]", 'x.toString() must return "[object SendableArray]"'); +SendableArray.prototype.toString = Object.prototype.toString; +var x = SendableArray(0, 1, 2); +assert.sameValue(x.toString(), "[object SendableArray]", 'x.toString() must return "[object SendableArray]"'); diff --git a/test/sendable/builtins/Array/S15.4.1_A1.1_T3.js b/test/sendable/builtins/Array/S15.4.1_A1.1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..934d3569e140b38d4bb6910a10073d0867cc24ef --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.1_A1.1_T3.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The [[Prototype]] property of the newly constructed object + is set to the original Array prototype object, the one that + is the initial value of Array.prototype +es5id: 15.4.1_A1.1_T3 +description: Checking use isPrototypeOf +---*/ + +assert.sameValue( + SendableArray.prototype.isPrototypeOf(SendableArray()), + true, + 'SendableArray.prototype.isPrototypeOf(SendableArray()) must return true' +); diff --git a/test/sendable/builtins/Array/S15.4.1_A1.2_T1.js b/test/sendable/builtins/Array/S15.4.1_A1.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..56bbb9d689b2079a3af80a8ecce14643ce66d33d --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.1_A1.2_T1.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: The [[Class]] property of the newly constructed object is set to "Array" +es5id: 15.4.1_A1.2_T1 +description: Checking use Object.prototype.toString +---*/ + +var x = SendableArray(); +x.getClass = Object.prototype.toString; +assert.sameValue(x.getClass(), "[object SendableArray]", 'x.getClass() must return "[object SendableArray]"'); +var x = SendableArray(0, 1, 2); +x.getClass = Object.prototype.toString; +assert.sameValue(x.getClass(), "[object SendableArray]", 'x.getClass() must return "[object SendableArray]"'); diff --git a/test/sendable/builtins/Array/S15.4.1_A1.3_T1.js b/test/sendable/builtins/Array/S15.4.1_A1.3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..49eaf28369f088f6561153e18b1423dec6c5d88a --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.1_A1.3_T1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + This description of Array constructor applies if and only if + the Array constructor is given no arguments or at least two arguments +es5id: 15.4.1_A1.3_T1 +description: Checking case when Array constructor is given one argument +---*/ + +var x = SendableArray(2); +assert.notSameValue(x.length, 1, 'The value of x.length is not 1'); +assert.notSameValue(x[0], 2, 'The value of x[0] is not 2'); diff --git a/test/sendable/builtins/Array/S15.4.1_A2.1_T1.js b/test/sendable/builtins/Array/S15.4.1_A2.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..7a778123ccefab3263cd34b0c3f2b5ebb32b91eb --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.1_A2.1_T1.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The length property of the newly constructed object; + is set to the number of arguments +es5id: 15.4.1_A2.1_T1 +description: Array constructor is given no arguments or at least two arguments +---*/ +assert.sameValue(SendableArray().length, 0, 'The value of SendableArray().length is expected to be 0'); +assert.sameValue(SendableArray(0, 1, 0, 1).length, 4, 'The value of SendableArray(0, 1, 0, 1).length is expected to be 4'); +assert.sameValue( + SendableArray(undefined, undefined).length, + 2, + 'The value of SendableArray(undefined, undefined).length is expected to be 2' +); diff --git a/test/sendable/builtins/Array/S15.4.1_A2.2_T1.js b/test/sendable/builtins/Array/S15.4.1_A2.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..4847b889444f70613692e4e23d9fe0e40932f8c1 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.1_A2.2_T1.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The 0 property of the newly constructed object is set to item0 + (if supplied); the 1 property of the newly constructed object is set to item1 + (if supplied); and, in general, for as many arguments as there are, the k property + of the newly constructed object is set to argument k, where the first argument is + considered to be argument number 0 +es5id: 15.4.1_A2.2_T1 +description: Checking correct work this algorithm +---*/ +var x = SendableArray( + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, + 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 +); +for (var i = 0; i < 100; i++) { + var result = true; + if (x[i] !== i) { + result = false; + } +} +assert.sameValue(result, true, 'The value of result is expected to be true'); diff --git a/test/sendable/builtins/Array/S15.4.1_A3.1_T1.js b/test/sendable/builtins/Array/S15.4.1_A3.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..b8c424781963051e63e38a193b28202720b22ee1 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.1_A3.1_T1.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + When Array is called as a function rather than as a constructor, + it creates and initialises a new Array object +es5id: 15.4.1_A3.1_T1 +description: Checking use typeof, instanceof +---*/ + +assert.sameValue(typeof SendableArray(), "object", 'The value of `typeof SendableArray()` is expected to be "object"'); +assert.sameValue( + SendableArray() instanceof SendableArray, + true, + 'The result of evaluating (SendableArray() instanceof SendableArray) is expected to be true' +); diff --git a/test/sendable/builtins/Array/S15.4.2.1_A1.1_T1.js b/test/sendable/builtins/Array/S15.4.2.1_A1.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..71b3232dc5128ae3b782b3b6ac6007900b87b90c --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.2.1_A1.1_T1.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The [[Prototype]] property of the newly constructed object + is set to the original Array prototype object, the one that + is the initial value of Array.prototype +es5id: 15.4.2.1_A1.1_T1 +description: > + Create new property of Array.prototype. When new Array object has + this property +---*/ + +SendableArray.prototype.myproperty = 1; +var x = new SendableArray(); +assert.sameValue(x.myproperty, 1, 'The value of x.myproperty is expected to be 1'); +assert.sameValue(x.hasOwnProperty('myproperty'), false, 'x.hasOwnProperty("myproperty") must return false'); diff --git a/test/sendable/builtins/Array/S15.4.2.1_A1.1_T2.js b/test/sendable/builtins/Array/S15.4.2.1_A1.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..b02e04ae2f898493e41f0d7362c392763469b890 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.2.1_A1.1_T2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The [[Prototype]] property of the newly constructed object + is set to the original Array prototype object, the one that + is the initial value of Array.prototype +es5id: 15.4.2.1_A1.1_T2 +description: Array.prototype.toString = Object.prototype.toString +---*/ + +SendableArray.prototype.toString = Object.prototype.toString; +var x = new SendableArray(); +assert.sameValue(x.toString(), "[object SendableArray]", 'x.toString() must return "[object SendableArray]"'); +SendableArray.prototype.toString = Object.prototype.toString; +var x = new SendableArray(0, 1, 2); +assert.sameValue(x.toString(), "[object SendableArray]", 'x.toString() must return "[object SendableArray]"'); diff --git a/test/sendable/builtins/Array/S15.4.2.1_A1.1_T3.js b/test/sendable/builtins/Array/S15.4.2.1_A1.1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..9a1c62735b06a84da350ce71ca14d7f1c7ed5a20 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.2.1_A1.1_T3.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The [[Prototype]] property of the newly constructed object + is set to the original Array prototype object, the one that + is the initial value of Array.prototype +es5id: 15.4.2.1_A1.1_T3 +description: Checking use isPrototypeOf +---*/ +assert.sameValue( + SendableArray.prototype.isPrototypeOf(new SendableArray()), + true, + 'SendableArray.prototype.isPrototypeOf(new SendableArray()) must return true' +); diff --git a/test/sendable/builtins/Array/S15.4.2.1_A1.2_T1.js b/test/sendable/builtins/Array/S15.4.2.1_A1.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..76145021bf6c9bc487b1642aed0410ba31567fde --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.2.1_A1.2_T1.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: The [[Class]] property of the newly constructed object is set to "Array" +es5id: 15.4.2.1_A1.2_T1 +description: Checking use Object.prototype.toString +---*/ + +var x = new SendableArray(); +x.getClass = Object.prototype.toString; +assert.sameValue(x.getClass(), "[object SendableArray]", 'x.getClass() must return "[object SendableArray]"'); +var x = new SendableArray(0, 1, 2); +x.getClass = Object.prototype.toString; +assert.sameValue(x.getClass(), "[object SendableArray]", 'x.getClass() must return "[object SendableArray]"'); diff --git a/test/sendable/builtins/Array/S15.4.2.1_A1.3_T1.js b/test/sendable/builtins/Array/S15.4.2.1_A1.3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..4a5fa6300db1690eb5cff58ea8090e9470b03642 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.2.1_A1.3_T1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + This description of Array constructor applies if and only if + the Array constructor is given no arguments or at least two arguments +es5id: 15.4.2.1_A1.3_T1 +description: Checking case when Array constructor is given one argument +---*/ + +var x = new SendableArray(2); +assert.notSameValue(x.length, 1, 'The value of x.length is not 1'); +assert.notSameValue(x[0], 2, 'The value of x[0] is not 2'); diff --git a/test/sendable/builtins/Array/S15.4.2.1_A2.1_T1.js b/test/sendable/builtins/Array/S15.4.2.1_A2.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..6ea53b0c58d06bffd439aab8cdeae47ed6190f1b --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.2.1_A2.1_T1.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The length property of the newly constructed object; + is set to the number of arguments +es5id: 15.4.2.1_A2.1_T1 +description: Array constructor is given no arguments or at least two arguments +---*/ +assert.sameValue(new SendableArray().length, 0, 'The value of new SendableArray().length is expected to be 0'); +assert.sameValue(new SendableArray(0, 1, 0, 1).length, 4, 'The value of new SendableArray(0, 1, 0, 1).length is expected to be 4'); +assert.sameValue( + new SendableArray(undefined, undefined).length, + 2, + 'The value of new SendableArray(undefined, undefined).length is expected to be 2' +); diff --git a/test/sendable/builtins/Array/S15.4.2.1_A2.2_T1.js b/test/sendable/builtins/Array/S15.4.2.1_A2.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..73fde085fe1f35b02bd3b99a0fb7335f111f92dd --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.2.1_A2.2_T1.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The 0 property of the newly constructed object is set to item0 + (if supplied); the 1 property of the newly constructed object is set to item1 + (if supplied); and, in general, for as many arguments as there are, the k property + of the newly constructed object is set to argument k, where the first argument is + considered to be argument number 0 +es5id: 15.4.2.1_A2.2_T1 +description: Checking correct work this algorithm +---*/ + +var x = new SendableArray( + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, + 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 +); +for (var i = 0; i < 100; i++) { + var result = true; + if (x[i] !== i) { + result = false; + } +} +assert.sameValue(result, true, 'The value of result is expected to be true'); diff --git a/test/sendable/builtins/Array/S15.4.3_A1.1_T1.js b/test/sendable/builtins/Array/S15.4.3_A1.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..24a3df9105df5984fb617f486588c91a7e313cea --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.3_A1.1_T1.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The value of the internal [[Prototype]] property of + the Array constructor is the Function prototype object +es5id: 15.4.3_A1.1_T1 +description: > + Create new property of Function.prototype. When Array constructor + has this property +---*/ + +Function.prototype.myproperty = 1; +assert.sameValue(SendableArray.myproperty, 1, 'The value of SendableArray.myproperty is expected to be 1'); +assert.sameValue(SendableArray.hasOwnProperty('myproperty'), false, 'SendableArray.hasOwnProperty("myproperty") must return false'); diff --git a/test/sendable/builtins/Array/S15.4.3_A1.1_T2.js b/test/sendable/builtins/Array/S15.4.3_A1.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..5f42caeb9b93dd1215decf003440e1c3683b6d90 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.3_A1.1_T2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The value of the internal [[Prototype]] property of + the Array constructor is the Function prototype object +es5id: 15.4.3_A1.1_T2 +description: Function.prototype.toString = Object.prototype.toString +---*/ + +Function.prototype.toString = Object.prototype.toString; +assert.sameValue( + SendableArray.toString(), + "[object Function]", + 'SendableArray.toString() must return "[object Function]"' +); diff --git a/test/sendable/builtins/Array/S15.4.3_A1.1_T3.js b/test/sendable/builtins/Array/S15.4.3_A1.1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..fc22f086d4d014f0619cf665b1c69c14a16f7f42 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.3_A1.1_T3.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The value of the internal [[Prototype]] property of + the Array constructor is the Function prototype object +es5id: 15.4.3_A1.1_T3 +description: Checking use isPrototypeOf +---*/ +assert.sameValue( + Function.prototype.isPrototypeOf(SendableArray), + true, + 'Function.prototype.isPrototypeOf(SendableArray) must return true' +); diff --git a/test/sendable/builtins/Array/S15.4.5.1_A1.2_T2.js b/test/sendable/builtins/Array/S15.4.5.1_A1.2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..a6a3e0809fa6e5d1d5d16ba6687fc5a2859813c8 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.5.1_A1.2_T2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + For every integer k that is less than the value of + the length property of A but not less than ToUint32(length), + if A itself has a property (not an inherited property) named ToString(k), + then delete that property +es5id: 15.4.5.1_A1.2_T2 +description: Checking an inherited property +---*/ + +SendableArray.prototype[2] = -1; +var x = [0, 1, 2]; +assert.sameValue(x[2], 2, 'The value of x[2] is expected to be 2'); +x.length = 2; +assert.sameValue(x[2], -1, 'The value of x[2] is expected to be -1'); diff --git a/test/sendable/builtins/Array/S15.4.5.1_A2.1_T1.js b/test/sendable/builtins/Array/S15.4.5.1_A2.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..748289cd94171b6e5e24a341cafd17b2a1f59fb4 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.5.1_A2.1_T1.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If P is not an array index, return + (Create a property with name P, set its value to V and give it empty attributes) +es5id: 15.4.5.1_A2.1_T1 +description: P in [4294967295, -1, true] +---*/ + +var x = []; +x[4294967295] = 1; +assert.sameValue(x.length, 0, 'The value of x.length is expected to be 0'); +assert.sameValue(x[4294967295], 1, 'The value of x[4294967295] is expected to be 1'); +x = []; +x[-1] = 1; +assert.sameValue(x.length, 0, 'The value of x.length is expected to be 0'); +assert.sameValue(x[-1], 1, 'The value of x[-1] is expected to be 1'); +x = []; +x[true] = 1; +assert.sameValue(x.length, 0, 'The value of x.length is expected to be 0'); +assert.sameValue(x[true], 1, 'The value of x[true] is expected to be 1'); diff --git a/test/sendable/builtins/Array/S15.4.5.1_A2.2_T1.js b/test/sendable/builtins/Array/S15.4.5.1_A2.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..d5db0c74276796dca8a4575c3962882770153b6c --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.5.1_A2.2_T1.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If ToUint32(P) is less than the value of + the length property of A, then return +es5id: 15.4.5.1_A2.2_T1 +description: length === 100, P in [0, 98, 99] +---*/ + +var x = SendableArray(100); +x[0] = 1; +assert.sameValue(x.length, 100, 'The value of x.length is expected to be 100'); +x[98] = 1; +assert.sameValue(x.length, 100, 'The value of x.length is expected to be 100'); +x[99] = 1; +assert.sameValue(x.length, 100, 'The value of x.length is expected to be 100'); diff --git a/test/sendable/builtins/Array/S15.4.5.1_A2.3_T1.js b/test/sendable/builtins/Array/S15.4.5.1_A2.3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..2348b9753067a906bb5a9de6a5992413390e22d8 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.5.1_A2.3_T1.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If ToUint32(P) is less than the value of + the length property of A, change (or set) length to ToUint32(P)+1 +es5id: 15.4.5.1_A2.3_T1 +description: length = 100, P in [100, 199] +---*/ + +var x = SendableArray(100); +x[100] = 1; +assert.sameValue(x.length, 101, 'The value of x.length is expected to be 101'); +x[199] = 1; +assert.sameValue(x.length, 200, 'The value of x.length is expected to be 200'); diff --git a/test/sendable/builtins/Array/S15.4.5.2_A1_T1.js b/test/sendable/builtins/Array/S15.4.5.2_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..ab23a4ce07306f72afbaba185d9ad54c359fc516 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.5.2_A1_T1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + Every Array object has a length property whose value is + always a nonnegative integer less than 2^32. The value of the length property is + numerically greater than the name of every property whose name is an array index +es5id: 15.4.5.2_A1_T1 +description: Checking boundary points +---*/ + +var x = []; +assert.sameValue(x.length, 0, 'The value of x.length is expected to be 0'); +x[0] = 1; +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +x[1] = 1; +assert.sameValue(x.length, 2, 'The value of x.length is expected to be 2'); +x[2147483648] = 1; +assert.sameValue(x.length, 2147483649, 'The value of x.length is expected to be 2147483649'); +x[4294967294] = 1; +assert.sameValue(x.length, 4294967295, 'The value of x.length is expected to be 4294967295'); diff --git a/test/sendable/builtins/Array/S15.4.5.2_A1_T2.js b/test/sendable/builtins/Array/S15.4.5.2_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..8060baf982f17ee1363015788ec25349338597ef --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.5.2_A1_T2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + Every Array object has a length property whose value is + always a nonnegative integer less than 2^32. The value of the length property is + numerically greater than the name of every property whose name is an array index +es5id: 15.4.5.2_A1_T2 +description: P = "2^32 - 1" is not index array +---*/ + +var x = []; +x[4294967295] = 1; +assert.sameValue(x.length, 0, 'The value of x.length is expected to be 0'); +var y = []; +y[1] = 1; +y[4294967295] = 1; +assert.sameValue(y.length, 2, 'The value of y.length is expected to be 2'); diff --git a/test/sendable/builtins/Array/S15.4.5.2_A2_T1.js b/test/sendable/builtins/Array/S15.4.5.2_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..482e437b447ba2ba22e3a0eaad2eb094827bcae6 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.5.2_A2_T1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If a property is added whose name is an array index, + the length property is changed +es5id: 15.4.5.2_A2_T1 +description: Checking length property +---*/ + +var x = []; +assert.sameValue(x.length, 0, 'The value of x.length is expected to be 0'); +x[0] = 1; +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +x[1] = 1; +assert.sameValue(x.length, 2, 'The value of x.length is expected to be 2'); +x[9] = 1; +assert.sameValue(x.length, 10, 'The value of x.length is expected to be 10'); diff --git a/test/sendable/builtins/Array/S15.4.5.2_A3_T1.js b/test/sendable/builtins/Array/S15.4.5.2_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..ad929c8f9d758a59b8c7ff90b341c108d795f36e --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.5.2_A3_T1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If the length property is changed, every property whose name + is an array index whose value is not smaller than the new length is automatically deleted +es5id: 15.4.5.2_A3_T1 +description: > + If new length greater than the name of every property whose name + is an array index +---*/ + +var x = []; +x.length = 1; +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +x[5] = 1; +x.length = 10; +assert.sameValue(x.length, 10, 'The value of x.length is expected to be 10'); +assert.sameValue(x[5], 1, 'The value of x[5] is expected to be 1'); diff --git a/test/sendable/builtins/Array/S15.4.5.2_A3_T2.js b/test/sendable/builtins/Array/S15.4.5.2_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..9668838663e4c1cac1cc4b01d257b185ccb86b63 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.5.2_A3_T2.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If the length property is changed, every property whose name + is an array index whose value is not smaller than the new length is automatically deleted +es5id: 15.4.5.2_A3_T2 +description: > + If new length greater than the name of every property whose name + is an array index +---*/ + +var x = []; +x[1] = 1; +x[3] = 3; +x[5] = 5; +x.length = 4; +assert.sameValue(x.length, 4, 'The value of x.length is expected to be 4'); +assert.sameValue(x[5], undefined, 'The value of x[5] is expected to equal undefined'); +assert.sameValue(x[3], 3, 'The value of x[3] is expected to be 3'); +x.length = new Number(6); +assert.sameValue(x[5], undefined, 'The value of x[5] is expected to equal undefined'); +x.length = 0; +assert.sameValue(x[0], undefined, 'The value of x[0] is expected to equal undefined'); +x.length = 1; +assert.sameValue(x[1], undefined, 'The value of x[1] is expected to equal undefined'); diff --git a/test/sendable/builtins/Array/S15.4.5.2_A3_T3.js b/test/sendable/builtins/Array/S15.4.5.2_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..c73331bea8fd58c93b4324508fa649e0fc8a503f --- /dev/null +++ b/test/sendable/builtins/Array/S15.4.5.2_A3_T3.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If the length property is changed, every property whose name + is an array index whose value is not smaller than the new length is automatically deleted +es5id: 15.4.5.2_A3_T3 +description: "[[Put]] (length, 4294967296)" +---*/ + +var x = []; +x.length = 4294967295; +assert.sameValue(x.length, 4294967295, 'The value of x.length is expected to be 4294967295'); +try { + x = []; + x.length = 4294967296; + throw new Test262Error('#2.1: x = []; x.length = 4294967296 throw RangeError. Actual: x.length === ' + (x.length)); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/S15.4_A1.1_T10.js b/test/sendable/builtins/Array/S15.4_A1.1_T10.js new file mode 100644 index 0000000000000000000000000000000000000000..35be576a29cd4c44f998540c5a82b6e5d7cc40ce --- /dev/null +++ b/test/sendable/builtins/Array/S15.4_A1.1_T10.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + A property name P (in the form of a string value) is an array index + if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2^32 - 1 +es5id: 15.4_A1.1_T10 +description: Array index is power of two +---*/ + +var x = []; +var k = 1; +for (var i = 0; i < 32; i++) { + k = k * 2; + x[k - 2] = k; +} +k = 1; +for (i = 0; i < 32; i++) { + k = k * 2; + assert.sameValue(x[k - 2], k, 'The value of x[k - 2] is expected to equal the value of k'); +} diff --git a/test/sendable/builtins/Array/S15.4_A1.1_T4.js b/test/sendable/builtins/Array/S15.4_A1.1_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..2f96dd7f649db17fa38b28634e1793b053f86871 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4_A1.1_T4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + A property name P (in the form of a string value) is an array index + if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2^32 - 1 +es5id: 15.4_A1.1_T4 +description: Checking for string primitive +---*/ + +var x = []; +x["0"] = 0; +assert.sameValue(x[0], 0, 'The value of x[0] is expected to be 0'); +var y = []; +y["1"] = 1; +assert.sameValue(y[1], 1, 'The value of y[1] is expected to be 1'); diff --git a/test/sendable/builtins/Array/S15.4_A1.1_T5.js b/test/sendable/builtins/Array/S15.4_A1.1_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..13e9dbc4919a839fddb9329b534a6924e9613f21 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4_A1.1_T5.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + A property name P (in the form of a string value) is an array index + if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2^32 - 1 +es5id: 15.4_A1.1_T5 +description: Checking for null and undefined +---*/ + +var x = []; +x[null] = 0; +assert.sameValue(x[0], undefined, 'The value of x[0] is expected to equal undefined'); +assert.sameValue(x["null"], 0, 'The value of x["null"] is expected to be 0'); +var y = []; +y[undefined] = 0; +assert.sameValue(y[0], undefined, 'The value of y[0] is expected to equal undefined'); +assert.sameValue(y["undefined"], 0, 'The value of y["undefined"] is expected to be 0'); diff --git a/test/sendable/builtins/Array/S15.4_A1.1_T6.js b/test/sendable/builtins/Array/S15.4_A1.1_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..45e5034706b921c0d5b31656c3d8aa4cdb124e72 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4_A1.1_T6.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + A property name P (in the form of a string value) is an array index + if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2^32 - 1 +es5id: 15.4_A1.1_T6 +description: Checking for Boolean object +---*/ + +var x = []; +x[new Boolean(true)] = 1; +assert.sameValue(x[1], undefined, 'The value of x[1] is expected to equal undefined'); +assert.sameValue(x["true"], 1, 'The value of x["true"] is expected to be 1'); +x[new Boolean(false)] = 0; +assert.sameValue(x[0], undefined, 'The value of x[0] is expected to equal undefined'); +assert.sameValue(x["false"], 0, 'The value of x["false"] is expected to be 0'); diff --git a/test/sendable/builtins/Array/S15.4_A1.1_T7.js b/test/sendable/builtins/Array/S15.4_A1.1_T7.js new file mode 100644 index 0000000000000000000000000000000000000000..9eb3a1107868ea2f8b393b50bfc972954848ad05 --- /dev/null +++ b/test/sendable/builtins/Array/S15.4_A1.1_T7.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + A property name P (in the form of a string value) is an array index + if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2^32 - 1 +es5id: 15.4_A1.1_T7 +description: Checking for Number object +---*/ + +var x = []; +x[new Number(0)] = 0; +assert.sameValue(x[0], 0, 'The value of x[0] is expected to be 0'); +var y = []; +y[new Number(1)] = 1; +assert.sameValue(y[1], 1, 'The value of y[1] is expected to be 1'); +var z = []; +z[new Number(1.1)] = 1; +assert.sameValue(z["1.1"], 1, 'The value of z["1.1"] is expected to be 1'); diff --git a/test/sendable/builtins/Array/S15.4_A1.1_T8.js b/test/sendable/builtins/Array/S15.4_A1.1_T8.js new file mode 100644 index 0000000000000000000000000000000000000000..3d5b7172b2424bddc1174f707738e4e734b6c2df --- /dev/null +++ b/test/sendable/builtins/Array/S15.4_A1.1_T8.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + A property name P (in the form of a string value) is an array index + if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2^32 - 1 +es5id: 15.4_A1.1_T8 +description: Checking for Number object +---*/ + +var x = []; +x[new String("0")] = 0; +assert.sameValue(x[0], 0, 'The value of x[0] is expected to be 0'); +var y = []; +y[new String("1")] = 1; +assert.sameValue(y[1], 1, 'The value of y[1] is expected to be 1'); +var z = []; +z[new String("1.1")] = 1; +assert.sameValue(z["1.1"], 1, 'The value of z["1.1"] is expected to be 1'); diff --git a/test/sendable/builtins/Array/S15.4_A1.1_T9.js b/test/sendable/builtins/Array/S15.4_A1.1_T9.js new file mode 100644 index 0000000000000000000000000000000000000000..58d0ee61ceee38e7b43fb48f58d276a8d738353b --- /dev/null +++ b/test/sendable/builtins/Array/S15.4_A1.1_T9.js @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + A property name P (in the form of a string value) is an array index + if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2^32 - 1 +es5id: 15.4_A1.1_T9 +description: If Type(value) is Object, evaluate ToPrimitive(value, String) +---*/ + +var x = []; +var object = { + valueOf: function() { + return 1 + } +}; +x[object] = 0; +assert.sameValue(x["[object Object]"], 0, 'The value of x["[object Object]"] is expected to be 0'); +x = []; +var object = { + valueOf: function() { + return 1 + }, + toString: function() { + return 0 + } +}; +x[object] = 0; +assert.sameValue(x[0], 0, 'The value of x[0] is expected to be 0'); +x = []; +var object = { + valueOf: function() { + return 1 + }, + toString: function() { + return {} + } +}; +x[object] = 0; +assert.sameValue(x[1], 0, 'The value of x[1] is expected to be 0'); +try { + x = []; + var object = { + valueOf: function() { + throw "error" + }, + toString: function() { + return 1 + } + }; + x[object] = 0; + assert.sameValue(x[1], 0, 'The value of x[1] is expected to be 0'); +} +catch (e) { + assert.notSameValue(e, "error", 'The value of e is not "error"'); +} +x = []; +var object = { + toString: function() { + return 1 + } +}; +x[object] = 0; +assert.sameValue(x[1], 0, 'The value of x[1] is expected to be 0'); +x = []; +var object = { + valueOf: function() { + return {} + }, + toString: function() { + return 1 + } +} +x[object] = 0; +assert.sameValue(x[1], 0, 'The value of x[1] is expected to be 0'); +try { + x = []; + var object = { + valueOf: function() { + return 1 + }, + toString: function() { + throw "error" + } + }; + x[object]; + throw new Test262Error('#7.1: x = []; var object = {valueOf: function() {return 1}, toString: function() {throw "error"}}; x[object] throw "error". Actual: ' + (x[object])); +} +catch (e) { + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); +} +try { + x = []; + var object = { + valueOf: function() { + return {} + }, + toString: function() { + return {} + } + }; + x[object]; + throw new Test262Error('#8.1: x = []; var object = {valueOf: function() {return {}}, toString: function() {return {}}}; x[object] throw TypeError. Actual: ' + (x[object])); +} +catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/Symbol.species/length.js b/test/sendable/builtins/Array/Symbol.species/length.js new file mode 100644 index 0000000000000000000000000000000000000000..af2885c948d086473fc4b095c7a10e8b6be31aef --- /dev/null +++ b/test/sendable/builtins/Array/Symbol.species/length.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +es6id: 22.1.2.5 +description: > + get Array [ @@species ].length is 0. +info: | + get Array [ @@species ] + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.species] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArray, Symbol.species); +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/Symbol.species/return-value.js b/test/sendable/builtins/Array/Symbol.species/return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..18742ed7fd38472d31e15b95d037fcf1807aa1c7 --- /dev/null +++ b/test/sendable/builtins/Array/Symbol.species/return-value.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-get-array-@@species +description: Return value of @@species accessor method +info: | + 1. Return the this value. +features: [Symbol.species] +---*/ + +var thisVal = {}; +var accessor = Object.getOwnPropertyDescriptor(SendableArray, Symbol.species).get; +assert.sameValue(accessor.call(thisVal), thisVal); diff --git a/test/sendable/builtins/Array/Symbol.species/symbol-species-name.js b/test/sendable/builtins/Array/Symbol.species/symbol-species-name.js new file mode 100644 index 0000000000000000000000000000000000000000..24bf9a9bc0b5d085064beeb2aba11c0f93c57157 --- /dev/null +++ b/test/sendable/builtins/Array/Symbol.species/symbol-species-name.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +es6id: 22.1.2.5 +description: > + Array[Symbol.species] accessor property get name +info: | + 22.1.2.5 get Array [ @@species ] + The value of the name property of this function is "get [Symbol.species]". +features: [Symbol.species] +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableArray, Symbol.species); +verifyProperty(descriptor.get, "name", { + value: "get [Symbol.species]", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/Symbol.species/symbol-species.js b/test/sendable/builtins/Array/Symbol.species/symbol-species.js new file mode 100644 index 0000000000000000000000000000000000000000..690616743833cd7910f47af2b004cfa9ef9f128f --- /dev/null +++ b/test/sendable/builtins/Array/Symbol.species/symbol-species.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + Array has a property at `Symbol.species` +esid: sec-get-array-@@species +author: Sam Mikes +description: Array[Symbol.species] exists per spec +includes: [propertyHelper.js] +features: [Symbol.species] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArray, Symbol.species); +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); +verifyNotWritable(SendableArray, Symbol.species, Symbol.species); +verifyNotEnumerable(SendableArray, Symbol.species); +verifyConfigurable(SendableArray, Symbol.species); diff --git a/test/sendable/builtins/Array/constructor.js b/test/sendable/builtins/Array/constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..87c405c346f2684d406353c9b6825020e311402d --- /dev/null +++ b/test/sendable/builtins/Array/constructor.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-constructor-array +description: > + The Array constructor is a built-in function +---*/ + +assert.sameValue(typeof SendableArray, 'function', 'The value of `typeof SendableArray` is expected to be "function"'); diff --git a/test/sendable/builtins/Array/from/Array.from-descriptor.js b/test/sendable/builtins/Array/from/Array.from-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..ac278823ce8e0f81f92757823155afb3ae17f37d --- /dev/null +++ b/test/sendable/builtins/Array/from/Array.from-descriptor.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Testing descriptor property of Array.from +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray, "from", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/from/Array.from-name.js b/test/sendable/builtins/Array/from/Array.from-name.js new file mode 100644 index 0000000000000000000000000000000000000000..b1625beb4fdecb51594ecb296050f56af9855868 --- /dev/null +++ b/test/sendable/builtins/Array/from/Array.from-name.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: '`name` property' +info: | + ES6 Section 17: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. Unless otherwise specified, this value is the name that is given to + the function in this specification. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.from, "name", { + value: "from", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/from/Array.from_arity.js b/test/sendable/builtins/Array/from/Array.from_arity.js new file mode 100644 index 0000000000000000000000000000000000000000..5fcfb835bab91e8d5e19b394659bf6db73f819d9 --- /dev/null +++ b/test/sendable/builtins/Array/from/Array.from_arity.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: > + The length property of the Array.from method is 1. +info: | + 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) + The length property of the from method is 1. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.from, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/from/Array.from_forwards-length-for-array-likes.js b/test/sendable/builtins/Array/from/Array.from_forwards-length-for-array-likes.js new file mode 100644 index 0000000000000000000000000000000000000000..221e03557798f116935f06aa5c1935d921f2f843 --- /dev/null +++ b/test/sendable/builtins/Array/from/Array.from_forwards-length-for-array-likes.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: > + If this is a constructor, and items doesn't have an @@iterator, + returns a new instance of this +info: | + 22.1.2.1 SendableArray.from ( items [ , mapfn [ , thisArg ] ] ) + 4. Let usingIterator be GetMethod(items, @@iterator). + 6. If usingIterator is not undefined, then + 12. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + 13. Else, + a. Let A be ArrayCreate(len). + 19. Return A. +---*/ + +var result; +function myCollection() { + this.args = arguments; +} +result = SendableArray.from.call(myCollection, { + length: 42 +}); +assert.sameValue(result.args.length, 1, 'The value of result.args.length is expected to be 1'); +assert.sameValue(result.args[0], 42, 'The value of result.args[0] is expected to be 42'); +assert( + result instanceof myCollection, + 'The result of evaluating (result instanceof myCollection) is expected to be true' +); diff --git a/test/sendable/builtins/Array/from/array-like-has-length-but-no-indexes-with-values.js b/test/sendable/builtins/Array/from/array-like-has-length-but-no-indexes-with-values.js new file mode 100644 index 0000000000000000000000000000000000000000..c577424b14fcc99cf621759a30c26d38e0363fc6 --- /dev/null +++ b/test/sendable/builtins/Array/from/array-like-has-length-but-no-indexes-with-values.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: > + Creates an array with length that is equal to the value of the + length property of the given array-like, regardless of + the presence of corresponding indices and values. +info: | + Array.from ( items [ , mapfn [ , thisArg ] ] ) + 7. Let arrayLike be ! ToObject(items). + 8. Let len be ? LengthOfArrayLike(arrayLike). + 9. If IsConstructor(C) is true, then + a. Let A be ? Construct(C, « 𝔽(len) »). + 10. Else, + a. Let A be ? ArrayCreate(len). +includes: [compareArray.js] +---*/ + +const length = 5; +const newlyCreatedArray = SendableArray.from({ length }); +assert.sameValue( + newlyCreatedArray.length, + length, + "The newly created array's length is equal to the value of the length property for the provided array like object" +); +assert.compareArray(newlyCreatedArray, [undefined, undefined, undefined, undefined, undefined]); +const newlyCreatedAndMappedArray = SendableArray.from({ length }).map(x => 1); +assert.sameValue( + newlyCreatedAndMappedArray.length, + length, + "The newly created and mapped array's length is equal to the value of the length property for the provided array like object" +); +assert.compareArray(newlyCreatedAndMappedArray, [1, 1, 1, 1, 1]); diff --git a/test/sendable/builtins/Array/from/calling-from-valid-1-noStrict.js b/test/sendable/builtins/Array/from/calling-from-valid-1-noStrict.js new file mode 100644 index 0000000000000000000000000000000000000000..cc4cce1c825a47c1820404e031d021c21035286b --- /dev/null +++ b/test/sendable/builtins/Array/from/calling-from-valid-1-noStrict.js @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Map function without thisArg on non strict mode +info: | + 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) + 10. Let len be ToLength(Get(arrayLike, "length")). + 11. ReturnIfAbrupt(len). + 12. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + 13. Else, + b. Let A be ArrayCreate(len). + 14. ReturnIfAbrupt(A). + 15. Let k be 0. + 16. Repeat, while k < len + a. Let Pk be ToString(k). + b. Let kValue be Get(arrayLike, Pk). + c. ReturnIfAbrupt(kValue). + d. If mapping is true, then + i. Let mappedValue be Call(mapfn, T, «kValue, k»). +flags: [noStrict] +---*/ + +var list = { + '0': 41, + '1': 42, + '2': 43, + length: 3 +}; +var calls = []; +function mapFn(value) { + calls.push({ + args: arguments, + thisArg: this + }); + return value * 2; +} +var result = SendableArray.from(list, mapFn); +assert.sameValue(result.length, 3, 'The value of result.length is expected to be 3'); +assert.sameValue(result[0], 82, 'The value of result[0] is expected to be 82'); +assert.sameValue(result[1], 84, 'The value of result[1] is expected to be 84'); +assert.sameValue(result[2], 86, 'The value of result[2] is expected to be 86'); +assert.sameValue(calls.length, 3, 'The value of calls.length is expected to be 3'); +assert.sameValue(calls[0].args.length, 2, 'The value of calls[0].args.length is expected to be 2'); +assert.sameValue(calls[0].args[0], 41, 'The value of calls[0].args[0] is expected to be 41'); +assert.sameValue(calls[0].args[1], 0, 'The value of calls[0].args[1] is expected to be 0'); +assert.sameValue(calls[0].thisArg, this, 'The value of calls[0].thisArg is expected to be this'); +assert.sameValue(calls[1].args.length, 2, 'The value of calls[1].args.length is expected to be 2'); +assert.sameValue(calls[1].args[0], 42, 'The value of calls[1].args[0] is expected to be 42'); +assert.sameValue(calls[1].args[1], 1, 'The value of calls[1].args[1] is expected to be 1'); +assert.sameValue(calls[1].thisArg, this, 'The value of calls[1].thisArg is expected to be this'); +assert.sameValue(calls[2].args.length, 2, 'The value of calls[2].args.length is expected to be 2'); +assert.sameValue(calls[2].args[0], 43, 'The value of calls[2].args[0] is expected to be 43'); +assert.sameValue(calls[2].args[1], 2, 'The value of calls[2].args[1] is expected to be 2'); +assert.sameValue(calls[2].thisArg, this, 'The value of calls[2].thisArg is expected to be this'); diff --git a/test/sendable/builtins/Array/from/calling-from-valid-1-onlyStrict.js b/test/sendable/builtins/Array/from/calling-from-valid-1-onlyStrict.js new file mode 100644 index 0000000000000000000000000000000000000000..6aef93e63c2bb4a7b549627a9b78ec049439edb5 --- /dev/null +++ b/test/sendable/builtins/Array/from/calling-from-valid-1-onlyStrict.js @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Map function without thisArg on strict mode +info: | + 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) + 10. Let len be ToLength(Get(arrayLike, "length")). + 11. ReturnIfAbrupt(len). + 12. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + 13. Else, + b. Let A be ArrayCreate(len). + 14. ReturnIfAbrupt(A). + 15. Let k be 0. + 16. Repeat, while k < len + a. Let Pk be ToString(k). + b. Let kValue be Get(arrayLike, Pk). + c. ReturnIfAbrupt(kValue). + d. If mapping is true, then + i. Let mappedValue be Call(mapfn, T, «kValue, k»). +flags: [onlyStrict] +---*/ + +var list = { + '0': 41, + '1': 42, + '2': 43, + length: 3 +}; +var calls = []; +function mapFn(value) { + calls.push({ + args: arguments, + thisArg: this + }); + return value * 2; +} +var result = SendableArray.from(list, mapFn); +assert.sameValue(result.length, 3, 'The value of result.length is expected to be 3'); +assert.sameValue(result[0], 82, 'The value of result[0] is expected to be 82'); +assert.sameValue(result[1], 84, 'The value of result[1] is expected to be 84'); +assert.sameValue(result[2], 86, 'The value of result[2] is expected to be 86'); +assert.sameValue(calls.length, 3, 'The value of calls.length is expected to be 3'); +assert.sameValue(calls[0].args.length, 2, 'The value of calls[0].args.length is expected to be 2'); +assert.sameValue(calls[0].args[0], 41, 'The value of calls[0].args[0] is expected to be 41'); +assert.sameValue(calls[0].args[1], 0, 'The value of calls[0].args[1] is expected to be 0'); +assert.sameValue(calls[0].thisArg, undefined, 'The value of calls[0].thisArg is expected to equal undefined'); +assert.sameValue(calls[1].args.length, 2, 'The value of calls[1].args.length is expected to be 2'); +assert.sameValue(calls[1].args[0], 42, 'The value of calls[1].args[0] is expected to be 42'); +assert.sameValue(calls[1].args[1], 1, 'The value of calls[1].args[1] is expected to be 1'); +assert.sameValue(calls[1].thisArg, undefined, 'The value of calls[1].thisArg is expected to equal undefined'); +assert.sameValue(calls[2].args.length, 2, 'The value of calls[2].args.length is expected to be 2'); +assert.sameValue(calls[2].args[0], 43, 'The value of calls[2].args[0] is expected to be 43'); +assert.sameValue(calls[2].args[1], 2, 'The value of calls[2].args[1] is expected to be 2'); +assert.sameValue(calls[2].thisArg, undefined, 'The value of calls[2].thisArg is expected to equal undefined'); diff --git a/test/sendable/builtins/Array/from/calling-from-valid-2.js b/test/sendable/builtins/Array/from/calling-from-valid-2.js new file mode 100644 index 0000000000000000000000000000000000000000..311e2c1e48e7a68cc4372490b264873c131c3216 --- /dev/null +++ b/test/sendable/builtins/Array/from/calling-from-valid-2.js @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Calling from with a valid map function with thisArg +info: | + 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) + 10. Let len be ToLength(Get(arrayLike, "length")). + 11. ReturnIfAbrupt(len). + 12. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + 13. Else, + b. Let A be ArrayCreate(len). + 14. ReturnIfAbrupt(A). + 15. Let k be 0. + 16. Repeat, while k < len + a. Let Pk be ToString(k). + b. Let kValue be Get(arrayLike, Pk). + c. ReturnIfAbrupt(kValue). + d. If mapping is true, then + i. Let mappedValue be Call(mapfn, T, «kValue, k»). +---*/ + +var list = { + '0': 41, + '1': 42, + '2': 43, + length: 3 +}; +var calls = []; +var thisArg = {}; +function mapFn(value) { + calls.push({ + args: arguments, + thisArg: this + }); + return value * 2; +} +var result = SendableArray.from(list, mapFn, thisArg); +assert.sameValue(result.length, 3, 'The value of result.length is expected to be 3'); +assert.sameValue(result[0], 82, 'The value of result[0] is expected to be 82'); +assert.sameValue(result[1], 84, 'The value of result[1] is expected to be 84'); +assert.sameValue(result[2], 86, 'The value of result[2] is expected to be 86'); +assert.sameValue(calls.length, 3, 'The value of calls.length is expected to be 3'); +assert.sameValue(calls[0].args.length, 2, 'The value of calls[0].args.length is expected to be 2'); +assert.sameValue(calls[0].args[0], 41, 'The value of calls[0].args[0] is expected to be 41'); +assert.sameValue(calls[0].args[1], 0, 'The value of calls[0].args[1] is expected to be 0'); +assert.sameValue(calls[0].thisArg, thisArg, 'The value of calls[0].thisArg is expected to equal the value of thisArg'); +assert.sameValue(calls[1].args.length, 2, 'The value of calls[1].args.length is expected to be 2'); +assert.sameValue(calls[1].args[0], 42, 'The value of calls[1].args[0] is expected to be 42'); +assert.sameValue(calls[1].args[1], 1, 'The value of calls[1].args[1] is expected to be 1'); +assert.sameValue(calls[1].thisArg, thisArg, 'The value of calls[1].thisArg is expected to equal the value of thisArg'); +assert.sameValue(calls[2].args.length, 2, 'The value of calls[2].args.length is expected to be 2'); +assert.sameValue(calls[2].args[0], 43, 'The value of calls[2].args[0] is expected to be 43'); +assert.sameValue(calls[2].args[1], 2, 'The value of calls[2].args[1] is expected to be 2'); +assert.sameValue(calls[2].thisArg, thisArg, 'The value of calls[2].thisArg is expected to equal the value of thisArg'); diff --git a/test/sendable/builtins/Array/from/elements-added-after.js b/test/sendable/builtins/Array/from/elements-added-after.js new file mode 100644 index 0000000000000000000000000000000000000000..49302693347305365a75a4e92a233de3aba4ac9a --- /dev/null +++ b/test/sendable/builtins/Array/from/elements-added-after.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Elements added after the call to from +esid: sec-array.from +---*/ + +var arrayIndex = -1; +var originalLength = 7; +var obj = { + length: originalLength, + 0: 2, + 1: 4, + 2: 8, + 3: 16, + 4: 32, + 5: 64, + 6: 128 +}; +var array = new SendableArray(2, 4, 8, 16, 32, 64, 128); +function mapFn(value, index) { + arrayIndex++; + assert.sameValue(value, obj[arrayIndex], 'The value of value is expected to equal the value of obj[arrayIndex]'); + assert.sameValue(index, arrayIndex, 'The value of index is expected to equal the value of arrayIndex'); + obj[originalLength + arrayIndex] = 2 * arrayIndex + 1; + + return obj[arrayIndex]; +} +var a = SendableArray.from(obj, mapFn); +assert.sameValue(a.length, array.length, 'The value of a.length is expected to equal the value of array.length'); + +for (var j = 0; j < a.length; j++) { + assert.sameValue(a[j], array[j], 'The value of a[j] is expected to equal the value of array[j]'); +} diff --git a/test/sendable/builtins/Array/from/elements-deleted-after.js b/test/sendable/builtins/Array/from/elements-deleted-after.js new file mode 100644 index 0000000000000000000000000000000000000000..8d3e962098f37f5257d2f73e6666b60a3913c739 --- /dev/null +++ b/test/sendable/builtins/Array/from/elements-deleted-after.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Elements deleted after the call started and before visited are not + visited +esid: sec-array.from +---*/ + +var originalArray = new SendableArray(0, 1, -2, 4, -8, 16); +var array = new SendableArray(0, 1, -2, 4, -8, 16); +var a = new SendableArray(); +var arrayIndex = -1; +function mapFn(value, index) { + this.arrayIndex++; + assert.sameValue(value, array[this.arrayIndex], 'The value of value is expected to equal the value of array[this.arrayIndex]'); + assert.sameValue(index, this.arrayIndex, 'The value of index is expected to equal the value of this.arrayIndex'); + array.splice(array.length - 1, 1); + return 127; +} + +a = SendableArray.from(array, mapFn, this); +assert.sameValue(a.length, originalArray.length / 2, 'The value of a.length is expected to be originalArray.length / 2'); +for (var j = 0; j < originalArray.length / 2; j++) { + assert.sameValue(a[j], 127, 'The value of a[j] is expected to be 127'); +} diff --git a/test/sendable/builtins/Array/from/elements-updated-after.js b/test/sendable/builtins/Array/from/elements-updated-after.js new file mode 100644 index 0000000000000000000000000000000000000000..813239c51b53ac3aa36f524ed35ebdb4c73086d5 --- /dev/null +++ b/test/sendable/builtins/Array/from/elements-updated-after.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Elements are updated after the call to from +esid: sec-array.from +---*/ + +var array = new SendableArray(127, 4, 8, 16, 32, 64, 128); +var arrayIndex = -1; +function mapFn(value, index) { + arrayIndex++; + if (index + 1 < array.length) { + array[index + 1] = 127; + } + assert.sameValue(value, 127, 'The value of value is expected to be 127'); + assert.sameValue(index, arrayIndex, 'The value of index is expected to equal the value of arrayIndex'); + return value; +} +var a = SendableArray.from(array, mapFn); +assert.sameValue(a.length, array.length, 'The value of a.length is expected to equal the value of array.length'); +for (var j = 0; j < a.length; j++) { + assert.sameValue(a[j], 127, 'The value of a[j] is expected to be 127'); +} diff --git a/test/sendable/builtins/Array/from/from-array.js b/test/sendable/builtins/Array/from/from-array.js new file mode 100644 index 0000000000000000000000000000000000000000..76ed086b33b54739b88059dbe2d5449156ebc682 --- /dev/null +++ b/test/sendable/builtins/Array/from/from-array.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Passing a valid array +esid: sec-array.from +---*/ + +var array = new SendableArray(0, 'foo', undefined, Infinity); +var result = SendableArray.from(array); +assert.sameValue(result.length, 4, 'The value of result.length is expected to be 4'); +assert.sameValue(result[0], 0, 'The value of result[0] is expected to be 0'); +assert.sameValue(result[1], 'foo', 'The value of result[1] is expected to be "foo"'); +assert.sameValue(result[2], undefined, 'The value of result[2] is expected to equal undefined'); +assert.sameValue(result[3], Infinity, 'The value of result[3] is expected to equal Infinity'); +assert.notSameValue( + result, array, + 'The value of result is expected to not equal the value of `array`' +); +assert(result instanceof SendableArray, 'The result of evaluating (result instanceof Array) is expected to be true'); diff --git a/test/sendable/builtins/Array/from/from-string.js b/test/sendable/builtins/Array/from/from-string.js new file mode 100644 index 0000000000000000000000000000000000000000..a5f42038520cf0893018d2d3a90b7a953336e978 --- /dev/null +++ b/test/sendable/builtins/Array/from/from-string.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Testing SendableArray.from when passed a String +---*/ + +var arrLikeSource = 'Test'; +var result = SendableArray.from(arrLikeSource); +assert.sameValue(result.length, 4, 'The value of result.length is expected to be 4'); +assert.sameValue(result[0], 'T', 'The value of result[0] is expected to be "T"'); +assert.sameValue(result[1], 'e', 'The value of result[1] is expected to be "e"'); +assert.sameValue(result[2], 's', 'The value of result[2] is expected to be "s"'); +assert.sameValue(result[3], 't', 'The value of result[3] is expected to be "t"'); diff --git a/test/sendable/builtins/Array/from/get-iter-method-err.js b/test/sendable/builtins/Array/from/get-iter-method-err.js new file mode 100644 index 0000000000000000000000000000000000000000..a71742f1caadacd9d970ff908b7eb77a323ccb69 --- /dev/null +++ b/test/sendable/builtins/Array/from/get-iter-method-err.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Error accessing items' `Symbol.iterator` attribute +info: | + 4. Let usingIterator be GetMethod(items, @@iterator). + 5. ReturnIfAbrupt(usingIterator). +features: [Symbol.iterator] +---*/ + +var items = {}; +Object.defineProperty(items, Symbol.iterator, { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + SendableArray.from(items); +}, 'SendableArray.from(items) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/from/items-is-arraybuffer.js b/test/sendable/builtins/Array/from/items-is-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..3b12add8a8e75f1c8856dfb1b193291b17137446 --- /dev/null +++ b/test/sendable/builtins/Array/from/items-is-arraybuffer.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Return empty array if items argument is an ArrayBuffer +info: | + 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) + 4. Let usingIterator be GetMethod(items, @@iterator). + 5. ReturnIfAbrupt(usingIterator). +---*/ + +var arrayBuffer = new ArrayBuffer(7); +var result = SendableArray.from(arrayBuffer); +assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0'); diff --git a/test/sendable/builtins/Array/from/items-is-null-throws.js b/test/sendable/builtins/Array/from/items-is-null-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..df7c0b127cf814efe0d067262781ceb4e5c05709 --- /dev/null +++ b/test/sendable/builtins/Array/from/items-is-null-throws.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Throws a TypeError if items argument is null +info: | + 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) + 4. Let usingIterator be GetMethod(items, @@iterator). + 5. ReturnIfAbrupt(usingIterator). +---*/ + +assert.throws(TypeError, function() { + SendableArray.from(null); +}, 'SendableArray.from(null) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/from/iter-adv-err.js b/test/sendable/builtins/Array/from/iter-adv-err.js new file mode 100644 index 0000000000000000000000000000000000000000..eef63c553daa3bab76c3832de267d1b986240903 --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-adv-err.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Error advancing iterator +info: | + 6. If usingIterator is not undefined, then + g. Repeat + i. Let Pk be ToString(k). + ii. Let next be IteratorStep(iterator). + iii. ReturnIfAbrupt(next). +features: [Symbol.iterator] +---*/ + +var items = {}; +items[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; +assert.throws(Test262Error, function() { + SendableArray.from(items); +}, 'SendableArray.from(items) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/from/iter-cstm-ctor-err.js b/test/sendable/builtins/Array/from/iter-cstm-ctor-err.js new file mode 100644 index 0000000000000000000000000000000000000000..518b5bd192d0f88752c233b5c04f3695a2c5d49e --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-cstm-ctor-err.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: > + Error creating object with custom constructor (traversed via iterator) +info: | + 6. If usingIterator is not undefined, then + a. If IsConstructor(C) is true, then + i. Let A be Construct(C). + b. Else, + i. Let A be ArrayCreate(0). + c. ReturnIfAbrupt(A). +features: [Symbol.iterator] +---*/ + +var C = function() { + throw new Test262Error(); +}; +var items = {}; +items[Symbol.iterator] = function() {}; +assert.throws(Test262Error, function() { + SendableArray.from.call(C, items); +}, 'SendableArray.from.call(C, items) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/from/iter-cstm-ctor.js b/test/sendable/builtins/Array/from/iter-cstm-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..2b4003cbad86ff3a7cb96e5c344f2aab618af062 --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-cstm-ctor.js @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Creating object with custom constructor (traversed via iterator) +info: | + 6. If usingIterator is not undefined, then + a. If IsConstructor(C) is true, then + i. Let A be Construct(C). + b. Else, + i. Let A be ArrayCreate(0). + c. ReturnIfAbrupt(A). +features: [Symbol.iterator] +---*/ + +var thisVal, args; +var callCount = 0; +var C = function() { + thisVal = this; + args = arguments; + callCount += 1; +}; +var result; +var items = {}; +items[Symbol.iterator] = function() { + return { + next: function() { + return { + done: true + }; + } + }; +}; +result = SendableArray.from.call(C, items); +assert( + result instanceof C, 'The result of evaluating (result instanceof C) is expected to be true' +); +assert.sameValue( + result.constructor, + C, + 'The value of result.constructor is expected to equal the value of C' +); +assert.sameValue(callCount, 1, 'The value of callCount is expected to be 1'); +assert.sameValue(thisVal, result, 'The value of thisVal is expected to equal the value of result'); +assert.sameValue(args.length, 0, 'The value of args.length is expected to be 0'); diff --git a/test/sendable/builtins/Array/from/iter-get-iter-err.js b/test/sendable/builtins/Array/from/iter-get-iter-err.js new file mode 100644 index 0000000000000000000000000000000000000000..4ffda72374013a78b1af3b97ee523519a8261c2d --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-get-iter-err.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Error creating iterator object +info: | + 6. If usingIterator is not undefined, then + d. Let iterator be GetIterator(items, usingIterator). + e. ReturnIfAbrupt(iterator). +features: [Symbol.iterator] +---*/ + +var itemsPoisonedSymbolIterator = {}; +itemsPoisonedSymbolIterator[Symbol.iterator] = function() { + throw new Test262Error(); +}; +assert.throws(Test262Error, function() { + SendableArray.from(itemsPoisonedSymbolIterator); +}, 'SendableArray.from(itemsPoisonedSymbolIterator) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/from/iter-get-iter-val-err.js b/test/sendable/builtins/Array/from/iter-get-iter-val-err.js new file mode 100644 index 0000000000000000000000000000000000000000..1e8719de5622bea0497232fc049dbc562ecf5520 --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-get-iter-val-err.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Error retrieving value of iterator result +info: | + 6. If usingIterator is not undefined, then + g. Repeat + v. Let nextValue be IteratorValue(next). + vi. ReturnIfAbrupt(nextValue). +features: [Symbol.iterator] +---*/ + +var itemsPoisonedIteratorValue = {}; +var poisonedValue = {}; +Object.defineProperty(poisonedValue, 'value', { + get: function() { + throw new Test262Error(); + } +}); +itemsPoisonedIteratorValue[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; +assert.throws(Test262Error, function() { + SendableArray.from(itemsPoisonedIteratorValue); +}, 'SendableArray.from(itemsPoisonedIteratorValue) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/from/iter-map-fn-args.js b/test/sendable/builtins/Array/from/iter-map-fn-args.js new file mode 100644 index 0000000000000000000000000000000000000000..0dad143ea12c64514cc9ee84651ab8acb8046608 --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-map-fn-args.js @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: > + Arguments of mapping function (traversed via iterator) +info: | + 2. If mapfn is undefined, let mapping be false. + 3. else + a. If IsCallable(mapfn) is false, throw a TypeError exception. + b. If thisArg was supplied, let T be thisArg; else let T be undefined. + c. Let mapping be true + 6. If usingIterator is not undefined, then + g. Repeat + vii. If mapping is true, then + 1. Let mappedValue be Call(mapfn, T, «nextValue, k»). + 2. If mappedValue is an abrupt completion, return + IteratorClose(iterator, mappedValue). + 3. Let mappedValue be mappedValue.[[value]]. +features: [Symbol.iterator] +---*/ + +var args = []; +var firstResult = { + done: false, + value: {} +}; +var secondResult = { + done: false, + value: {} +}; +var mapFn = function(value, idx) { + args.push(arguments); +}; +var items = {}; +var nextResult = firstResult; +var nextNextResult = secondResult; + +items[Symbol.iterator] = function() { + return { + next: function() { + var result = nextResult; + nextResult = nextNextResult; + nextNextResult = { + done: true + }; + return result; + } + }; +}; +SendableArray.from(items, mapFn); +assert.sameValue(args.length, 2, 'The value of args.length is expected to be 2'); +assert.sameValue(args[0].length, 2, 'The value of args[0].length is expected to be 2'); +assert.sameValue( + args[0][0], firstResult.value, 'The value of args[0][0] is expected to equal the value of firstResult.value' +); +assert.sameValue(args[0][1], 0, 'The value of args[0][1] is expected to be 0'); +assert.sameValue(args[1].length, 2, 'The value of args[1].length is expected to be 2'); +assert.sameValue( + args[1][0], secondResult.value, 'The value of args[1][0] is expected to equal the value of secondResult.value' +); +assert.sameValue(args[1][1], 1, 'The value of args[1][1] is expected to be 1'); diff --git a/test/sendable/builtins/Array/from/iter-map-fn-err.js b/test/sendable/builtins/Array/from/iter-map-fn-err.js new file mode 100644 index 0000000000000000000000000000000000000000..2350d32c9330a6c92ac890e689d0b3886db8cb8c --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-map-fn-err.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Error invoking map function (traversed via iterator) +info: | + 6. If usingIterator is not undefined, then + g. Repeat + vii. If mapping is true, then + 1. Let mappedValue be Call(mapfn, T, «nextValue, k»). + 2. If mappedValue is an abrupt completion, return + IteratorClose(iterator, mappedValue). +features: [Symbol.iterator] +---*/ + +var closeCount = 0; +var mapFn = function() { + throw new Test262Error(); +}; +var items = {}; +items[Symbol.iterator] = function() { + return { + return: function() { + closeCount += 1; + }, + next: function() { + return { + done: false + }; + } + }; +}; +assert.throws(Test262Error, function() { + SendableArray.from(items, mapFn); +}, 'SendableArray.from(items, mapFn) throws a Test262Error exception'); +assert.sameValue(closeCount, 1, 'The value of closeCount is expected to be 1'); diff --git a/test/sendable/builtins/Array/from/iter-map-fn-return.js b/test/sendable/builtins/Array/from/iter-map-fn-return.js new file mode 100644 index 0000000000000000000000000000000000000000..332d04b881cb848d79d945b66f0645fb39bdb86d --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-map-fn-return.js @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Value returned by mapping function (traversed via iterator) +info: | + 2. If mapfn is undefined, let mapping be false. + 3. else + a. If IsCallable(mapfn) is false, throw a TypeError exception. + b. If thisArg was supplied, let T be thisArg; else let T be undefined. + c. Let mapping be true + 6. If usingIterator is not undefined, then + g. Repeat + vii. If mapping is true, then + 1. Let mappedValue be Call(mapfn, T, «nextValue, k»). + 2. If mappedValue is an abrupt completion, return + IteratorClose(iterator, mappedValue). + 3. Let mappedValue be mappedValue.[[value]]. +features: [Symbol.iterator] +---*/ + +var thisVals = new SendableArray(); +var nextResult = { + done: false, + value: {} +}; +var nextNextResult = { + done: false, + value: {} +}; +var firstReturnVal = {}; +var secondReturnVal = {}; +var mapFn = function(value, idx) { + var returnVal = nextReturnVal; + nextReturnVal = nextNextReturnVal; + nextNextReturnVal = null; + return returnVal; +}; +var nextReturnVal = firstReturnVal; +var nextNextReturnVal = secondReturnVal; +var items = {}; +var result; +items[Symbol.iterator] = function() { + return { + next: function() { + var result = nextResult; + nextResult = nextNextResult; + nextNextResult = { + done: true + }; + return result; + } + }; +}; + +result = SendableArray.from(items, mapFn); +assert.sameValue(result.length, 2, 'The value of result.length is expected to be 2'); +assert.sameValue(result[0], firstReturnVal, 'The value of result[0] is expected to equal the value of firstReturnVal'); +assert.sameValue( + result[1], + secondReturnVal, + 'The value of result[1] is expected to equal the value of secondReturnVal' +); diff --git a/test/sendable/builtins/Array/from/iter-map-fn-this-arg.js b/test/sendable/builtins/Array/from/iter-map-fn-this-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..08a7f7881a1ca093c601fe0b427597efc369c5b7 --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-map-fn-this-arg.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: > + `this` value of mapping function with custom `this` argument (traversed via iterator) +info: | + 2. If mapfn is undefined, let mapping be false. + 3. else + a. If IsCallable(mapfn) is false, throw a TypeError exception. + b. If thisArg was supplied, let T be thisArg; else let T be undefined. + c. Let mapping be true + 6. If usingIterator is not undefined, then + g. Repeat + vii. If mapping is true, then + 1. Let mappedValue be Call(mapfn, T, «nextValue, k»). +features: [Symbol.iterator] +---*/ + +var thisVals = []; +var nextResult = { + done: false, + value: {} +}; +var nextNextResult = { + done: false, + value: {} +}; +var mapFn = function() { + thisVals.push(this); +}; +var items = {}; +var thisVal = {}; +items[Symbol.iterator] = function() { + return { + next: function() { + var result = nextResult; + nextResult = nextNextResult; + nextNextResult = { + done: true + }; + return result; + } + }; +}; +SendableArray.from(items, mapFn, thisVal); +assert.sameValue(thisVals.length, 2, 'The value of thisVals.length is expected to be 2'); +assert.sameValue(thisVals[0], thisVal, 'The value of thisVals[0] is expected to equal the value of thisVal'); +assert.sameValue(thisVals[1], thisVal, 'The value of thisVals[1] is expected to equal the value of thisVal'); diff --git a/test/sendable/builtins/Array/from/iter-map-fn-this-non-strict.js b/test/sendable/builtins/Array/from/iter-map-fn-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..ffb619a30783668938a7c707021481015421c7df --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-map-fn-this-non-strict.js @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: > + `this` value of mapping function in non-strict mode (traversed via iterator) +info: | + 2. If mapfn is undefined, let mapping be false. + 3. else + a. If IsCallable(mapfn) is false, throw a TypeError exception. + b. If thisArg was supplied, let T be thisArg; else let T be undefined. + c. Let mapping be true + 6. If usingIterator is not undefined, then + g. Repeat + vii. If mapping is true, then + 1. Let mappedValue be Call(mapfn, T, «nextValue, k»). +features: [Symbol.iterator] +flags: [noStrict] +---*/ + +var thisVals = new SendableArray(); +var nextResult = { + done: false, + value: {} +}; +var nextNextResult = { + done: false, + value: {} +}; +var mapFn = function() { + thisVals.push(this); +}; +var items = {}; +var global = function() { + return this; +}(); +items[Symbol.iterator] = function() { + return { + next: function() { + var result = nextResult; + nextResult = nextNextResult; + nextNextResult = { + done: true + }; + return result; + } + }; +}; +SendableArray.from(items, mapFn); +assert.sameValue(thisVals.length, 2, 'The value of thisVals.length is expected to be 2'); +assert.sameValue(thisVals[0], global, 'The value of thisVals[0] is expected to equal the value of global'); +assert.sameValue(thisVals[1], global, 'The value of thisVals[1] is expected to equal the value of global'); diff --git a/test/sendable/builtins/Array/from/iter-map-fn-this-strict.js b/test/sendable/builtins/Array/from/iter-map-fn-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..59b07371cc3dba62a2d59ca1b92fbb71b31bf4da --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-map-fn-this-strict.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: > + `this` value of mapping function in strict mode (traversed via iterator) +info: | + 2. If mapfn is undefined, let mapping be false. + 3. else + a. If IsCallable(mapfn) is false, throw a TypeError exception. + b. If thisArg was supplied, let T be thisArg; else let T be undefined. + c. Let mapping be true + 6. If usingIterator is not undefined, then + g. Repeat + vii. If mapping is true, then + 1. Let mappedValue be Call(mapfn, T, «nextValue, k»). +features: [Symbol.iterator] +flags: [onlyStrict] +---*/ + +var thisVals = new SendableArray(); +var nextResult = { + done: false, + value: {} +}; +var nextNextResult = { + done: false, + value: {} +}; +var mapFn = function() { + thisVals.push(this); +}; +var items = {}; +items[Symbol.iterator] = function() { + return { + next: function() { + var result = nextResult; + nextResult = nextNextResult; + nextNextResult = { + done: true + }; + return result; + } + }; +}; +SendableArray.from(items, mapFn); +assert.sameValue(thisVals.length, 2, 'The value of thisVals.length is expected to be 2'); +assert.sameValue(thisVals[0], undefined, 'The value of thisVals[0] is expected to equal undefined'); +assert.sameValue(thisVals[1], undefined, 'The value of thisVals[1] is expected to equal undefined'); diff --git a/test/sendable/builtins/Array/from/iter-set-elem-prop-err.js b/test/sendable/builtins/Array/from/iter-set-elem-prop-err.js new file mode 100644 index 0000000000000000000000000000000000000000..c7685b3cf30d4c72c5e32691af2f61fdf7f78a6f --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-set-elem-prop-err.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Error setting property on result value (traversed via iterator) +info: | + 6. If usingIterator is not undefined, then + g. Repeat + ix. Let defineStatus be CreateDataPropertyOrThrow(A, Pk, + mappedValue). + x. If defineStatus is an abrupt completion, return + IteratorClose(iterator, defineStatus). +features: [Symbol.iterator] +---*/ + +var constructorSetsIndex0ConfigurableFalse = function() { + Object.defineProperty(this, '0', { + writable: true, + configurable: false + }); +}; +var closeCount = 0; +var items = {}; +var nextResult = { + done: false +}; +items[Symbol.iterator] = function() { + return { + return: function() { + closeCount += 1; + }, + next: function() { + var result = nextResult; + nextResult = { + done: true + }; + return result; + } + }; +}; +assert.throws(TypeError, function() { + SendableArray.from.call(constructorSetsIndex0ConfigurableFalse, items); +}, 'SendableArray.from.call(constructorSetsIndex0ConfigurableFalse, items) throws a TypeError exception'); +assert.sameValue(closeCount, 1, 'The value of closeCount is expected to be 1'); diff --git a/test/sendable/builtins/Array/from/iter-set-elem-prop-non-writable.js b/test/sendable/builtins/Array/from/iter-set-elem-prop-non-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..f752ed0d2bba8889d4d04f9597be7ce0102c1377 --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-set-elem-prop-non-writable.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: > + Non-writable properties are overwritten by CreateDataProperty. + (result object's "0" is non-writable, items is iterable) +info: | + SendableArray.from ( items [ , mapfn [ , thisArg ] ] ) + 5. If usingIterator is not undefined, then + e. Repeat, + viii. Let defineStatus be CreateDataPropertyOrThrow(A, Pk, mappedValue). +features: [generators] +includes: [propertyHelper.js] +---*/ + +var items = function* () { + yield 2; +}; +var A = function(_length) { + Object.defineProperty(this, "0", { + value: 1, + writable: false, + enumerable: false, + configurable: true, + }); +}; +var res = SendableArray.from.call(A, items()); +verifyProperty(res, "0", { + value: 2, + writable: true, + enumerable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/from/iter-set-elem-prop.js b/test/sendable/builtins/Array/from/iter-set-elem-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..ce3ecb465002ae4f03355829bb188f43221c3781 --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-set-elem-prop.js @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Setting property on result value (traversed via iterator) +info: | + 6. If usingIterator is not undefined, then + g. Repeat + ix. Let defineStatus be CreateDataPropertyOrThrow(A, Pk, + mappedValue). +features: [Symbol.iterator] +---*/ + +var items = {}; +var firstIterResult = { + done: false, + value: {} +}; +var secondIterResult = { + done: false, + value: {} +}; +var thirdIterResult = { + done: true, + value: {} +}; +var nextIterResult = firstIterResult; +var nextNextIterResult = secondIterResult; +var result; +items[Symbol.iterator] = function() { + return { + next: function() { + var result = nextIterResult; + + nextIterResult = nextNextIterResult; + nextNextIterResult = thirdIterResult; + + return result; + } + }; +}; +result = SendableArray.from(items); +assert.sameValue( + result[0], + firstIterResult.value, + 'The value of result[0] is expected to equal the value of firstIterResult.value' +); +assert.sameValue( + result[1], + secondIterResult.value, + 'The value of result[1] is expected to equal the value of secondIterResult.value' +); diff --git a/test/sendable/builtins/Array/from/iter-set-length-err.js b/test/sendable/builtins/Array/from/iter-set-length-err.js new file mode 100644 index 0000000000000000000000000000000000000000..b5050832d618029e5955c91e56218ecd17cd7d81 --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-set-length-err.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Error setting length of object (traversed via iterator) +info: | + 6. If usingIterator is not undefined, then + g. Repeat + iv. If next is false, then + 1. Let setStatus be Set(A, "length", k, true). + 2. ReturnIfAbrupt(setStatus). +features: [Symbol.iterator] +---*/ + +var poisonedPrototypeLength = function() {}; +var items = {}; +Object.defineProperty(poisonedPrototypeLength.prototype, 'length', { + set: function(_) { + throw new Test262Error(); + } +}); +items[Symbol.iterator] = function() { + return { + next: function() { + return { + done: true + }; + } + }; +}; +assert.throws(Test262Error, function() { + SendableArray.from.call(poisonedPrototypeLength, items); +}, 'SendableArray.from.call(poisonedPrototypeLength, items) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/from/iter-set-length.js b/test/sendable/builtins/Array/from/iter-set-length.js new file mode 100644 index 0000000000000000000000000000000000000000..4aed93aafe9df87078bf334e70b42855d09e0c6f --- /dev/null +++ b/test/sendable/builtins/Array/from/iter-set-length.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Setting length of object (traversed via iterator) +info: | + 6. If usingIterator is not undefined, then + g. Repeat + iv. If next is false, then + 1. Let setStatus be Set(A, "length", k, true). + 2. ReturnIfAbrupt(setStatus). + 3. Return A. +features: [Symbol.iterator] +---*/ + +var items = {}; +var result, nextIterResult, lastIterResult; +items[Symbol.iterator] = function() { + return { + next: function() { + var result = nextIterResult; + nextIterResult = lastIterResult; + return result; + } + }; +}; +nextIterResult = lastIterResult = { + done: true +}; +result = SendableArray.from(items); +assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0'); +nextIterResult = { + done: false +}; +lastIterResult = { + done: true +}; +result = SendableArray.from(items); +assert.sameValue(result.length, 1, 'The value of result.length is expected to be 1'); diff --git a/test/sendable/builtins/Array/from/mapfn-is-not-callable-typeerror.js b/test/sendable/builtins/Array/from/mapfn-is-not-callable-typeerror.js new file mode 100644 index 0000000000000000000000000000000000000000..bd6d76f9cda5b7d8e572553edc10db63d75f3fa2 --- /dev/null +++ b/test/sendable/builtins/Array/from/mapfn-is-not-callable-typeerror.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.from +description: Throws a TypeError if mapFn is not callable +info: | + 22.1.2.1 SendableArray.from ( items [ , mapfn [ , thisArg ] ] ) + 2. If mapfn is undefined, let mapping be false. + 3. else + a. If IsCallable(mapfn) is false, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + SendableArray.from([], null); +}, 'SendableArray.from([], null) throws a TypeError exception'); +assert.throws(TypeError, function() { + SendableArray.from([], {}); +}, 'SendableArray.from([], {}) throws a TypeError exception'); +assert.throws(TypeError, function() { + SendableArray.from([], 'string'); +}, 'SendableArray.from([], "string") throws a TypeError exception'); +assert.throws(TypeError, function() { + SendableArray.from([], true); +}, 'SendableArray.from([], true) throws a TypeError exception'); +assert.throws(TypeError, function() { + SendableArray.from([], 42); +}, 'SendableArray.from([], 42) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/from/mapfn-is-symbol-throws.js b/test/sendable/builtins/Array/from/mapfn-is-symbol-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..e6cf2ad2dcb1b9cb9032d7bfd0ed699287fdcbfd --- /dev/null +++ b/test/sendable/builtins/Array/from/mapfn-is-symbol-throws.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.from +description: Throws a TypeError if mapFn is not callable (Symbol) +info: | + 22.1.2.1 SendableArray.from ( items [ , mapfn [ , thisArg ] ] ) + 2. If mapfn is undefined, let mapping be false. + 3. else + a. If IsCallable(mapfn) is false, throw a TypeError exception. +features: + - Symbol +---*/ + +assert.throws(TypeError, function() { + SendableArray.from([], Symbol('1')); +}, 'SendableArray.from([], Symbol("1")) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/from/mapfn-throws-exception.js b/test/sendable/builtins/Array/from/mapfn-throws-exception.js new file mode 100644 index 0000000000000000000000000000000000000000..ee7225725ea96e3e759ae636b4d43718a9d07e0d --- /dev/null +++ b/test/sendable/builtins/Array/from/mapfn-throws-exception.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: mapFn throws an exception +esid: sec-SendableArray.from +es6id: 22.1.2.1 +---*/ + +var array = new SendableArray(2, 4, 8, 16, 32, 64, 128); +function mapFnThrows(value, index, obj) { + throw new Test262Error(); +} +assert.throws(Test262Error, function() { + SendableArray.from(array, mapFnThrows); +}, 'SendableArray.from(array, mapFnThrows) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/from/not-a-constructor.js b/test/sendable/builtins/Array/from/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..a1f8896286d93e1cb6587e225eefaea4d4e9d93e --- /dev/null +++ b/test/sendable/builtins/Array/from/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.from does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(Array.from), false, 'isConstructor(Array.from) must return false'); +assert.throws(TypeError, () => { + new SendableArray.from([]); +}, 'new SendableArray.from([]) throws a TypeError exception'); + diff --git a/test/sendable/builtins/Array/from/proto-from-ctor-realm.js b/test/sendable/builtins/Array/from/proto-from-ctor-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..80444b128b40fe1e7632d85c63f2704db6ad51bc --- /dev/null +++ b/test/sendable/builtins/Array/from/proto-from-ctor-realm.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.from +es6id: 22.1.2.1 +description: Default [[Prototype]] value derived from realm of the constructor +info: | + 5. If usingIterator is not undefined, then + a. If IsConstructor(C) is true, then + i. Let A be ? Construct(C). + 9.1.14 GetPrototypeFromConstructor + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. +features: [cross-realm] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; +var a = SendableArray.from.call(C, []); +assert.sameValue( + Object.getPrototypeOf(a), + other.Object.prototype, + 'Object.getPrototypeOf(SendableArray.from.call(C, [])) returns other.Object.prototype' +); diff --git a/test/sendable/builtins/Array/from/source-array-boundary.js b/test/sendable/builtins/Array/from/source-array-boundary.js new file mode 100644 index 0000000000000000000000000000000000000000..1364dd81750db62e11e13ac717ac6f8379cf6b6b --- /dev/null +++ b/test/sendable/builtins/Array/from/source-array-boundary.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Source array with boundary values +esid: sec-SendableArray.from +es6id: 22.1.2.1 +---*/ + +var array = new SendableArray(Number.MAX_VALUE, Number.MIN_VALUE, Number.NaN, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY); +var arrayIndex = -1; +function mapFn(value, index) { + this.arrayIndex++; + assert.sameValue(value, array[this.arrayIndex], 'The value of value is expected to equal the value of array[this.arrayIndex]'); + assert.sameValue(index, this.arrayIndex, 'The value of index is expected to equal the value of this.arrayIndex'); + return value; +} +var a = SendableArray.from(array, mapFn, this); +assert.sameValue(a.length, array.length, 'The value of a.length is expected to equal the value of array.length'); +assert.sameValue(a[0], Number.MAX_VALUE, 'The value of a[0] is expected to equal the value of Number.MAX_VALUE'); +assert.sameValue(a[1], Number.MIN_VALUE, 'The value of a[1] is expected to equal the value of Number.MIN_VALUE'); +assert.sameValue(a[2], Number.NaN, 'The value of a[2] is expected to equal the value of Number.NaN'); +assert.sameValue(a[3], Number.NEGATIVE_INFINITY, 'The value of a[3] is expected to equal the value of Number.NEGATIVE_INFINITY'); +assert.sameValue(a[4], Number.POSITIVE_INFINITY, 'The value of a[4] is expected to equal the value of Number.POSITIVE_INFINITY'); diff --git a/test/sendable/builtins/Array/from/source-object-constructor.js b/test/sendable/builtins/Array/from/source-object-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..8830a4ef7e947d576c083af9847bfe576e597f22 --- /dev/null +++ b/test/sendable/builtins/Array/from/source-object-constructor.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + SendableArray.from uses a constructor other than Array. +esid: sec-SendableArray.from +es6id: 22.1.2.1 +---*/ + +assert.sameValue( + SendableArray.from.call(Object, []).constructor, + Object, + 'The value of Array.from.call(Object, []).constructor is expected to equal the value of Object' +); diff --git a/test/sendable/builtins/Array/from/source-object-iterator-1.js b/test/sendable/builtins/Array/from/source-object-iterator-1.js new file mode 100644 index 0000000000000000000000000000000000000000..17c06ced169d03c5927ba0879cc95bcab78abd92 --- /dev/null +++ b/test/sendable/builtins/Array/from/source-object-iterator-1.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Source object has iterator which throws +esid: sec-SendableArray.from +es6id: 22.1.2.1 +features: [Symbol.iterator] +---*/ + +var array = new SendableArray(2, 4, 8, 16, 32, 64, 128); +var obj = { + [Symbol.iterator]() { + return { + index: 0, + next() { + throw new Test262Error(); + }, + isDone: false, + get val() { + this.index++; + if (this.index > 7) { + this.isDone = true; + } + return 1 << this.index; + } + }; + } +}; +assert.throws(Test262Error, function() { + SendableArray.from(obj); +}, 'SendableArray.from(obj) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/from/source-object-iterator-2.js b/test/sendable/builtins/Array/from/source-object-iterator-2.js new file mode 100644 index 0000000000000000000000000000000000000000..db59c7c555e5da3e05d5fc347689cf628c3d2099 --- /dev/null +++ b/test/sendable/builtins/Array/from/source-object-iterator-2.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Source object has iterator +esid: sec-SendableArray.from +es6id: 22.1.2.1 +features: [Symbol.iterator] +---*/ + +var array = new SendableArray(2, 4, 8, 16, 32, 64, 128); +var obj = { + [Symbol.iterator]() { + return { + index: 0, + next() { + return { + value: this.val, + done: this.isDone + }; + }, + isDone: false, + get val() { + this.index++; + if (this.index > 7) { + this.isDone = true; + } + return 1 << this.index; + } + }; + } +}; +var a = SendableArray.from.call(Object, obj); +assert.sameValue(typeof a, typeof {}, 'The value of `typeof a` is expected to be typeof {}'); +for (var j = 0; j < a.length; j++) { + assert.sameValue(a[j], array[j], 'The value of a[j] is expected to equal the value of array[j]'); +} diff --git a/test/sendable/builtins/Array/from/source-object-length-set-elem-prop-err.js b/test/sendable/builtins/Array/from/source-object-length-set-elem-prop-err.js new file mode 100644 index 0000000000000000000000000000000000000000..a8f400814048c0a381e948c1cb8b296239a91f96 --- /dev/null +++ b/test/sendable/builtins/Array/from/source-object-length-set-elem-prop-err.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.from +description: > + TypeError is thrown if CreateDataProperty fails. + (items is not iterable) +info: | + SendableArray.from ( items [ , mapfn [ , thisArg ] ] ) + 4. Let usingIterator be ? GetMethod(items, @@iterator). + 5. If usingIterator is not undefined, then + 6. NOTE: items is not an Iterable so assume it is an array-like object. + 12. Repeat, while k < len + e. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue). + CreateDataPropertyOrThrow ( O, P, V ) + 3. Let success be ? CreateDataProperty(O, P, V). + 4. If success is false, throw a TypeError exception. +---*/ + +var items = { + length: 1, +}; +var A1 = function(_length) { + this.length = 0; + Object.preventExtensions(this); +}; +assert.throws(TypeError, function() { + SendableArray.from.call(A1, items); +}, 'SendableArray.from.call(A1, items) throws a TypeError exception'); +var A2 = function(_length) { + Object.defineProperty(this, "0", { + writable: true, + configurable: false, + }); +}; +assert.throws(TypeError, function() { + SendableArray.from.call(A2, items); +}, 'SendableArray.from.call(A2, items) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/from/source-object-length-set-elem-prop-non-writable.js b/test/sendable/builtins/Array/from/source-object-length-set-elem-prop-non-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..9ad2f8386dd9bd333097835300757a4cebbe0fc5 --- /dev/null +++ b/test/sendable/builtins/Array/from/source-object-length-set-elem-prop-non-writable.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.from +description: > + Non-writable properties are overwritten by CreateDataProperty. + (result object's "0" is non-writable, items is not iterable) +info: | + SendableArray.from ( items [ , mapfn [ , thisArg ] ] ) + 4. Let usingIterator be ? GetMethod(items, @@iterator). + 5. If usingIterator is not undefined, then + 6. NOTE: items is not an Iterable so assume it is an array-like object. + 12. Repeat, while k < len + e. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue). +includes: [propertyHelper.js] +---*/ + +var items = { + "0": 2, + length: 1, +}; +var A = function(_length) { + Object.defineProperty(this, "0", { + value: 1, + writable: false, + enumerable: false, + configurable: true, + }); +}; +var res = SendableArray.from.call(A, items); +verifyProperty(res, "0", { + value: 2, + writable: true, + enumerable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/from/source-object-length.js b/test/sendable/builtins/Array/from/source-object-length.js new file mode 100644 index 0000000000000000000000000000000000000000..ce127de8cece59b5970e47887678e30a2cfbd32e --- /dev/null +++ b/test/sendable/builtins/Array/from/source-object-length.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Source is an object with length property and one item is deleted + from the source +esid: sec-SendableArray.from +es6id: 22.1.2.1 +---*/ + +var array = new SendableArray(2, 4, 0, 16); +var expectedArray = new SendableArray(2, 4, undefined, 16); +var obj = { + length: 4, + 0: 2, + 1: 4, + 2: 0, + 3: 16 +}; +delete obj[2]; +var a = SendableArray.from(obj); +for (var j = 0; j < expectedArray.length; j++) { + assert.sameValue(a[j], expectedArray[j], 'The value of a[j] is expected to equal the value of expectedArray[j]'); +} diff --git a/test/sendable/builtins/Array/from/source-object-missing.js b/test/sendable/builtins/Array/from/source-object-missing.js new file mode 100644 index 0000000000000000000000000000000000000000..408039d0166fe40e71b0a27ac9c8ee6147adc5f6 --- /dev/null +++ b/test/sendable/builtins/Array/from/source-object-missing.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Source is an object with missing values +esid: sec-SendableArray.from +es6id: 22.1.2.1 +---*/ + +var array = new SendableArray(2, 4, undefined, 16); +var obj = { + length: 4, + 0: 2, + 1: 4, + 3: 16 +}; +var a = SendableArray.from.call(Object, obj); +assert.sameValue(typeof a, "object", 'The value of `typeof a` is expected to be "object"'); +for (var j = 0; j < a.length; j++) { + assert.sameValue(a[j], array[j], 'The value of a[j] is expected to equal the value of array[j]'); +} diff --git a/test/sendable/builtins/Array/from/source-object-without.js b/test/sendable/builtins/Array/from/source-object-without.js new file mode 100644 index 0000000000000000000000000000000000000000..5482e800ef2c33cbafdf19ff3755735b923c433f --- /dev/null +++ b/test/sendable/builtins/Array/from/source-object-without.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: Source is an object without length property +esid: sec-SendableArray.from +es6id: 22.1.2.1 +---*/ + +var obj = { + 0: 2, + 1: 4, + 2: 8, + 3: 16 +} +var a = SendableArray.from(obj); +assert.sameValue(a.length, 0, 'The value of a.length is expected to be 0'); diff --git a/test/sendable/builtins/Array/from/this-null.js b/test/sendable/builtins/Array/from/this-null.js new file mode 100644 index 0000000000000000000000000000000000000000..594b1864c4290bea9c7a20b291d7f7522d1dae35 --- /dev/null +++ b/test/sendable/builtins/Array/from/this-null.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.from +es6id: 22.1.2.1 +description: Does not throw if this is null +---*/ + +var result = SendableArray.from.call(null, []); +assert(result instanceof SendableArray, 'The result of evaluating (result instanceof SendableArray) is expected to be true'); +assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0'); diff --git a/test/sendable/builtins/Array/fromAsync/async-iterable-async-mapped-awaits-once.js b/test/sendable/builtins/Array/fromAsync/async-iterable-async-mapped-awaits-once.js new file mode 100644 index 0000000000000000000000000000000000000000..1a2f0ef6768067ef512c46656be66d6d0d33c2a1 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/async-iterable-async-mapped-awaits-once.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Async-iterable awaits each input once with mapping callback +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + async function* generateInput () { + yield* [ 0, 1, 2 ]; + } + const input = generateInput(); + let awaitCounter = 0; + await SendableArray.fromAsync(input, v => { + return { + // This “then” method should occur three times: + // one for each value from the input. + then (resolve, reject) { + awaitCounter ++; + resolve(v); + }, + }; + }); + assert.sameValue(awaitCounter, 3); +}); diff --git a/test/sendable/builtins/Array/fromAsync/async-iterable-input-does-not-await-input.js b/test/sendable/builtins/Array/fromAsync/async-iterable-input-does-not-await-input.js new file mode 100644 index 0000000000000000000000000000000000000000..cf3e975b7a9df8a3ab4890f91c4b64f9a280861d --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/async-iterable-input-does-not-await-input.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Async-iterable input does not await input values. +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const prom = Promise.resolve({}); + const expected = [ prom ]; + function createInput () { + return { + // The following async iterator will yield one value + // (the promise named “prom”). + [Symbol.asyncIterator]() { + let i = 0; + return { + async next() { + if (i > 0) { + return { done: true }; + } + i++; + return { value: prom, done: false } + }, + }; + }, + }; + } + const input = createInput(); + const output = await SendableArray.fromAsync(input); + assert.compareArray(output, expected); +}); diff --git a/test/sendable/builtins/Array/fromAsync/async-iterable-input-iteration-err.js b/test/sendable/builtins/Array/fromAsync/async-iterable-input-iteration-err.js new file mode 100644 index 0000000000000000000000000000000000000000..6bdc50984bd73dda617444098b8c066d3630817b --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/async-iterable-input-iteration-err.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync promise rejects if iteration of input fails. +flags: [async] +features: [SendableArray.fromAsync] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + async function *generateInput () { + throw new Test262Error('This error should be propagated.'); + } + const input = generateInput(); + const outputPromise = SendableArray.fromAsync(input); + await assert.throwsAsync(Test262Error, () => outputPromise); +}); diff --git a/test/sendable/builtins/Array/fromAsync/async-iterable-input.js b/test/sendable/builtins/Array/fromAsync/async-iterable-input.js new file mode 100644 index 0000000000000000000000000000000000000000..3e7bb8a0cb7c6b315c77d7c59b4e5ea9f4b98654 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/async-iterable-input.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Async-iterable input is transferred to the output array. +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expected = [ 0, 1, 2 ]; + async function* generateInput () { + yield* expected; + } + const input = generateInput(); + const output = await SendableArray.fromAsync(input); + assert.compareArray(output, expected); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-array-add-to-empty.js b/test/sendable/builtins/Array/fromAsync/asyncitems-array-add-to-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..7912ad5162edf6b46108243791407afaba8ae912 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-array-add-to-empty.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync respects array mutation +info: | + SendableArray.fromAsync + 3.j.ii.3. Let next be Await(IteratorStep(iteratorRecord)). + IteratorStep + 1. Let result be IteratorNext(iteratorRecord). + IteratorNext + 1.a. Let result be Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). + %AsyncFromSyncIteratorPrototype%.next + 6.a. Let result be Completion(IteratorNext(syncIteratorRecord)). + IteratorNext + 1.a. Let result be Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). + Array.prototype [ @@iterator ] ( ) + Array.prototype.values ( ) + 2. Return CreateArrayIterator(O, value). + CreateArrayIterator + 1.b.iii. If index ≥ len, return NormalCompletion(undefined). +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const items = []; + const promise = SendableArray.fromAsync(items); + // By the time we get here, the first next() call has already happened, and returned + // { done: true }. We then return from the loop in Array.fromAsync 3.j.ii. with the empty array, + // and the following line no longer affects that. + items.push(7); + const result = await promise; + assert.compareArray(result, []); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-array-add-to-singleton.js b/test/sendable/builtins/Array/fromAsync/asyncitems-array-add-to-singleton.js new file mode 100644 index 0000000000000000000000000000000000000000..d47342df042147d7b337b310ce0211283a5491c6 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-array-add-to-singleton.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync respects array mutation +info: | + SendableArray.fromAsync + 3.j.ii.3. Let next be Await(IteratorStep(iteratorRecord)). + IteratorStep + 1. Let result be IteratorNext(iteratorRecord). + IteratorNext + 1.a. Let result be Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). + %AsyncFromSyncIteratorPrototype%.next + 6.a. Let result be Completion(IteratorNext(syncIteratorRecord)). + IteratorNext + 1.a. Let result be Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). + Array.prototype [ @@iterator ] ( ) + Array.prototype.values ( ) + 2. Return CreateArrayIterator(O, value). + CreateArrayIterator + 1.b.iii. If index ≥ len, return NormalCompletion(undefined). +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const items = [1]; + const promise = SendableArray.fromAsync(items); + // At this point, the first element of `items` has been read, but the iterator will take other + // changes into account. + items.push(7); + const result = await promise; + assert.compareArray(result, [1, 7]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-array-add.js b/test/sendable/builtins/Array/fromAsync/asyncitems-array-add.js new file mode 100644 index 0000000000000000000000000000000000000000..97ffe13d31f5d500c4c2afa51f88e07f57597b3c --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-array-add.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Array.fromAsync respects array mutation +info: | + Array.fromAsync + 3.j.ii.3. Let next be ? Await(IteratorStep(iteratorRecord)). + IteratorStep + 1. Let result be ? IteratorNext(iteratorRecord). + IteratorNext + 1.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). + %AsyncFromSyncIteratorPrototype%.next + 6.a. Let result be Completion(IteratorNext(syncIteratorRecord)). + IteratorNext + 1.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). + Array.prototype [ @@iterator ] ( ) + Array.prototype.values ( ) + 2. Return CreateArrayIterator(O, value). + CreateArrayIterator + 1.b.iii. If index ≥ len, return NormalCompletion(undefined). +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [Array.fromAsync] +---*/ + +asyncTest(async function () { + const items = [1, 2, 3]; + const promise = SendableArray.fromAsync(items); + // At this point, the first element of `items` has been read, but the iterator will take other + // changes into account. + items.push(4); + const result = await promise; + assert.compareArray(result, [1, 2, 3, 4]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-array-mutate.js b/test/sendable/builtins/Array/fromAsync/asyncitems-array-mutate.js new file mode 100644 index 0000000000000000000000000000000000000000..5292c8b3b77365e635da6db8667efa831f378630 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-array-mutate.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.fromasync +description: > + SendableArray.fromAsync respects array mutation +info: | + SendableArray.fromAsync + 3.j.ii.3. Let next be ? Await(IteratorStep(iteratorRecord)). + IteratorStep + 1. Let result be ? IteratorNext(iteratorRecord). + IteratorNext + 1.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). + %AsyncFromSyncIteratorPrototype%.next + 6.a. Let result be Completion(IteratorNext(syncIteratorRecord)). + IteratorNext + 1.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). + Array.prototype [ @@iterator ] ( ) + Array.prototype.values ( ) + 2. Return CreateArrayIterator(O, value). + CreateArrayIterator + 1.b.iii. If index ≥ len, return NormalCompletion(undefined). +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [Array.fromAsync] +---*/ + +asyncTest(async function () { + const items = [1, 2, 3]; + const promise = SendableArray.fromAsync(items); + // At this point, the first element of `items` has been read, but the iterator will take other + // changes into account. + items[0] = 7; + items[1] = 8; + const result = await promise; + assert.compareArray(result, [1, 8, 3]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-array-remove.js b/test/sendable/builtins/Array/fromAsync/asyncitems-array-remove.js new file mode 100644 index 0000000000000000000000000000000000000000..32491a6932a0dbd099179103e2e39300723f2777 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-array-remove.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync respects array mutation +info: | + SendableArray.fromAsync + 3.j.ii.3. Let next be ? Await(IteratorStep(iteratorRecord)). + IteratorStep + 1. Let result be ? IteratorNext(iteratorRecord). + IteratorNext + 1.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). + %AsyncFromSyncIteratorPrototype%.next + 6.a. Let result be Completion(IteratorNext(syncIteratorRecord)). + IteratorNext + 1.a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). + Array.prototype [ @@iterator ] ( ) + Array.prototype.values ( ) + 2. Return CreateArrayIterator(O, value). + CreateArrayIterator + 1.b.iii. If index ≥ len, return NormalCompletion(undefined). +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [Array.fromAsync] +---*/ + +asyncTest(async function () { + const items = [1, 2, 3]; + const promise = SendableArray.fromAsync(items); + // At this point, the first element of `items` has been read, but the iterator will take other + // changes into account. + items.pop(); + const result = await promise; + assert.compareArray(result, [1, 2]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-arraybuffer.js b/test/sendable/builtins/Array/fromAsync/asyncitems-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..515abad4663e0a52f5e2588313602ad42013d9ef --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-arraybuffer.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync doesn't special-case ArrayBuffer +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const items = new ArrayBuffer(7); + const result = await SendableArray.fromAsync(items); + assert.compareArray(result, []); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-holes.js b/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-holes.js new file mode 100644 index 0000000000000000000000000000000000000000..91b9927fea76a8af260eb34993393ab8150bab8e --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-holes.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Array-like object with holes treats the holes as undefined +info: | + 3.k.vii.2. Let _kValue_ be ? Get(_arrayLike_, _Pk_). +features: [Array.fromAsync] +flags: [async] +includes: [asyncHelpers.js, compareArray.js] +---*/ + +asyncTest(async function () { + const arrayLike = Object.create(null); + arrayLike.length = 5; + arrayLike[0] = 0; + arrayLike[1] = 1; + arrayLike[2] = 2; + arrayLike[4] = 4; + const array = await SendableArray.fromAsync(arrayLike); + assert.compareArray(array, [0, 1, 2, undefined, 4], "holes in array-like treated as undefined"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-length-accessor-throws.js b/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-length-accessor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..1f7be51b4080f11886adc417bfb5f444a265b3e7 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-length-accessor-throws.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Rejects on array-like object whose length cannot be gotten +info: | + 3.k.iii. Let _len_ be ? LengthOfArrayLike(_arrayLike_). +features: [SendableArray.fromAsync] +flags: [async] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + await assert.throwsAsync(Test262Error, () => SendableArray.fromAsync({ + get length() { + throw new Test262Error('accessing length property fails'); + } + }), "Promise should be rejected if array-like length getter throws"); + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync({ + length: 1n, + 0: 0 + }), "Promise should be rejected if array-like length can't be converted to a number"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-promise.js b/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-promise.js new file mode 100644 index 0000000000000000000000000000000000000000..0a0ac1a75bc425e35735e1e8f25cb2bfcb86bfbc --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-promise.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync tries the various properties in order and awaits promises +includes: [asyncHelpers.js, compareArray.js, temporalHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const actual = []; + const items = TemporalHelpers.propertyBagObserver(actual, { + length: 2, + 0: Promise.resolve(2), + 1: Promise.resolve(1), + }, "items"); + const result = await SendableArray.fromAsync(items); + assert.compareArray(result, [2, 1]); + assert.compareArray(actual, [ + "get items[Symbol.asyncIterator]", + "get items[Symbol.iterator]", + "get items.length", + "get items.length.valueOf", + "call items.length.valueOf", + "get items[0]", + "get items[1]", + ]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-too-long.js b/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-too-long.js new file mode 100644 index 0000000000000000000000000000000000000000..eefeaf9406a1a73b10b7eb62e799bfdfafc9a849 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-arraylike-too-long.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Promise is rejected if the length of the array-like to copy is out of range +info: | + j. If _iteratorRecord_ is not *undefined*, then + k. Else, + iv. If IsConstructor(_C_) is *true*, then + v. Else, + 1. Let _A_ be ? ArrayCreate(_len_). + ArrayCreate, step 1: + 1. If _length_ > 2³² - 1, throw a *RangeError* exception. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const notConstructor = {}; + await assert.throwsAsync(RangeError, () => SendableArray.fromAsync.call(notConstructor, { + length: 4294967296 // 2³² + }), "Array-like with excessive length"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-exists.js b/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-exists.js new file mode 100644 index 0000000000000000000000000000000000000000..4d0f93b6055e91a0111e8c0310fdd00d0c4911b1 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-exists.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync tries the various properties in order +includes: [asyncHelpers.js, compareArray.js, temporalHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + async function * asyncGen() { + for (let i = 0; i < 4; i++) { + yield Promise.resolve(i * 2); + } + } + const actual = []; + const items = {}; + TemporalHelpers.observeProperty(actual, items, Symbol.asyncIterator, asyncGen, "items"); + TemporalHelpers.observeProperty(actual, items, Symbol.iterator, undefined, "items"); + TemporalHelpers.observeProperty(actual, items, "length", 2, "items"); + TemporalHelpers.observeProperty(actual, items, 0, 2, "items"); + TemporalHelpers.observeProperty(actual, items, 1, 1, "items"); + const result = await SendableArray.fromAsync(items); + assert.compareArray(result, [0, 2, 4, 6]); + assert.compareArray(actual, [ + "get items[Symbol.asyncIterator]", + ]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-not-callable.js b/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..1b2b6c28dc1d9c851f0680a0590de33bf5ba5f3a --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-not-callable.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync rejects if the @@asyncIterator property is not callable +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + for (const v of [true, "", Symbol(), 1, 1n, {}]) { + await assert.throwsAsync(TypeError, + () => SendableArray.fromAsync({ [Symbol.asyncIterator]: v }), + `@@asyncIterator = ${typeof v}`); + } +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-null.js b/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-null.js new file mode 100644 index 0000000000000000000000000000000000000000..a86aa1fb36a6a63af0124bee7cc5660c5fab39cd --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-null.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync tries the various properties in order +includes: [asyncHelpers.js, compareArray.js, temporalHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const actual = []; + const items = {}; + TemporalHelpers.observeProperty(actual, items, Symbol.asyncIterator, null, "items"); + TemporalHelpers.observeProperty(actual, items, Symbol.iterator, undefined, "items"); + TemporalHelpers.observeProperty(actual, items, "length", 2, "items"); + TemporalHelpers.observeProperty(actual, items, 0, 2, "items"); + TemporalHelpers.observeProperty(actual, items, 1, 1, "items"); + const result = await SendableArray.fromAsync(items); + assert.compareArray(result, [2, 1]); + assert.compareArray(actual, [ + "get items[Symbol.asyncIterator]", + "get items[Symbol.iterator]", + "get items.length", + "get items[0]", + "get items[1]", + ]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-sync.js b/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-sync.js new file mode 100644 index 0000000000000000000000000000000000000000..3fedc9bce40ae426ceeaa750c8d4b9e3e761bd4f --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-sync.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync handles a sync iterator returned from @@asyncIterator +includes: [asyncHelpers.js, compareArray.js, temporalHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + function * syncGen() { + for (let i = 0; i < 4; i++) { + yield i * 2; + } + } + const actual = []; + const items = {}; + TemporalHelpers.observeProperty(actual, items, Symbol.asyncIterator, syncGen, "items"); + TemporalHelpers.observeProperty(actual, items, Symbol.iterator, undefined, "items"); + TemporalHelpers.observeProperty(actual, items, "length", 2, "items"); + TemporalHelpers.observeProperty(actual, items, 0, 2, "items"); + TemporalHelpers.observeProperty(actual, items, 1, 1, "items"); + const result = await SendableArray.fromAsync(items); + assert.compareArray(result, [0, 2, 4, 6]); + assert.compareArray(actual, [ + "get items[Symbol.asyncIterator]", + ]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-throws.js b/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..35c1d0018176788db212d93d35d9e9374a893f54 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-asynciterator-throws.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync rejects if getting the @@asyncIterator property throws +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + await assert.throwsAsync(Test262Error, + () => SendableArray.fromAsync({ get [Symbol.asyncIterator]() { throw new Test262Error() } })); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-bigint.js b/test/sendable/builtins/Array/fromAsync/asyncitems-bigint.js new file mode 100644 index 0000000000000000000000000000000000000000..e1f6b0b88aa00a5ade0b377785f33cd82e58cac4 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-bigint.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync treats a BigInt as an array-like +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + BigInt.prototype.length = 2; + BigInt.prototype[0] = 1; + BigInt.prototype[1] = 2; + const result = await SendableArray.fromAsync(1n); + assert.compareArray(result, [1, 2]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-boolean.js b/test/sendable/builtins/Array/fromAsync/asyncitems-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..b78589b9e82f789b533c8735ef1b21ec70f4c448 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-boolean.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync treats a boolean as an array-like +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + Boolean.prototype.length = 2; + Boolean.prototype[0] = 1; + Boolean.prototype[1] = 2; + const result = await SendableArray.fromAsync(true); + assert.compareArray(result, [1, 2]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-function.js b/test/sendable/builtins/Array/fromAsync/asyncitems-function.js new file mode 100644 index 0000000000000000000000000000000000000000..13ef3bad7906d3b0c4606a2a849c5001a5dabd6a --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-function.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync treats a function as an array-like, reading elements up to fn.length +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const fn = function(a, b) {}; + fn[0] = 1; + fn[1] = 2; + fn[2] = 3; + const result = await SendableArray.fromAsync(fn); + assert.compareArray(result, [1, 2]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-exists.js b/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-exists.js new file mode 100644 index 0000000000000000000000000000000000000000..2d76eeee1352b806c0bed540464abc07c784d1f5 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-exists.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync handles a sync iterator returned from @@iterator +includes: [asyncHelpers.js, compareArray.js, temporalHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + function * syncGen() { + for (let i = 0; i < 4; i++) { + yield i * 2; + } + } + const actual = []; + const items = {}; + TemporalHelpers.observeProperty(actual, items, Symbol.asyncIterator, undefined, "items"); + TemporalHelpers.observeProperty(actual, items, Symbol.iterator, syncGen, "items"); + TemporalHelpers.observeProperty(actual, items, "length", 2, "items"); + TemporalHelpers.observeProperty(actual, items, 0, 2, "items"); + TemporalHelpers.observeProperty(actual, items, 1, 1, "items"); + const result = await SendableArray.fromAsync(items); + assert.compareArray(result, [0, 2, 4, 6]); + assert.compareArray(actual, [ + "get items[Symbol.asyncIterator]", + "get items[Symbol.iterator]", + ]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-not-callable.js b/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..56b19682f004416056e916cd24c23aacd221df17 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-not-callable.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync rejects if the @@iterator property is not callable +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + for (const v of [true, "", Symbol(), 1, 1n, {}]) { + await assert.throwsAsync(TypeError, + () => SendableArray.fromAsync({ [Symbol.iterator]: v }), + `@@iterator = ${typeof v}`); + } +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-null.js b/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-null.js new file mode 100644 index 0000000000000000000000000000000000000000..04b6d5062746704c0f0b89260cc2d76d46d26a5c --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-null.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync tries the various properties in order +includes: [asyncHelpers.js, compareArray.js, temporalHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const actual = []; + const items = {}; + TemporalHelpers.observeProperty(actual, items, Symbol.asyncIterator, undefined, "items"); + TemporalHelpers.observeProperty(actual, items, Symbol.iterator, null, "items"); + TemporalHelpers.observeProperty(actual, items, "length", 2, "items"); + TemporalHelpers.observeProperty(actual, items, 0, 2, "items"); + TemporalHelpers.observeProperty(actual, items, 1, 1, "items"); + const result = await SendableArray.fromAsync(items); + assert.compareArray(result, [2, 1]); + assert.compareArray(actual, [ + "get items[Symbol.asyncIterator]", + "get items[Symbol.iterator]", + "get items.length", + "get items[0]", + "get items[1]", + ]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-promise.js b/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-promise.js new file mode 100644 index 0000000000000000000000000000000000000000..da9d9cf2a4cfe100370b11306c9c19fe0fc4964d --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-promise.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync handles an async iterator returned from @@iterator +includes: [asyncHelpers.js, compareArray.js, temporalHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + function * asyncGen() { + for (let i = 0; i < 4; i++) { + yield Promise.resolve(i * 2); + } + } + const actual = []; + const items = {}; + TemporalHelpers.observeProperty(actual, items, Symbol.asyncIterator, undefined, "items"); + TemporalHelpers.observeProperty(actual, items, Symbol.iterator, asyncGen, "items"); + TemporalHelpers.observeProperty(actual, items, "length", 2, "items"); + TemporalHelpers.observeProperty(actual, items, 0, 2, "items"); + TemporalHelpers.observeProperty(actual, items, 1, 1, "items"); + const result = await SendableArray.fromAsync(items); + assert.compareArray(result, [0, 2, 4, 6]); + assert.compareArray(actual, [ + "get items[Symbol.asyncIterator]", + "get items[Symbol.iterator]", + ]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-throws.js b/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9915b6dc4d1754d87eb6c3bd8d4ac3f727903277 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-iterator-throws.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync rejects if getting the @@iterator property throws +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + await assert.throwsAsync(Test262Error, + () => SendableArray.fromAsync({ get [Symbol.iterator]() { throw new Test262Error() } })); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-null-undefined.js b/test/sendable/builtins/Array/fromAsync/asyncitems-null-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..3fc9978441d8a83bbb7a903ec060861c67d32bb8 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-null-undefined.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync rejects with a TypeError if the asyncItems argument is null or undefined +info: | + 3.c. Let usingAsyncIterator be ? GetMethod(asyncItems, @@asyncIterator). +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync(null), "null asyncItems"); + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync(undefined), "undefined asyncItems"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-number.js b/test/sendable/builtins/Array/fromAsync/asyncitems-number.js new file mode 100644 index 0000000000000000000000000000000000000000..4b2c5eea249dfe5228f550dff161a92a05b8bea1 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-number.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync treats a Number as an array-like +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + Number.prototype.length = 2; + Number.prototype[0] = 1; + Number.prototype[1] = 2; + const result = await SendableArray.fromAsync(1); + assert.compareArray(result, [1, 2]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-object-not-arraylike.js b/test/sendable/builtins/Array/fromAsync/asyncitems-object-not-arraylike.js new file mode 100644 index 0000000000000000000000000000000000000000..e7005b29bccb0cc6899e45e080af2d2f33b56fa5 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-object-not-arraylike.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Treats an asyncItems object that isn't an array-like as a 0-length array-like +info: | + 3.k.iii. Let _len_ be ? LengthOfArrayLike(_arrayLike_). +features: [SendableArray.fromAsync] +flags: [async] +includes: [asyncHelpers.js, compareArray.js] +---*/ + +asyncTest(async function () { + const notArrayLike = Object.create(null); + notArrayLike[0] = 0; + notArrayLike[1] = 1; + notArrayLike[2] = 2; + const array = await SendableArray.fromAsync(notArrayLike); + assert.compareArray(array, [], "non-array-like object is treated as 0-length array-like"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-operations.js b/test/sendable/builtins/Array/fromAsync/asyncitems-operations.js new file mode 100644 index 0000000000000000000000000000000000000000..8be0b6b425f2d3bd6d4a7b3e7810f1ad1422ad1e --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-operations.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync tries the various properties in order +includes: [asyncHelpers.js, compareArray.js, temporalHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const actual = []; + const items = {}; + TemporalHelpers.observeProperty(actual, items, Symbol.asyncIterator, undefined, "items"); + TemporalHelpers.observeProperty(actual, items, Symbol.iterator, undefined, "items"); + TemporalHelpers.observeProperty(actual, items, "length", 2, "items"); + TemporalHelpers.observeProperty(actual, items, 0, 2, "items"); + TemporalHelpers.observeProperty(actual, items, 1, 1, "items"); + const result = await SendableArray.fromAsync(items); + assert.compareArray(result, [2, 1]); + assert.compareArray(actual, [ + "get items[Symbol.asyncIterator]", + "get items[Symbol.iterator]", + "get items.length", + "get items[0]", + "get items[1]", + ]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-string.js b/test/sendable/builtins/Array/fromAsync/asyncitems-string.js new file mode 100644 index 0000000000000000000000000000000000000000..f971ba5a047790eea72c08a1480bdcf908ff26df --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-string.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync iterates over a string +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const result = await SendableArray.fromAsync("test"); + assert.compareArray(result, ["t", "e", "s", "t"]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-symbol.js b/test/sendable/builtins/Array/fromAsync/asyncitems-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..59062ae56fe4f2576c75175bc850cc434a2cd160 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-symbol.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + SendableArray.fromAsync treats a Symbol as an array-like +includes: [asyncHelpers.js, compareArray.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + Symbol.prototype.length = 2; + Symbol.prototype[0] = 1; + Symbol.prototype[1] = 2; + const result = await SendableArray.fromAsync(Symbol()); + assert.compareArray(result, [1, 2]); +}); diff --git a/test/sendable/builtins/Array/fromAsync/asyncitems-uses-intrinsic-iterator-symbols.js b/test/sendable/builtins/Array/fromAsync/asyncitems-uses-intrinsic-iterator-symbols.js new file mode 100644 index 0000000000000000000000000000000000000000..7b51b4879c985c59607e7e2b67c04f0b1383472b --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/asyncitems-uses-intrinsic-iterator-symbols.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Use the intrinsic @@iterator and @@asyncIterator to check iterability +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + // Replace the user-reachable Symbol.iterator and Symbol.asyncIterator with + // fake symbol keys + const originalSymbol = globalThis.Symbol; + const fakeIteratorSymbol = Symbol("iterator"); + const fakeAsyncIteratorSymbol = Symbol("asyncIterator"); + globalThis.Symbol = { + iterator: fakeIteratorSymbol, + asyncIterator: fakeAsyncIteratorSymbol, + }; + const input = { + length: 3, + 0: 0, + 1: 1, + 2: 2, + [fakeIteratorSymbol]() { + throw new Test262Error("The fake Symbol.iterator method should not be called"); + }, + [fakeAsyncIteratorSymbol]() { + throw new Test262Error("The fake Symbol.asyncIterator method should not be called"); + } + }; + const output = await SendableArray.fromAsync(input); + assert.compareArray(output, [0, 1, 2]); + globalThis.Symbol = originalSymbol; +}); diff --git a/test/sendable/builtins/Array/fromAsync/builtin.js b/test/sendable/builtins/Array/fromAsync/builtin.js new file mode 100644 index 0000000000000000000000000000000000000000..682f928e9c63e84a97d0612c244c08796f70436e --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/builtin.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: SendableArray.fromAsync meets the requirements for built-in objects +info: | + Unless specified otherwise, a built-in object that is callable as a function + is a built-in function object with the characteristics described in 10.3. + Unless specified otherwise, the [[Extensible]] internal slot of a built-in + object initially has the value *true*. + Unless otherwise specified every built-in function and every built-in + constructor has the Function prototype object, which is the initial value of + the expression Function.prototype (20.2.3), as the value of its [[Prototype]] + internal slot. + Built-in functions that are not constructors do not have a "prototype" + property unless otherwise specified in the description of a particular + function. +features: [SendableArray.fromAsync] +---*/ + +assert(Object.isExtensible(SendableArray.fromAsync), "Array.fromAsync is extensible"); +assert.sameValue( + Object.getPrototypeOf(SendableArray.fromAsync), + Function.prototype, + "Prototype of SendableArray.fromAsync is Function.prototype" +); +assert.sameValue( + Object.getOwnPropertyDescriptor(SendableArray.fromAsync, "prototype"), + undefined, + "SendableArray.fromAsync has no own prototype property" +); diff --git a/test/sendable/builtins/Array/fromAsync/length.js b/test/sendable/builtins/Array/fromAsync/length.js new file mode 100644 index 0000000000000000000000000000000000000000..01abbccdd8f61d47e98effbe1e8e6384c673c515 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/length.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Value and property descriptor of SendableArray.fromAsync.length +info: | + Every built-in function object, including constructors, has a *"length"* + property whose value is a non-negative integral Number. Unless otherwise + specified, this value is equal to the number of required parameters shown in + the subclause heading for the function description. Optional parameters and + rest parameters are not included in the parameter count. + + Unless otherwise specified, the *"length"* property of a built-in function + object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, + [[Configurable]]: *true* }. +includes: [propertyHelper.js] +features: [SendableArray.fromAsync] +---*/ + +verifyProperty(SendableArray.fromAsync, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-async-arraylike.js b/test/sendable/builtins/Array/fromAsync/mapfn-async-arraylike.js new file mode 100644 index 0000000000000000000000000000000000000000..e3901be68425777957dc7ebe59b768a5cc569c30 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-async-arraylike.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + An asynchronous mapping function is applied to each (awaited) item of an + arraylike. +info: | + 3.k.vii.4. If _mapping_ is *true*, then + a. Let _mappedValue_ be ? Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + b. Let _mappedValue_ be ? Await(_mappedValue_). + ... + 6. Perform ? CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). +flags: [async] +includes: [asyncHelpers.js, compareArray.js] +features: [SendableArray.fromAsync] +---*/ + +const arrayLike = { + length: 4, + 0: 0, + 1: 2, + 2: Promise.resolve(4), + 3: 6, +}; +async function asyncMap(val, ix) { + return Promise.resolve(val * ix); +} +asyncTest(async () => { + const result = await SendableArray.fromAsync(arrayLike, asyncMap); + assert.compareArray(result, [0, 2, 8, 18], "async mapfn should be applied to arraylike"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-async-iterable-async.js b/test/sendable/builtins/Array/fromAsync/mapfn-async-iterable-async.js new file mode 100644 index 0000000000000000000000000000000000000000..8c5ed6db4d4be0119f15ca9daf8cc8fe5eb85788 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-async-iterable-async.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + An asynchronous mapping function is applied to each item yielded by an + asynchronous iterable. +info: | + 3.j.ii.6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + ... + c. Set _mappedValue_ to Await(_mappedValue_). + ... + ... + 8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). +flags: [async] +includes: [asyncHelpers.js, compareArray.js] +features: [SendableArray.fromAsync] +---*/ + +async function* asyncGen() { + for (let i = 0; i < 4; i++) { + yield Promise.resolve(i * 2); + } +} +async function asyncMap(val, ix) { + return Promise.resolve(val * ix); +} +asyncTest(async () => { + const result = await SendableArray.fromAsync({ [Symbol.asyncIterator]: asyncGen }, asyncMap); + assert.compareArray(result, [0, 2, 8, 18], "async mapfn should be applied to async iterable"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-async-iterable-sync.js b/test/sendable/builtins/Array/fromAsync/mapfn-async-iterable-sync.js new file mode 100644 index 0000000000000000000000000000000000000000..87c923299b4589d5f65e477991d6e9d4fea8de7e --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-async-iterable-sync.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + An asynchronous mapping function is applied to each item yielded by a + synchronous iterable. +info: | + 3.j.ii.6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + c. Set _mappedValue_ to Await(_mappedValue_). + 8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). +flags: [async] +includes: [asyncHelpers.js, compareArray.js] +features: [SendableArray.fromAsync] +---*/ + +function* syncGen() { + for (let i = 0; i < 4; i++) { + yield i * 2; + } +} +async function asyncMap(val, ix) { + return Promise.resolve(val * ix); +} +asyncTest(async () => { + const result = await SendableArray.fromAsync({ [Symbol.iterator]: syncGen }, asyncMap); + assert.compareArray(result, [0, 2, 8, 18], "async mapfn should be applied to sync iterable"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-async-throws-close-async-iterator.js b/test/sendable/builtins/Array/fromAsync/mapfn-async-throws-close-async-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..38c8a37be0449ac0cb0c3ecdac01eaf31c95e73c --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-async-throws-close-async-iterator.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + The iterator of an asynchronous iterable is closed when the asynchronous + mapping function throws. +info: | + 3.j.ii.6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + c. Set _mappedValue_ to Await(_mappedValue_). + d. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_). +flags: [async] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +let closed = false; +const iterator = { + next() { + return Promise.resolve({ value: 1, done: false }); + }, + return() { + closed = true; + return Promise.resolve({ done: true }); + }, + [Symbol.asyncIterator]() { + return this; + } +} +asyncTest(async () => { + await assert.throwsAsync(Error, () => SendableArray.fromAsync(iterator, async (val) => { + assert.sameValue(val, 1, "mapfn receives value from iterator"); + throw new Error("mapfn throws"); + }), "async mapfn rejecting should cause fromAsync to reject"); + assert(closed, "async mapfn rejecting should close iterator") +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-async-throws-close-sync-iterator.js b/test/sendable/builtins/Array/fromAsync/mapfn-async-throws-close-sync-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..fa2a256474bdf26ef0634096df4ee4352a793e85 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-async-throws-close-sync-iterator.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + The iterator of a synchronous iterable is closed when the asynchronous mapping + function throws. +info: | + 3.j.ii.6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + ... + c. Set _mappedValue_ to Await(_mappedValue_). + d. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_). +flags: [async] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +let closed = false; +const iterator = { + next() { + return { value: 1, done: false }; + }, + return() { + closed = true; + return { done: true }; + }, + [Symbol.iterator]() { + return this; + } +} +asyncTest(async () => { + await assert.throwsAsync(Error, () => SendableArray.fromAsync(iterator, async (val) => { + assert.sameValue(val, 1, "mapfn receives value from iterator"); + throw new Error("mapfn throws"); + }), "async mapfn rejecting should cause fromAsync to reject"); + assert(closed, "async mapfn rejecting should close iterator") +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-async-throws.js b/test/sendable/builtins/Array/fromAsync/mapfn-async-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..7dc188d365ca3665eaee681f552762b6696f3d74 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-async-throws.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + The output promise rejects if the asynchronous mapping function rejects. +info: | + 3.j.ii.6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + ... + c. Set _mappedValue_ to Await(_mappedValue_). + d. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_). +flags: [async] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async () => { + await assert.throwsAsync(Test262Error, () => SendableArray.fromAsync([1, 2, 3], async () => { + throw new Test262Error("mapfn throws"); + }), "async mapfn rejecting should cause fromAsync to reject"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-not-callable.js b/test/sendable/builtins/Array/fromAsync/mapfn-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..ed1a5ee0965d0bd60c7d34f39581c4251a6345d4 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-not-callable.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + A TypeError is thrown if the mapfn argument to Array.fromAsync is not callable +info: | + 3.a. If _mapfn_ is *undefined*, let _mapping_ be *false*. + b. Else, + i. If IsCallable(_mapfn_) is *false*, throw a *TypeError* exception. +flags: [async] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync, BigInt, Symbol] +---*/ + +asyncTest(async () => { + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync([], null), "null mapfn"); + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync([], {}), "non-callable object mapfn"); + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync([], "String"), "string mapfn"); + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync([], true), "boolean mapfn"); + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync([], 3.1416), "number mapfn"); + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync([], 42n), "bigint mapfn"); + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync([], Symbol()), "symbol mapfn"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-result-awaited-once-per-iteration.js b/test/sendable/builtins/Array/fromAsync/mapfn-result-awaited-once-per-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..3733267461ee517764a7e5b0719334a1b1afcec1 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-result-awaited-once-per-iteration.js @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + The returned value from each invocation of the asynchronous mapping function + is awaited exactly once. +info: | + 3.j.ii.6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + c. Set _mappedValue_ to Await(_mappedValue_). +flags: [async] +includes: [asyncHelpers.js, compareArray.js, temporalHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +const calls = []; +const expected = [ + "call mapping", + "get thenable_0.then", + "call thenable_0.then", + "call mapping", + "get thenable_1.then", + "call thenable_1.then", + "call mapping", + "get thenable_2.then", + "call thenable_2.then", +]; +function mapping(val, ix) { + calls.push("call mapping"); + const thenableName = `thenable_${ix}`; + return TemporalHelpers.propertyBagObserver(calls, { + then(resolve, reject) { + calls.push(`call ${thenableName}.then`); + resolve(val * 2); + } + }, thenableName) +} +asyncTest(async () => { + const result = await SendableArray.fromAsync([1, 2, 3], mapping); + assert.compareArray(result, [2, 4, 6], "mapping function applied"); + assert.compareArray(calls, expected, "observable operations"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-sync-arraylike.js b/test/sendable/builtins/Array/fromAsync/mapfn-sync-arraylike.js new file mode 100644 index 0000000000000000000000000000000000000000..f85da96cc7393e6623c0cc26dec9edfd63c138c2 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-sync-arraylike.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + A synchronous mapping function is applied to each (awaited) item of an + arraylike. +info: | + 3.k.vii.4. If _mapping_ is *true*, then + a. Let _mappedValue_ be ? Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + 6. Perform ? CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). +flags: [async] +includes: [asyncHelpers.js, compareArray.js] +features: [SendableArray.fromAsync] +---*/ + +const arrayLike = { + length: 4, + 0: 0, + 1: 2, + 2: Promise.resolve(4), + 3: 6, +}; +function syncMap(val, ix) { + return val * ix; +} +asyncTest(async () => { + const result = await SendableArray.fromAsync(arrayLike, syncMap); + assert.compareArray(result, [0, 2, 8, 18], "sync mapfn should be applied to arraylike"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-sync-iterable-async.js b/test/sendable/builtins/Array/fromAsync/mapfn-sync-iterable-async.js new file mode 100644 index 0000000000000000000000000000000000000000..452255a632ee450282e2985278597e1a965d82b5 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-sync-iterable-async.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + A synchronous mapping function is applied to each item yielded by an + asynchronous iterable. +info: | + 3.j.ii.6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + ... + ... + 8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). +flags: [async] +includes: [asyncHelpers.js, compareArray.js] +features: [SendableArray.fromAsync] +---*/ + +async function* asyncGen() { + for (let i = 0; i < 4; i++) { + yield Promise.resolve(i * 2); + } +} +function syncMap(val, ix) { + return val * ix; +} +asyncTest(async () => { + const result = await SendableArray.fromAsync({ [Symbol.asyncIterator]: asyncGen }, syncMap); + assert.compareArray(result, [0, 2, 8, 18], "sync mapfn should be applied to async iterable"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-sync-iterable-sync.js b/test/sendable/builtins/Array/fromAsync/mapfn-sync-iterable-sync.js new file mode 100644 index 0000000000000000000000000000000000000000..1a94eadbaa5cc0b6a522b514dba0528aeb0aedae --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-sync-iterable-sync.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + A synchronous mapping function is applied to each item yielded by a + synchronous iterable. +info: | + 3.j.ii.6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + 8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). +flags: [async] +includes: [asyncHelpers.js, compareArray.js] +features: [SendableArray.fromAsync] +---*/ + +function* syncGen() { + for (let i = 0; i < 4; i++) { + yield i * 2; + } +} +function syncMap(val, ix) { + return val * ix; +} +asyncTest(async () => { + const result = await SendableArray.fromAsync({ [Symbol.iterator]: syncGen }, syncMap); + assert.compareArray(result, [0, 2, 8, 18], "sync mapfn should be applied to sync iterable"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-sync-throws-close-async-iterator.js b/test/sendable/builtins/Array/fromAsync/mapfn-sync-throws-close-async-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..34414ddbf25b9c76fcaa979f8c20dc6ad945bec2 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-sync-throws-close-async-iterator.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + The iterator of an asynchronous iterable is closed when the synchronous + mapping function throws. +info: | + 3.j.ii.6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + b. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_). + ... +flags: [async] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +let closed = false; +const iterator = { + next() { + return Promise.resolve({ value: 1, done: false }); + }, + return() { + closed = true; + return Promise.resolve({ done: true }); + }, + [Symbol.asyncIterator]() { + return this; + } +} +asyncTest(async () => { + await assert.throwsAsync(Error, () => SendableArray.fromAsync(iterator, (val) => { + assert.sameValue(val, 1, "mapfn receives value from iterator"); + throw new Error("mapfn throws"); + }), "sync mapfn throwing should cause fromAsync to reject"); + assert(closed, "sync mapfn throwing should close iterator") +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-sync-throws-close-sync-iterator.js b/test/sendable/builtins/Array/fromAsync/mapfn-sync-throws-close-sync-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..6c7eca551070faf0b9ac2faa935721d24cdfde54 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-sync-throws-close-sync-iterator.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + The iterator of a synchronous iterable is closed when the synchronous mapping + function throws. +info: | + 3.j.ii.6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + b. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_). + ... +flags: [async] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +let closed = false; +const iterator = { + next() { + return { value: 1, done: false }; + }, + return() { + closed = true; + return { done: true }; + }, + [Symbol.iterator]() { + return this; + } +} +asyncTest(async () => { + await assert.throwsAsync(Error, () => SendableArray.fromAsync(iterator, (val) => { + assert.sameValue(val, 1, "mapfn receives value from iterator"); + throw new Error("mapfn throws"); + }), "sync mapfn throwing should cause fromAsync to reject"); + assert(closed, "sync mapfn throwing should close iterator") +}); diff --git a/test/sendable/builtins/Array/fromAsync/mapfn-sync-throws.js b/test/sendable/builtins/Array/fromAsync/mapfn-sync-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..89701e78e1dfff1f42ee3cc29e20f44d641c7e5e --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/mapfn-sync-throws.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + The output promise rejects if the synchronous mapping function throws. +info: | + 3.j.ii.6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + b. IfAbruptCloseAsyncIterator(_mappedValue_, _iteratorRecord_). + ... +flags: [async] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async () => { + await assert.throwsAsync(Test262Error, () => SendableArray.fromAsync([1, 2, 3], () => { + throw new Test262Error("mapfn throws"); + }), "sync mapfn throwing should cause fromAsync to reject"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/name.js b/test/sendable/builtins/Array/fromAsync/name.js new file mode 100644 index 0000000000000000000000000000000000000000..59d1a87c894bfb5587a983b50336805666c0bd60 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/name.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Value and property descriptor of Array.fromAsync.name +info: | + Every built-in function object, including constructors, has a *"name"* + property whose value is a String. Unless otherwise specified, this value is + the name that is given to the function in this specification. [...] + For functions that are specified as properties of objects, the name value is + the property name string used to access the function. + + Unless otherwise specified, the *"name"* property of a built-in function + object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [SendableArray.fromAsync] +---*/ + +verifyProperty(SendableArray.fromAsync, "name", { + value: "fromAsync", + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-input-does-not-use-array-prototype.js b/test/sendable/builtins/Array/fromAsync/non-iterable-input-does-not-use-array-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..11e27d2f241301d3232d08ae9266d370e2cb936a --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-input-does-not-use-array-prototype.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Non-iterable input does not use Array.prototype +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { +const arrayIterator = [].values(); +const IntrinsicArrayIteratorPrototype = +Object.getPrototypeOf(arrayIterator); +const intrinsicArrayIteratorPrototypeNext = +IntrinsicArrayIteratorPrototype.next; +try { +// Temporarily mutate the array iterator prototype to have an invalid +// “next” method. Just like Array.from, the fromAsync function should +// still work on non-iterable arraylike arguments. +IntrinsicArrayIteratorPrototype.next = function fakeNext () { + throw new Test262Error( + 'This fake next function should not be called; ' + + 'instead, each element should have been directly accessed.', + ); +}; +const expected = [ 0, 1, 2 ]; +const input = { + length: 3, + 0: 0, + 1: 1, + 2: 2, +}; +const output = await SendableArray.fromAsync(input); +assert.compareArray(output, expected); +} +finally { +// Reset the intrinsic array iterator +IntrinsicArrayIteratorPrototype.next = + intrinsicArrayIteratorPrototypeNext; +} +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-input-element-access-err.js b/test/sendable/builtins/Array/fromAsync/non-iterable-input-element-access-err.js new file mode 100644 index 0000000000000000000000000000000000000000..786155db73d7038979bdfb138310aad545553b38 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-input-element-access-err.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Result promise rejects if element access fails +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const input = { + length: 1, + get 0 () { + throw new Test262Error; + }, + }; + const outputPromise = SendableArray.fromAsync(input); + assert.throwsAsync(Test262Error, () => outputPromise); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-async-mapped-awaits-callback-result-once.js b/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-async-mapped-awaits-callback-result-once.js new file mode 100644 index 0000000000000000000000000000000000000000..6e9151740a53fd5795637b0c2408dfde1baf846e --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-async-mapped-awaits-callback-result-once.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Non-iterable input with thenable result with async mapped awaits each callback result once. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + let awaitCounter = 0; + const input = { + length: 3, + 0: 0, + 1: Promise.resolve(1), + 2: Promise.resolve(2), + 3: Promise.resolve(3), // This is ignored because the length is 3. + }; + await SendableArray.fromAsync(input, async v => { + return { + // This “then” method should occur three times: + // one for each value from the input. + then (resolve, reject) { + awaitCounter ++; + resolve(v); + }, + }; + }); + assert.sameValue(awaitCounter, 3); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-async-mapped-callback-err.js b/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-async-mapped-callback-err.js new file mode 100644 index 0000000000000000000000000000000000000000..b0a26430e177c7ffe13867966e81a240bdccf3d4 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-async-mapped-callback-err.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Non-iterable input with thenable result promise rejects if async map function callback throws. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + const inputThenable = { + then (resolve, reject) { + resolve(expectedValue); + }, + }; + const input = { + length: 1, + 0: inputThenable, + }; + const outputPromise = SendableArray.fromAsync(input, async v => { + throw new Test262Error; + }); + assert.throwsAsync(Test262Error, () => outputPromise); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-element-rejects.js b/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-element-rejects.js new file mode 100644 index 0000000000000000000000000000000000000000..3535c61794b34a1499fd03e1542b813139d12239 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-element-rejects.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Non-iterable input with thenable result promise rejects if thenable element rejects. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + const expected = [ expectedValue ]; + const inputThenable = { + then (resolve, reject) { + reject(new Test262Error); + }, + }; + const input = { + length: 1, + 0: inputThenable, + }; + const output = SendableArray.fromAsync(input); + await assert.throwsAsync(Test262Error, () => output); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-sync-mapped-callback-err.js b/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-sync-mapped-callback-err.js new file mode 100644 index 0000000000000000000000000000000000000000..9e5d00dacb1a338e408e2d6719961f9e0dd48828 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable-sync-mapped-callback-err.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Non iterable result promise rejects if sync map function callback throws. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const input = { + length: 1, + 0: 0, + }; + const outputPromise = SendableArray.fromAsync(input, v => { + throw new Test262Error; + }); + assert.throwsAsync(Test262Error, () => outputPromise); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable.js b/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable.js new file mode 100644 index 0000000000000000000000000000000000000000..164618cb0bae74707a9f1d2e8e1cfc1f253b25ca --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-input-with-thenable.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Non iterable input with thenables is transferred to the output array. +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expected = [ 0, 1, 2 ]; + const input = { + length: 3, + 0: 0, + 1: Promise.resolve(1), + 2: Promise.resolve(2), + 3: Promise.resolve(3), // This is ignored because the length is 3. + }; + const output = await SendableArray.fromAsync(input); + assert.compareArray(output, expected); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-input.js b/test/sendable/builtins/Array/fromAsync/non-iterable-input.js new file mode 100644 index 0000000000000000000000000000000000000000..57717ca3322ae7a5202d73125ffb1721b0dd0116 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-input.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Non iterable input without thenables is transferred to the output array. +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expected = [ 0, 1, 2 ]; + const input = { + length: 3, + 0: 0, + 1: 1, + 2: 2, + 3: 3, // This is ignored because the length is 3. + }; + const output = await SendableArray.fromAsync(input); + assert.compareArray(output, expected); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-sync-mapped-callback-err.js b/test/sendable/builtins/Array/fromAsync/non-iterable-sync-mapped-callback-err.js new file mode 100644 index 0000000000000000000000000000000000000000..80c4bf90c3e02f30c2d064e6ced913e42547939f --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-sync-mapped-callback-err.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Non iterable input with thenables awaits each input once without mapping callback +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + const inputThenable = { + then (resolve, reject) { + resolve(expectedValue); + }, + }; + const input = { + length: 1, + 0: inputThenable, + }; + const outputPromise = SendableArray.fromAsync(input, v => { + throw new Test262Error; + }); + await assert.throwsAsync(Test262Error, () => outputPromise); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-with-non-promise-thenable.js b/test/sendable/builtins/Array/fromAsync/non-iterable-with-non-promise-thenable.js new file mode 100644 index 0000000000000000000000000000000000000000..9c9fe366f8ffad752468bfa72f64a6764238d4f8 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-with-non-promise-thenable.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Non iterable input with non-promise thenables works. +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + const expected = [ expectedValue ]; + const inputThenable = { + then (resolve, reject) { + resolve(expectedValue); + }, + }; + const input = { + length: 1, + 0: inputThenable, + }; + const output = await SendableArray.fromAsync(input); + assert.compareArray(output, expected); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-async-mapped-awaits-once.js b/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-async-mapped-awaits-once.js new file mode 100644 index 0000000000000000000000000000000000000000..074cfe71f02fac01fbc0543dd2bc3e884980eecd --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-async-mapped-awaits-once.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Non-iterable input with thenables awaits each input once without mapping callback +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + const expected = [ expectedValue ]; + let awaitCounter = 0; + const inputThenable = { + then (resolve, reject) { + awaitCounter++; + resolve(expectedValue); + }, + }; + const input = { + length: 1, + 0: inputThenable, + }; + await SendableArray.fromAsync(input, async v => v); + assert.sameValue(awaitCounter, 1); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-awaits-once.js b/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-awaits-once.js new file mode 100644 index 0000000000000000000000000000000000000000..02688848e592a14e9d57f620813208e77ff2e380 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-awaits-once.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Non-iterable with thenables awaits each input value once without mapping callback. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + let awaitCounter = 0; + const inputThenable = { + then (resolve, reject) { + awaitCounter ++; + resolve(expectedValue); + }, + }; + const input = { + length: 1, + 0: inputThenable, + }; + await SendableArray.fromAsync(input); + assert.sameValue(awaitCounter, 1); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-sync-mapped-awaits-once.js b/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-sync-mapped-awaits-once.js new file mode 100644 index 0000000000000000000000000000000000000000..dacff54ca7213cb08bfa07572acb42f2b1b902fd --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-sync-mapped-awaits-once.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Non-iterable input with thenables awaits each input once with mapping callback +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + let awaitCounter = 0; + const inputThenable = { + then (resolve, reject) { + awaitCounter++; + resolve(expectedValue); + }, + }; + const input = { + length: 1, + 0: inputThenable, + }; + await SendableArray.fromAsync(input, v => v); + assert.sameValue(awaitCounter, 1); +}); diff --git a/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-then-method-err.js b/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-then-method-err.js new file mode 100644 index 0000000000000000000000000000000000000000..e790dc1a2639a5c3aafa28e5b8932a675980de3c --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/non-iterable-with-thenable-then-method-err.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Non-iterable input with thenable result promise is rejected if element's then method throws. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const inputThenable = { + then (resolve, reject) { + throw new Test262Error; + }, + }; + const input = { + length: 1, + 0: inputThenable, + }; + const outputPromise = SendableArray.fromAsync(input); + assert.throwsAsync(Test262Error, () => outputPromise); +}); diff --git a/test/sendable/builtins/Array/fromAsync/not-a-constructor.js b/test/sendable/builtins/Array/fromAsync/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..f950e9040cd0ff2b1346ecde65899c1083ba07ff --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/not-a-constructor.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: SendableArray.fromAsync is not a constructor +info: | + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in the + description of a particular function. +includes: [isConstructor.js] +features: [SendableArray.fromAsync, Reflect.construct] +---*/ + +assert(!isConstructor(SendableArray.fromAsync), "SendableArray.fromAsync is not a constructor"); +assert.throws(TypeError, () => new SendableArray.fromAsync(), "SendableArray.fromAsync throws when constructed"); diff --git a/test/sendable/builtins/Array/fromAsync/prop-desc.js b/test/sendable/builtins/Array/fromAsync/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..fd739fd69368d16022408902ad308dbad0946078 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/prop-desc.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Type and property descriptor of SendableArray.fromAsync +info: | + Every other data property described in clauses 19 through 28 and in Annex B.2 + has the attributes { [[Writable]]: *true*, [[Enumerable]]: *false*, + [[Configurable]]: *true* } unless otherwise specified. +includes: [propertyHelper.js] +features: [SendableArray.fromAsync] +---*/ + +assert.sameValue(typeof SendableArray.fromAsync, "function", "SendableArray.fromAsync is callable"); +verifyProperty(SendableArray, 'fromAsync', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/fromAsync/returned-promise-resolves-to-array.js b/test/sendable/builtins/Array/fromAsync/returned-promise-resolves-to-array.js new file mode 100644 index 0000000000000000000000000000000000000000..38e89d725a3dd9ce5fcfdbd5da59cfe8d84b2bf7 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/returned-promise-resolves-to-array.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Array.fromAsync returns a Promise that resolves to an Array in the normal case +info: | + 1. Let _C_ be the *this* value. + 3.e. If IsConstructor(_C_) is *true*, then + i. Let _A_ be ? Construct(_C_). +features: [SendableArray.fromAsync] +flags: [async] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + const promise = SendableArray.fromAsync([0, 1, 2]); + const array = await promise; + assert(SendableArray.isArray(array), "SendableArray.fromAsync returns a Promise that resolves to an Array"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/returns-promise.js b/test/sendable/builtins/Array/fromAsync/returns-promise.js new file mode 100644 index 0000000000000000000000000000000000000000..7608319e2ffed3ca1970037f8efc615e966587f0 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/returns-promise.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: SendableArray.fromAsync returns a Promise +info: | + 5. Return _promiseCapability_.[[Promise]]. +flags: [async] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + let p = SendableArray.fromAsync([0, 1, 2]); + assert(p instanceof Promise, "SendableArray.fromAsync returns a Promise"); + assert.sameValue( + Object.getPrototypeOf(p), + Promise.prototype, + "SendableArray.fromAsync returns an object with prototype Promise.prototype" + ); + p = SendableArray.fromAsync([0, 1, 2], () => { + throw new Test262Error("this will make the Promise reject"); + }) + assert(p instanceof Promise, "SendableArray.fromAsync returns a Promise even on error"); + assert.sameValue( + Object.getPrototypeOf(p), + Promise.prototype, + "SendableArray.fromAsync returns an object with prototype Promise.prototype even on error" + ); + await assert.throwsAsync(Test262Error, () => p, "Prevent unhandled rejection"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/sync-iterable-input-with-non-promise-thenable.js b/test/sendable/builtins/Array/fromAsync/sync-iterable-input-with-non-promise-thenable.js new file mode 100644 index 0000000000000000000000000000000000000000..d49efc4f8c197c12c532e70764b1f169c8654205 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/sync-iterable-input-with-non-promise-thenable.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Sync-iterable input with non-promise thenables works. +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + const expected = [ expectedValue ]; + const inputThenable = { + then (resolve, reject) { + resolve(expectedValue); + }, + }; + const input = [ inputThenable ].values(); + const output = await SendableArray.fromAsync(input); + assert.compareArray(output, expected); +}); diff --git a/test/sendable/builtins/Array/fromAsync/sync-iterable-input-with-thenable.js b/test/sendable/builtins/Array/fromAsync/sync-iterable-input-with-thenable.js new file mode 100644 index 0000000000000000000000000000000000000000..067834c959aa4c7cee74ce69d281a1a348854657 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/sync-iterable-input-with-thenable.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Sync-iterable input with thenables is transferred to the output array. +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expected = [ 0, 1, 2 ]; + const input = [ 0, Promise.resolve(1), Promise.resolve(2) ].values(); + const output = await SendableArray.fromAsync(input); + assert.compareArray(output, expected); +}); diff --git a/test/sendable/builtins/Array/fromAsync/sync-iterable-input.js b/test/sendable/builtins/Array/fromAsync/sync-iterable-input.js new file mode 100644 index 0000000000000000000000000000000000000000..775938712b57d7baffea7b9b5702e86e4d5138fc --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/sync-iterable-input.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Sync-iterable input with no promises is transferred to the output array. +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expected = [ 0, 1, 2 ]; + const input = [ 0, 1, 2 ].values(); + const output = await SendableArray.fromAsync(input); + assert.compareArray(output, expected); +}); diff --git a/test/sendable/builtins/Array/fromAsync/sync-iterable-iteration-err.js b/test/sendable/builtins/Array/fromAsync/sync-iterable-iteration-err.js new file mode 100644 index 0000000000000000000000000000000000000000..26db37aec0b0d0ff88178b8aae989c459b959c03 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/sync-iterable-iteration-err.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Sync iterable result promise rejects if iteration of input fails. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + function *generateInput () { + throw new Test262Error; + } + const input = generateInput(); + const outputPromise = SendableArray.fromAsync(input); + await assert.throwsAsync(Test262Error, () => outputPromise); +}); diff --git a/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-async-mapped-awaits-once.js b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-async-mapped-awaits-once.js new file mode 100644 index 0000000000000000000000000000000000000000..50c29f94ff146eb1ec9158fd9478a9f3de76da73 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-async-mapped-awaits-once.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Sync-iterable input with thenables awaits each input once with async mapping callback. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + let awaitCounter = 0; + const inputThenable = { + then (resolve, reject) { + awaitCounter++; + resolve(expectedValue); + }, + }; + const input = [ inputThenable ].values(); + await SendableArray.fromAsync(input, async v => v); + assert.sameValue(awaitCounter, 1); +}); diff --git a/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-async-mapped-callback-err.js b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-async-mapped-callback-err.js new file mode 100644 index 0000000000000000000000000000000000000000..2d50fbdf691ca77ebe8ff2746dec374b4b4d2520 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-async-mapped-callback-err.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Sync-iterable input with thenable result promise rejects if async map function callback throws. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const input = [ Promise.resolve(0) ].values(); + const outputPromise = SendableArray.fromAsync(input, async v => { + throw new Test262Error; + }); + await assert.throwsAsync(Test262Error, () => outputPromise); +}); diff --git a/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-awaits-once.js b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-awaits-once.js new file mode 100644 index 0000000000000000000000000000000000000000..89de8ede464c96595756457e2713c2a96199ce46 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-awaits-once.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Sync-iterable input with thenables awaits each input once without mapping callback +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + let awaitCounter = 0; + const inputThenable = { + then (resolve, reject) { + awaitCounter++; + resolve(expectedValue); + }, + }; + const input = [ inputThenable ].values(); + await SendableArray.fromAsync(input); + assert.sameValue(awaitCounter, 1); +}); diff --git a/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-element-rejects.js b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-element-rejects.js new file mode 100644 index 0000000000000000000000000000000000000000..dd86901b17ea938faf90216d93a3f51c6df57521 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-element-rejects.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Result promise rejects if then method of input fails. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const inputThenable = { + then (resolve, reject) { + reject(new Test262Error); + }, + }; + const input = [ inputThenable ].values(); + const output = SendableArray.fromAsync(input); + await assert.throwsAsync(Test262Error, () => output); +}); diff --git a/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-sync-mapped-awaits-once.js b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-sync-mapped-awaits-once.js new file mode 100644 index 0000000000000000000000000000000000000000..6540434f21134e40a660314647d3abf5b098f499 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-sync-mapped-awaits-once.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Sync-iterable input with mapfn awaits each input once with sync mapping callback +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + let awaitCounter = 0; + const inputThenable = { + then (resolve, reject) { + awaitCounter++; + resolve(expectedValue); + }, + }; + const input = [ inputThenable ].values(); + await SendableArray.fromAsync(input, v => v); + assert.sameValue(awaitCounter, 1); +}); diff --git a/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-sync-mapped-callback-err.js b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-sync-mapped-callback-err.js new file mode 100644 index 0000000000000000000000000000000000000000..fcd83026fa189e0d5fb65148e9e49f51123acde8 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-sync-mapped-callback-err.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Sync-iterable input with thenable result promise rejects if sync map function callback throws. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const input = [ Promise.resolve(0) ].values(); + const outputPromise = SendableArray.fromAsync(input, v => { + throw new Test262Error; + }); + await assert.throwsAsync(Test262Error, () => outputPromise); +}); diff --git a/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-then-method-err.js b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-then-method-err.js new file mode 100644 index 0000000000000000000000000000000000000000..254f8e533c0a63763dfbfc04826508282de98278 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/sync-iterable-with-thenable-then-method-err.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: Result promise rejects if then method of input fails. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const expectedValue = {}; + const expected = [ expectedValue ]; + const inputThenable = { + then (resolve, reject) { + throw new Test262Error(); + }, + }; + const input = [ inputThenable ].values(); + const output = SendableArray.fromAsync(input); + await assert.throwsAsync(Test262Error, () => output); +}); diff --git a/test/sendable/builtins/Array/fromAsync/this-constructor-operations.js b/test/sendable/builtins/Array/fromAsync/this-constructor-operations.js new file mode 100644 index 0000000000000000000000000000000000000000..21d9320e8446d9bcd6a87ef1bd91c9690f0d9373 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/this-constructor-operations.js @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Order of user-observable operations on a custom this-value and its instances +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +function formatPropertyName(propertyKey, objectName = "") { + switch (typeof propertyKey) { + case "symbol": + if (Symbol.keyFor(propertyKey) !== undefined) { + return `${objectName}[Symbol.for('${Symbol.keyFor(propertyKey)}')]`; + } else if (propertyKey.description.startsWith('Symbol.')) { + return `${objectName}[${propertyKey.description}]`; + } else { + return `${objectName}[Symbol('${propertyKey.description}')]` + } + case "string": + if (propertyKey !== String(Number(propertyKey))) + return objectName ? `${objectName}.${propertyKey}` : propertyKey; + // fall through + default: + // integer or string integer-index + return `${objectName}[${propertyKey}]`; + } +} +asyncTest(async function () { + const expectedCalls = [ + "construct MyArray", + "defineProperty A[0]", + "defineProperty A[1]", + "set A.length" + ]; + const actualCalls = []; + function MyArray(...args) { + actualCalls.push("construct MyArray"); + return new Proxy(Object.create(null), { + set(target, key, value) { + actualCalls.push(`set ${formatPropertyName(key, "A")}`); + return Reflect.set(target, key, value); + }, + defineProperty(target, key, descriptor) { + actualCalls.push(`defineProperty ${formatPropertyName(key, "A")}`); + return Reflect.defineProperty(target, key, descriptor); + } + }); + } + let result = await SendableArray.fromAsync.call(MyArray, [1, 2]); + assert.compareArray(expectedCalls, actualCalls, "order of operations for array argument"); + actualCalls.splice(0); // reset + const expectedCallsForArrayLike = [ + "construct MyArray", + "defineProperty A[0]", + "defineProperty A[1]", + "set A.length" + ]; + result = await SendableArray.fromAsync.call(MyArray, { + length: 2, + 0: 1, + 1: 2 + }); + assert.compareArray(expectedCallsForArrayLike, actualCalls, "order of operations for array-like argument"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/this-constructor-with-bad-length-setter.js b/test/sendable/builtins/Array/fromAsync/this-constructor-with-bad-length-setter.js new file mode 100644 index 0000000000000000000000000000000000000000..a1dcbc444394ad8ec72095ccc28aef2b2e733edd --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/this-constructor-with-bad-length-setter.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Rejects the promise if setting the length fails on an instance of a custom + this-value +info: | + 3.j.ii.4.a. Perform ? Set(_A_, *"length"*, 𝔽(_k_), *true*). + 3.k.viii. Perform ? Set(_A_, *"length"*, 𝔽(_len_), *true*) +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + class MyArray { + set length(v) { + throw new Test262Error("setter of length property throws") + } + } + await assert.throwsAsync(Test262Error, () => SendableArray.fromAsync.call(MyArray, [0, 1, 2]), "Promise rejected if setting length fails"); + await assert.throwsAsync(Test262Error, () => SendableArray.fromAsync.call(MyArray, { + length: 3, + 0: 0, + 1: 1, + 2: 2 + }), "Promise rejected if setting length from array-like fails"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/this-constructor-with-readonly-elements.js b/test/sendable/builtins/Array/fromAsync/this-constructor-with-readonly-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..2b67d71840a96557bda9bb0397a2e7f1c53d3675 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/this-constructor-with-readonly-elements.js @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Overwrites non-writable element properties on an instance of a custom + this-value +info: | + 3.j.ii.8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). + ... + 3.k.vii.6. Perform ? CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + function MyArray() { + this.length = 4; + for (let ix = 0; ix < this.length; ix++) { + Object.defineProperty(this, ix, { + enumerable: true, + writable: false, + configurable: true, + value: 99 + }); + } + } + let result = await SendableArray.fromAsync.call(MyArray, [0, 1, 2]); + assert.sameValue(result.length, 3, "Length property is overwritten"); + assert.sameValue(result[0], 0, "Read-only element 0 is overwritten"); + assert.sameValue(result[1], 1, "Read-only element 1 is overwritten"); + assert.sameValue(result[2], 2, "Read-only element 2 is overwritten"); + assert.sameValue(result[3], 99, "Element 3 is not overwritten"); + result = await SendableArray.fromAsync.call(MyArray, { + length: 3, + 0: 0, + 1: 1, + 2: 2, + 3: 3 // ignored + }); + assert.sameValue(result.length, 3, "Length property is overwritten"); + assert.sameValue(result[0], 0, "Read-only element 0 is overwritten"); + assert.sameValue(result[1], 1, "Read-only element 1 is overwritten"); + assert.sameValue(result[2], 2, "Read-only element 2 is overwritten"); + assert.sameValue(result[3], 99, "Element 3 is not overwritten"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/this-constructor-with-readonly-length.js b/test/sendable/builtins/Array/fromAsync/this-constructor-with-readonly-length.js new file mode 100644 index 0000000000000000000000000000000000000000..f291d8d49aa417c61ba1f30fca09d20eacd44d5e --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/this-constructor-with-readonly-length.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Promise is rejected if length property on an instance of a custom this-value + is non-writable +info: | + 3.j.ii.4.a. Perform ? Set(_A_, *"length"*, 𝔽(_k_), *true*). + 3.k.viii. Perform ? Set(_A_, *"length"*, 𝔽(_len_), *true*). + Note that there is no difference between strict mode and sloppy mode, because + we are not following runtime evaluation semantics. +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + function MyArray() { + Object.defineProperty(this, "length", { + enumerable: true, + writable: false, + configurable: true, + value: 99 + }); + } + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync.call(MyArray, [0, 1, 2]), "Setting read-only length fails"); + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync.call(MyArray, { + length: 3, + 0: 0, + 1: 1, + 2: 2 + }), "Setting read-only length fails in array-like case"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/this-constructor-with-unsettable-element-closes-async-iterator.js b/test/sendable/builtins/Array/fromAsync/this-constructor-with-unsettable-element-closes-async-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..91842c7e54ea6c82b463a64635efa679525e3c08 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/this-constructor-with-unsettable-element-closes-async-iterator.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-SendableArray.fromasync +description: > + Closes an async iterator if setting an element fails on an instance of a + custom this-value +info: | + 3.j.ii.8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). + 9. If _defineStatus_ is an abrupt completion, return ? AsyncIteratorClose(_iteratorRecord_, _defineStatus_). +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + function MyArray() { + Object.defineProperty(this, 0, { + enumerable: true, + writable: true, + configurable: false, + value: 0 + }); + } + let closed = false; + const iterator = { + next() { + return Promise.resolve({ value: 1, done: false }); + }, + return() { + closed = true; + return Promise.resolve({ done: true }); + }, + [Symbol.asyncIterator]() { + return this; + } + } + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync.call(MyArray, iterator), "Promise rejected if defining element fails"); + assert(closed, "element define failure should close iterator"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/this-constructor-with-unsettable-element-closes-sync-iterator.js b/test/sendable/builtins/Array/fromAsync/this-constructor-with-unsettable-element-closes-sync-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..dab88d9eb38c8617ed468f19ce7a5095ba86b566 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/this-constructor-with-unsettable-element-closes-sync-iterator.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Closes a sync iterator if setting an element fails on an instance of a custom + this-value +info: | + 3.j.ii.8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). + 9. If _defineStatus_ is an abrupt completion, return ? AsyncIteratorClose(_iteratorRecord_, _defineStatus_). +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + function MyArray() { + Object.defineProperty(this, 0, { + enumerable: true, + writable: true, + configurable: false, + value: 0 + }); + } + let closed = false; + const iterator = { + next() { + return { value: 1, done: false }; + }, + return() { + closed = true; + return { done: true }; + }, + [Symbol.iterator]() { + return this; + } + } + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync.call(MyArray, iterator), "Promise rejected if defining element fails"); + assert(closed, "element define failure should close iterator"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/this-constructor-with-unsettable-element.js b/test/sendable/builtins/Array/fromAsync/this-constructor-with-unsettable-element.js new file mode 100644 index 0000000000000000000000000000000000000000..96927ab3d7cdc3c6e7d2a01c1a4a2a2b1c47a24e --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/this-constructor-with-unsettable-element.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Rejects the promise if setting an element fails on an instance of a custom + this-value +info: | + 3.j.ii.8. Let _defineStatus_ be CreateDataPropertyOrThrow(_A_, _Pk_, _mappedValue_). + 9. If _defineStatus_ is an abrupt completion, return ? AsyncIteratorClose(_iteratorRecord_, _defineStatus_). +includes: [asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + function MyArray() { + Object.defineProperty(this, 0, { + enumerable: true, + writable: true, + configurable: false, + value: 0 + }); + } + await assert.throwsAsync(TypeError, () => SendableArray.fromAsync.call(MyArray, [0, 1, 2]), "Promise rejected if defining element fails"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/this-constructor.js b/test/sendable/builtins/Array/fromAsync/this-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..135eb46680d6ff661d895ac012500218309320c5 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/this-constructor.js @@ -0,0 +1,57 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Constructs the this-value once if asyncItems is iterable, twice if not, and + length and element properties are set correctly on the result +info: | + 3.e. If IsConstructor(_C_) is *true*, then + i. Let _A_ be ? Construct(_C_). + j. If _iteratorRecord_ is not *undefined*, then + k. Else, + iv. If IsConstructor(_C_) is *true*, then + 1. Let _A_ be ? Construct(_C_, « 𝔽(_len_) »). +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const constructorCalls = []; + function MyArray(...args) { + constructorCalls.push(args); + } + let result = await SendableArray.fromAsync.call(MyArray, [1, 2]); + assert(result instanceof MyArray, "result is an instance of the constructor this-value"); + assert.sameValue(result.length, 2, "length is set on result"); + assert.sameValue(result[0], 1, "element 0 is set on result"); + assert.sameValue(result[1], 2, "element 1 is set on result"); + assert.sameValue(constructorCalls.length, 1, "constructor is called once"); + assert.compareArray(constructorCalls[0], [], "constructor is called with no arguments"); + constructorCalls.splice(0); // reset + result = await SendableArray.fromAsync.call(MyArray, { + length: 2, + 0: 1, + 1: 2 + }); + assert(result instanceof MyArray, "result is an instance of the constructor this-value"); + assert.sameValue(result.length, 2, "length is set on result"); + assert.sameValue(result[0], 1, "element 0 is set on result"); + assert.sameValue(result[1], 2, "element 1 is set on result"); + assert.sameValue(constructorCalls.length, 1, "constructor is called once"); + assert.compareArray(constructorCalls[0], [2], "constructor is called with a length argument"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/this-non-constructor.js b/test/sendable/builtins/Array/fromAsync/this-non-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..896250266635125fbbb07d036c2d1f353c0af19c --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/this-non-constructor.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + Constructs an intrinsic Array if this-value is not a constructor, and length + and element properties are set accordingly. +info: | + 3.e. If IsConstructor(_C_) is *true*, then + f. Else, + i. Let _A_ be ! ArrayCreate(0). + j. If _iteratorRecord_ is not *undefined*, then + k. Else, + iv. If IsConstructor(_C_) is *true*, then + v. Else, + 1. Let _A_ be ? ArrayCreate(_len_). +includes: [compareArray.js, asyncHelpers.js] +flags: [async] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async function () { + const thisValue = { + length: 4000, + 0: 32, + 1: 64, + 2: 128 + }; + let result = await SendableArray.fromAsync.call(thisValue, [1, 2]); + assert(Array.isArray(result), "result is an intrinsic Array"); + assert.compareArray(result, [1, 2], "result is not disrupted by properties of this-value"); + result = await SendableArray.fromAsync.call(thisValue, { + length: 2, + 0: 1, + 1: 2 + }); + assert(SendableArray.isArray(result), "result is an intrinsic SendableArray"); + assert.compareArray(result, [1, 2], "result is not disrupted by properties of this-value"); +}); diff --git a/test/sendable/builtins/Array/fromAsync/thisarg-object.js b/test/sendable/builtins/Array/fromAsync/thisarg-object.js new file mode 100644 index 0000000000000000000000000000000000000000..c0678ac843d335cd2cb2da71403706789cb8e2a8 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/thisarg-object.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: If thisArg is an object, it's bound to mapfn as the this-value +info: | + 6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). +flags: [async] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async () => { + const myThisValue = {}; + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue(this, myThisValue, "thisArg should be bound as the this-value of mapfn"); + }, myThisValue); +}); diff --git a/test/sendable/builtins/Array/fromAsync/thisarg-omitted-sloppy.js b/test/sendable/builtins/Array/fromAsync/thisarg-omitted-sloppy.js new file mode 100644 index 0000000000000000000000000000000000000000..f33dfd1d1d8fce622166982b5e5a6da48bad4094 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/thisarg-omitted-sloppy.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + If thisArg is omitted, mapfn is called with the global object as the + this-value in sloppy mode +info: | + 6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + + OrdinaryCallBindThis, when _F_.[[ThisMode]] is ~global~, where _F_ is the + function object: + 6. Else, + a. If _thisArgument_ is *undefined* or *null*, then + i. Let _globalEnv_ be _calleeRealm_.[[GlobalEnv]]. + ii. Assert: _globalEnv_ is a Global Environment Record. + iii. Let _thisValue_ be _globalEnv_.[[GlobalThisValue]]. +flags: [async, noStrict] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async () => { + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue( + this, + globalThis, + "the global should be bound as the this-value of mapfn when thisArg is omitted" + ); + }); +}); diff --git a/test/sendable/builtins/Array/fromAsync/thisarg-omitted-strict.js b/test/sendable/builtins/Array/fromAsync/thisarg-omitted-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..a81e092ba0f7073883ea6daf9def7e21ce2577c4 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/thisarg-omitted-strict.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + If thisArg is omitted, mapfn is called with undefined as the this-value in + strict mode +info: | + 6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + + In OrdinaryCallBindThis, _thisArgument_ is always bound as the this-value in + strict mode (_F_.[[ThisMode]] is ~strict~, where _F_ is the function object.) +flags: [async, onlyStrict] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async () => { + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue( + this, + undefined, + "undefined should be bound as the this-value of mapfn when thisArg is omitted" + ); + }); +}); diff --git a/test/sendable/builtins/Array/fromAsync/thisarg-primitive-sloppy.js b/test/sendable/builtins/Array/fromAsync/thisarg-primitive-sloppy.js new file mode 100644 index 0000000000000000000000000000000000000000..caf3ef270c21e2a59ce420ba81cebc112f785b6e --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/thisarg-primitive-sloppy.js @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + If thisArg is a primitive, mapfn is called with a wrapper this-value or the + global, according to the usual rules of sloppy mode +info: | + 6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + OrdinaryCallBindThis, when _F_.[[ThisMode]] is ~global~, where _F_ is the + function object: + 6. Else, + a. If _thisArgument_ is *undefined* or *null*, then + i. Let _globalEnv_ be _calleeRealm_.[[GlobalEnv]]. + ii. Assert: _globalEnv_ is a Global Environment Record. + iii. Let _thisValue_ be _globalEnv_.[[GlobalThisValue]]. + b. Else, + i. Let _thisValue_ be ! ToObject(_thisArgument_). + ii. NOTE: ToObject produces wrapper objects using _calleeRealm_. +flags: [async, noStrict] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async () => { + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue( + this, + globalThis, + "the global should be bound as the this-value of mapfn when thisArg is undefined" + ); + }, undefined); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue( + this, + globalThis, + "the global should be bound as the this-value of mapfn when thisArg is null" + ); + }, null); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.notSameValue(this, "string", "string thisArg should not be bound as the this-value of mapfn"); + assert.sameValue(typeof this, "object", "a String wrapper object should be bound as the this-value of mapfn when thisArg is a string") + assert.sameValue(this.valueOf(), "string", "String wrapper object should have the same primitive value as thisArg"); + }, "string"); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.notSameValue(this, 3.1416, "number thisArg should be not bound as the this-value of mapfn"); + assert.sameValue(typeof this, "object", "a Number wrapper object should be bound as the this-value of mapfn when thisArg is a number") + assert.sameValue(this.valueOf(), 3.1416, "Number wrapper object should have the same primitive value as thisArg"); + }, 3.1416); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.notSameValue(this, 42n, "bigint thisArg should not be bound as the this-value of mapfn"); + assert.sameValue(typeof this, "object", "a BigInt wrapper object should be bound as the this-value of mapfn when thisArg is a bigint") + assert.sameValue(this.valueOf(), 42n, "BigInt wrapper object should have the same primitive value as thisArg"); + }, 42n); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.notSameValue(this, true, "boolean thisArg should not be bound as the this-value of mapfn"); + assert.sameValue(typeof this, "object", "a Boolean wrapper object should be bound as the this-value of mapfn when thisArg is a boolean") + assert.sameValue(this.valueOf(), true, "Boolean wrapper object should have the same primitive value as thisArg"); + }, true); + const symbolThis = Symbol("symbol"); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.notSameValue(this, symbolThis, "symbol thisArg should not be bound as the this-value of mapfn"); + assert.sameValue(typeof this, "object", "a Symbol wrapper object should be bound as the this-value of mapfn when thisArg is a symbol") + assert.sameValue(this.valueOf(), symbolThis, "Symbol wrapper object should have the same primitive value as thisArg"); + }, symbolThis); +}); diff --git a/test/sendable/builtins/Array/fromAsync/thisarg-primitive-strict.js b/test/sendable/builtins/Array/fromAsync/thisarg-primitive-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..d82c697c399bd5cd179f899e48d0130d06120060 --- /dev/null +++ b/test/sendable/builtins/Array/fromAsync/thisarg-primitive-strict.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.fromasync +description: > + If thisArg is a primitive, mapfn is called with it as the this-value in strict + mode +info: | + 6. If _mapping_ is *true*, then + a. Let _mappedValue_ be Call(_mapfn_, _thisArg_, « _nextValue_, 𝔽(_k_) »). + + In OrdinaryCallBindThis, _thisArgument_ is always bound as the this-value in + strict mode (_F_.[[ThisMode]] is ~strict~, where _F_ is the function object.) +flags: [async, onlyStrict] +includes: [asyncHelpers.js] +features: [SendableArray.fromAsync] +---*/ + +asyncTest(async () => { + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue(this, undefined, "undefined thisArg should be bound as the this-value of mapfn"); + }, undefined); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue(this, null, "null thisArg should be bound as the this-value of mapfn"); + }, null); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue(this, "string", "string thisArg should be bound as the this-value of mapfn"); + }, "string"); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue(this, 3.1416, "number thisArg should be bound as the this-value of mapfn"); + }, 3.1416); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue(this, 42n, "bigint thisArg should be bound as the this-value of mapfn"); + }, 42n); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue(this, true, "boolean thisArg should be bound as the this-value of mapfn"); + }, true); + const symbolThis = Symbol("symbol"); + await SendableArray.fromAsync([1, 2, 3], async function () { + assert.sameValue(this, symbolThis, "symbol thisArg should be bound as the this-value of mapfn"); + }, symbolThis); +}); diff --git a/test/sendable/builtins/Array/is-a-constructor.js b/test/sendable/builtins/Array/is-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..bc7083db37bc4f8fadf68717a58768337eb73cc5 --- /dev/null +++ b/test/sendable/builtins/Array/is-a-constructor.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array implements [[Construct]] +info: | + IsConstructor ( argument ) + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct] +---*/ + +assert.sameValue(isConstructor(SendableArray), true, 'isConstructor(SendableArray) must return true'); +new SendableArray(); + diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-0-1.js b/test/sendable/builtins/Array/isArray/15.4.3.2-0-1.js new file mode 100644 index 0000000000000000000000000000000000000000..423ffb7f31a218a8cf281784624bd336e6970c31 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-0-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-0-1 +description: SendableArray.isArray must exist as a function +---*/ + +var f = SendableArray.isArray; +assert.sameValue(typeof f, "function", 'The value of `typeof f` is expected to be "function"'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-0-2.js b/test/sendable/builtins/Array/isArray/15.4.3.2-0-2.js new file mode 100644 index 0000000000000000000000000000000000000000..723373455c1190c8c0e4d9475f94929739e4331b --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-0-2.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-0-2 +description: SendableArray.isArray must exist as a function taking 1 parameter +---*/ + +assert.sameValue(SendableArray.isArray.length, 1, 'The value of Array.isArray.length is expected to be 1'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-0-3.js b/test/sendable/builtins/Array/isArray/15.4.3.2-0-3.js new file mode 100644 index 0000000000000000000000000000000000000000..d0ec834464e60ad70c5ad151c3afb2c8e4b33cba --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-0-3.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-0-3 +description: SendableArray.isArray return true if its argument is an Array +---*/ + +assert.sameValue(SendableArray.isArray(), true, 'SendableArray.isArray([]) must return true'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-0-4.js b/test/sendable/builtins/Array/isArray/15.4.3.2-0-4.js new file mode 100644 index 0000000000000000000000000000000000000000..a2d07d23bb6ecdac9628a3866fc3656b2fbd8eef --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-0-4.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +description: SendableArray.isArray return false if its argument is not an Array +---*/ + +assert.sameValue(SendableArray.isArray(42), false, 'SendableArray.isArray(42) must return false'); +assert.sameValue(SendableArray.isArray(undefined), false, 'SendableArray.isArray(undefined) must return false'); +assert.sameValue(SendableArray.isArray(true), false, 'SendableArray.isArray(true) must return false'); +assert.sameValue(SendableArray.isArray("abc"), false, 'SendableArray.isArray("abc") must return false'); +assert.sameValue(SendableArray.isArray({}), false, 'SendableArray.isArray({}) must return false'); +assert.sameValue(SendableArray.isArray(null), false, 'SendableArray.isArray(null) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-0-5.js b/test/sendable/builtins/Array/isArray/15.4.3.2-0-5.js new file mode 100644 index 0000000000000000000000000000000000000000..f9701b15251c04a47f0bdf322bedf1867888cdff --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-0-5.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-0-5 +description: > + SendableArray.isArray return true if its argument is an Array + (Array.prototype) +---*/ + +assert.sameValue(SendableArray.isArray(SendableArray.prototype), true, 'SendableArray.isArray(SendableArray.prototype) must return true'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-0-6.js b/test/sendable/builtins/Array/isArray/15.4.3.2-0-6.js new file mode 100644 index 0000000000000000000000000000000000000000..78758e644bfb84d59de7b9766c4e48ab37f4f2b2 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-0-6.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-0-6 +description: SendableArray.isArray return true if its argument is an Array (new SendableArray()) +---*/ + +assert.sameValue(SendableArray.isArray(new SendableArray(10)), true, 'SendableArray.isArray(new SendableArray(10)) must return true'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-0-7.js b/test/sendable/builtins/Array/isArray/15.4.3.2-0-7.js new file mode 100644 index 0000000000000000000000000000000000000000..0f3b915ebbddad997650a3ea392c07ebcb522936 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-0-7.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-0-7 +description: SendableArray.isArray returns false if its argument is not an Array +---*/ + +assert.sameValue(SendableArray.isArray({}), false, 'SendableArray.isArray({}) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-1.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..4bcc527c1657021cbc6a598b2881ab2fbb2da792 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-1.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-1 +description: SendableArray.isArray applied to boolean primitive +---*/ + +assert.sameValue(SendableArray.isArray(true), false, 'SendableArray.isArray(true) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-10.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..b4f35753de975453a4ebb8ded814cb6e093a5091 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-10.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-10 +description: SendableArray.isArray applied to RegExp object +---*/ + +assert.sameValue(SendableArray.isArray(new RegExp()), false, 'SendableArray.isArray(new RegExp()) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-11.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..baa31343e80579885cee55c2a29de59a165e3550 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-11.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-11 +description: SendableArray.isArray applied to the JSON object +---*/ + +assert.sameValue(SendableArray.isArray(JSON), false, 'SendableArray.isArray(JSON) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-12.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..1e1ed4ae4f2e088e0c30620202152c1dd4aa0189 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-12.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-12 +description: SendableArray.isArray applied to Error object +---*/ + +assert.sameValue(SendableArray.isArray(new SyntaxError()), false, 'SendableArray.isArray(new SyntaxError()) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-13.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..ee3c1069e050dba70af5370eb4565e0be6aaa34e --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-13.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-13 +description: SendableArray.isArray applied to Arguments object +---*/ + +var arg; +(function fun() { + arg = arguments; +}(1, 2, 3)); +assert.sameValue(SendableArray.isArray(arg), false, 'SendableArray.isArray(arguments) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-15.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..a23773600298e891a2b2d0081e5abb7de0d032b1 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-15.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-15 +description: SendableArray.isArray applied to the global object +---*/ + +assert.sameValue(SendableArray.isArray(this), false, 'SendableArray.isArray(this) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-2.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..8d0d4a92ba962292e99673374e74bd557f8616a4 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-2.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-2 +description: SendableArray.isArray applied to Boolean Object +---*/ + +assert.sameValue(SendableArray.isArray(new Boolean(false)), false, 'Array.isArray(new Boolean(false)) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-3.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..1be6db1dbdd0222677304cc53a459ef60132c423 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-3.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-3 +description: SendableArray.isArray applied to number primitive +---*/ + +assert.sameValue(SendableArray.isArray(5), false, 'SendableArray.isArray(5) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-4.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..b04cf2f1b65ebee3c3055433ffd7e952cb9464cd --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-4.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-4 +description: SendableArray.isArray applied to Number object +---*/ + +assert.sameValue(SendableArray.isArray(new Number(-3)), false, 'Array.isArray(new Number(-3)) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-5.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..72d21029dec8667c710aae6323932e9ee22c2c14 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-5.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-5 +description: SendableArray.isArray applied to string primitive +---*/ + +assert.sameValue(SendableArray.isArray("abc"), false, 'SendableArray.isArray("abc") must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-6.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..abc16297031a5c0466e1f87778084a48159d9619 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-6.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-6 +description: SendableArray.isArray applied to String object +---*/ + +assert.sameValue(SendableArray.isArray(new String("hello\nworld\\!")), false, 'SendableArray.isArray(new String("hello\\nworld\\\\!")) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-7.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..2dfc57e652a0d1746cdeef569c37917a8bfa4f4c --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-7.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-7 +description: SendableArray.isArray applied to Function object +---*/ + +assert.sameValue(SendableArray.isArray(function() {}), false, 'SendableArray.isArray(function() {}) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-8.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..5d37a2eb1ce3edd0e78a5f120c891bc7e9658e31 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-8.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-8 +description: SendableArray.isArray applied to the Math object +---*/ + +assert.sameValue(SendableArray.isArray(Math), false, 'SendableArray.isArray(Math) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-1-9.js b/test/sendable/builtins/Array/isArray/15.4.3.2-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..75ccfaa840c79d9f47243a2d9ceaca8734d929d8 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-1-9.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-1-9 +description: SendableArray.isArray applied to Date object +---*/ + +assert.sameValue(SendableArray.isArray(new Date(0)), false, 'SendableArray.isArray(new Date(0)) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-2-1.js b/test/sendable/builtins/Array/isArray/15.4.3.2-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..01d83bc00ca1e83e05959fb254b2575025f49ac9 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-2-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-2-1 +description: SendableArray.isArray applied to an object with an array as the prototype +---*/ + +var proto = []; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +assert.sameValue(SendableArray.isArray(child), false, 'SendableArray.isArray(new Con()) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-2-2.js b/test/sendable/builtins/Array/isArray/15.4.3.2-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..b4acfb32b61161255412455bd65a68002cbd39c5 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-2-2.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-2-2 +description: > + SendableArray.isArray applied to an object with Array.prototype as the + prototype +---*/ + +var proto = Array.prototype; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +assert.sameValue(SendableArray.isArray(child), false, 'SendableArray.isArray(new Con()) must return false'); diff --git a/test/sendable/builtins/Array/isArray/15.4.3.2-2-3.js b/test/sendable/builtins/Array/isArray/15.4.3.2-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..81824f6db7b3949c8e28a2339706f8daf4bac553 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/15.4.3.2-2-3.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es5id: 15.4.3.2-2-3 +description: > + SendableArray.isArray applied to an Array-like object with length and some + indexed properties +---*/ + +assert.sameValue(SendableArray.isArray({ + 0: 12, + 1: 9, + length: 2 +}), false, 'SendableArray.isArray({0: 12, 1: 9, length: 2}) must return false'); diff --git a/test/sendable/builtins/Array/isArray/descriptor.js b/test/sendable/builtins/Array/isArray/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..d42d8fa199867965b91a7e741c3972d7bcc6fcf7 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/descriptor.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Testing descriptor property of Array.isArray +includes: [propertyHelper.js] +esid: sec-array.isarray +---*/ + +verifyProperty(SendableArray, "isArray", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/isArray/name.js b/test/sendable/builtins/Array/isArray/name.js new file mode 100644 index 0000000000000000000000000000000000000000..795c4aa8ab6a88494bf2192c718f90ca7f781429 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/name.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es6id: 22.1.2.2 +description: > + SendableArray.isArray.name is "isArray". +info: | + SendableArray.isArray ( arg ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.isArray, "name", { + value: "isArray", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/isArray/not-a-constructor.js b/test/sendable/builtins/Array/isArray/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..a591a7e0e65c5cd780f240911898337ab5c29abc --- /dev/null +++ b/test/sendable/builtins/Array/isArray/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableArray.isArray does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.isArray), false, 'isConstructor(SendableArray.isArray) must return false'); +assert.throws(TypeError, () => { + new SendableArray.isArray([]); +}, 'new SendableArray.isArray([]) throws a TypeError exception'); + diff --git a/test/sendable/builtins/Array/isArray/proxy-revoked.js b/test/sendable/builtins/Array/isArray/proxy-revoked.js new file mode 100644 index 0000000000000000000000000000000000000000..175c8231baf37cbfe61b9f6291e7fd0409bbd208 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/proxy-revoked.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es6id: 22.1.2.2 +description: Revoked proxy value produces a TypeError +info: | + 1. Return IsArray(arg). + 7.2.2 IsArray + 3. If argument is a Proxy exotic object, then + a. If the value of the [[ProxyHandler]] internal slot of argument is null, + throw a TypeError exception. + b. Let target be the value of the [[ProxyTarget]] internal slot of + argument. + c. Return IsArray(target). +features: [Proxy] +---*/ + +var handle = Proxy.revocable([], {}); +handle.revoke(); +assert.throws(TypeError, function() { + SendableArray.isArray(handle.proxy); +}, 'SendableArray.isArray(handle.proxy) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/isArray/proxy.js b/test/sendable/builtins/Array/isArray/proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..df25bee7fbaca11e099f55564f0e7c636e401fb6 --- /dev/null +++ b/test/sendable/builtins/Array/isArray/proxy.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.isarray +es6id: 22.1.2.2 +description: Proxy of an array is treated as an array +info: | + 1. Return IsArray(arg). + 7.2.2 IsArray + 3. If argument is a Proxy exotic object, then + a. If the value of the [[ProxyHandler]] internal slot of argument is null, + throw a TypeError exception. + b. Let target be the value of the [[ProxyTarget]] internal slot of + argument. + c. Return IsArray(target). +features: [Proxy] +---*/ + +var objectProxy = new Proxy({}, {}); +var arrayProxy = new Proxy([], {}); +var arrayProxyProxy = new Proxy(arrayProxy, {}); +assert.sameValue(SendableArray.isArray(objectProxy), false, 'SendableArray.isArray(new Proxy({}, {})) must return false'); +assert.sameValue(SendableArray.isArray(arrayProxy), true, 'SendableArray.isArray(new Proxy([], {})) must return true'); +assert.sameValue(SendableArray.isArray(arrayProxyProxy), true, 'SendableArray.isArray(new Proxy(arrayProxy, {})) must return true'); diff --git a/test/sendable/builtins/Array/length.js b/test/sendable/builtins/Array/length.js new file mode 100644 index 0000000000000000000000000000000000000000..2d8886eba4bcbc86f71174c857a89433a7cfcc8f --- /dev/null +++ b/test/sendable/builtins/Array/length.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-constructor +description: > + Array has a "length" property whose value is 1. +info: | + 22.1.1 The Array Constructor + The length property of the Array constructor function is 1. + ES7 section 17: Unless otherwise specified, the length property of a built-in + Function object has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/length/15.4.5.1-3.d-1.js b/test/sendable/builtins/Array/length/15.4.5.1-3.d-1.js new file mode 100644 index 0000000000000000000000000000000000000000..39e6fd53bf80b0e130328ac0bf7a8547621f4777 --- /dev/null +++ b/test/sendable/builtins/Array/length/15.4.5.1-3.d-1.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-properties-of-array-instances-length +es5id: 15.4.5.1-3.d-1 +description: > + Throw RangeError if attempt to set array length property to + 4294967296 (2**32) +---*/ + + +assert.throws(RangeError, function() { + [].length = 4294967296; +}, '[].length = 4294967296 throws a RangeError exception'); diff --git a/test/sendable/builtins/Array/length/15.4.5.1-3.d-2.js b/test/sendable/builtins/Array/length/15.4.5.1-3.d-2.js new file mode 100644 index 0000000000000000000000000000000000000000..543b3dcca1fba22e65923648b2364381c5c3b075 --- /dev/null +++ b/test/sendable/builtins/Array/length/15.4.5.1-3.d-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-properties-of-array-instances-length +es5id: 15.4.5.1-3.d-2 +description: > + Throw RangeError if attempt to set array length property to + 4294967297 (1+2**32) +---*/ + +assert.throws(RangeError, function() { + [].length = 4294967297; +}, '[].length = 4294967297 throws a RangeError exception'); diff --git a/test/sendable/builtins/Array/length/15.4.5.1-3.d-3.js b/test/sendable/builtins/Array/length/15.4.5.1-3.d-3.js new file mode 100644 index 0000000000000000000000000000000000000000..da8786615edff344679f0f5652c3656e53c89d10 --- /dev/null +++ b/test/sendable/builtins/Array/length/15.4.5.1-3.d-3.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-properties-of-array-instances-length +es5id: 15.4.5.1-3.d-3 +description: Set array length property to max value 4294967295 (2**32-1,) +---*/ + +var a = []; +a.length = 4294967295; +assert.sameValue(a.length, 4294967295, 'The value of a.length is expected to be 4294967295'); diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A1.1_T1.js b/test/sendable/builtins/Array/length/S15.4.2.2_A1.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..e58a6b324e1f2c64eba46640f0d32bc630b25ec5 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A1.1_T1.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-len +info: | + The [[Prototype]] property of the newly constructed object + is set to the original Array prototype object, the one that + is the initial value of Array.prototype +es5id: 15.4.2.2_A1.1_T1 +description: > + Create new property of Array.prototype. When new Array object has + this property +---*/ + +SendableArray.prototype.myproperty = 1; +var x = new SendableArray(0); +assert.sameValue(x.myproperty, 1, 'The value of x.myproperty is expected to be 1'); diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A1.1_T2.js b/test/sendable/builtins/Array/length/S15.4.2.2_A1.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..9490f2ebf488f01444c7b0dd159e26228aaf3709 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A1.1_T2.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-len +info: | + The [[Prototype]] property of the newly constructed object + is set to the original Array prototype object, the one that + is the initial value of Array.prototype +es5id: 15.4.2.2_A1.1_T2 +description: Array.prototype.toString = Object.prototype.toString +---*/ + +SendableArray.prototype.toString = Object.prototype.toString; +var x = new SendableArray(0); +assert.sameValue(x.toString(), "[object SendableArray]", 'x.toString() must return "[object SendableArray]"'); diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A1.1_T3.js b/test/sendable/builtins/Array/length/S15.4.2.2_A1.1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..892913a7582261cf80770d0c0ac6f1d82828a0b3 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A1.1_T3.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-len +info: | + The [[Prototype]] property of the newly constructed object + is set to the original Array prototype object, the one that + is the initial value of Array.prototype +es5id: 15.4.2.2_A1.1_T3 +description: Checking use isPrototypeOf +---*/ + +assert.sameValue( + SendableArray.prototype.isPrototypeOf(new SendableArray(0)), + true, + 'SendableArray.prototype.isPrototypeOf(new SendableArray(0)) must return true' +); diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A1.2_T1.js b/test/sendable/builtins/Array/length/S15.4.2.2_A1.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..6ec4e62b159cba4bf4738a66ca2e28cac1cc5d9d --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A1.2_T1.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array-len +info: The [[Class]] property of the newly constructed object is set to "Array" +es5id: 15.4.2.2_A1.2_T1 +description: Checking use Object.prototype.toString +---*/ + +var x = new SendableArray(0); +assert.sameValue(Object.prototype.toString.call(x), "[object Array]", 'Object.prototype.toString.call(new SendableArray(0)) must return "[object SendableArray]"'); diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A2.1_T1.js b/test/sendable/builtins/Array/length/S15.4.2.2_A2.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..fd3a37605e07302b1fa7eed02e530bdcf1514940 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A2.1_T1.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray-len +info: | + If the argument len is a Number and ToUint32(len) is equal to len, + then the length property of the newly constructed object is set to ToUint32(len) +es5id: 15.4.2.2_A2.1_T1 +description: SendableArray constructor is given one argument +---*/ + +var x = new SendableArray(0); +assert.sameValue(x.length, 0, 'The value of x.length is expected to be 0'); +var x = new SendableArray(1); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +var x = new SendableArray(4294967295); +assert.sameValue(x.length, 4294967295, 'The value of x.length is expected to be 4294967295'); diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A2.2_T1.js b/test/sendable/builtins/Array/length/S15.4.2.2_A2.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..1d51ee0f9bd5109366ea20b02fbcaddf2259f405 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A2.2_T1.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray-len +info: | + If the argument len is a Number and ToUint32(len) is not equal to len, + a RangeError exception is thrown +es5id: 15.4.2.2_A2.2_T1 +description: Use try statement. len = -1, 4294967296, 4294967297 +---*/ + +try { + new SendableArray(-1); + throw new Test262Error('#1.1: new SendableArray(-1) throw RangeError. Actual: ' + (new SendableArray(-1))); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +try { + new SendableArray(4294967296); + throw new Test262Error('#2.1: new Array(4294967296) throw RangeError. Actual: ' + (new SendableArray(4294967296))); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +try { + new SendableArray(4294967297); + throw new Test262Error('#3.1: new Array(4294967297) throw RangeError. Actual: ' + (new SendableArray(4294967297))); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A2.2_T2.js b/test/sendable/builtins/Array/length/S15.4.2.2_A2.2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..823aad71c7bdacdec4f24a6b660901ee9a6cc62e --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A2.2_T2.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray-len +info: | + If the argument len is a Number and ToUint32(len) is not equal to len, + a RangeError exception is thrown +es5id: 15.4.2.2_A2.2_T2 +description: Use try statement. len = NaN, +/-Infinity +---*/ + +try { + new SendableArray(NaN); + throw new Test262Error('#1.1: new SendableArray(NaN) throw RangeError. Actual: ' + (new SendableArray(NaN))); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +try { + new SendableArray(Number.POSITIVE_INFINITY); + throw new Test262Error('#2.1: new Array(Number.POSITIVE_INFINITY) throw RangeError. Actual: ' + (new SendableArray(Number.POSITIVE_INFINITY))); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +try { + new SendableArray(Number.NEGATIVE_INFINITY); + throw new Test262Error('#3.1: new Array(Number.NEGATIVE_INFINITY) throw RangeError. Actual: ' + (new SendableArray(Number.NEGATIVE_INFINITY))); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A2.2_T3.js b/test/sendable/builtins/Array/length/S15.4.2.2_A2.2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..0def49c11c95b1f610a0200cad73c3d232595278 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A2.2_T3.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray-len +info: | + If the argument len is a Number and ToUint32(len) is not equal to len, + a RangeError exception is thrown +es5id: 15.4.2.2_A2.2_T3 +description: Use try statement. len = 1.5, Number.MAX_VALUE, Number.MIN_VALUE +---*/ + +try { + new SendableArray(1.5); + throw new Test262Error('#1.1: new SendableArray(1.5) throw RangeError. Actual: ' + (new SendableArray(1.5))); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +try { + new SendableArray(Number.MAX_VALUE); + throw new Test262Error('#2.1: new Array(Number.MAX_VALUE) throw RangeError. Actual: ' + (new SendableArray(Number.MAX_VALUE))); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +try { + new SendableArray(Number.MIN_VALUE); + throw new Test262Error('#3.1: new Array(Number.MIN_VALUE) throw RangeError. Actual: ' + (new SendableArray(Number.MIN_VALUE))); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T1.js b/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..5de009ad57c22ea1887579bf1aba4c85298d8bfe --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray-len +info: | + If the argument len is not a Number, then the length property of + the newly constructed object is set to 1 and the 0 property of + the newly constructed object is set to len +es5id: 15.4.2.2_A2.3_T1 +description: Checking for null and undefined +---*/ + +var x = new SendableArray(null); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], null, 'The value of x[0] is expected to be null'); +var x = new SendableArray(undefined); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], undefined, 'The value of x[0] is expected to equal undefined'); diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T2.js b/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..72b6a66ce9ed46ccdf2a2b78f83bb5416e9892dc --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray-len +info: | + If the argument len is not a Number, then the length property of + the newly constructed object is set to 1 and the 0 property of + the newly constructed object is set to len +es5id: 15.4.2.2_A2.3_T2 +description: Checking for boolean primitive and Boolean object +---*/ + +var x = new SendableArray(true); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], true, 'The value of x[0] is expected to be true'); +var obj = new Boolean(false); +var x = new SendableArray(obj); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], obj, 'The value of x[0] is expected to equal the value of obj'); diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T3.js b/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..2a792641ad7f3df2d759023d0a38070e8d870ba3 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray-len +info: | + If the argument len is not a Number, then the length property of + the newly constructed object is set to 1 and the 0 property of + the newly constructed object is set to len +es5id: 15.4.2.2_A2.3_T3 +description: Checking for boolean primitive and Boolean object +---*/ + +var x = new SendableArray("1"); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], "1", 'The value of x[0] is expected to be "1"'); +var obj = new String("0"); +var x = new SendableArray(obj); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], obj, 'The value of x[0] is expected to equal the value of obj'); diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T4.js b/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..4c09ad53cf8e238e012f538720962cc4cce6423b --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T4.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray-len +info: | + If the argument len is not a Number, then the length property of + the newly constructed object is set to 1 and the 0 property of + the newly constructed object is set to len +es5id: 15.4.2.2_A2.3_T4 +description: Checking for Number object +---*/ + +var obj = new Number(0); +var x = new SendableArray(obj); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], obj, 'The value of x[0] is expected to equal the value of obj'); +var obj = new Number(1); +var x = new SendableArray(obj); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], obj, 'The value of x[0] is expected to equal the value of obj'); +var obj = new Number(4294967295); +var x = new SendableArray(obj); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], obj, 'The value of x[0] is expected to equal the value of obj'); diff --git a/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T5.js b/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..c1c6d3ae549c7cf181fce58d661ec5af9fe088df --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.2.2_A2.3_T5.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray-len +info: | + If the argument len is not a Number, then the length property of + the newly constructed object is set to 1 and the 0 property of + the newly constructed object is set to len +es5id: 15.4.2.2_A2.3_T5 +description: Checking for Number object +---*/ + +var obj = new Number(-1); +var x = new SendableArray(obj); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], obj, 'The value of x[0] is expected to equal the value of obj'); +var obj = new Number(4294967296); +var x = new SendableArray(obj); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], obj, 'The value of x[0] is expected to equal the value of obj'); +var obj = new Number(4294967297); +var x = new SendableArray(obj); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +assert.sameValue(x[0], obj, 'The value of x[0] is expected to equal the value of obj'); diff --git a/test/sendable/builtins/Array/length/S15.4.4_A1.3_T1.js b/test/sendable/builtins/Array/length/S15.4.4_A1.3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..8606adccbe44528cd8231d637f2ac974cbb9c155 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.4_A1.3_T1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-properties-of-the-array-prototype-object +info: SendableArray prototype object has a length property +es5id: 15.4.4_A1.3_T1 +description: SendableArray.prototype.length === 0 +---*/ + +assert.sameValue(SendableArray.prototype.length, 0, 'The value of SendableArray.prototype.length is expected to be 0'); diff --git a/test/sendable/builtins/Array/length/S15.4.5.1_A1.1_T1.js b/test/sendable/builtins/Array/length/S15.4.5.1_A1.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..8f78dccbfa9eedbaa6e4d4b668099a68e640d164 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.5.1_A1.1_T1.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-exotic-objects-defineownproperty-p-desc +info: If ToUint32(length) !== ToNumber(length), throw RangeError +es5id: 15.4.5.1_A1.1_T1 +description: length in [4294967296, -1, 1.5] +---*/ + +try { + var x = []; + x.length = 4294967296; + throw new Test262Error('#1.1: x = []; x.length = 4294967296 throw RangeError. Actual: x.length === ' + (x.length)); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +try { + x = []; + x.length = -1; + throw new Test262Error('#2.1: x = []; x.length = -1 throw RangeError. Actual: x.length === ' + (x.length)); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +try { + x = []; + x.length = 1.5; + throw new Test262Error('#3.1: x = []; x.length = 1.5 throw RangeError. Actual: x.length === ' + (x.length)); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/length/S15.4.5.1_A1.1_T2.js b/test/sendable/builtins/Array/length/S15.4.5.1_A1.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..16ff8c4019237eae7fcb9bde909abe239e2c22be --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.5.1_A1.1_T2.js @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-exotic-objects-defineownproperty-p-desc +info: If ToUint32(length) !== ToNumber(length), throw RangeError +es5id: 15.4.5.1_A1.1_T2 +description: length in [NaN, Infinity, -Infinity, undefined] +---*/ + +try { + var x = []; + x.length = NaN; + throw new Test262Error('#1.1: x = []; x.length = NaN throw RangeError. Actual: x.length === ' + (x.length)); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +try { + x = []; + x.length = Number.POSITIVE_INFINITY; + throw new Test262Error('#2.1: x = []; x.length = Number.POSITIVE_INFINITY throw RangeError. Actual: x.length === ' + (x.length)); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +try { + x = []; + x.length = Number.NEGATIVE_INFINITY; + throw new Test262Error('#3.1: x = []; x.length = Number.NEGATIVE_INFINITY throw RangeError. Actual: x.length === ' + (x.length)); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +try { + x = []; + x.length = undefined; + throw new Test262Error('#4.1: x = []; x.length = undefined throw RangeError. Actual: x.length === ' + (x.length)); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/length/S15.4.5.1_A1.2_T1.js b/test/sendable/builtins/Array/length/S15.4.5.1_A1.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..bb3902950f340e7199cd89dce2b27e65baf879bf --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.5.1_A1.2_T1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-exotic-objects-defineownproperty-p-desc +info: | + For every integer k that is less than the value of + the length property of A but not less than ToUint32(length), + if A itself has a property (not an inherited property) named ToString(k), + then delete that property +es5id: 15.4.5.1_A1.2_T1 +description: Change length of array +---*/ + +var x = [0, , 2, , 4]; +x.length = 4; +assert.sameValue(x[4], undefined, 'The value of x[4] is expected to equal undefined'); +x.length = 3; +assert.sameValue(x[3], undefined, 'The value of x[3] is expected to equal undefined'); +assert.sameValue(x[2], 2, 'The value of x[2] is expected to be 2'); diff --git a/test/sendable/builtins/Array/length/S15.4.5.1_A1.2_T3.js b/test/sendable/builtins/Array/length/S15.4.5.1_A1.2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..5cccdc02672086571ae595d0f5139f0140e00b43 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.5.1_A1.2_T3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-exotic-objects-defineownproperty-p-desc +info: | + For every integer k that is less than the value of + the length property of A but not less than ToUint32(length), + if A itself has a property (not an inherited property) named ToString(k), + then delete that property +es5id: 15.4.5.1_A1.2_T3 +description: Checking an inherited property +---*/ + +SendableArray.prototype[2] = 2; +var x = new SendableArray(0, 1); +x.length = 3; +assert.sameValue(x.hasOwnProperty('2'), false, 'x.hasOwnProperty("2") must return false'); +x.length = 2; +assert.sameValue(x[2], 2, 'The value of x[2] is expected to be 2'); diff --git a/test/sendable/builtins/Array/length/S15.4.5.1_A1.3_T1.js b/test/sendable/builtins/Array/length/S15.4.5.1_A1.3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..f7ac8281062695bce6cd6a947da8907b4e963440 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.5.1_A1.3_T1.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-exotic-objects-defineownproperty-p-desc +info: Set the value of property length of A to Uint32(length) +es5id: 15.4.5.1_A1.3_T1 +description: length is object or primitve +---*/ + +var x = new SendableArray(); +x.length = true; +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +x = new SendableArray(0); +x.length = null; +assert.sameValue(x.length, 0, 'The value of x.length is expected to be 0'); +x = new SendableArray(0); +x.length = new Boolean(false); +assert.sameValue(x.length, 0, 'The value of x.length is expected to be 0'); +x = new SendableArray(); +x.length = new Number(1); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +x = new SendableArray(); +x.length = "1"; +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +x = new SendableArray(); +x.length = new String("1"); +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); diff --git a/test/sendable/builtins/Array/length/S15.4.5.1_A1.3_T2.js b/test/sendable/builtins/Array/length/S15.4.5.1_A1.3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..3b1afff947e0e8fe22920ffbb1e04001619ddad3 --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.5.1_A1.3_T2.js @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-exotic-objects-defineownproperty-p-desc +info: Set the value of property length of A to Uint32(length) +es5id: 15.4.5.1_A1.3_T2 +description: Uint32 use ToNumber and ToPrimitve +---*/ + +var x = []; +x.length = { + valueOf: function() { + return 2 + } +}; +assert.sameValue(x.length, 2, 'The value of x.length is expected to be 2'); +x = []; +x.length = { + valueOf: function() { + return 2 + }, + toString: function() { + return 1 + } +}; +assert.sameValue(x.length, 2, 'The value of x.length is expected to be 2'); +x = []; +x.length = { + valueOf: function() { + return 2 + }, + toString: function() { + return {} + } +}; +assert.sameValue(x.length, 2, 'The value of x.length is expected to be 2'); +try { + x = []; + x.length = { + valueOf: function() { + return 2 + }, + toString: function() { + throw "error" + } + }; + assert.sameValue(x.length, 2, 'The value of x.length is expected to be 2'); +} +catch (e) { + assert.notSameValue(e, "error", 'The value of e is not "error"'); +} +x = []; +x.length = { + toString: function() { + return 1 + } +}; +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +x = []; +x.length = { + valueOf: function() { + return {} + }, + toString: function() { + return 1 + } +} +assert.sameValue(x.length, 1, 'The value of x.length is expected to be 1'); +try { + x = []; + x.length = { + valueOf: function() { + throw "error" + }, + toString: function() { + return 1 + } + }; + x.length; + throw new Test262Error('#7.1: x = []; x.length = {valueOf: function() {throw "error"}, toString: function() {return 1}}; x.length throw "error". Actual: ' + (x.length)); +} +catch (e) { + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); +} +try { + x = []; + x.length = { + valueOf: function() { + return {} + }, + toString: function() { + return {} + } + }; + x.length; + throw new Test262Error('#8.1: x = []; x.length = {valueOf: function() {return {}}, toString: function() {return {}}} x.length throw TypeError. Actual: ' + (x.length)); +} +catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/length/S15.4.5.2_A3_T4.js b/test/sendable/builtins/Array/length/S15.4.5.2_A3_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..c54202d8049b6c2362bf1ae517fb2cb97db486ff --- /dev/null +++ b/test/sendable/builtins/Array/length/S15.4.5.2_A3_T4.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-properties-of-array-instances-length +info: | + If the length property is changed, every property whose name + is an array index whose value is not smaller than the new length is automatically deleted +es5id: 15.4.5.2_A3_T4 +description: > + If new length greater than the name of every property whose name + is an array index +---*/ + +var x = [0, 1, 2]; +x[4294967294] = 4294967294; +x.length = 2; +assert.sameValue(x[0], 0, 'The value of x[0] is expected to be 0'); +assert.sameValue(x[1], 1, 'The value of x[1] is expected to be 1'); +assert.sameValue(x[2], undefined, 'The value of x[2] is expected to equal undefined'); +assert.sameValue(x[4294967294], undefined, 'The value of x[4294967294] is expected to equal undefined'); diff --git a/test/sendable/builtins/Array/length/define-own-prop-length-coercion-order-set.js b/test/sendable/builtins/Array/length/define-own-prop-length-coercion-order-set.js new file mode 100644 index 0000000000000000000000000000000000000000..44c2ab0567f8c4e92e1f62385f2ae92ce7199536 --- /dev/null +++ b/test/sendable/builtins/Array/length/define-own-prop-length-coercion-order-set.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-arraysetlength +description: > + [[Value]] is coerced to number before current descriptor's [[Writable]] check. +info: | + ArraySetLength ( A, Desc ) + 3. Let newLen be ? ToUint32(Desc.[[Value]]). + 4. Let numberLen be ? ToNumber(Desc.[[Value]]). + 7. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length"). + 12. If oldLenDesc.[[Writable]] is false, return false. +features: [Symbol, Symbol.toPrimitive, Reflect, Reflect.set] +includes: [compareArray.js] +---*/ + +var array = new SendableArray(1, 2, 3); +var hints = new SendableArray(); +var length = {}; +length[Symbol.toPrimitive] = function(hint) { + hints.push(hint); + Object.defineProperty(array, "length", {writable: false}); + return 0; +}; +assert.throws(TypeError, function() { + "use strict"; + array.length = length; +}, '`"use strict"; SendableArray.length = length` throws a TypeError exception'); +assert.compareArray(hints, ["number", "number"], 'The value of hints is expected to be ["number", "number"]'); +array = new SendableArray(1, 2, 3); +hints = new SendableArray(); +assert( + !Reflect.set(array, "length", length), + 'The value of !Reflect.set(SendableArray, "length", length) is expected to be true' +); +assert.compareArray(hints, ["number", "number"], 'The value of hints is expected to be ["number", "number"]'); diff --git a/test/sendable/builtins/Array/length/define-own-prop-length-coercion-order.js b/test/sendable/builtins/Array/length/define-own-prop-length-coercion-order.js new file mode 100644 index 0000000000000000000000000000000000000000..d074b762232494868288f90327c6d7fed3baccf0 --- /dev/null +++ b/test/sendable/builtins/Array/length/define-own-prop-length-coercion-order.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-arraysetlength +description: > + [[Value]] is coerced to number before descriptor validation. +info: | + ArraySetLength ( A, Desc ) + 3. Let newLen be ? ToUint32(Desc.[[Value]]). + 4. Let numberLen be ? ToNumber(Desc.[[Value]]). + 7. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length"). + 11. If newLen ≥ oldLen, then + a. Return OrdinaryDefineOwnProperty(A, "length", newLenDesc). + OrdinaryDefineOwnProperty ( O, P, Desc ) + 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current). + ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) + 7. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) are both true, then + a. If current.[[Configurable]] is false and current.[[Writable]] is false, then + i. If Desc.[[Writable]] is present and Desc.[[Writable]] is true, return false. +features: [Reflect] +---*/ + +var array = new SendableArray(1, 2); +var valueOfCalls = 0; +var length = { + valueOf: function() { + valueOfCalls += 1; + if (valueOfCalls !== 1) { + // skip first coercion at step 3 + Object.defineProperty(array, "length", {writable: false}); + } + return array.length; + }, +}; + +assert.throws(TypeError, function() { + Object.defineProperty(array, "length", {value: length, writable: true}); +}, 'Object.defineProperty(array, "length", {value: length, writable: true}) throws a TypeError exception'); +assert.sameValue(valueOfCalls, 2, 'The value of valueOfCalls is expected to be 2'); + + +array = new SendableArray(1, 2); +valueOfCalls = 0; + +assert( + !Reflect.defineProperty(array, "length", {value: length, writable: true}), + 'The value of !Reflect.defineProperty(array, "length", {value: length, writable: true}) is expected to be true' +); +assert.sameValue(valueOfCalls, 2, 'The value of valueOfCalls is expected to be 2'); diff --git a/test/sendable/builtins/Array/length/define-own-prop-length-error.js b/test/sendable/builtins/Array/length/define-own-prop-length-error.js new file mode 100644 index 0000000000000000000000000000000000000000..bcf2f6226df44fdc62afb3da07f4862b17e5c086 --- /dev/null +++ b/test/sendable/builtins/Array/length/define-own-prop-length-error.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-arraysetlength +description: > + Setting an invalid array length throws a RangeError +info: | + ArraySetLength ( A, Desc ) + 5. If SameValueZero(newLen, numberLen) is false, throw a RangeError exception. +---*/ + +assert.throws(RangeError, function () { + Object.defineProperty(new SendableArray(), 'length', { value: -1, configurable: true }); +}); +assert.throws(RangeError, function () { + // the string is intentionally "computed" here to ensure there are no optimization bugs + Object.defineProperty(new SendableArray(), 'len' + 'gth', { value: -1, configurable: true }); +}); diff --git a/test/sendable/builtins/Array/length/define-own-prop-length-no-value-order.js b/test/sendable/builtins/Array/length/define-own-prop-length-no-value-order.js new file mode 100644 index 0000000000000000000000000000000000000000..5b3895de4c30ac842e911a4fff6349d62caaf1cc --- /dev/null +++ b/test/sendable/builtins/Array/length/define-own-prop-length-no-value-order.js @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-arraysetlength +description: > + Ordinary descriptor validation if [[Value]] is absent. +info: | + ArraySetLength ( A, Desc ) + 1. If Desc.[[Value]] is absent, then + a. Return OrdinaryDefineOwnProperty(A, "length", Desc). + OrdinaryDefineOwnProperty ( O, P, Desc ) + 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current). + ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) + 4. If current.[[Configurable]] is false, then + a. If Desc.[[Configurable]] is present and its value is true, return false. + b. If Desc.[[Enumerable]] is present and + ! SameValue(Desc.[[Enumerable]], current.[[Enumerable]]) is false, return false. + 6. Else if ! SameValue(! IsDataDescriptor(current), ! IsDataDescriptor(Desc)) is false, then + a. If current.[[Configurable]] is false, return false. + 7. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) are both true, then + a. If current.[[Configurable]] is false and current.[[Writable]] is false, then + i. If Desc.[[Writable]] is present and Desc.[[Writable]] is true, return false. +features: [Reflect] +---*/ + +assert.throws(TypeError, function() { + Object.defineProperty(new SendableArray(), "length", {configurable: true}); +}, 'Object.defineProperty([], "length", {configurable: true}) throws a TypeError exception'); + +assert( + !Reflect.defineProperty(new SendableArray(), "length", {enumerable: true}), + 'The value of !Reflect.defineProperty([], "length", {enumerable: true}) is expected to be true' +); + +assert.throws(TypeError, function() { + Object.defineProperty(new SendableArray(), "length", { + get: function() { + throw new Test262Error("[[Get]] shouldn't be called"); + }, + }); +}, 'Object.defineProperty([], "length", {get: function() {throw new Test262Error("[[Get]] shouldn"t be called");},}) throws a TypeError exception'); + +assert( + !Reflect.defineProperty(new SendableArray(), "length", {set: function(_value) {}}), + 'The value of !Reflect.defineProperty([], "length", {set: function(_value) {}}) is expected to be true' +); + +var array = new SendableArray(); +Object.defineProperty(array, "length", {writable: false}); +assert.throws(TypeError, function() { + Object.defineProperty(array, "length", {writable: true}); +}, 'Object.defineProperty(array, "length", {writable: true}) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/length/define-own-prop-length-overflow-order.js b/test/sendable/builtins/Array/length/define-own-prop-length-overflow-order.js new file mode 100644 index 0000000000000000000000000000000000000000..97e1f775127b9d581c783ff8c5f02c305699b527 --- /dev/null +++ b/test/sendable/builtins/Array/length/define-own-prop-length-overflow-order.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-arraysetlength +description: > + [[Value]] is checked for overflow before descriptor validation. +info: | + ArraySetLength ( A, Desc ) + 3. Let newLen be ? ToUint32(Desc.[[Value]]). + 4. Let numberLen be ? ToNumber(Desc.[[Value]]). + 5. If newLen ≠ numberLen, throw a RangeError exception. +---*/ + +assert.throws(RangeError, function() { + Object.defineProperty(new SendableArray(), "length", {value: -1, configurable: true}); +}, 'Object.defineProperty([], "length", {value: -1, configurable: true}) throws a RangeError exception'); + +assert.throws(RangeError, function() { + Object.defineProperty(new SendableArray(), "length", {value: NaN, enumerable: true}); +}, 'Object.defineProperty([], "length", {value: NaN, enumerable: true}) throws a RangeError exception'); + +var array = new SendableArray(); +Object.defineProperty(array, "length", {writable: false}); +assert.throws(RangeError, function() { + Object.defineProperty(array, "length", {value: Number.MAX_SAFE_INTEGER, writable: true}); +}, 'Object.defineProperty(array, "length", {value: Number.MAX_SAFE_INTEGER, writable: true}) throws a RangeError exception'); diff --git a/test/sendable/builtins/Array/length/define-own-prop-length-overflow-realm.js b/test/sendable/builtins/Array/length/define-own-prop-length-overflow-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..c2a8efdd80708031aa74aff58d9e4a723bde1571 --- /dev/null +++ b/test/sendable/builtins/Array/length/define-own-prop-length-overflow-realm.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-exotic-objects-defineownproperty-p-desc +es6id: 9.4.2.1 +description: > + Error when setting a length larger than 2**32 (honoring the Realm of the + current execution context) +info: | + 2. If P is "length", then + a. Return ? ArraySetLength(A, Desc). +features: [cross-realm] +---*/ + +var OArray = $262.createRealm().global.SendableArray; +var array = new OArray(); + +assert.throws(RangeError, function() { + array.length = 4294967296; +}, 'array.length = 4294967296 throws a RangeError exception'); diff --git a/test/sendable/builtins/Array/name.js b/test/sendable/builtins/Array/name.js new file mode 100644 index 0000000000000000000000000000000000000000..299abc681bdbfcddec22275cb9ab8d4e8f5fdec2 --- /dev/null +++ b/test/sendable/builtins/Array/name.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-constructor +description: > + The "name" property of Array +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. Unless otherwise specified, this value is the name that is given to + the function in this specification. + [...] + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray, "name", { + value: "SendableArray", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/of/construct-this-with-the-number-of-arguments.js b/test/sendable/builtins/Array/of/construct-this-with-the-number-of-arguments.js new file mode 100644 index 0000000000000000000000000000000000000000..0d9d8fd964660bad30b023d94bce5ef22c3d538e --- /dev/null +++ b/test/sendable/builtins/Array/of/construct-this-with-the-number-of-arguments.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +es6id: 22.1.2.3 +description: Passes the number of arguments to the constructor it calls. +info: | + SendableArray.of ( ...items ) + 1. Let len be the actual number of arguments passed to this function. + 2. Let items be the List of arguments passed to this function. + 3. Let C be the this value. + 4. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + ... +---*/ + +var len; +var hits = 0; +function C(length) { + len = length; + hits++; +} +SendableArray.of.call(C); +assert.sameValue(len, 0, 'The value of len is expected to be 0'); +assert.sameValue(hits, 1, 'The value of hits is expected to be 1'); +SendableArray.of.call(C, 'a', 'b') +assert.sameValue(len, 2, 'The value of len is expected to be 2'); +assert.sameValue(hits, 2, 'The value of hits is expected to be 2'); +SendableArray.of.call(C, false, null, undefined); +assert.sameValue( + len, 3, + 'The value of len is expected to be 3' +); +assert.sameValue(hits, 3, 'The value of hits is expected to be 3'); diff --git a/test/sendable/builtins/Array/of/creates-a-new-array-from-arguments.js b/test/sendable/builtins/Array/of/creates-a-new-array-from-arguments.js new file mode 100644 index 0000000000000000000000000000000000000000..488fe9d23c99d1582819db290f7af996474abc43 --- /dev/null +++ b/test/sendable/builtins/Array/of/creates-a-new-array-from-arguments.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +es6id: 22.1.2.3 +description: > + SendableArray.of method creates a new Array with a variable number of arguments. +info: | + 22.1.2.3 SendableArray.of ( ...items ) + 7. Let k be 0. + 8. Repeat, while k < len + a. Let kValue be items[k]. + b. Let Pk be ToString(k). + c. Let defineStatus be CreateDataPropertyOrThrow(A,Pk, kValue). + d. ReturnIfAbrupt(defineStatus). + e. Increase k by 1. + 9. Let setStatus be Set(A, "length", len, true). + 10. ReturnIfAbrupt(setStatus). + 11. Return A. +---*/ + +var a1 = SendableArray.of('Mike', 'Rick', 'Leo'); +assert.sameValue( + a1.length, 3, + 'The value of a1.length is expected to be 3' +); +assert.sameValue(a1[0], 'Mike', 'The value of a1[0] is expected to be "Mike"'); +assert.sameValue(a1[1], 'Rick', 'The value of a1[1] is expected to be "Rick"'); +assert.sameValue(a1[2], 'Leo', 'The value of a1[2] is expected to be "Leo"'); +var a2 = SendableArray.of(undefined, false, null, undefined); +assert.sameValue( + a2.length, 4, + 'The value of a2.length is expected to be 4' +); +assert.sameValue(a2[0], undefined, 'The value of a2[0] is expected to equal undefined'); +assert.sameValue(a2[1], false, 'The value of a2[1] is expected to be false'); +assert.sameValue(a2[2], null, 'The value of a2[2] is expected to be null'); +assert.sameValue(a2[3], undefined, 'The value of a2[3] is expected to equal undefined'); +var a3 = SendableArray.of(); +assert.sameValue(a3.length, 0, 'The value of a3.length is expected to be 0'); diff --git a/test/sendable/builtins/Array/of/does-not-use-prototype-properties.js b/test/sendable/builtins/Array/of/does-not-use-prototype-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..f243c7761643924412e51b1220c4360b31c8c063 --- /dev/null +++ b/test/sendable/builtins/Array/of/does-not-use-prototype-properties.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +es6id: 22.1.2.3 +description: Array.of does not use prototype properties for arguments. +info: | + It defines elements rather than assigning to them. +---*/ + +Object.defineProperty(SendableArray.prototype, "0", { + set: function(v) { + throw new Test262Error('Should define own properties'); + } +}); +var arr = SendableArray.of(true); +assert.sameValue(arr[0], true, 'The value of arr[0] is expected to be true'); +function Custom() {} +Object.defineProperty(Custom.prototype, "0", { + set: function(v) { + throw new Test262Error('Should define own properties'); + } +}); +var custom = SendableArray.of.call(Custom, true); +assert.sameValue(custom[0], true, 'The value of custom[0] is expected to be true'); diff --git a/test/sendable/builtins/Array/of/does-not-use-set-for-indices.js b/test/sendable/builtins/Array/of/does-not-use-set-for-indices.js new file mode 100644 index 0000000000000000000000000000000000000000..8965ef3ee56e3f8d60e081a7fce47bff7a50cb31 --- /dev/null +++ b/test/sendable/builtins/Array/of/does-not-use-set-for-indices.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: > + Non-writable properties are overwritten by CreateDataProperty. + (result object's "0" is non-writable) +info: | + SendableArray.of ( ...items ) + 7. Repeat, while k < len + c. Perform ? CreateDataPropertyOrThrow(A, Pk, kValue). +includes: [propertyHelper.js] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + value: 1, + writable: false, + enumerable: false, + configurable: true, + }); +}; +var res = SendableArray.of.call(A, 2); +verifyProperty(res, "0", { + value: 2, + writable: true, + enumerable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/of/length.js b/test/sendable/builtins/Array/of/length.js new file mode 100644 index 0000000000000000000000000000000000000000..45867c995935dd1353bbccaa69e1aeaa4995b3f1 --- /dev/null +++ b/test/sendable/builtins/Array/of/length.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: > + SendableArray.of.length value and property descriptor +info: | + SendableArray.of ( ...items ) + The length property of the of function is 0. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.of, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/of/name.js b/test/sendable/builtins/Array/of/name.js new file mode 100644 index 0000000000000000000000000000000000000000..a804310834e5f682f7c0aace5b24921373dea0b4 --- /dev/null +++ b/test/sendable/builtins/Array/of/name.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: > + SendableArray.of.name value and property descriptor +info: | + SendableArray.of ( ...items ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.of, "name", { + value: "of", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/of/not-a-constructor.js b/test/sendable/builtins/Array/of/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..3944d50616f435b3754ff9a791b1b1cce6ce33f9 --- /dev/null +++ b/test/sendable/builtins/Array/of/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableArray.of does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.of), false, 'isConstructor(SendableArray.of) must return false'); +assert.throws(TypeError, () => { + new SendableArray.of(1); +}, '`new SendableArray.of(1)` throws a TypeError exception'); + diff --git a/test/sendable/builtins/Array/of/of.js b/test/sendable/builtins/Array/of/of.js new file mode 100644 index 0000000000000000000000000000000000000000..0f9537967fda0b8e2a1d1fbfc52625987d6e901f --- /dev/null +++ b/test/sendable/builtins/Array/of/of.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: > + SendableArray.of property descriptor +info: | + SendableArray.of ( ...items ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray, "of", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/of/proto-from-ctor-realm.js b/test/sendable/builtins/Array/of/proto-from-ctor-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..4b6e6fa495eeabbdde4ed791dd92b2a240ae3826 --- /dev/null +++ b/test/sendable/builtins/Array/of/proto-from-ctor-realm.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: Default [[Prototype]] value derived from realm of the constructor +info: | + 4. If IsConstructor(C) is true, then + a. Let A be ? Construct(C, « len »). + 9.1.14 GetPrototypeFromConstructor + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. +features: [cross-realm] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; +var a = SendableArray.of.call(C, 1, 2, 3); +assert.sameValue( + Object.getPrototypeOf(a), + other.Object.prototype, + 'Object.getPrototypeOf(SendableArray.of.call(C, 1, 2, 3)) returns other.Object.prototype' +); diff --git a/test/sendable/builtins/Array/of/return-a-custom-instance.js b/test/sendable/builtins/Array/of/return-a-custom-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..2857e2494ef0a6bcd08767c9c68a1a360b03c2dd --- /dev/null +++ b/test/sendable/builtins/Array/of/return-a-custom-instance.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: > + Returns an instance from a custom constructor. +info: | + SendableArray.of ( ...items ) + 4. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + 11. Return A. +---*/ + +function Coop() {} +var coop = SendableArray.of.call(Coop, 'Mike', 'Rick', 'Leo'); +assert.sameValue( + coop.length, 3, + 'The value of coop.length is expected to be 3' +); +assert.sameValue( + coop[0], 'Mike', + 'The value of coop[0] is expected to be "Mike"' +); +assert.sameValue( + coop[1], 'Rick', + 'The value of coop[1] is expected to be "Rick"' +); +assert.sameValue( + coop[2], 'Leo', + 'The value of coop[2] is expected to be "Leo"' +); +assert(coop instanceof Coop, 'The result of evaluating (coop instanceof Coop) is expected to be true'); diff --git a/test/sendable/builtins/Array/of/return-a-new-array-object.js b/test/sendable/builtins/Array/of/return-a-new-array-object.js new file mode 100644 index 0000000000000000000000000000000000000000..9a4e3cd21b254d831535c568c70aa307952133fb --- /dev/null +++ b/test/sendable/builtins/Array/of/return-a-new-array-object.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: > + Returns a new SendableArray. +info: | + SendableArray.of ( ...items ) + 1. Let len be the actual number of arguments passed to this function. + 2. Let items be the List of arguments passed to this function. + 3. Let C be the this value. + 4. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + 5. Else, + b. Let A be ArrayCreate(len). + 11. Return A. +---*/ + +var result = SendableArray.of(); +assert(result instanceof SendableArray, 'The result of evaluating (result instanceof SendableArray) is expected to be true'); + +result = SendableArray.of.call(undefined); +assert( + result instanceof SendableArray, + 'The result of evaluating (result instanceof SendableArray) is expected to be true' +); +result = SendableArray.of.call(Math.cos); +assert( + result instanceof SendableArray, + 'The result of evaluating (result instanceof SendableArray) is expected to be true' +); +result = SendableArray.of.call(Math.cos.bind(Math)); +assert( + result instanceof SendableArray, + 'The result of evaluating (result instanceof SendableArray) is expected to be true' +); diff --git a/test/sendable/builtins/Array/of/return-abrupt-from-contructor.js b/test/sendable/builtins/Array/of/return-abrupt-from-contructor.js new file mode 100644 index 0000000000000000000000000000000000000000..773678f60048176647ea148c42c4609d9eea0e71 --- /dev/null +++ b/test/sendable/builtins/Array/of/return-abrupt-from-contructor.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: > + Return abrupt from this' constructor +info: | + SendableArray.of ( ...items ) + 1. Let len be the actual number of arguments passed to this function. + 2. Let items be the List of arguments passed to this function. + 3. Let C be the this value. + 4. If IsConstructor(C) is true, then + a. Let A be Construct(C, «len»). + 5. Else, + b. Let A be ArrayCreate(len). + 6. ReturnIfAbrupt(A). + ... +---*/ + +function T() { + throw new Test262Error(); +} +assert.throws(Test262Error, function() { + SendableArray.of.call(T); +}, 'SendableArray.of.call(T) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/of/return-abrupt-from-data-property-using-proxy.js b/test/sendable/builtins/Array/of/return-abrupt-from-data-property-using-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..a1e227825f7c6bf229ed40d950498a0f40b118eb --- /dev/null +++ b/test/sendable/builtins/Array/of/return-abrupt-from-data-property-using-proxy.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: > + Return abrupt from Data Property creation +info: | + SendableArray.of ( ...items ) + 7. Let k be 0. + 8. Repeat, while k < len + a. Let kValue be items[k]. + b. Let Pk be ToString(k). + c. Let defineStatus be CreateDataPropertyOrThrow(A,Pk, kValue). + d. ReturnIfAbrupt(defineStatus). + 7.3.6 CreateDataPropertyOrThrow (O, P, V) + 3. Let success be CreateDataProperty(O, P, V). + 4. ReturnIfAbrupt(success). +features: [Proxy] +---*/ + +function T() { + return new Proxy({}, { + defineProperty: function() { + throw new Test262Error(); + } + }); +} +assert.throws(Test262Error, function() { + SendableArray.of.call(T, 'Bob'); +}, 'SendableArray.of.call(T, "Bob") throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/of/return-abrupt-from-data-property.js b/test/sendable/builtins/Array/of/return-abrupt-from-data-property.js new file mode 100644 index 0000000000000000000000000000000000000000..8d5a8a36ece64fd46827024755d9894852f602c6 --- /dev/null +++ b/test/sendable/builtins/Array/of/return-abrupt-from-data-property.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: > + Return abrupt from Data Property creation +info: | + SendableArray.of ( ...items ) + 7. Let k be 0. + 8. Repeat, while k < len + a. Let kValue be items[k]. + b. Let Pk be ToString(k). + c. Let defineStatus be CreateDataPropertyOrThrow(A,Pk, kValue). + d. ReturnIfAbrupt(defineStatus). + 7.3.6 CreateDataPropertyOrThrow (O, P, V) + 3. Let success be CreateDataProperty(O, P, V). + 4. ReturnIfAbrupt(success). + 5. If success is false, throw a TypeError exception. +---*/ + +function T1() { + Object.preventExtensions(this); +} +assert.throws(TypeError, function() { + SendableArray.of.call(T1, 'Bob'); +}, 'SendableArray.of.call(T1, "Bob") throws a TypeError exception'); +function T2() { + Object.defineProperty(this, 0, { + configurable: false, + writable: true, + enumerable: true + }); +} +assert.throws(TypeError, function() { + SendableArray.of.call(T2, 'Bob'); +}, 'SendableArray.of.call(T2, "Bob") throws a TypeError exception') diff --git a/test/sendable/builtins/Array/of/return-abrupt-from-setting-length.js b/test/sendable/builtins/Array/of/return-abrupt-from-setting-length.js new file mode 100644 index 0000000000000000000000000000000000000000..726733bc94351d360f0afbbe082f4e5e2a8fa063 --- /dev/null +++ b/test/sendable/builtins/Array/of/return-abrupt-from-setting-length.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: > + Return abrupt from setting the length property. +info: | + SendableArray.of ( ...items ) + 9. Let setStatus be Set(A, "length", len, true). + 10. ReturnIfAbrupt(setStatus). +---*/ + +function T() { + Object.defineProperty(this, 'length', { + set: function() { + throw new Test262Error(); + } + }); +} +assert.throws(Test262Error, function() { + SendableArray.of.call(T); +}, 'SendableArray.of.call(T) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/of/sets-length.js b/test/sendable/builtins/Array/of/sets-length.js new file mode 100644 index 0000000000000000000000000000000000000000..2fdb9553795f8ccff925d1bea7b2fc8de42231b4 --- /dev/null +++ b/test/sendable/builtins/Array/of/sets-length.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.of +description: > + Calls the length setter if available +info: | + SendableArray.of ( ...items ) + 9. Let setStatus be Set(A, "length", len, true). +---*/ + +var hits = 0; +var value; +var _this_; +function Pack() { + Object.defineProperty(this, "length", { + set: function(len) { + hits++; + value = len; + _this_ = this; + } + }); +} +var result = SendableArray.of.call(Pack, 'wolves', 'cards', 'cigarettes', 'lies'); +assert.sameValue(hits, 1, 'The value of hits is expected to be 1'); +assert.sameValue( + value, 4, + 'The value of value is expected to be 4' +); +assert.sameValue(_this_, result, 'The value of _this_ is expected to equal the value of result'); diff --git a/test/sendable/builtins/Array/prop-desc.js b/test/sendable/builtins/Array/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..d4ce336e34ac863b4045efd501f3f274c6e07df0 --- /dev/null +++ b/test/sendable/builtins/Array/prop-desc.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-constructor +description: > + Property descriptor of Array +info: | + 22.1.1 The Array Constructor + * is the initial value of the Array property of the global object. + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(this, 'SendableArray', { + value: SendableArray, + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/property-cast-boolean-primitive.js b/test/sendable/builtins/Array/property-cast-boolean-primitive.js new file mode 100644 index 0000000000000000000000000000000000000000..0b8be7b28c532434f29c3255cd38051ca30a49f1 --- /dev/null +++ b/test/sendable/builtins/Array/property-cast-boolean-primitive.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + A property name P (in the form of a string value) is an array index + if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2^32 - 1 +es5id: 15.4_A1.1_T1 +description: Checking for boolean primitive +---*/ + +var x = []; +x[true] = 1; +assert.sameValue(x[1], undefined, 'The value of x[1] is expected to equal undefined'); +assert.sameValue(x["true"], 1, 'The value of x["true"] is expected to be 1'); +x[false] = 0; +assert.sameValue(x[0], undefined, 'The value of x[0] is expected to equal undefined'); +assert.sameValue(x["false"], 0, 'The value of x["false"] is expected to be 0') diff --git a/test/sendable/builtins/Array/property-cast-nan-infinity.js b/test/sendable/builtins/Array/property-cast-nan-infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..b094fedf42f34546943587ede47faec9950e2014 --- /dev/null +++ b/test/sendable/builtins/Array/property-cast-nan-infinity.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + A property name P (in the form of a string value) is an array index + if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2^32 - 1 +es5id: 15.4_A1.1_T2 +description: Checking for number primitive +---*/ + +var x = []; +x[NaN] = 1; +assert.sameValue(x[0], undefined, 'The value of x[0] is expected to equal undefined'); +assert.sameValue(x["NaN"], 1, 'The value of x["NaN"] is expected to be 1'); +var y = []; +y[Number.POSITIVE_INFINITY] = 1; +assert.sameValue(y[0], undefined, 'The value of y[0] is expected to equal undefined'); +assert.sameValue(y["Infinity"], 1, 'The value of y["Infinity"] is expected to be 1'); +var z = []; +z[Number.NEGATIVE_INFINITY] = 1; +assert.sameValue(z[0], undefined, 'The value of z[0] is expected to equal undefined'); +assert.sameValue(z["-Infinity"], 1, 'The value of z["-Infinity"] is expected to be 1'); diff --git a/test/sendable/builtins/Array/property-cast-number.js b/test/sendable/builtins/Array/property-cast-number.js new file mode 100644 index 0000000000000000000000000000000000000000..87e50b307d05c3b01a2e0c7f0a4c2bbb2035f02c --- /dev/null +++ b/test/sendable/builtins/Array/property-cast-number.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + A property name P (in the form of a string value) is an array index + if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2^32 - 1 +es5id: 15.4_A1.1_T3 +description: Checking for number primitive +---*/ + +var x = []; +x[4294967296] = 1; +assert.sameValue(x[0], undefined, 'The value of x[0] is expected to equal undefined'); +assert.sameValue(x["4294967296"], 1, 'The value of x["4294967296"] is expected to be 1'); +var y = []; +y[4294967297] = 1; +if (y[1] !== undefined) { + throw new Test262Error('#3: y = []; y[4294967297] = 1; y[1] === undefined. Actual: ' + (y[1])); +} +//CHECK#4 +if (y["4294967297"] !== 1) { + throw new Test262Error('#4: y = []; y[4294967297] = 1; y["4294967297"] === 1. Actual: ' + (y["4294967297"])); +} +//CHECK#5 +var z = []; +z[1.1] = 1; +if (z[1] !== undefined) { + throw new Test262Error('#5: z = []; z[1.1] = 1; z[1] === undefined. Actual: ' + (z[1])); +} +//CHECK#6 +if (z["1.1"] !== 1) { + throw new Test262Error('#6: z = []; z[1.1] = 1; z["1.1"] === 1. Actual: ' + (z["1.1"])); +} diff --git a/test/sendable/builtins/Array/proto-from-ctor-realm-one.js b/test/sendable/builtins/Array/proto-from-ctor-realm-one.js new file mode 100644 index 0000000000000000000000000000000000000000..701d69f1d8b26f1d8db9d82d162bcdc6dd667999 --- /dev/null +++ b/test/sendable/builtins/Array/proto-from-ctor-realm-one.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-len +description: Default [[Prototype]] value derived from realm of the NewTarget. +info: | + Array ( len ) + 3. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget. + 4. Let proto be ? GetPrototypeFromConstructor(newTarget, "%Array.prototype%"). + 5. Let array be ! ArrayCreate(0, proto). + 9. Return array. + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [cross-realm, Reflect, Symbol] +---*/ + +var other = $262.createRealm().global; +var newTarget = new other.Function(); +var arr; +newTarget.prototype = undefined; +arr = Reflect.construct(SendableArray, [1], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [1], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = null; +arr = Reflect.construct(SendableArray, [1], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [1], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = true; +arr = Reflect.construct(SendableArray, [1], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [1], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = ''; +arr = Reflect.construct(SendableArray, [1], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [1], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = Symbol(); +arr = Reflect.construct(SendableArray, [1], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [1], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = 0; +arr = Reflect.construct(SendableArray, [1], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [1], newTarget)) returns other.SendableArray.prototype'); diff --git a/test/sendable/builtins/Array/proto-from-ctor-realm-two.js b/test/sendable/builtins/Array/proto-from-ctor-realm-two.js new file mode 100644 index 0000000000000000000000000000000000000000..af504426102ebc901b4b85d01bfac9e5110f87b0 --- /dev/null +++ b/test/sendable/builtins/Array/proto-from-ctor-realm-two.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-items +description: Default [[Prototype]] value derived from realm of the NewTarget. +---*/ + +var other = $262.createRealm().global; +var newTarget = new other.Function(); +var arr; +newTarget.prototype = undefined; +arr = Reflect.construct(SendableArray, ['a', 'b'], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, ["a", "b"], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = null; +arr = Reflect.construct(SendableArray, ['a', 'b'], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, ["a", "b"], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = false; +arr = Reflect.construct(SendableArray, ['a', 'b'], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, ["a", "b"], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = ''; +arr = Reflect.construct(SendableArray, ['a', 'b'], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, ["a", "b"], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = Symbol(); +arr = Reflect.construct(SendableArray, ['a', 'b'], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, ["a", "b"], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = -1; +arr = Reflect.construct(SendableArray, ['a', 'b'], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, ["a", "b"], newTarget)) returns other.SendableArray.prototype'); diff --git a/test/sendable/builtins/Array/proto-from-ctor-realm-zero.js b/test/sendable/builtins/Array/proto-from-ctor-realm-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..3a5112fa5ba6ab6cd9fc1ccb17e1fe51cce1d90b --- /dev/null +++ b/test/sendable/builtins/Array/proto-from-ctor-realm-zero.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array-constructor-array +description: Default [[Prototype]] value derived from realm of the NewTarget. +---*/ + +var other = $262.createRealm().global; +var newTarget = new other.Function(); +var arr; +newTarget.prototype = undefined; +arr = Reflect.construct(SendableArray, [], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = null; +arr = Reflect.construct(SendableArray, [], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = true; +arr = Reflect.construct(SendableArray, [], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = 'str'; +arr = Reflect.construct(SendableArray, [], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = Symbol(); +arr = Reflect.construct(SendableArray, [], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [], newTarget)) returns other.SendableArray.prototype'); +newTarget.prototype = 1; +arr = Reflect.construct(SendableArray, [], newTarget); +assert.sameValue(Object.getPrototypeOf(arr), other.SendableArray.prototype, 'Object.getPrototypeOf(Reflect.construct(SendableArray, [], newTarget)) returns other.SendableArray.prototype'); diff --git a/test/sendable/builtins/Array/proto.js b/test/sendable/builtins/Array/proto.js new file mode 100644 index 0000000000000000000000000000000000000000..d87b7f272682303859d8c2588fd43c142fe21a7a --- /dev/null +++ b/test/sendable/builtins/Array/proto.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-properties-of-the-array-constructor +description: > + The prototype of the Array constructor is the intrinsic object %FunctionPrototype%. +info: | + 22.1.2 Properties of the Array Constructor + The value of the [[Prototype]] internal slot of the Array constructor is the + intrinsic object %FunctionPrototype%. +---*/ + +assert.sameValue( + Object.getPrototypeOf(SendableArray), + Function.prototype, + 'Object.getPrototypeOf(SendableArray) returns Function.prototype' +); diff --git a/test/sendable/builtins/Array/prototype/Symbol.iterator.js b/test/sendable/builtins/Array/prototype/Symbol.iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..e498e63a5db3da1779464205c897d19de671e309 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/Symbol.iterator.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Initial state of the Symbol.iterator property +info: | + The initial value of the @@iterator property is the same function object as + the initial value of the Array.prototype.values property. + Per ES6 section 17, the method should exist on the Array prototype, and it + should be writable and configurable, but not enumerable. +includes: [propertyHelper.js] +features: [Symbol.iterator] +esid: sec-array.prototype-@@iterator +---*/ + +assert.sameValue(SendableArray.prototype[Symbol.iterator], SendableArray.prototype.values); +verifyProperty(SendableArray.prototype, Symbol.iterator, { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/Symbol.iterator/not-a-constructor.js b/test/sendable/builtins/Array/prototype/Symbol.iterator/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..095e8463674a0de129849dd3171f0fe5b5aa8904 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/Symbol.iterator/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype[Symbol.iterator] does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, Symbol, Symbol.iterator, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype[Symbol.iterator]), + false, + 'isConstructor(SendableArray.prototype[Symbol.iterator]) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype[Symbol.iterator](); +}); + diff --git a/test/sendable/builtins/Array/prototype/Symbol.unscopables/array-find-from-last.js b/test/sendable/builtins/Array/prototype/Symbol.unscopables/array-find-from-last.js new file mode 100644 index 0000000000000000000000000000000000000000..8ac13dc4833b7f9787f57c59b4b8e01019660ece --- /dev/null +++ b/test/sendable/builtins/Array/prototype/Symbol.unscopables/array-find-from-last.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype-@@unscopables +description: > + Initial value of `Symbol.unscopables` property +includes: [propertyHelper.js] +features: [Symbol.unscopables, array-find-from-last] +---*/ + +var unscopables = SendableArray.prototype[Symbol.unscopables]; +assert.sameValue(Object.getPrototypeOf(unscopables), null); +assert.sameValue(unscopables.findLast, true, '`findLast` property value'); +verifyProperty(unscopables, "findLast", { + writable: true, + enumerable: true, + configurable: true +}); +assert.sameValue(unscopables.findLastIndex, true, '`findLastIndex` property value'); +verifyProperty(unscopables, "findLastIndex", { + writable: true, + enumerable: true, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/Symbol.unscopables/change-array-by-copy.js b/test/sendable/builtins/Array/prototype/Symbol.unscopables/change-array-by-copy.js new file mode 100644 index 0000000000000000000000000000000000000000..ebc7f1379649e646debf5403a654f0b986740e57 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/Symbol.unscopables/change-array-by-copy.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype-@@unscopables +description: > + Initial value of `Symbol.unscopables` property +includes: [propertyHelper.js] +features: [Symbol.unscopables, change-array-by-copy] +---*/ + +var unscopables = SendableArray.prototype[Symbol.unscopables]; +for (const unscopable of ["toReversed", "toSorted", "toSpliced"]) { + verifyProperty(unscopables, unscopable, { + value: true, + writable: true, + configurable: true + }) +}; +assert(!Object.prototype.hasOwnProperty.call(unscopables, "with"), "does not have `with`"); diff --git a/test/sendable/builtins/Array/prototype/Symbol.unscopables/prop-desc.js b/test/sendable/builtins/Array/prototype/Symbol.unscopables/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..eecd840f95ecaa85df28231547bf0f1d786ebdea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/Symbol.unscopables/prop-desc.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype-@@unscopables +description: > + Property descriptor for initial value of `Symbol.unscopables` property +info: | + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.unscopables] +---*/ + +verifyProperty(SendableArray.prototype, Symbol.unscopables, { + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/Symbol.unscopables/value.js b/test/sendable/builtins/Array/prototype/Symbol.unscopables/value.js new file mode 100644 index 0000000000000000000000000000000000000000..2ea94392bb8e40c13e4200dd49d70bbb2480c4cb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/Symbol.unscopables/value.js @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype-@@unscopables +description: > + Initial value of `Symbol.unscopables` property +includes: [propertyHelper.js] +features: [Symbol.unscopables] +---*/ + +var unscopables = SendableArray.prototype[Symbol.unscopables]; +assert.sameValue(Object.getPrototypeOf(unscopables), null); +assert.sameValue(unscopables.copyWithin, true, '`copyWithin` property value'); +verifyProperty(unscopables, "copyWithin", { + writable: true, + enumerable: true, + configurable: true +}); +assert.sameValue(unscopables.entries, true, '`entries` property value'); +verifyProperty(unscopables, "entries", { + writable: true, + enumerable: true, + configurable: true +}); +assert.sameValue(unscopables.fill, true, '`fill` property value'); +verifyProperty(unscopables, "fill", { + writable: true, + enumerable: true, + configurable: true +}); +assert.sameValue(unscopables.find, true, '`find` property value'); +verifyProperty(unscopables, "find", { + writable: true, + enumerable: true, + configurable: true +}); +assert.sameValue(unscopables.findIndex, true, '`findIndex` property value'); +verifyProperty(unscopables, "findIndex", { + writable: true, + enumerable: true, + configurable: true +}); +assert.sameValue(unscopables.flat, true, '`flat` property value'); +verifyProperty(unscopables, "flat", { + writable: true, + enumerable: true, + configurable: true +}); +assert.sameValue(unscopables.flatMap, true, '`flatMap` property value'); +verifyProperty(unscopables, "flatMap", { + writable: true, + enumerable: true, + configurable: true +}); +assert.sameValue(unscopables.includes, true, '`includes` property value'); +verifyProperty(unscopables, "includes", { + writable: true, + enumerable: true, + configurable: true +}); +assert.sameValue(unscopables.keys, true, '`keys` property value'); +verifyProperty(unscopables, "keys", { + writable: true, + enumerable: true, + configurable: true +}); +assert.sameValue(unscopables.values, true, '`values` property value'); +verifyProperty(unscopables, "values", { + writable: true, + enumerable: true, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/at/coerced-index-resize.js b/test/sendable/builtins/Array/prototype/at/coerced-index-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..6cac062fe6fa04846a3e5439bfded79f572686a8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/coerced-index-resize.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Array.p.at behaves correctly on TypedArrays backed by resizable buffers when + the TypedArray is resized during parameter conversion +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function ArrayAtHelper(ta, index) { + return SendableArray.prototype.at.call(ta, index); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2); + return 0; + } + }; + assert.sameValue(ArrayAtHelper(fixedLength, evil), undefined); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let evil = { + valueOf: () => { + rab.resize(2); + return -1; + } + }; + // The TypedArray is *not* out of bounds since it's length-tracking. + assert.sameValue(ArrayAtHelper(lengthTracking, evil), undefined); +} diff --git a/test/sendable/builtins/Array/prototype/at/index-argument-tointeger.js b/test/sendable/builtins/Array/prototype/at/index-argument-tointeger.js new file mode 100644 index 0000000000000000000000000000000000000000..5466fbd3cdb836db0ae396c44d48ee1cda5352b0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/index-argument-tointeger.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Property type and descriptor. +info: | + Array.prototype.at( index ) + Let relativeIndex be ? ToInteger(index). +features: [Array.prototype.at] +---*/ +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof Array.prototype.at` is expected to be "function"' +); +let valueOfCallCount = 0; +let index = { + valueOf() { + valueOfCallCount++; + return 1; + } +}; +let a = new SendableArray(0,1,2,3); +assert.sameValue(a.at(index), 1, 'a.at({valueOf() {valueOfCallCount++; return 1;}}) must return 1'); +assert.sameValue(valueOfCallCount, 1, 'The value of valueOfCallCount is expected to be 1'); diff --git a/test/sendable/builtins/Array/prototype/at/index-non-numeric-argument-tointeger-invalid.js b/test/sendable/builtins/Array/prototype/at/index-non-numeric-argument-tointeger-invalid.js new file mode 100644 index 0000000000000000000000000000000000000000..8114042a4dacf3c277bae95e2b139f62e5aa0e45 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/index-non-numeric-argument-tointeger-invalid.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Property type and descriptor. +info: | + Array.prototype.at( index ) + Let relativeIndex be ? ToInteger(index). +features: [Array.prototype.at] +---*/ +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof Array.prototype.at` is expected to be "function"' +); +let a = new SendableArray(0,1,2,3); +assert.throws(TypeError, () => { + a.at(Symbol()); +}, 'a.at(Symbol()) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/at/index-non-numeric-argument-tointeger.js b/test/sendable/builtins/Array/prototype/at/index-non-numeric-argument-tointeger.js new file mode 100644 index 0000000000000000000000000000000000000000..160e7bbd46874185b1f93271d84596e096034729 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/index-non-numeric-argument-tointeger.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Property type and descriptor. +info: | + Array.prototype.at( index ) + Let relativeIndex be ? ToInteger(index). +features: [Array.prototype.at] +---*/ +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof Array.prototype.at` is expected to be "function"' +); +let a = new SendableArray(0,1,2,3); +assert.sameValue(a.at(false), 0, 'a.at(false) must return 0'); +assert.sameValue(a.at(null), 0, 'a.at(null) must return 0'); +assert.sameValue(a.at(undefined), 0, 'a.at(undefined) must return 0'); +assert.sameValue(a.at(""), 0, 'a.at("") must return 0'); +assert.sameValue(a.at(function() {}), 0, 'a.at(function() {}) must return 0'); +assert.sameValue(a.at([]), 0, 'a.at([]) must return 0'); +assert.sameValue(a.at(true), 1, 'a.at(true) must return 1'); +assert.sameValue(a.at("1"), 1, 'a.at("1") must return 1'); diff --git a/test/sendable/builtins/Array/prototype/at/length.js b/test/sendable/builtins/Array/prototype/at/length.js new file mode 100644 index 0000000000000000000000000000000000000000..7f5bb702b84f676a1c36ab50323fb40fb3f0f497 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/length.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Array.prototype.at.length value and descriptor. +info: | + Array.prototype.at( index ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [Array.prototype.at] +---*/ +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof Array.prototype.at` is expected to be "function"' +); +verifyProperty(SendableArray.prototype.at, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/at/name.js b/test/sendable/builtins/Array/prototype/at/name.js new file mode 100644 index 0000000000000000000000000000000000000000..f771119fab0fe0c90f4ded600778e965710355d0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/name.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Array.prototype.at.name value and descriptor. +info: | + Array.prototype.at( index ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [Array.prototype.at] +---*/ +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof Array.prototype.at` is expected to be "function"' +); +assert.sameValue( + SendableArray.prototype.at.name, 'at', + 'The value of Array.prototype.at.name is expected to be "at"' +); +verifyProperty(SendableArray.prototype.at, 'name', { + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/at/prop-desc.js b/test/sendable/builtins/Array/prototype/at/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..4738e006586047de056364fa66a8233eb95b98a6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/prop-desc.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Property type and descriptor. +info: | + Array.prototype.at( index ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [Array.prototype.at] +---*/ +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof Array.prototype.at` is expected to be "function"' +); +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof Array.prototype.at` is expected to be "function"' +); +verifyProperty(SendableArray.prototype, 'at', { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/at/return-abrupt-from-this.js b/test/sendable/builtins/Array/prototype/at/return-abrupt-from-this.js new file mode 100644 index 0000000000000000000000000000000000000000..ac927e51c59e1bc197aaa3d316b7916afcc29173 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/return-abrupt-from-this.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Return abrupt from ToObject(this value). +info: | + Array.prototype.at( index ) + Let O be ? ToObject(this value). +features: [Array.prototype.at] +---*/ +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof SendableArray.prototype.at` is expected to be "function"' +); +assert.throws(TypeError, () => { + SendableArray.prototype.at.call(undefined); +}, 'sendableArray.prototype.at.call(undefined) throws a TypeError exception'); +assert.throws(TypeError, () => { + SendableArray.prototype.at.call(null); +}, 'SendableArray.prototype.at.call(null) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/at/returns-item-relative-index.js b/test/sendable/builtins/Array/prototype/at/returns-item-relative-index.js new file mode 100644 index 0000000000000000000000000000000000000000..ae5a0c426855749d0d3c1971edb1f76752341fae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/returns-item-relative-index.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Returns the item value at the specified relative index +info: | + Array.prototype.at ( ) + Let O be ? ToObject(this value). + Let len be ? LengthOfArrayLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). +features: [Array.prototype.at] +---*/ +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof Array.prototype.at` is expected to be "function"' +); +let a = new SendableArray(1, 2, 3, 4, undefined, 5); +assert.sameValue(a.at(0), 1, 'a.at(0) must return 1'); +assert.sameValue(a.at(-1), 5, 'a.at(-1) must return 5'); +assert.sameValue(a.at(-2), undefined, 'a.at(-2) returns undefined'); +assert.sameValue(a.at(-3), 4, 'a.at(-3) must return 4'); +assert.sameValue(a.at(-4), 3, 'a.at(-4) must return 3'); diff --git a/test/sendable/builtins/Array/prototype/at/returns-item.js b/test/sendable/builtins/Array/prototype/at/returns-item.js new file mode 100644 index 0000000000000000000000000000000000000000..bc4322174a00f489794aa6afc650d4d0234ebb55 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/returns-item.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Returns the item value at the specified index +info: | + Array.prototype.at ( ) + Let O be ? ToObject(this value). + Let len be ? LengthOfArrayLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). +features: [Array.prototype.at] +---*/ +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof Array.prototype.at` is expected to be "function"' +); +let a = new SendableArray(1, 2, 3, 4, undefined, 5); +assert.sameValue(a.at(0), 1, 'a.at(0) must return 1'); +assert.sameValue(a.at(1), 2, 'a.at(1) must return 2'); +assert.sameValue(a.at(2), 3, 'a.at(2) must return 3'); +assert.sameValue(a.at(3), 4, 'a.at(3) must return 4'); +assert.sameValue(a.at(4), undefined, 'a.at(4) returns undefined'); +assert.sameValue(a.at(5), 5, 'a.at(5) must return 5'); diff --git a/test/sendable/builtins/Array/prototype/at/returns-undefined-for-holes-in-sparse-arrays.js b/test/sendable/builtins/Array/prototype/at/returns-undefined-for-holes-in-sparse-arrays.js new file mode 100644 index 0000000000000000000000000000000000000000..9fad78476f5466916c14db819cd628d37a0a1087 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/returns-undefined-for-holes-in-sparse-arrays.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Returns the item value at the specified index, respecting holes in sparse arrays. +info: | + Array.prototype.at ( ) + Let O be ? ToObject(this value). + Let len be ? LengthOfArrayLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). +features: [Array.prototype.at] +---*/ +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof Array.prototype.at` is expected to be "function"' +); +let a = new SendableArray(0, 1, undefined, 3, 4, undefined, 6); +assert.sameValue(a.at(0), 0, 'a.at(0) must return 0'); +assert.sameValue(a.at(1), 1, 'a.at(1) must return 1'); +assert.sameValue(a.at(2), undefined, 'a.at(2) returns undefined'); +assert.sameValue(a.at(3), 3, 'a.at(3) must return 3'); +assert.sameValue(a.at(4), 4, 'a.at(4) must return 4'); +assert.sameValue(a.at(5), undefined, 'a.at(5) returns undefined'); +assert.sameValue(a.at(6), 6, 'a.at(6) must return 6'); +assert.sameValue(a.at(-0), 0, 'a.at(-0) must return 0'); +assert.sameValue(a.at(-1), 6, 'a.at(-1) must return 6'); +assert.sameValue(a.at(-2), undefined, 'a.at(-2) returns undefined'); +assert.sameValue(a.at(-3), 4, 'a.at(-3) must return 4'); +assert.sameValue(a.at(-4), 3, 'a.at(-4) must return 3'); +assert.sameValue(a.at(-5), undefined, 'a.at(-5) returns undefined'); +assert.sameValue(a.at(-6), 1, 'a.at(-6) must return 1'); diff --git a/test/sendable/builtins/Array/prototype/at/returns-undefined-for-out-of-range-index.js b/test/sendable/builtins/Array/prototype/at/returns-undefined-for-out-of-range-index.js new file mode 100644 index 0000000000000000000000000000000000000000..e4ae5fdfb8d25cae75926d9300938d8e43bf385d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/returns-undefined-for-out-of-range-index.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Returns undefined if the specified index less than or greater than the available index range. +info: | + Array.prototype.at( index ) + If k < 0 or k ≥ len, then return undefined. +features: [Array.prototype.at] +---*/ +assert.sameValue( + typeof SendableArray.prototype.at, + 'function', + 'The value of `typeof Array.prototype.at` is expected to be "function"' +); +let a = new SendableArray(); +assert.sameValue(a.at(-2), undefined, 'a.at(-2) returns undefined'); // wrap around the end +assert.sameValue(a.at(0), undefined, 'a.at(0) returns undefined'); +assert.sameValue(a.at(1), undefined, 'a.at(1) returns undefined'); + diff --git a/test/sendable/builtins/Array/prototype/at/typed-array-resizable-buffer.js b/test/sendable/builtins/Array/prototype/at/typed-array-resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..2b7ce64213183dbaa55423a6b684bddcc4cb16f5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/at/typed-array-resizable-buffer.js @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.at +description: > + Array.p.at behaves correctly on TypedArrays backed by resizable buffers +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function ArrayAtHelper(ta, index) { + const result = SendableArray.prototype.at.call(ta, index); + return Convert(result); +}for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + let ta_write = new ctor(rab); + for (let i = 0; i < 4; ++i) { + ta_write[i] = MayNeedBigInt(ta_write, i); + } + assert.sameValue(ArrayAtHelper(fixedLength, -1), 3); + assert.sameValue(ArrayAtHelper(lengthTracking, -1), 3); + assert.sameValue(ArrayAtHelper(fixedLengthWithOffset, -1), 3); + assert.sameValue(ArrayAtHelper(lengthTrackingWithOffset, -1), 3); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(ArrayAtHelper(fixedLength, -1), undefined); + assert.sameValue(ArrayAtHelper(fixedLengthWithOffset, -1), undefined); + assert.sameValue(ArrayAtHelper(lengthTracking, -1), 2); + assert.sameValue(ArrayAtHelper(lengthTrackingWithOffset, -1), 2); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(ArrayAtHelper(fixedLength, -1), undefined); + assert.sameValue(ArrayAtHelper(fixedLengthWithOffset, -1), undefined); + assert.sameValue(ArrayAtHelper(lengthTrackingWithOffset, -1), undefined); + assert.sameValue(ArrayAtHelper(lengthTracking, -1), 0); + // Grow so that all TAs are back in-bounds. New memory is zeroed. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(ArrayAtHelper(fixedLength, -1), 0); + assert.sameValue(ArrayAtHelper(lengthTracking, -1), 0); + assert.sameValue(ArrayAtHelper(fixedLengthWithOffset, -1), 0); + assert.sameValue(ArrayAtHelper(lengthTrackingWithOffset, -1), 0); +} diff --git a/test/sendable/builtins/Array/prototype/concat/15.4.4.4-5-b-iii-3-b-1.js b/test/sendable/builtins/Array/prototype/concat/15.4.4.4-5-b-iii-3-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..c923d4ba6c9ae7e7357c3a692c8c4312a1a956e8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/15.4.4.4-5-b-iii-3-b-1.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-SendableArray.prototype.concat +description: > + SendableArray.prototype.concat will concat an Array when index property + (read-only) exists in SendableArray.prototype (Step 5.b.iii.3.b) +includes: [propertyHelper.js] +---*/ + +Object.defineProperty(SendableArray.prototype, "0", { + value: 100, + writable: false, + configurable: true +}); +var oldArr = [101]; +var newArr = SendableArray.prototype.concat.call(oldArr); +verifyProperty(newArr, "0", { + value: 101, + writable: true, + enumerable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/concat/15.4.4.4-5-c-i-1.js b/test/sendable/builtins/Array/prototype/concat/15.4.4.4-5-c-i-1.js new file mode 100644 index 0000000000000000000000000000000000000000..eeb0f8e474beb608e49734cec16efe26932317c2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/15.4.4.4-5-c-i-1.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + Array.prototype.concat will concat an Array when index property + (read-only) exists in Array.prototype (Step 5.c.i) +includes: [propertyHelper.js] +---*/ + +Object.defineProperty(SendableArray.prototype, "0", { + value: 100, + writable: false, + configurable: true +}); +var newArrayFromConcat = SendableArray.prototype.concat.call(101); +assert( + newArrayFromConcat[0] instanceof Number, + 'The result of evaluating (newArrayFromConcat[0] instanceof Number) is expected to be true' +); +verifyProperty(newArrayFromConcat, "0", { + writable: true, + enumerable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T1.js b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..97d6751d8edaf1673fae46f74a5013780be5bb7e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T1.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +info: | + When the concat method is called with zero or more arguments item1, item2, + etc., it returns an array containing the array elements of the object followed by + the array elements of each argument in order +es5id: 15.4.4.4_A1_T1 +description: Checking this algorithm, items are Array object +---*/ +var x = new SendableArray(); +var y = new SendableArray(0, 1); +var z = new SendableArray(2, 3, 4); +var arr = x.concat(y, z); +arr.getClass = Object.prototype.toString; +assert.sameValue(arr.getClass(), "[object Array]", 'arr.getClass() must return "[object Array]"'); +assert.sameValue(arr[0], 0, 'The value of arr[0] is expected to be 0'); +assert.sameValue(arr[1], 1, 'The value of arr[1] is expected to be 1'); +assert.sameValue(arr[2], 2, 'The value of arr[2] is expected to be 2'); +assert.sameValue(arr[3], 3, 'The value of arr[3] is expected to be 3'); +assert.sameValue(arr[4], 4, 'The value of arr[4] is expected to be 4'); +assert.sameValue(arr.length, 5, 'The value of arr.length is expected to be 5'); diff --git a/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T2.js b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..13a80f3ea6c5b7259c6fc72f86d50827ee683676 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T2.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +info: | + When the concat method is called with zero or more arguments item1, item2, + etc., it returns an array containing the array elements of the object followed by + the array elements of each argument in order +es5id: 15.4.4.4_A1_T2 +description: Checking this algorithm, items are objects and primitives +---*/ + +var x = [0]; +var y = new Object(); +var z = new SendableArray(1, 2); +var arr = x.concat(y, z, -1, true, "NaN"); +arr.getClass = Object.prototype.toString; +assert.sameValue(arr.getClass(), "[object Array]", 'arr.getClass() must return "[object Array]"'); +assert.sameValue(arr[0], 0, 'The value of arr[0] is expected to be 0'); +assert.sameValue(arr[1], y, 'The value of arr[1] is expected to equal the value of y'); +assert.sameValue(arr[2], 1, 'The value of arr[2] is expected to be 1'); +assert.sameValue(arr[3], 2, 'The value of arr[3] is expected to be 2'); +assert.sameValue(arr[4], -1, 'The value of arr[4] is expected to be -1'); +assert.sameValue(arr[5], true, 'The value of arr[5] is expected to be true'); +assert.sameValue(arr[6], "NaN", 'The value of arr[6] is expected to be "NaN"'); +assert.sameValue(arr.length, 7, 'The value of arr.length is expected to be 7'); diff --git a/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T3.js b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..d879bb2e20ac17d8b020e7592cd578d691bd0622 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T3.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +info: | + When the concat method is called with zero or more arguments item1, item2, + etc., it returns an array containing the array elements of the object followed by + the array elements of each argument in order +es5id: 15.4.4.4_A1_T3 +description: Checking this algorithm with no items +---*/ + +var x = [0, 1]; +var arr = x.concat(); +arr.getClass = Object.prototype.toString; +assert.sameValue(arr.getClass(), "[object Array]", 'arr.getClass() must return "[object Array]"'); +assert.sameValue(arr[0], 0, 'The value of arr[0] is expected to be 0'); +assert.sameValue(arr[1], 1, 'The value of arr[1] is expected to be 1'); +assert.sameValue(arr.length, 2, 'The value of arr.length is expected to be 2'); +assert.notSameValue(arr, x, 'The value of arr is expected to not equal the value of `x`'); diff --git a/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T4.js b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..2c5ceed5543f69466505a34de8dd0285f63de68b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A1_T4.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +info: | + When the concat method is called with zero or more arguments item1, item2, + etc., it returns an array containing the array elements of the object followed by + the array elements of each argument in order +es5id: 15.4.4.4_A1_T4 +description: Checking this algorithm, items are [], [,] +---*/ + +var x = [, 1]; +var arr = x.concat([], [, ]); +arr.getClass = Object.prototype.toString; +assert.sameValue(arr.getClass(), "[object Array]", 'arr.getClass() must return "[object Array]"'); +assert.sameValue(arr[0], undefined, 'The value of arr[0] is expected to equal undefined'); +assert.sameValue(arr[1], 1, 'The value of arr[1] is expected to be 1'); +assert.sameValue(arr[2], undefined, 'The value of arr[2] is expected to equal undefined'); +assert.sameValue(arr.length, 3, 'The value of arr.length is expected to be 3'); diff --git a/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A2_T1.js b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..966abd6ac3dc4e0f6a6545b57eadce8d6b0126d9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A2_T1.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +info: | + The concat function is intentionally generic. + It does not require that its this value be an Array object +es5id: 15.4.4.4_A2_T1 +description: Checking this for Object object, items are objects and primitives +---*/ + +var x = {}; +x.concat = SendableArray.prototype.concat; +var y = new Object(); +var z = new SendableArray(1, 2); +var arr = x.concat(y, z, -1, true, "NaN"); +arr.getClass = Object.prototype.toString; +assert.sameValue(arr.getClass(), "[object Array]", 'arr.getClass() must return "[object Array]"'); +assert.sameValue(arr[0], x, 'The value of arr[0] is expected to equal the value of x'); +assert.sameValue(arr[1], y, 'The value of arr[1] is expected to equal the value of y'); +assert.sameValue(arr[2], 1, 'The value of arr[2] is expected to be 1'); +assert.sameValue(arr[3], 2, 'The value of arr[3] is expected to be 2'); +assert.sameValue(arr[4], -1, 'The value of arr[4] is expected to be -1'); +assert.sameValue(arr[5], true, 'The value of arr[5] is expected to be true'); +assert.sameValue(arr[6], "NaN", 'The value of arr[6] is expected to be "NaN"'); +assert.sameValue(arr.length, 7, 'The value of arr.length is expected to be 7'); diff --git a/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A2_T2.js b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..5113f4bb8c42683f638d25932b5ad303cc2a8c9b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A2_T2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.concat +info: | + The concat function is intentionally generic. + It does not require that its this value be an Array object +es5id: 15.4.4.4_A2_T2 +description: Checking this for Object object with no items +---*/ + +var x = {}; +x.concat = SendableArray.prototype.concat; +var arr = x.concat(); +arr.getClass = Object.prototype.toString; +assert.sameValue(arr.getClass(), "[object Array]", 'arr.getClass() must return "[object Array]"'); +assert.sameValue(arr[0], x, 'The value of arr[0] is expected to equal the value of x'); +assert.sameValue(arr.length, 1, 'The value of arr.length is expected to be 1'); diff --git a/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A3_T1.js b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..dc5ce76240c5cf252d8dae5f769a93128ba8dfc8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A3_T1.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.concat +info: "[[Get]] from not an inherited property" +es5id: 15.4.4.4_A3_T1 +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[1] = 1; +var x = [0]; +x.length = 2; +var arr = x.concat(); +assert.sameValue(arr[0], 0, 'The value of arr[0] is expected to be 0'); +assert.sameValue(arr[1], 1, 'The value of arr[1] is expected to be 1'); +assert.sameValue(arr.hasOwnProperty('1'), true, 'arr.hasOwnProperty("1") must return true'); +Object.prototype[1] = 1; +Object.prototype.length = 2; +Object.prototype.concat = SendableArray.prototype.concat; +x = { + 0: 0 +}; +var arr = x.concat(); +assert.sameValue(arr[0], x, 'The value of arr[0] is expected to equal the value of x'); +assert.sameValue(arr[1], 1, 'The value of arr[1] is expected to be 1'); +assert.sameValue(arr.hasOwnProperty('1'), false, 'arr.hasOwnProperty("1") must return false'); diff --git a/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A3_T2.js b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..5edc3e6d66f14b060b1b30dbd82449ed9b5ae09b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A3_T2.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +info: Array.prototype.concat uses [[Get]] on 'length' to determine array length +es5id: 15.4.4.4_A3_T2 +description: > + checking whether non-ownProperties are seen, copied by Array.prototype.concat: Array.prototype[1] +---*/ + +var a = [0]; +assert.sameValue(a.length, 1, 'The value of a.length is expected to be 1'); +a.length = 3; +assert.sameValue(a[1], undefined, 'The value of a[1] is expected to equal undefined'); +assert.sameValue(a[2], undefined, 'The value of a[2] is expected to equal undefined'); +SendableArray.prototype[2] = 2; +assert.sameValue(a[1], undefined, 'The value of a[1] is expected to equal undefined'); +assert.sameValue(a[2], 2, 'The value of a[2] is expected to be 2'); +assert.sameValue(a.hasOwnProperty('1'), false, 'a.hasOwnProperty("1") must return false'); +assert.sameValue(a.hasOwnProperty('2'), false, 'a.hasOwnProperty("2") must return false'); +var b = a.concat(); +assert.sameValue(b.length, 3, 'The value of b.length is expected to be 3'); +assert.sameValue(b[0], 0, 'The value of b[0] is expected to be 0'); +assert.sameValue(b[1], undefined, 'The value of b[1] is expected to equal undefined'); +assert.sameValue(b[2], 2, 'The value of b[2] is expected to be 2'); +assert.sameValue(b.hasOwnProperty('1'), false, 'b.hasOwnProperty("1") must return false'); +assert.sameValue(b.hasOwnProperty('2'), true, 'b.hasOwnProperty("2") must return true'); diff --git a/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A3_T3.js b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..faca42ffbd0f671a2bf763f3ea61bba8719ca914 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/S15.4.4.4_A3_T3.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.concat +info: Array.prototype.concat uses [[Get]] on 'length' to determine array length +es5id: 15.4.4.4_A3_T3 +description: > + checking whether non-ownProperties are seen, copied by Array.prototype.concat: Object.prototype[1] +---*/ + +var a = [0]; +assert.sameValue(a.length, 1, 'The value of a.length is expected to be 1'); +a.length = 3; +assert.sameValue(a[1], undefined, 'The value of a[1] is expected to equal undefined'); +assert.sameValue(a[2], undefined, 'The value of a[2] is expected to equal undefined'); +Object.prototype[2] = 2; +assert.sameValue(a[1], undefined, 'The value of a[1] is expected to equal undefined'); +assert.sameValue(a[2], 2, 'The value of a[2] is expected to be 2'); +assert.sameValue(a.hasOwnProperty('1'), false, 'a.hasOwnProperty("1") must return false'); +assert.sameValue(a.hasOwnProperty('2'), false, 'a.hasOwnProperty("2") must return false'); +var b = a.concat(); +assert.sameValue(b.length, 3, 'The value of b.length is expected to be 3'); +assert.sameValue(b[0], 0, 'The value of b[0] is expected to be 0'); +assert.sameValue(b[1], undefined, 'The value of b[1] is expected to equal undefined'); +assert.sameValue(b[2], 2, 'The value of b[2] is expected to be 2'); +assert.sameValue(b.hasOwnProperty('1'), false, 'b.hasOwnProperty("1") must return false'); +assert.sameValue(b.hasOwnProperty('2'), true, 'b.hasOwnProperty("2") must return true'); diff --git a/test/sendable/builtins/Array/prototype/concat/arg-length-exceeding-integer-limit.js b/test/sendable/builtins/Array/prototype/concat/arg-length-exceeding-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..e98d363be71bf0da68d955321b0eb8f0476f9d19 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/arg-length-exceeding-integer-limit.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + TypeError is thrown if "length" of result array exceeds 2^53 - 1. +info: | + Array.prototype.concat ( ...arguments ) + + [...] + 5. Repeat, while items is not empty + [...] + c. If spreadable is true, then + [...] + ii. Let len be ? LengthOfArrayLike(E). + iii. If n + len > 2^53 - 1, throw a TypeError exception. + [...] +features: [Symbol.isConcatSpreadable, Proxy] +---*/ + +var spreadableLengthOutOfRange = {}; +spreadableLengthOutOfRange.length = Number.MAX_SAFE_INTEGER; +spreadableLengthOutOfRange[Symbol.isConcatSpreadable] = true; +assert.throws(TypeError, function() { + [1].concat(spreadableLengthOutOfRange); +}, '[1].concat(spreadableLengthOutOfRange) throws a TypeError exception'); +var proxyForArrayWithLengthOutOfRange = new Proxy([], { + get: function(_target, key) { + if (key === "length") { + return Number.MAX_SAFE_INTEGER; + } + }, +}); +assert.throws(TypeError, function() { + [].concat(1, proxyForArrayWithLengthOutOfRange); +}, '[].concat(1, proxyForArrayWithLengthOutOfRange) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/arg-length-near-integer-limit.js b/test/sendable/builtins/Array/prototype/concat/arg-length-near-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..729b3b779ac2475f2abc06644a0f2a96756984d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/arg-length-near-integer-limit.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + Elements are copied from a spreadable array-like object + whose "length" property is near the integer limit. +info: | + Array.prototype.concat ( ...arguments ) + + [...] + 5. Repeat, while items is not empty + [...] + c. If spreadable is true, then + [...] + ii. Let len be ? LengthOfArrayLike(E). + iii. If n + len > 2^53 - 1, throw a TypeError exception. + iv. Repeat, while k < len + [...] + 3. If exists is true, then + a. Let subElement be ? Get(E, P). + [...] +features: [Symbol.isConcatSpreadable] +---*/ + +var spreadableHasPoisonedIndex = { + length: Number.MAX_SAFE_INTEGER, + get 0() { + throw new Test262Error(); + }, +}; +spreadableHasPoisonedIndex[Symbol.isConcatSpreadable] = true; +assert.throws(Test262Error, function() { + [].concat(spreadableHasPoisonedIndex); +}, '[].concat(spreadableHasPoisonedIndex) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/call-with-boolean.js b/test/sendable/builtins/Array/prototype/concat/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..f89534b805adeb2d659b541b1fb29e77c2525aa4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.concat.call(true)[0] instanceof Boolean, + true, + 'The result of evaluating (SendableArray.prototype.concat.call(true)[0] instanceof Boolean) is expected to be true' +); +assert.sameValue( + SendableArray.prototype.concat.call(false)[0] instanceof Boolean, + true, + 'The result of evaluating (SendableArray.prototype.concat.call(false)[0] instanceof Boolean) is expected to be true' +); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_array-like-length-to-string-throws.js b/test/sendable/builtins/Array/prototype/concat/concat_array-like-length-to-string-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..49a8ac137c6d6bba8ba084fd7a97a1ce172fc01e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_array-like-length-to-string-throws.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat array like length to string throws +features: [Symbol.isConcatSpreadable] +---*/ +var objWithPoisonedLengthToString = { + "length": { + toString: function() { + throw new Test262Error(); + }, + valueOf: null + }, + "1": "A", + "3": "B", + "5": "C" +}; +objWithPoisonedLengthToString[Symbol.isConcatSpreadable] = true; +assert.throws(Test262Error, function() { + [].concat(objWithPoisonedLengthToString); +}, '[].concat(objWithPoisonedLengthToString) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_array-like-length-value-of-throws.js b/test/sendable/builtins/Array/prototype/concat/concat_array-like-length-value-of-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..20d570911955fa30c5038d8c5d85e39ce3f6ed46 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_array-like-length-value-of-throws.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat array like length valueOf throws +features: [Symbol.isConcatSpreadable] +---*/ +var objWithPoisonedLengthValueOf = { + "length": { + valueOf: function() { + throw new Test262Error(); + }, + toString: null + }, + "1": "A", + "3": "B", + "5": "C" +}; +objWithPoisonedLengthValueOf[Symbol.isConcatSpreadable] = true; +assert.throws(Test262Error, function() { + [].concat(objWithPoisonedLengthValueOf); +}, '[].concat(objWithPoisonedLengthValueOf) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_array-like-negative-length.js b/test/sendable/builtins/Array/prototype/concat/concat_array-like-negative-length.js new file mode 100644 index 0000000000000000000000000000000000000000..42cf9fa68e2a2caade1f74890fb47e356f3a454f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_array-like-negative-length.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat array like negative length +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var obj = { + "length": -4294967294, + "1": "A", + "3": "B", + "5": "C" +}; +obj[Symbol.isConcatSpreadable] = true; +assert.compareArray([].concat(obj), [], '[].concat({"length": -4294967294, "1": "A", "3": "B", "5": "C"}) must return []'); +obj.length = -4294967294; +assert.compareArray([].concat(obj), [], '[].concat({"length": -4294967294, "1": "A", "3": "B", "5": "C"}) must return []'); +obj.length = "-4294967294"; +assert.compareArray([].concat(obj), [], '[].concat({"length": -4294967294, "1": "A", "3": "B", "5": "C"}) must return []'); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_array-like-primitive-non-number-length.js b/test/sendable/builtins/Array/prototype/concat/concat_array-like-primitive-non-number-length.js new file mode 100644 index 0000000000000000000000000000000000000000..96a658d3ae8ae09db8ed98174e6a8514f747601c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_array-like-primitive-non-number-length.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat array like primitive non number length +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var obj = { + "1": "A", + "3": "B", + "5": "C" +}; +obj[Symbol.isConcatSpreadable] = true; +obj.length = { + toString: function() { + return "SIX"; + }, + valueOf: null +}; +assert.compareArray([].concat(obj), [], '[].concat({"1": "A", "3": "B", "5": "C"}) must return []'); +obj.length = { + toString: null, + valueOf: function() { + return "SIX"; + } +}; +assert.compareArray([].concat(obj), [], '[].concat({"1": "A", "3": "B", "5": "C"}) must return []'); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_array-like-string-length.js b/test/sendable/builtins/Array/prototype/concat/concat_array-like-string-length.js new file mode 100644 index 0000000000000000000000000000000000000000..993ea37d45cd6fca9635e4dcbd2df7e20b797f0a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_array-like-string-length.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat array like string length +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var obj = { + "length": "6", + "1": "A", + "3": "B", + "5": "C" +}; +obj[Symbol.isConcatSpreadable] = true; +var obj2 = { + length: 3, + "0": "0", + "1": "1", + "2": "2" +}; +var arr = ["X", "Y", "Z"]; +var expected = [ + void 0, "A", void 0, "B", void 0, "C", + obj2, + "X", "Y", "Z" +]; +var actual = SendableArray.prototype.concat.call(obj, obj2, arr); +assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected'); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_array-like-to-length-throws.js b/test/sendable/builtins/Array/prototype/concat/concat_array-like-to-length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9dd87a297db20f5254ea7872d0ecc4ce213fd215 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_array-like-to-length-throws.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat array like to length throws +features: [Symbol.isConcatSpreadable] +---*/ +var spreadableWithBrokenLength = { + "length": { + valueOf: null, + toString: null + }, + "1": "A", + "3": "B", + "5": "C" +}; +spreadableWithBrokenLength[Symbol.isConcatSpreadable] = true; +var obj2 = { + length: 3, + "0": "0", + "1": "1", + "2": "2" +}; +var arr = ["X", "Y", "Z"]; +assert.throws(TypeError, function() { + SendableArray.prototype.concat.call(spreadableWithBrokenLength, obj2, arr); +}, 'SendableArray.prototype.concat.call(spreadableWithBrokenLength, obj2, arr) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_array-like.js b/test/sendable/builtins/Array/prototype/concat/concat_array-like.js new file mode 100644 index 0000000000000000000000000000000000000000..4ac8174aceb681250b2d76dd115428a7422fb477 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_array-like.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat array like +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var obj = { + "length": 6, + "1": "A", + "3": "B", + "5": "C" +}; +obj[Symbol.isConcatSpreadable] = true; +var obj2 = { + length: 3, + "0": "0", + "1": "1", + "2": "2" +}; +var arr = ["X", "Y", "Z"]; +var expected = [ + void 0, "A", void 0, "B", void 0, "C", + obj2, + "X", "Y", "Z" +]; +var actual = SendableArray.prototype.concat.call(obj, obj2, arr); +assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected'); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_holey-sloppy-arguments.js b/test/sendable/builtins/Array/prototype/concat/concat_holey-sloppy-arguments.js new file mode 100644 index 0000000000000000000000000000000000000000..d8066ddcfae93caab434cc09e4ddee5f9166fdbe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_holey-sloppy-arguments.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat holey sloppy arguments +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var args = (function(a) { + return arguments; +})(1, 2, 3); +delete args[1]; +args[Symbol.isConcatSpreadable] = true; +assert.compareArray([1, void 0, 3, 1, void 0, 3], [].concat(args, args), + '[1, void 0, 3, 1, void 0, 3] must return the same value returned by [].concat(args, args)' +); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_large-typed-array.js b/test/sendable/builtins/Array/prototype/concat/concat_large-typed-array.js new file mode 100644 index 0000000000000000000000000000000000000000..d04f0dd7263c65c7775e39e853ef7d9e02393ef9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_large-typed-array.js @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat large typed array +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +function concatTypedArray(type, elems, modulo) { + var items = new SendableArray(elems); + var ta_by_len = new type(elems); + for (var i = 0; i < elems; ++i) { + ta_by_len[i] = items[i] = modulo === false ? i : elems % modulo; + } + var ta = new type(items); + assert.compareArray([].concat(ta, ta), [ta, ta]); + ta[Symbol.isConcatSpreadable] = true; + assert.compareArray([].concat(ta), items); + assert.compareArray([].concat(ta_by_len, ta_by_len), [ta_by_len, ta_by_len]); + ta_by_len[Symbol.isConcatSpreadable] = true; + assert.compareArray([].concat(ta_by_len), items); + // TypedArray with fake `length`. + ta = new type(1); + var defValue = ta[0]; + var expected = new SendableArray(4000); + expected[0] = defValue; + Object.defineProperty(ta, "length", { + value: 4000 + }); + ta[Symbol.isConcatSpreadable] = true; + assert.compareArray([].concat(ta), expected); +} +// Float16Array cannot be included in this because it cannot precisely represent integers above 2048 +var max = [Math.pow(2, 8), Math.pow(2, 16), Math.pow(2, 32), false, false]; +[ + Uint8Array, + Uint16Array, + Uint32Array, + Float32Array, + Float64Array +].forEach(function(ctor, i) { + concatTypedArray(ctor, 4000, max[i]); +}); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_length-throws.js b/test/sendable/builtins/Array/prototype/concat/concat_length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..8508593944ca6e4d2eed15315e09702d4e19d386 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_length-throws.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat length throws +features: [Symbol.isConcatSpreadable] +---*/ +var spreadablePoisonedLengthGetter = {}; +spreadablePoisonedLengthGetter[Symbol.isConcatSpreadable] = true; +Object.defineProperty(spreadablePoisonedLengthGetter, "length", { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + [].concat(spreadablePoisonedLengthGetter); +}, '[].concat(spreadablePoisonedLengthGetter) throws a Test262Error exception'); + +assert.throws(Test262Error, function() { + SendableArray.prototype.concat.call(spreadablePoisonedLengthGetter, 1, 2, 3); +}, 'SendableArray.prototype.concat.call(spreadablePoisonedLengthGetter, 1, 2, 3) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_no-prototype.js b/test/sendable/builtins/Array/prototype/concat/concat_no-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..a00b77353a4410893356bdcfe8ea2ac4ddd5763b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_no-prototype.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat no prototype +---*/ +assert.sameValue( + SendableArray.prototype.concat.prototype, + void 0, + 'The value of SendableArray.prototype.concat.prototype is expected to be void 0' +); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_non-array.js b/test/sendable/builtins/Array/prototype/concat/concat_non-array.js new file mode 100644 index 0000000000000000000000000000000000000000..a4d8260ccf270a5f4f99f7fc5f414887645b43c0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_non-array.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: array-concat-non-array +includes: [compareArray.js] +---*/ +// +// test262 --command "v8 --harmony-classes --harmony_object_literals" array-concat-non-array +// +class NonArray { + constructor() { + SendableArray.apply(this, arguments); + } +} + +var obj = new NonArray(1, 2, 3); +var result = SendableArray.prototype.concat.call(obj, 4, 5, 6); +assert.sameValue(SendableArray, result.constructor, 'The value of Array is expected to equal the value of result.constructor'); +assert.sameValue( + result instanceof NonArray, + false, + 'The result of evaluating (result instanceof NonArray) is expected to be false' +); +assert.compareArray(result, [obj, 4, 5, 6], 'The value of result is expected to be [obj, 4, 5, 6]'); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_sloppy-arguments-throws.js b/test/sendable/builtins/Array/prototype/concat/concat_sloppy-arguments-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..926648771812f47187ba86d427ff0ce2f6911e2a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_sloppy-arguments-throws.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat sloppy arguments throws +features: [Symbol.isConcatSpreadable] +---*/ +var args = (function(a) { + return arguments; +})(1, 2, 3); +Object.defineProperty(args, 0, { + get: function() { + throw new Test262Error(); + } +}); +args[Symbol.isConcatSpreadable] = true; +assert.throws(Test262Error, function() { + return [].concat(args, args); +}, 'return [].concat(args, args) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_sloppy-arguments-with-dupes.js b/test/sendable/builtins/Array/prototype/concat/concat_sloppy-arguments-with-dupes.js new file mode 100644 index 0000000000000000000000000000000000000000..35dbd1de8a519317947ebdd10fba04ae8744f4e3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_sloppy-arguments-with-dupes.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat sloppy arguments with dupes +flags: [noStrict] +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var args = (function(a, a, a) { + return arguments; +})(1, 2, 3); +args[Symbol.isConcatSpreadable] = true; +assert.compareArray([].concat(args, args), [1, 2, 3, 1, 2, 3], + '[].concat((function(a, a, a) {return arguments;})(1, 2, 3), (function(a, a, a) {return arguments;})(1, 2, 3)) must return [1, 2, 3, 1, 2, 3]' +); +Object.defineProperty(args, "length", { + value: 6 +}); +assert.compareArray([].concat(args), [1, 2, 3, void 0, void 0, void 0], + '[].concat((function(a, a, a) {return arguments;})(1, 2, 3)) must return [1, 2, 3, void 0, void 0, void 0]' +); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_sloppy-arguments.js b/test/sendable/builtins/Array/prototype/concat/concat_sloppy-arguments.js new file mode 100644 index 0000000000000000000000000000000000000000..daee5f4c937be1321c04837a2506e2ac008d5c9d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_sloppy-arguments.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat sloppy arguments +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var args = (function(a, b, c) { + return arguments; +})(1, 2, 3); +args[Symbol.isConcatSpreadable] = true; +assert.compareArray([].concat(args, args), [1, 2, 3, 1, 2, 3], + '[].concat((function(a, b, c) {return arguments;})(1, 2, 3), (function(a, b, c) {return arguments;})(1, 2, 3)) must return [1, 2, 3, 1, 2, 3]' +); +Object.defineProperty(args, "length", { + value: 6 +}); +assert.compareArray([].concat(args), [1, 2, 3, void 0, void 0, void 0], + '[].concat((function(a, b, c) {return arguments;})(1, 2, 3)) must return [1, 2, 3, void 0, void 0, void 0]' +); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_small-typed-array.js b/test/sendable/builtins/Array/prototype/concat/concat_small-typed-array.js new file mode 100644 index 0000000000000000000000000000000000000000..2c5e648f38c0be7c40026a855c26956366e8cf06 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_small-typed-array.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat small typed array +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +function concatTypedArray(type, elems, modulo) { + var items = new SendableArray(elems); + var ta_by_len = new type(elems); + for (var i = 0; i < elems; ++i) { + ta_by_len[i] = items[i] = modulo === false ? i : elems % modulo; + } + var ta = new type(items); + assert.compareArray([].concat(ta, ta), [ta, ta]); + ta[Symbol.isConcatSpreadable] = true; + assert.compareArray([].concat(ta), items); + assert.compareArray([].concat(ta_by_len, ta_by_len), [ta_by_len, ta_by_len]); + ta_by_len[Symbol.isConcatSpreadable] = true; + assert.compareArray([].concat(ta_by_len), items); + // TypedArray with fake `length`. + ta = new type(1); + var defValue = ta[0]; + var expected = new SendableArray(4000); + expected[0] = defValue; + Object.defineProperty(ta, "length", { + value: 4000 + }); + ta[Symbol.isConcatSpreadable] = true; + assert.compareArray([].concat(ta), expected); +} +var max = [Math.pow(2, 8), Math.pow(2, 16), Math.pow(2, 32), false, false]; +var TAs = [ + Uint8Array, + Uint16Array, + Uint32Array, + Float32Array, + Float64Array +]; +if (typeof Float16Array !== 'undefined') { + max.push(false); + TAs.push(Float16Array); +} + +TAs.forEach(function(ctor, i) { + concatTypedArray(ctor, 1, max[i]); +}); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_spreadable-boolean-wrapper.js b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-boolean-wrapper.js new file mode 100644 index 0000000000000000000000000000000000000000..b66af29d308da63bb83edc7d44ec1793250f097b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-boolean-wrapper.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat Symbol.isConcatSpreadable boolean wrapper +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var bool = new Boolean(true) +// Boolean wrapper objects are not concat-spreadable by default +assert.compareArray([bool], [].concat(bool), '[bool] must return the same value returned by [].concat(bool)'); +// Boolean wrapper objects may be individually concat-spreadable +bool[Symbol.isConcatSpreadable] = true; +bool.length = 3; +bool[0] = 1, bool[1] = 2, bool[2] = 3; +assert.compareArray([1, 2, 3], [].concat(bool), + '[1, 2, 3] must return the same value returned by [].concat(bool)' +); +Boolean.prototype[Symbol.isConcatSpreadable] = true; +// Boolean wrapper objects may be concat-spreadable +assert.compareArray([], [].concat(new Boolean(true)), + '[] must return the same value returned by [].concat(new Boolean(true))' +); +Boolean.prototype[0] = 1; +Boolean.prototype[1] = 2; +Boolean.prototype[2] = 3; +Boolean.prototype.length = 3; +assert.compareArray([1, 2, 3], [].concat(new Boolean(true)), + '[1, 2, 3] must return the same value returned by [].concat(new Boolean(true))' +); +// Boolean values are never concat-spreadable +assert.compareArray([true], [].concat(true), '[true] must return the same value returned by [].concat(true)'); +delete Boolean.prototype[Symbol.isConcatSpreadable]; +delete Boolean.prototype[0]; +delete Boolean.prototype[1]; +delete Boolean.prototype[2]; +delete Boolean.prototype.length; diff --git a/test/sendable/builtins/Array/prototype/concat/concat_spreadable-function.js b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-function.js new file mode 100644 index 0000000000000000000000000000000000000000..61f382e0879d06980d4e52f1562999f46ff452c4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-function.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat Symbol.isConcatSpreadable function +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var fn = function(a, b, c) {} +// Functions are not concat-spreadable by default +assert.compareArray([fn], [].concat(fn), '[fn] must return the same value returned by [].concat(fn)'); +// Functions may be individually concat-spreadable +fn[Symbol.isConcatSpreadable] = true; +fn[0] = 1, fn[1] = 2, fn[2] = 3; +assert.compareArray([1, 2, 3], [].concat(fn), '[1, 2, 3] must return the same value returned by [].concat(fn)'); +Function.prototype[Symbol.isConcatSpreadable] = true; +// Functions may be concat-spreadable +assert.compareArray([void 0, void 0, void 0], [].concat(function(a, b, c) {}), + '[void 0, void 0, void 0] must return the same value returned by [].concat(function(a, b, c) {})' +); +Function.prototype[0] = 1; +Function.prototype[1] = 2; +Function.prototype[2] = 3; +assert.compareArray([1, 2, 3], [].concat(function(a, b, c) {}), + '[1, 2, 3] must return the same value returned by [].concat(function(a, b, c) {})' +); +delete Function.prototype[Symbol.isConcatSpreadable]; +delete Function.prototype[0]; +delete Function.prototype[1]; +delete Function.prototype[2]; diff --git a/test/sendable/builtins/Array/prototype/concat/concat_spreadable-getter-throws.js b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-getter-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..383c711e2cce5e4ca65e24924b26614e309959b7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-getter-throws.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat Symbol.isConcatSpreadable getter throws +features: [Symbol.isConcatSpreadable] +---*/ +var spreadablePoisonedGetter = {}; +Object.defineProperty(spreadablePoisonedGetter, Symbol.isConcatSpreadable, { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + [].concat(spreadablePoisonedGetter); +}, '[].concat(spreadablePoisonedGetter) throws a Test262Error exception'); + +assert.throws(Test262Error, function() { + SendableArray.prototype.concat.call(spreadablePoisonedGetter, 1, 2, 3); +}, 'SendableArray.prototype.concat.call(spreadablePoisonedGetter, 1, 2, 3) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_spreadable-number-wrapper.js b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-number-wrapper.js new file mode 100644 index 0000000000000000000000000000000000000000..63db81933a6545cb8fa42832e8f58886e7b0e4e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-number-wrapper.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat Symbol.isConcatSpreadable number wrapper +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var num = new Number(true) +// Number wrapper objects are not concat-spreadable by default +assert.compareArray([num], [].concat(num), '[num] must return the same value returned by [].concat(num)'); +// Number wrapper objects may be individually concat-spreadable +num[Symbol.isConcatSpreadable] = true; +num.length = 3; +num[0] = 1, num[1] = 2, num[2] = 3; +assert.compareArray([1, 2, 3], [].concat(num), '[1, 2, 3] must return the same value returned by [].concat(num)'); +Number.prototype[Symbol.isConcatSpreadable] = true; +// Number wrapper objects may be concat-spreadable +assert.compareArray([], [].concat(new Number(123)), + '[] must return the same value returned by [].concat(new Number(123))' +); +Number.prototype[0] = 1; +Number.prototype[1] = 2; +Number.prototype[2] = 3; +Number.prototype.length = 3; +assert.compareArray([1, 2, 3], [].concat(new Number(123)), + '[1, 2, 3] must return the same value returned by [].concat(new Number(123))' +); +// Number values are never concat-spreadable +assert.compareArray([true], [].concat(true), '[true] must return the same value returned by [].concat(true)'); +delete Number.prototype[Symbol.isConcatSpreadable]; +delete Number.prototype[0]; +delete Number.prototype[1]; +delete Number.prototype[2]; +delete Number.prototype.length; diff --git a/test/sendable/builtins/Array/prototype/concat/concat_spreadable-reg-exp.js b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-reg-exp.js new file mode 100644 index 0000000000000000000000000000000000000000..fc3ca84d0f41202c82e92fb76250a1b77d217f6c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-reg-exp.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat Symbol.isConcatSpreadable reg exp +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var re = /abc/; +// RegExps are not concat-spreadable by default +assert.compareArray([].concat(re), [re], '[].concat(/abc/) must return [re]'); +// RegExps may be individually concat-spreadable +re[Symbol.isConcatSpreadable] = true; +re[0] = 1, re[1] = 2, re[2] = 3, re.length = 3; +assert.compareArray([].concat(re), [1, 2, 3], '[].concat(/abc/) must return [1, 2, 3]'); +// RegExps may be concat-spreadable +RegExp.prototype[Symbol.isConcatSpreadable] = true; +RegExp.prototype.length = 3; +assert.compareArray([].concat(/abc/), [void 0, void 0, void 0], + '[].concat(/abc/) must return [void 0, void 0, void 0]' +); +RegExp.prototype[0] = 1; +RegExp.prototype[1] = 2; +RegExp.prototype[2] = 3; +assert.compareArray([].concat(/abc/), [1, 2, 3], + '[].concat(/abc/) must return [1, 2, 3]' +); +delete RegExp.prototype[Symbol.isConcatSpreadable]; +delete RegExp.prototype[0]; +delete RegExp.prototype[1]; +delete RegExp.prototype[2]; +delete RegExp.prototype.length; diff --git a/test/sendable/builtins/Array/prototype/concat/concat_spreadable-sparse-object.js b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-sparse-object.js new file mode 100644 index 0000000000000000000000000000000000000000..89b7435721319233f19dd6c8de31c98b6763a30a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-sparse-object.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat Symbol.isConcatSpreadable sparse object +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var obj = { + length: 5 +}; +obj[Symbol.isConcatSpreadable] = true; +assert.compareArray([void 0, void 0, void 0, void 0, void 0], [].concat(obj), + '[void 0, void 0, void 0, void 0, void 0] must return the same value returned by [].concat(obj)' +); +obj.length = 4000; +assert.compareArray(new SendableArray(4000), [].concat(obj), + 'new SendableArray(4000) must return the same value returned by [].concat(obj)' +); diff --git a/test/sendable/builtins/Array/prototype/concat/concat_spreadable-string-wrapper.js b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-string-wrapper.js new file mode 100644 index 0000000000000000000000000000000000000000..c84fac1b7ba2f28c1270543e56467f1efdcd645b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_spreadable-string-wrapper.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat Symbol.isConcatSpreadable string wrapper +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var str1 = new String("yuck\uD83D\uDCA9") +// String wrapper objects are not concat-spreadable by default +assert.compareArray([str1], [].concat(str1), '[str1] must return the same value returned by [].concat(str1)'); +// String wrapper objects may be individually concat-spreadable +str1[Symbol.isConcatSpreadable] = true; +assert.compareArray(["y", "u", "c", "k", "\uD83D", "\uDCA9"], [].concat(str1), + '["y", "u", "c", "k", "uD83D", "uDCA9"] must return the same value returned by [].concat(str1)' +); +String.prototype[Symbol.isConcatSpreadable] = true; +// String wrapper objects may be concat-spreadable +assert.compareArray(["y", "u", "c", "k", "\uD83D", "\uDCA9"], [].concat(new String("yuck\uD83D\uDCA9")), + '["y", "u", "c", "k", "uD83D", "uDCA9"] must return the same value returned by [].concat(new String("yuckuD83DuDCA9"))' +); +// String values are never concat-spreadable +assert.compareArray(["yuck\uD83D\uDCA9"], [].concat("yuck\uD83D\uDCA9"), + '["yuckuD83DuDCA9"] must return the same value returned by [].concat("yuckuD83DuDCA9")' +); +delete String.prototype[Symbol.isConcatSpreadable]; diff --git a/test/sendable/builtins/Array/prototype/concat/concat_strict-arguments.js b/test/sendable/builtins/Array/prototype/concat/concat_strict-arguments.js new file mode 100644 index 0000000000000000000000000000000000000000..3017642060ea312ef99e1eb8ceb385b42e2f608d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/concat_strict-arguments.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Array.prototype.concat strict arguments +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ +var args = (function(a, b, c) { + "use strict"; + return arguments; +})(1, 2, 3); +args[Symbol.isConcatSpreadable] = true; +assert.compareArray([].concat(args, args), [1, 2, 3, 1, 2, 3], + '[].concat("(function(a, b, c) {"use strict"; return arguments;})(1, 2, 3)", "(function(a, b, c) {"use strict"; return arguments;})(1, 2, 3)") must return [1, 2, 3, 1, 2, 3]' +); +Object.defineProperty(args, "length", { + value: 6 +}); +assert.compareArray([].concat(args), [1, 2, 3, void 0, void 0, void 0], + '[].concat("(function(a, b, c) {"use strict"; return arguments;})(1, 2, 3)") must return [1, 2, 3, void 0, void 0, void 0]' +); diff --git a/test/sendable/builtins/Array/prototype/concat/create-ctor-non-object.js b/test/sendable/builtins/Array/prototype/concat/create-ctor-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..40fd42325ca4a050f4d9edcf0a300cffd2b53845 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-ctor-non-object.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + Behavior when `constructor` property is neither an Object nor undefined +info: | + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + + 9.4.2.3 ArraySpeciesCreate + + [...] + 5. Let C be ? Get(originalArray, "constructor"). + [...] + 9. If IsConstructor(C) is false, throw a TypeError exception. +---*/ +var a = []; +a.constructor = null; +assert.throws(TypeError, function() { + a.concat(); +}, 'a.concat() throws a TypeError exception'); +a = []; +a.constructor = 1; +assert.throws(TypeError, function() { + a.concat(); +}, 'a.concat() throws a TypeError exception'); +a = []; +a.constructor = 'string'; +assert.throws(TypeError, function() { + a.concat(); +}, 'a.concat() throws a TypeError exception'); +a = []; +a.constructor = true; +assert.throws(TypeError, function() { + a.concat(); +}, 'a.concat() throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-ctor-poisoned.js b/test/sendable/builtins/Array/prototype/concat/create-ctor-poisoned.js new file mode 100644 index 0000000000000000000000000000000000000000..6b8a080a721e863d057bb946c5e2a1d6b2499291 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-ctor-poisoned.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Abrupt completion from `constructor` property access +info: | + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + 9.4.2.3 ArraySpeciesCreate + [...] + 5. Let C be ? Get(originalArray, "constructor"). +---*/ + +var a = []; +Object.defineProperty(a, 'constructor', { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + a.concat(); +}, 'a.concat() throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-non-array.js b/test/sendable/builtins/Array/prototype/concat/create-non-array.js new file mode 100644 index 0000000000000000000000000000000000000000..e67eff8dd70a4db2e356f23a6896b1ed6880d949 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-non-array.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Constructor is ignored for non-Array values +info: | + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + 9.4.2.3 ArraySpeciesCreate + [...] + 3. Let isArray be ? IsArray(originalArray). + 4. If isArray is false, return ? ArrayCreate(length). +---*/ + +var obj = { + length: 0 +}; +var callCount = 0; +var result; +Object.defineProperty(obj, 'constructor', { + get: function() { + callCount += 1; + } +}); +result = SendableArray.prototype.concat.call(obj); +assert.sameValue(callCount, 0, 'The value of callCount is expected to be 0'); +assert.sameValue( + Object.getPrototypeOf(result), + SendableArray.prototype, + 'Object.getPrototypeOf(SendableArray.prototype.concat.call(obj)) returns SendableArray.prototype' +); +assert(SendableArray.isArray(result), 'SendableArray.isArray(result) must return true'); +assert.sameValue(result.length, 1, 'The value of result.length is expected to be 1'); +assert.sameValue(result[0], obj, 'The value of result[0] is expected to equal the value of obj'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-proto-from-ctor-realm-array.js b/test/sendable/builtins/Array/prototype/concat/create-proto-from-ctor-realm-array.js new file mode 100644 index 0000000000000000000000000000000000000000..13160e5d50fa4d6d55d9daa30d8346b50d7fb6ce --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-proto-from-ctor-realm-array.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Prefer Array constructor of current realm record +info: | + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + [...] + 9.4.2.3 ArraySpeciesCreate + [...] + 5. Let C be ? Get(originalArray, "constructor"). + 6. If IsConstructor(C) is true, then + a. Let thisRealm be the current Realm Record. + b. Let realmC be ? GetFunctionRealm(C). + c. If thisRealm and realmC are not the same Realm Record, then + i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, let C + be undefined. + [...] +features: [cross-realm, Symbol.species] +---*/ + +var array = []; +var callCount = 0; +var OArray = $262.createRealm().global.Array; +var speciesDesc = { + get: function() { + callCount += 1; + } +}; +var result; +array.constructor = OArray; + +Object.defineProperty(SendableArray, Symbol.species, speciesDesc); +Object.defineProperty(OArray, Symbol.species, speciesDesc); + +result = array.concat(); + +assert.sameValue( + Object.getPrototypeOf(result), + SendableArray.prototype, + 'Object.getPrototypeOf(array.concat()) returns Array.prototype' +); +assert.sameValue(callCount, 0, 'The value of callCount is expected to be 0'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-proto-from-ctor-realm-non-array.js b/test/sendable/builtins/Array/prototype/concat/create-proto-from-ctor-realm-non-array.js new file mode 100644 index 0000000000000000000000000000000000000000..45da43f570c2e875894b5aac6671a305e7636272 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-proto-from-ctor-realm-non-array.js @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Accept non-Array constructors from other realms +info: | + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + [...] + 9.4.2.3 ArraySpeciesCreate + [...] + 5. Let C be ? Get(originalArray, "constructor"). + 6. If IsConstructor(C) is true, then + a. Let thisRealm be the current Realm Record. + b. Let realmC be ? GetFunctionRealm(C). + c. If thisRealm and realmC are not the same Realm Record, then + i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, let C + be undefined. + [...] +features: [cross-realm, Symbol.species] +---*/ + +var array = []; +var callCount = 0; +var CustomCtor = function() {}; +var OObject = $262.createRealm().global.Object; +var speciesDesc = { + get: function() { + callCount += 1; + } +}; +var result; +array.constructor = OObject; +OObject[Symbol.species] = CustomCtor; + +Object.defineProperty(SendableArray, Symbol.species, speciesDesc); + +result = array.concat(); + +assert.sameValue( + Object.getPrototypeOf(result), + CustomCtor.prototype, + 'Object.getPrototypeOf(array.concat()) returns CustomCtor.prototype' +); +assert.sameValue(callCount, 0, 'The value of callCount is expected to be 0'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-proxy.js b/test/sendable/builtins/Array/prototype/concat/create-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..467ee3bb8ec544b2330bf0758bfaf183cefbfaf5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-proxy.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Species constructor of a Proxy object whose target is an array +info: | + [...] + 2. Let A be ? ArraySpeciesCreate(O, 0). + [...] + 7. Return A. + 9.4.2.3 ArraySpeciesCreate + [...] + 3. Let isArray be ? IsArray(originalArray). + 7.2.2 IsArray + [...] + 3. If argument is a Proxy exotic object, then + a. If the value of the [[ProxyHandler]] internal slot of argument is + null, throw a TypeError exception. + b. Let target be the value of the [[ProxyTarget]] internal slot of + argument. + c. Return ? IsArray(target). +features: [Proxy, Symbol.species] +---*/ + +var array = []; +var proxy = new Proxy(new Proxy(array, {}), {}); +var Ctor = function() {}; +var result; + +array.constructor = function() {}; +array.constructor[Symbol.species] = Ctor; + +result = SendableArray.prototype.concat.call(proxy); + +assert.sameValue( + Object.getPrototypeOf(result), + Ctor.prototype, + 'Object.getPrototypeOf(Array.prototype.concat.call(proxy)) returns Ctor.prototype' +); diff --git a/test/sendable/builtins/Array/prototype/concat/create-revoked-proxy.js b/test/sendable/builtins/Array/prototype/concat/create-revoked-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..e457cfe784391d4da462c2d4cf5414167b386447 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-revoked-proxy.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Abrupt completion from constructor that is a revoked Proxy object +info: | + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + 9.4.2.3 ArraySpeciesCreate + [...] + 3. Let isArray be ? IsArray(originalArray). + 7.2.2 IsArray + [...] + 3. If argument is a Proxy exotic object, then + a. If the value of the [[ProxyHandler]] internal slot of argument is + null, throw a TypeError exception. +features: [Proxy] +---*/ + +var o = Proxy.revocable([], {}); +var callCount = 0; +Object.defineProperty(o.proxy, 'constructor', { + get: function() { + callCount += 1; + } +}); +o.revoke(); +assert.throws(TypeError, function() { + SendableArray.prototype.concat.call(o.proxy); +}, 'SendableArray.prototype.concat.call(o.proxy) throws a TypeError exception'); +assert.sameValue(callCount, 0, 'The value of callCount is expected to be 0'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species-abrupt.js b/test/sendable/builtins/Array/prototype/concat/create-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..ae29a921b02a5520c5dcbbb293170bc0552a2f7f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species-abrupt.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Species constructor returns an abrupt completion +info: | + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + 9.4.2.3 ArraySpeciesCreate + [...] + 5. Let C be ? Get(originalArray, "constructor"). + [...] + 7. If Type(C) is Object, then + a. Let C be ? Get(C, @@species). + b. If C is null, let C be undefined. + [...] + 10. Return ? Construct(C, « length »). +features: [Symbol.species] +---*/ + +var Ctor = function() { + throw new Test262Error(); +}; +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; +assert.throws(Test262Error, function() { + a.concat(); +}, 'a.concat() throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species-non-ctor.js b/test/sendable/builtins/Array/prototype/concat/create-species-non-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..507a2c2607c32480667795c37920205d978ca871 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species-non-ctor.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + Behavior when the @@species attribute is a non-constructor object +info: | + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + 9.4.2.3 ArraySpeciesCreate + 5. Let C be ? Get(originalArray, "constructor"). + 7. If Type(C) is Object, then + a. Let C be ? Get(C, @@species). + b. If C is null, let C be undefined. + 9. If IsConstructor(C) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Symbol.species, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(parseInt), + false, + 'precondition: isConstructor(parseInt) must return false' +); +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = parseInt; +assert.throws(TypeError, function() { + a.concat(); +}, 'a.concat() throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species-non-extensible-spreadable.js b/test/sendable/builtins/Array/prototype/concat/create-species-non-extensible-spreadable.js new file mode 100644 index 0000000000000000000000000000000000000000..491c46d627e2c6c4d8688abfa51299912911aedc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species-non-extensible-spreadable.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + TypeError is thrown if CreateDataProperty fails. + (result object is non-extensible, argument is spreadable) +info: | + Array.prototype.concat ( ...arguments ) + 5. Repeat, while items is not empty + c. If spreadable is true, then + iv. Repeat, while k < len + 3. If exists is true, then + b. Perform ? CreateDataPropertyOrThrow(A, ! ToString(n), subElement). + CreateDataPropertyOrThrow ( O, P, V ) + 3. Let success be ? CreateDataProperty(O, P, V). + 4. If success is false, throw a TypeError exception. +features: [Symbol.species] +---*/ + +var A = function(_length) { + this.length = 0; + Object.preventExtensions(this); +}; +var arr = []; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.concat([1]); +}, 'arr.concat([1]) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species-non-extensible.js b/test/sendable/builtins/Array/prototype/concat/create-species-non-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..a45e4f1d59bad176e39c4ce0d2374f0f6cd411a7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species-non-extensible.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.concat +description: > + TypeError is thrown if CreateDataProperty fails. + (result object is non-extensible, argument is not spreadable) +info: | + Array.prototype.concat ( ...arguments ) + 5. Repeat, while items is not empty + c. If spreadable is true, then + d. Else, + iii. Perform ? CreateDataPropertyOrThrow(A, ! ToString(n), E). + CreateDataPropertyOrThrow ( O, P, V ) + 3. Let success be ? CreateDataProperty(O, P, V). + 4. If success is false, throw a TypeError exception. +features: [Symbol.species] +---*/ + +var A = function(_length) { + this.length = 0; + Object.preventExtensions(this); +}; +var arr = []; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.concat(1); +}, 'arr.concat(1) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species-null.js b/test/sendable/builtins/Array/prototype/concat/create-species-null.js new file mode 100644 index 0000000000000000000000000000000000000000..78d0bd32185891280837e594d6e574288225a89e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species-null.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + A null value for the @@species constructor is interpreted as `undefined` +info: | + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + 9.4.2.3 ArraySpeciesCreate + [...] + 5. Let C be ? Get(originalArray, "constructor"). + [...] + 7. If Type(C) is Object, then + a. Let C be ? Get(C, @@species). + b. If C is null, let C be undefined. + 8. If C is undefined, return ? ArrayCreate(length). +features: [Symbol.species] +---*/ + +var a = []; +var result; +a.constructor = {}; +a.constructor[Symbol.species] = null; +result = a.concat(); +assert.sameValue( + Object.getPrototypeOf(result), + SendableArray.prototype, + 'Object.getPrototypeOf(a.concat()) returns SendableArray.prototype' +); +assert(SendableArray.isArray(result), 'SendableArray.isArray(result) must return true'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species-poisoned.js b/test/sendable/builtins/Array/prototype/concat/create-species-poisoned.js new file mode 100644 index 0000000000000000000000000000000000000000..1774333caaee3df24b047885bb99080d16137ac8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species-poisoned.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Abrupt completion from `@@species` property access +info: | + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + 9.4.2.3 ArraySpeciesCreate + 5. Let C be ? Get(originalArray, "constructor"). + 7. If Type(C) is Object, then + a. Let C be ? Get(C, @@species). +features: [Symbol.species] +---*/ + +var a = []; +a.constructor = {}; +Object.defineProperty(a.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + a.concat(); +}, 'a.concat() throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species-undef.js b/test/sendable/builtins/Array/prototype/concat/create-species-undef.js new file mode 100644 index 0000000000000000000000000000000000000000..e017fac43314865819a5b3ca93a44a2c4728041e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species-undef.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + An undefined value for the @@species constructor triggers the creation of + an Array exotic object +info: | + 9. Let A be ? ArraySpeciesCreate(O, actualDeleteCount). + 9.4.2.3 ArraySpeciesCreate + 5. Let C be ? Get(originalArray, "constructor"). + 7. If Type(C) is Object, then + a. Let C be ? Get(C, @@species). + b. If C is null, let C be undefined. + 8. If C is undefined, return ? ArrayCreate(length). +features: [Symbol.species] +---*/ + +var a = []; +var result; +a.constructor = {}; +a.constructor[Symbol.species] = undefined; +result = a.concat(); +assert.sameValue( + Object.getPrototypeOf(result), + SendableArray.prototype, + 'Object.getPrototypeOf(a.concat()) returns SendableArray.prototype' +); +assert(SendableArray.isArray(result), 'SendableArray.isArray(result) must return true'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species-with-non-configurable-property-spreadable.js b/test/sendable/builtins/Array/prototype/concat/create-species-with-non-configurable-property-spreadable.js new file mode 100644 index 0000000000000000000000000000000000000000..6f58108196b405c5f70400d758f5b5d0e88b3e75 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species-with-non-configurable-property-spreadable.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + TypeError is thrown if CreateDataProperty fails. + (result object's "0" is non-configurable, argument is spreadable) +info: | + Array.prototype.concat ( ...arguments ) + 5. Repeat, while items is not empty + c. If spreadable is true, then + iv. Repeat, while k < len + 3. If exists is true, then + b. Perform ? CreateDataPropertyOrThrow(A, ! ToString(n), subElement). + CreateDataPropertyOrThrow ( O, P, V ) + 3. Let success be ? CreateDataProperty(O, P, V). + 4. If success is false, throw a TypeError exception. +features: [Symbol.species] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + writable: true, + configurable: false, + }); +}; +var arr = []; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.concat([1]); +}, 'arr.concat([1]) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species-with-non-configurable-property.js b/test/sendable/builtins/Array/prototype/concat/create-species-with-non-configurable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..79ed2b767de4c3c81a1eb2e9fb0a439571ef4f24 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species-with-non-configurable-property.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + TypeError is thrown if CreateDataProperty fails. + (result object's "0" is non-configurable, argument is non-spreadable) +info: | + Array.prototype.concat ( ...arguments ) + 5. Repeat, while items is not empty + c. If spreadable is true, then + d. Else, + iii. Perform ? CreateDataPropertyOrThrow(A, ! ToString(n), E). + CreateDataPropertyOrThrow ( O, P, V ) + 3. Let success be ? CreateDataProperty(O, P, V). + 4. If success is false, throw a TypeError exception. +features: [Symbol.species] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + set: function(_value) {}, + configurable: false, + }); +}; +var arr = []; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.concat(1); +}, 'arr.concat(1) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species-with-non-writable-property-spreadable.js b/test/sendable/builtins/Array/prototype/concat/create-species-with-non-writable-property-spreadable.js new file mode 100644 index 0000000000000000000000000000000000000000..fdaf8760053141747716f56c7263635b706de39f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species-with-non-writable-property-spreadable.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + Non-writable properties are overwritten by CreateDataProperty. + (result object's "0" is non-writable, argument is spreadable) +info: | + Array.prototype.concat ( ...arguments ) + 5. Repeat, while items is not empty + c. If spreadable is true, then + iv. Repeat, while k < len + 3. If exists is true, then + b. Perform ? CreateDataPropertyOrThrow(A, ! ToString(n), subElement). +features: [Symbol.species] +includes: [propertyHelper.js] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + value: 1, + writable: false, + enumerable: false, + configurable: true, + }); +}; +var arr = []; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +var res = arr.concat([2]); +verifyProperty(res, "0", { + value: 2, + writable: true, + enumerable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species-with-non-writable-property.js b/test/sendable/builtins/Array/prototype/concat/create-species-with-non-writable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..b9b1e6b74aac4e8d384baac059b9195c4ef2559c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species-with-non-writable-property.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + Non-writable properties are overwritten by CreateDataProperty. + (result object's "0" is non-writable, argument is not spreadable) +info: | + Array.prototype.concat ( ...arguments ) + 5. Repeat, while items is not empty + c. If spreadable is true, then + iv. Repeat, while k < len + 3. If exists is true, then + b. Perform ? CreateDataPropertyOrThrow(A, ! ToString(n), subElement). +features: [Symbol.species] +includes: [propertyHelper.js] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + value: 1, + writable: false, + enumerable: false, + configurable: true, + }); +}; +var arr = []; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +var res = arr.concat(2); +verifyProperty(res, "0", { + value: 2, + writable: true, + enumerable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/concat/create-species.js b/test/sendable/builtins/Array/prototype/concat/create-species.js new file mode 100644 index 0000000000000000000000000000000000000000..f1191afbccb8392e5303f30bc5c4e2b1203d015a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/create-species.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Species constructor is used to create a new instance +info: | + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + 9.4.2.3 ArraySpeciesCreate + 5. Let C be ? Get(originalArray, "constructor"). + 7. If Type(C) is Object, then + a. Let C be ? Get(C, @@species). + b. If C is null, let C be undefined. + 10. Return ? Construct(C, « length »). +features: [Symbol.species] +---*/ + +var thisValue, args, result; +var callCount = 0; +var instance = []; +var Ctor = function() { + callCount += 1; + thisValue = this; + args = arguments; + return instance; +}; +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; +result = a.concat(); +assert.sameValue(callCount, 1, 'The value of callCount is expected to be 1'); +assert.sameValue( + Object.getPrototypeOf(thisValue), + Ctor.prototype, + 'Object.getPrototypeOf(this) returns Ctor.prototype' +); +assert.sameValue(args.length, 1, 'The value of args.length is expected to be 1'); +assert.sameValue(args[0], 0, 'The value of args[0] is expected to be 0'); +assert.sameValue(result, instance, 'The value of result is expected to equal the value of instance'); diff --git a/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-get-err.js b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-get-err.js new file mode 100644 index 0000000000000000000000000000000000000000..a2d1447246c45be7ed1a395b5e47401d39d6370c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-get-err.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: Error thrown when accessing `Symbol.isConcatSpreadable` property +info: | + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let A be ArraySpeciesCreate(O, 0). + 4. ReturnIfAbrupt(A). + 5. Let n be 0. + 6. Let items be a List whose first element is O and whose subsequent + elements are, in left to right order, the arguments that were passed to + this function invocation. + 7. Repeat, while items is not empty + a. Remove the first element from items and let E be the value of the element. + b. Let spreadable be IsConcatSpreadable(E). + c. ReturnIfAbrupt(spreadable). + ES6 22.1.3.1.1: Runtime Semantics: IsConcatSpreadable ( O ) + 1. If Type(O) is not Object, return false. + 2. Let spreadable be Get(O, @@isConcatSpreadable). + 3. ReturnIfAbrupt(spreadable). +features: [Symbol.isConcatSpreadable] +---*/ + +var o = {}; +Object.defineProperty(o, Symbol.isConcatSpreadable, { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.concat.call(o); +}, 'SendableArray.prototype.concat.call(o) throws a Test262Error exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-get-order.js b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-get-order.js new file mode 100644 index 0000000000000000000000000000000000000000..4d7ae64937ca21a56c184acc2a529dc510fff4f9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-get-order.js @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + Symbol.isConcatSpreadable should be looked up once for `this value` and + once for each argument, after ArraySpeciesCreate routine. +info: | + Array.prototype.concat ( ...arguments ) + 1. Let O be ? ToObject(this value). + 2. Let A be ? ArraySpeciesCreate(O, 0). + 5. Repeat, while items is not empty + a. Remove the first element from items and let E be the value of the element. + b. Let spreadable be ? IsConcatSpreadable(E). + ArraySpeciesCreate ( originalArray, length ) + 5. Let C be ? Get(originalArray, "constructor"). + Runtime Semantics: IsConcatSpreadable ( O ) + 1. If Type(O) is not Object, return false. + 2. Let spreadable be ? Get(O, @@isConcatSpreadable). +includes: [compareArray.js] +features: [Symbol.isConcatSpreadable] +---*/ + +var calls = []; +var descConstructor = { + get: function() { + calls.push("constructor"); + return Array; + }, + configurable: true, +}; +var descSpreadable = { + get: function() { + calls.push("isConcatSpreadable"); + }, + configurable: true, +}; +var arr1 = []; +Object.defineProperty(arr1, "constructor", descConstructor); +Object.defineProperty(arr1, Symbol.isConcatSpreadable, descSpreadable); + +assert.compareArray(arr1.concat(1), [1], 'arr1.concat(1) must return [1]'); +assert.compareArray( + calls, + ["constructor", "isConcatSpreadable"], + 'The value of calls is expected to be ["constructor", "isConcatSpreadable"]' +); +calls = []; +var arr2 = []; +var arg = {}; +Object.defineProperty(arr2, "constructor", descConstructor); +Object.defineProperty(arg, Symbol.isConcatSpreadable, descSpreadable); +assert.compareArray(arr2.concat(arg), [arg], 'arr2.concat({}) must return [arg]'); +assert.compareArray( + calls, + ["constructor", "isConcatSpreadable"], + 'The value of calls is expected to be ["constructor", "isConcatSpreadable"]' +); diff --git a/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-is-array-proxy-revoked.js b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-is-array-proxy-revoked.js new file mode 100644 index 0000000000000000000000000000000000000000..e0609ac012d10f0316566ee7f5ce1e6a2647c7df --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-is-array-proxy-revoked.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-isconcatspreadable +description: Revoked proxy value produces a TypeError when supplied to IsArray +info: | + 5. Repeat, while items is not empty + a. Remove the first element from items and let E be the value of the + element. + b. Let spreadable be ? IsConcatSpreadable(E). + c. If spreadable is true, then + e. Else E is added as a single item rather than spread, + ES6 22.1.3.1.1: Runtime Semantics: IsConcatSpreadable ( O ) + 1. If Type(O) is not Object, return false. + 2. Let spreadable be ? Get(O, @@isConcatSpreadable). + 3. If spreadable is not undefined, return ToBoolean(spreadable). + 4. Return ? IsArray(O). + 7.2.2 IsArray + 3. If argument is a Proxy exotic object, then + a. If the value of the [[ProxyHandler]] internal slot of argument is null, + throw a TypeError exception. + b. Let target be the value of the [[ProxyTarget]] internal slot of + argument. + c. Return ? IsArray(target). +features: [Proxy, Symbol.isConcatSpreadable] +---*/ + +var target = []; +var handle = Proxy.revocable(target, { + get: function(_, key) { + // Defer proxy revocation until after property access to ensure that the + // expected TypeError originates from the IsArray operation. + if (key === Symbol.isConcatSpreadable) { + handle.revoke(); + } + return target[key]; + } +}); +assert.throws(TypeError, function() { + [].concat(handle.proxy); +}, '[].concat(handle.proxy) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-proxy-revoked.js b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-proxy-revoked.js new file mode 100644 index 0000000000000000000000000000000000000000..d3c4e8b3f967f9dfb6f6886929646286a2a44205 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-proxy-revoked.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-isconcatspreadable +description: > + Revoked proxy value produces a TypeError during access of + `Symbol.isConcatSpreadable` property +info: | + 5. Repeat, while items is not empty + a. Remove the first element from items and let E be the value of the + element. + b. Let spreadable be ? IsConcatSpreadable(E). + c. If spreadable is true, then + e. Else E is added as a single item rather than spread, + ES6 22.1.3.1.1: Runtime Semantics: IsConcatSpreadable ( O ) + 1. If Type(O) is not Object, return false. + 2. Let spreadable be ? Get(O, @@isConcatSpreadable). + 7.3.1 Get + 3. Return ? O.[[Get]](P, O). + 9.5.8 [[Get]] + 2. Let handler be O.[[ProxyHandler]]. + 3. If handler is null, throw a TypeError exception. +features: [Proxy] +---*/ + +var handle = Proxy.revocable([], {}); +handle.revoke(); +assert.throws(TypeError, function() { + [].concat(handle.proxy); +}, '[].concat(handle.proxy) throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-proxy.js b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..6119460a388b1328acea7480244508af8a5e7410 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-proxy.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-isconcatspreadable +description: > + Proxies who final targets are arrays are considered spreadable +info: | + 5. Repeat, while items is not empty + a. Remove the first element from items and let E be the value of the + element. + b. Let spreadable be ? IsConcatSpreadable(E). + c. If spreadable is true, then + e. Else E is added as a single item rather than spread, + ES6 22.1.3.1.1: Runtime Semantics: IsConcatSpreadable ( O ) + 1. If Type(O) is not Object, return false. + 2. Let spreadable be ? Get(O, @@isConcatSpreadable). + 3. If spreadable is not undefined, return ToBoolean(spreadable). + 4. Return ? IsArray(O). + 7.2.2 IsArray + 3. If argument is a Proxy exotic object, then + a. If the value of the [[ProxyHandler]] internal slot of argument is null, + throw a TypeError exception. + b. Let target be the value of the [[ProxyTarget]] internal slot of + argument. + c. Return ? IsArray(target). +features: [Proxy, Symbol.isConcatSpreadable] +---*/ + +var arrayProxy = new Proxy([], {}); +var arrayProxyProxy = new Proxy(arrayProxy, {}); +var spreadable = {}; +spreadable[Symbol.isConcatSpreadable] = true; +var spreadableProxy = new Proxy(spreadable, {}); +assert.sameValue([].concat(arrayProxy).length, 0, 'The value of [].concat(arrayProxy).length is expected to be 0'); +assert.sameValue( + [].concat(arrayProxyProxy).length, 0, 'The value of [].concat(arrayProxyProxy).length is expected to be 0' +); +assert.sameValue( + [].concat(spreadableProxy).length, + 0, + 'The value of [].concat(spreadableProxy).length is expected to be 0' +); diff --git a/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-val-falsey.js b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-val-falsey.js new file mode 100644 index 0000000000000000000000000000000000000000..149be4ce8c66b8736ac7543f25d5d152498313dd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-val-falsey.js @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + The `Symbol.isConcatSpreadable` property is defined and coerces to `false` +info: | + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let A be ArraySpeciesCreate(O, 0). + 4. ReturnIfAbrupt(A). + 5. Let n be 0. + 6. Let items be a List whose first element is O and whose subsequent + elements are, in left to right order, the arguments that were passed to + this function invocation. + 7. Repeat, while items is not empty + a. Remove the first element from items and let E be the value of the element. + b. Let spreadable be IsConcatSpreadable(E). + c. ReturnIfAbrupt(spreadable). + d. If spreadable is true, then + e. Else E is added as a single item rather than spread, + ES6 22.1.3.1.1: Runtime Semantics: IsConcatSpreadable ( O ) + 1. If Type(O) is not Object, return false. + 2. Let spreadable be Get(O, @@isConcatSpreadable). + 3. ReturnIfAbrupt(spreadable). + 4. If spreadable is not undefined, return ToBoolean(spreadable). +features: [Symbol.isConcatSpreadable] +---*/ + +var item = [1, 2]; +var result; +item[Symbol.isConcatSpreadable] = null; +result = [].concat(item); +assert.sameValue(result.length, 1, 'The value of result.length is expected to be 1'); +assert.sameValue(result[0], item, 'The value of result[0] is expected to equal the value of item'); +item[Symbol.isConcatSpreadable] = false; +result = [].concat(item); +assert.sameValue(result.length, 1, 'The value of result.length is expected to be 1'); +assert.sameValue(result[0], item, 'The value of result[0] is expected to equal the value of item'); +item[Symbol.isConcatSpreadable] = 0; +result = [].concat(item); +assert.sameValue(result.length, 1, 'The value of result.length is expected to be 1'); +assert.sameValue(result[0], item, 'The value of result[0] is expected to equal the value of item'); +item[Symbol.isConcatSpreadable] = NaN; +result = [].concat(item); +assert.sameValue(result.length, 1, 'The value of result.length is expected to be 1'); +assert.sameValue(result[0], item, 'The value of result[0] is expected to equal the value of item'); diff --git a/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-val-truthy.js b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-val-truthy.js new file mode 100644 index 0000000000000000000000000000000000000000..91eed2edd46856e1c74d7aacce7adca59903020d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-val-truthy.js @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + The `Symbol.isConcatSpreadable` property is defined and coerces to `true` +info: | + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let A be ArraySpeciesCreate(O, 0). + 4. ReturnIfAbrupt(A). + 5. Let n be 0. + 6. Let items be a List whose first element is O and whose subsequent + elements are, in left to right order, the arguments that were passed to + this function invocation. + 7. Repeat, while items is not empty + a. Remove the first element from items and let E be the value of the element. + b. Let spreadable be IsConcatSpreadable(E). + c. ReturnIfAbrupt(spreadable). + d. If spreadable is true, then + ES6 22.1.3.1.1: Runtime Semantics: IsConcatSpreadable ( O ) + 1. If Type(O) is not Object, return false. + 2. Let spreadable be Get(O, @@isConcatSpreadable). + 3. ReturnIfAbrupt(spreadable). + 4. If spreadable is not undefined, return ToBoolean(spreadable). +features: [Symbol, Symbol.isConcatSpreadable] +---*/ + +var item = {}; +var result; +item[Symbol.isConcatSpreadable] = true; +result = [].concat(item); +assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0'); +item[Symbol.isConcatSpreadable] = 86; +result = [].concat(item); +assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0'); +item[Symbol.isConcatSpreadable] = 'string'; +result = [].concat(item); +assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0'); +item[Symbol.isConcatSpreadable] = Symbol(); +result = [].concat(item); +assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0'); +item[Symbol.isConcatSpreadable] = {}; +result = [].concat(item); +assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0'); diff --git a/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-val-undefined.js b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-val-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..9ff95202f7f9c4e279fa58e7ed6095ed81d143b5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/is-concat-spreadable-val-undefined.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + The `Symbol.isConcatSpreadable` property is defined as the value `undefined` +info: | + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let A be ArraySpeciesCreate(O, 0). + 4. ReturnIfAbrupt(A). + 5. Let n be 0. + 6. Let items be a List whose first element is O and whose subsequent + elements are, in left to right order, the arguments that were passed to + this function invocation. + 7. Repeat, while items is not empty + a. Remove the first element from items and let E be the value of the element. + b. Let spreadable be IsConcatSpreadable(E). + c. ReturnIfAbrupt(spreadable). + d. If spreadable is true, then + e. Else E is added as a single item rather than spread, + ES6 22.1.3.1.1: Runtime Semantics: IsConcatSpreadable ( O ) + 1. If Type(O) is not Object, return false. + 2. Let spreadable be Get(O, @@isConcatSpreadable). + 3. ReturnIfAbrupt(spreadable). + 4. If spreadable is not undefined, return ToBoolean(spreadable). + 5. Return IsArray(O). +features: [Symbol.isConcatSpreadable] +---*/ + +var item = []; +var result; +item[Symbol.isConcatSpreadable] = undefined; +result = [].concat(item); +assert.sameValue(result.length, 0, 'The value of result.length is expected to be 0'); diff --git a/test/sendable/builtins/Array/prototype/concat/length.js b/test/sendable/builtins/Array/prototype/concat/length.js new file mode 100644 index 0000000000000000000000000000000000000000..451db021d76aa9cacdec1c9b51bd979fec69c335 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/length.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + The "length" property of Array.prototype.concat +info: | + 22.1.3.1 Array.prototype.concat ( ...arguments ) + The length property of the concat method is 1. + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.concat, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/concat/name.js b/test/sendable/builtins/Array/prototype/concat/name.js new file mode 100644 index 0000000000000000000000000000000000000000..84fa9722666f7dbbf857082904b8b5dcbfac109c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + Array.prototype.concat.name is "concat". +info: | + Array.prototype.concat ( ...arguments ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.concat, "name", { + value: "concat", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/concat/not-a-constructor.js b/test/sendable/builtins/Array/prototype/concat/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..cad5cabacda91b137330c7655b6bf1e17f81b6d7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.concat does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.concat), + false, + 'isConstructor(SendableArray.prototype.concat) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.concat([]); +}, 'new SendableArray.prototype.concat([]) throws a TypeError exception'); + diff --git a/test/sendable/builtins/Array/prototype/concat/prop-desc.js b/test/sendable/builtins/Array/prototype/concat/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..79bc394b32e72ccf7de4f57ff1fa4c48912aa306 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/concat/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.concat +description: > + "concat" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.concat, 'function', 'The value of `typeof SendableArray.prototype.concat` is expected to be "function"'); +verifyProperty(SendableArray.prototype, "concat", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/constructor.js b/test/sendable/builtins/Array/prototype/constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..6419736e75e0314674d9dd111e5e9153760b7627 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.constructor +description: > + Array.prototype.constructor +info: | + 22.1.3.2 Array.prototype.constructor + The initial value of Array.prototype.constructor is the intrinsic object %Array%. + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(SendableArray.prototype.constructor, SendableArray); +verifyProperty(SendableArray.prototype, "constructor", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/call-with-boolean.js b/test/sendable/builtins/Array/prototype/copyWithin/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..8bd0d38e2b570c1b9aec56737e02aa97a676c943 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copyWithin +description: Array.prototype.copyWithin applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.copyWithin.call(true) instanceof Boolean, + true, + 'The result of evaluating (SendableArray.prototype.copyWithin.call(true) instanceof Boolean) is expected to be true' +); +assert.sameValue( + SendableArray.prototype.copyWithin.call(false) instanceof Boolean, + true, + 'The result of evaluating (SendableArray.prototype.copyWithin.call(false) instanceof Boolean) is expected to be true' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-end.js b/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-end.js new file mode 100644 index 0000000000000000000000000000000000000000..f0275398a5d04c09c3f8ca0d7657132c7be42123 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-end.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + end argument is coerced to an integer values. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 11. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0, null), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(1, 0, null) must return [0, 1, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0, NaN), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(1, 0, NaN) must return [0, 1, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0, false), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(1, 0, false) must return [0, 1, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0, true), [0, 0, 2, 3], + '[0, 1, 2, 3].copyWithin(1, 0, true) must return [0, 0, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0, '-2'), [0, 0, 1, 3], + '[0, 1, 2, 3].copyWithin(1, 0, "-2") must return [0, 0, 1, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0, -2.5), [0, 0, 1, 3], + '[0, 1, 2, 3].copyWithin(1, 0, -2.5) must return [0, 0, 1, 3]' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-start-change-start.js b/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-start-change-start.js new file mode 100644 index 0000000000000000000000000000000000000000..0549639c96d520a585de8d2d9d5b911cd68aa842 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-start-change-start.js @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + SECURITY: start argument is coerced to an integer value + and side effects change the length of the array so that + the start is out of bounds +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 8. Let relativeStart be ToInteger(start). +includes: [compareArray.js] +---*/ + + +// make a long integer Array +function longDenseArray(){ + var a = [0]; + for(var i = 0; i < 1024; i++){ + a[i] = i; + } + return a; +} +function shorten(){ + currArray.length = 20; + return 1000; +} +var array = []; +array.length = 20; +var currArray = longDenseArray(); +assert.compareArray( + currArray.copyWithin(0, {valueOf: shorten}), array, + 'currArray.copyWithin(0, {valueOf: shorten}) returns array' +); +currArray = longDenseArray(); +Object.setPrototypeOf(currArray, longDenseArray()); +var array2 = longDenseArray(); +array2.length = 20; +for(var i = 0; i < 24; i++){ + array2[i] = Object.getPrototypeOf(currArray)[i+1000]; +} +assert.compareArray( + currArray.copyWithin(0, {valueOf: shorten}), array2, + 'currArray.copyWithin(0, {valueOf: shorten}) returns array2' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-start-change-target.js b/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-start-change-target.js new file mode 100644 index 0000000000000000000000000000000000000000..3eac18b6462a80a922e9e687e1c0837328ca1aa1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-start-change-target.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + SECURITY: start argument is coerced to an integer value + and side effects change the length of the array so that + the target is out of bounds +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 8. Let relativeStart be ToInteger(start). +includes: [compareArray.js] +---*/ + +// make a long integer Array +function longDenseArray(){ + var a = [0]; + for(var i = 0; i < 1024; i++){ + a[i] = i; + } + return a; +} +function shorten(){ + currArray.length = 20; + return 1; +} +var array = longDenseArray(); +array.length = 20; +for(var i = 0; i < 19; i++){ + array[i+1000] = array[i+1]; +} +var currArray = longDenseArray(); +assert.compareArray( + currArray.copyWithin(1000, {valueOf: shorten}), array, + 'currArray.copyWithin(1000, {valueOf: shorten}) returns array' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-start.js b/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-start.js new file mode 100644 index 0000000000000000000000000000000000000000..e4209ef8022b7026e29e80dd4d69654043e21a83 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-start.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + start argument is coerced to an integer value. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 8. Let relativeStart be ToInteger(start). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, undefined), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(1, undefined) must return [0, 0, 1, 2]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, false), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(1, false) must return [0, 0, 1, 2]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, NaN), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(1, NaN) must return [0, 0, 1, 2]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, null), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(1, null) must return [0, 0, 1, 2]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, true), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, true) must return [1, 2, 3, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, '1'), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, "1") must return [1, 2, 3, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0.5), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(1, 0.5) must return [0, 0, 1, 2]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 1.5), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, 1.5) must return [1, 2, 3, 3]' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-target.js b/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-target.js new file mode 100644 index 0000000000000000000000000000000000000000..ef2ccb4a8427d06fadfd878d863a987703f1feed --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/coerced-values-target.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + target argument is coerced to an integer value. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 5. Let relativeTarget be ToInteger(target). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(undefined, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(undefined, 1) must return [1, 2, 3, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(false, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(false, 1) must return [1, 2, 3, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(NaN, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(NaN, 1) must return [1, 2, 3, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(null, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(null, 1) must return [1, 2, 3, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(true, 0), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(true, 0) must return [0, 0, 1, 2]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin('1', 0), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin("1", 0) must return [0, 0, 1, 2]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(0.5, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0.5, 1) must return [1, 2, 3, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(1.5, 0), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(1.5, 0) must return [0, 0, 1, 2]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin({}, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin({}, 1) must return [1, 2, 3, 3]' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/fill-holes.js b/test/sendable/builtins/Array/prototype/copyWithin/fill-holes.js new file mode 100644 index 0000000000000000000000000000000000000000..e40908fbf6b9b4e7fda7faaf975ba14074cd3cb3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/fill-holes.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Loop from each property, even empty holes. +---*/ + +var arr = [0, 1, , , 1]; +arr.copyWithin(0, 1, 4); +assert.sameValue(arr.length, 5); +assert.sameValue(arr[0], 1); +assert.sameValue(arr[4], 1); +assert.sameValue(arr.hasOwnProperty(1), false); +assert.sameValue(arr.hasOwnProperty(2), false); +assert.sameValue(arr.hasOwnProperty(3), false); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/length-near-integer-limit.js b/test/sendable/builtins/Array/prototype/copyWithin/length-near-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..c0612cb287c5a405eba7ef0169d249def4cf0b37 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/length-near-integer-limit.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.copywithin +description: > + Elements are copied and deleted in an array-like object + whose "length" property is near the integer limit. +info: | + Array.prototype.copyWithin ( target, start [ , end ] ) + 1. Let O be ? ToObject(this value). + 2. Let len be ? LengthOfArrayLike(O). + 9. Let count be min(final - from, len - to). + 12. Repeat, while count > 0 + d. If fromPresent is true, then + i. Let fromVal be ? Get(O, fromKey). + ii. Perform ? Set(O, toKey, fromVal, true). + e. Else, + i. Assert: fromPresent is false. + ii. Perform ? DeletePropertyOrThrow(O, toKey). +---*/ + +var startIndex = Number.MAX_SAFE_INTEGER - 3; +var arrayLike = { + 0: 0, + 1: 1, + 2: 2, + length: Number.MAX_SAFE_INTEGER, +}; +arrayLike[startIndex] = -3; +arrayLike[startIndex + 2] = -1; +SendableArray.prototype.copyWithin.call(arrayLike, 0, startIndex, startIndex + 3); +assert.sameValue(arrayLike[0], -3); +assert.sameValue(1 in arrayLike, false); +assert.sameValue(arrayLike[2], -1); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/length.js b/test/sendable/builtins/Array/prototype/copyWithin/length.js new file mode 100644 index 0000000000000000000000000000000000000000..6cd39a1650c36ca86bb39cb4a23bf030b0af126a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/length.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: Array.prototype.copyWithin.length value and descriptor. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + The length property of the copyWithin method is 2. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.copyWithin, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/name.js b/test/sendable/builtins/Array/prototype/copyWithin/name.js new file mode 100644 index 0000000000000000000000000000000000000000..ea5b69be7f3046e099723987c94e9b7214661e5e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/name.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Array.prototype.copyWithin.name value and descriptor. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.copyWithin, "name", { + value: "copyWithin", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/negative-end.js b/test/sendable/builtins/Array/prototype/copyWithin/negative-end.js new file mode 100644 index 0000000000000000000000000000000000000000..2a5fd4a2d78c5ee2fc7849f1ca3c150db0d904d2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/negative-end.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Set values with negative end argument. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 11. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 12. ReturnIfAbrupt(relativeEnd). + 13. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let + final be min(relativeEnd, len). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 1, -1), [1, 2, 2, 3], + '[0, 1, 2, 3].copyWithin(0, 1, -1) must return [1, 2, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(2, 0, -1), [0, 1, 0, 1, 2], + '[0, 1, 2, 3, 4].copyWithin(2, 0, -1) must return [0, 1, 0, 1, 2]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(1, 2, -2), [0, 2, 2, 3, 4], + '[0, 1, 2, 3, 4].copyWithin(1, 2, -2) must return [0, 2, 2, 3, 4]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, -2, -1), [2, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(0, -2, -1) must return [2, 1, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(2, -2, -1), [0, 1, 3, 3, 4], + '[0, 1, 2, 3, 4].copyWithin(2, -2, -1) must return [0, 1, 3, 3, 4]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(-3, -2, -1), [0, 2, 2, 3], + '[0, 1, 2, 3].copyWithin(-3, -2, -1) must return [0, 2, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(-2, -3, -1), [0, 1, 2, 2, 3], + '[0, 1, 2, 3, 4].copyWithin(-2, -3, -1) must return [0, 1, 2, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(-5, -2, -1), [3, 1, 2, 3, 4], + '[0, 1, 2, 3, 4].copyWithin(-5, -2, -1) must return [3, 1, 2, 3, 4]' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/negative-out-of-bounds-end.js b/test/sendable/builtins/Array/prototype/copyWithin/negative-out-of-bounds-end.js new file mode 100644 index 0000000000000000000000000000000000000000..9c4db4cf19360787538714e28554bd224d359637 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/negative-out-of-bounds-end.js @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Set values with negative out of bounds end argument. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 11. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 12. ReturnIfAbrupt(relativeEnd). + 13. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let + final be min(relativeEnd, len). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 1, -10), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(0, 1, -10) must return [0, 1, 2, 3]' +); +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity) must return [1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, -2, -10), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(0, -2, -10) must return [0, 1, 2, 3]' +); +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity) must return [1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, -9, -10), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(0, -9, -10) must return [0, 1, 2, 3]' +); +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity) must return [1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(-3, -2, -10), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(-3, -2, -10) must return [0, 1, 2, 3]' +); +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity) must return [1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(-7, -8, -9), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(-7, -8, -9) must return [0, 1, 2, 3]' +); +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity) must return [1, 2, 3, 4, 5]' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/negative-out-of-bounds-start.js b/test/sendable/builtins/Array/prototype/copyWithin/negative-out-of-bounds-start.js new file mode 100644 index 0000000000000000000000000000000000000000..b8479b2ba4759896ce874c75622769e788d049aa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/negative-out-of-bounds-start.js @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Set values with out of bounds negative start argument. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 10. If relativeStart < 0, let from be max((len + relativeStart),0); else let + from be min(relativeStart, len). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, -10), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(0, -10) must return [0, 1, 2, 3]' +); +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(0, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(0, -Infinity) must return [1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(2, -10), [0, 1, 0, 1, 2], + '[0, 1, 2, 3, 4].copyWithin(2, -10) must return [0, 1, 0, 1, 2]' +); +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(2, -Infinity), [1, 2, 1, 2, 3], + '[1, 2, 3, 4, 5].copyWithin(2, -Infinity) must return [1, 2, 1, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(10, -10), [0, 1, 2, 3, 4], + '[0, 1, 2, 3, 4].copyWithin(10, -10) must return [0, 1, 2, 3, 4]' +); +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(10, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(10, -Infinity) must return [1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(-9, -10), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(-9, -10) must return [0, 1, 2, 3]' +); +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(-9, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(-9, -Infinity) must return [1, 2, 3, 4, 5]' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/negative-out-of-bounds-target.js b/test/sendable/builtins/Array/prototype/copyWithin/negative-out-of-bounds-target.js new file mode 100644 index 0000000000000000000000000000000000000000..48eea8e9faba99f715b80086d4ae8b06ac284a86 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/negative-out-of-bounds-target.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Set values with out of bounds negative target argument. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to + be min(relativeTarget, len). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(-10, 0), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(-10, 0) must return [0, 1, 2, 3]' +); +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(-Infinity, 0), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 0) must return [1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(-10, 2), [2, 3, 4, 3, 4], + '[0, 1, 2, 3, 4].copyWithin(-10, 2) must return [2, 3, 4, 3, 4]' +); +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(-Infinity, 2), [3, 4, 5, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 2) must return [3, 4, 5, 4, 5]' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/negative-start.js b/test/sendable/builtins/Array/prototype/copyWithin/negative-start.js new file mode 100644 index 0000000000000000000000000000000000000000..ebf4103fe6eada94aecf89e328f0b5c7c7d05b78 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/negative-start.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Set values with negative start argument. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 10. If relativeStart < 0, let from be max((len + relativeStart),0); else let + from be min(relativeStart, len). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, -1), [3, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(0, -1) must return [3, 1, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(2, -2), [0, 1, 3, 4, 4], + '[0, 1, 2, 3, 4].copyWithin(2, -2) must return [0, 1, 3, 4, 4]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(1, -2), [0, 3, 4, 3, 4], + '[0, 1, 2, 3, 4].copyWithin(1, -2) must return [0, 3, 4, 3, 4]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(-1, -2), [0, 1, 2, 2], + '[0, 1, 2, 3].copyWithin(-1, -2) must return [0, 1, 2, 2]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(-2, -3), [0, 1, 2, 2, 3], + '[0, 1, 2, 3, 4].copyWithin(-2, -3) must return [0, 1, 2, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(-5, -2), [3, 4, 2, 3, 4], + '[0, 1, 2, 3, 4].copyWithin(-5, -2) must return [3, 4, 2, 3, 4]' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/negative-target.js b/test/sendable/builtins/Array/prototype/copyWithin/negative-target.js new file mode 100644 index 0000000000000000000000000000000000000000..31cd0a25296b066f1ef935c8950aff0fc5cb413e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/negative-target.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Set values with negative target argument. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to + be min(relativeTarget, len). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(-1, 0), [0, 1, 2, 0], + '[0, 1, 2, 3].copyWithin(-1, 0) must return [0, 1, 2, 0]' +); +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(-2, 2), [0, 1, 2, 2, 3], + '[0, 1, 2, 3, 4].copyWithin(-2, 2) must return [0, 1, 2, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(-1, 2), [0, 1, 2, 2], + '[0, 1, 2, 3].copyWithin(-1, 2) must return [0, 1, 2, 2]' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/non-negative-out-of-bounds-end.js b/test/sendable/builtins/Array/prototype/copyWithin/non-negative-out-of-bounds-end.js new file mode 100644 index 0000000000000000000000000000000000000000..c754d03447cfb268ea135cd9f1fc112b925dcf64 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/non-negative-out-of-bounds-end.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Max value of end position is the this.length. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to + be min(relativeTarget, len). + 10. If relativeStart < 0, let from be max((len + relativeStart),0); else let + from be min(relativeStart, len). + 11. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 14. Let count be min(final-from, len-to). + 15. If from 0 + a. If fromPresent is true, then + i. Let fromVal be Get(O, fromKey). + iii. Let setStatus be Set(O, toKey, fromVal, true). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 1, 6), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, 1, 6) must return [1, 2, 3, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 1, Infinity), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, 1, Infinity) must return [1, 2, 3, 3]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(1, 3, 6), [0, 3, 4, 5, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 6) must return [0, 3, 4, 5, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(1, 3, Infinity), [0, 3, 4, 5, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, Infinity) must return [0, 3, 4, 5, 4, 5]' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js b/test/sendable/builtins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js new file mode 100644 index 0000000000000000000000000000000000000000..c2f831b19576fdb993914912a937a3163a9d449b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Max values of target and start positions are this.length. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to + be min(relativeTarget, len). + 10. If relativeStart < 0, let from be max((len + relativeStart),0); else let + from be min(relativeStart, len). + 11. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 14. Let count be min(final-from, len-to). + 15. If from 0 +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(6, 0), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(6, 0) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(7, 0), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(7, 0) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(Infinity, 0), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(Infinity, 0) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(6, 2), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(6, 2) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(7, 2), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(7, 2) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(Infinity, 2), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(Infinity, 2) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(0, 6), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(0, 6) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(0, 7), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(0, 7) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(0, Infinity), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(0, Infinity) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(2, 6), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(2, 6) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(1, 7), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(1, 7) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(3, Infinity), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(3, Infinity) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(6, 6), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(6, 6) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(10, 10), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(10, 10) must return [0, 1, 2, 3, 4, 5]' +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(Infinity, Infinity), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(Infinity, Infinity) must return [0, 1, 2, 3, 4, 5]' +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/non-negative-target-and-start.js b/test/sendable/builtins/Array/prototype/copyWithin/non-negative-target-and-start.js new file mode 100644 index 0000000000000000000000000000000000000000..cdbb2bf72646962d2e722dd96e849b2aee3e2eac --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/non-negative-target-and-start.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Copy values with non-negative target and start positions. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to + be min(relativeTarget, len). + 10. If relativeStart < 0, let from be max((len + relativeStart),0); else let + from be min(relativeStart, len). + 11. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 14. Let count be min(final-from, len-to). + 15. If from 0 + a. If fromPresent is true, then + i. Let fromVal be Get(O, fromKey). + iii. Let setStatus be Set(O, toKey, fromVal, true). +includes: [compareArray.js] +---*/ + +assert.compareArray( + ['a', 'b', 'c', 'd', 'e', 'f'].copyWithin(0, 0), + ['a', 'b', 'c', 'd', 'e', 'f'] +); +assert.compareArray( + ['a', 'b', 'c', 'd', 'e', 'f'].copyWithin(0, 2), + ['c', 'd', 'e', 'f', 'e', 'f'] +); +assert.compareArray( + ['a', 'b', 'c', 'd', 'e', 'f'].copyWithin(3, 0), + ['a', 'b', 'c', 'a', 'b', 'c'] +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(1, 4), + [0, 4, 5, 3, 4, 5] +); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/non-negative-target-start-and-end.js b/test/sendable/builtins/Array/prototype/copyWithin/non-negative-target-start-and-end.js new file mode 100644 index 0000000000000000000000000000000000000000..df2eade4820dfff772746b4e731de566dcfd9fab --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/non-negative-target-start-and-end.js @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Copy values with non-negative target, start and end positions. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to + be min(relativeTarget, len). + 10. If relativeStart < 0, let from be max((len + relativeStart),0); else let + from be min(relativeStart, len). + 11. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 14. Let count be min(final-from, len-to). + 15. If from 0 + a. If fromPresent is true, then + i. Let fromVal be Get(O, fromKey). + iii. Let setStatus be Set(O, toKey, fromVal, true). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 0, 0), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(0, 0, 0) must return [0, 1, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 0, 2), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(0, 0, 2) must return [0, 1, 2, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 1, 2), [1, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(0, 1, 2) must return [1, 1, 2, 3]' +); +/* + * 15. If from + Array.prototype.copyWithin does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.copyWithin), + false, + 'isConstructor(SendableArray.prototype.copyWithin) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.copyWithin(); +}); + diff --git a/test/sendable/builtins/Array/prototype/copyWithin/prop-desc.js b/test/sendable/builtins/Array/prototype/copyWithin/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..e81bb713cfb5814e6bd94f7f3ae931805a4d5274 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/prop-desc.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: Property type and descriptor. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.copyWithin, + 'function', + '`typeof SendableArray.prototype.copyWithin` is `function`' +); +verifyProperty(SendableArray.prototype, "copyWithin", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/resizable-buffer.js b/test/sendable/builtins/Array/prototype/copyWithin/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..ef9982c13a1a1e9df9b37cafa96f0f1bef23d413 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/resizable-buffer.js @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Array.p.copyWithin behaves correctly when the receiver is backed by + resizable buffer +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const ArrayCopyWithinHelper = (ta, ...rest) => { + Array.prototype.copyWithin.call(ta, ...rest); +}; +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + // Orig. array: [0, 1, 2, 3] + // [0, 1, 2, 3] << fixedLength + // [2, 3] << fixedLengthWithOffset + // [0, 1, 2, 3, ...] << lengthTracking + // [2, 3, ...] << lengthTrackingWithOffset + ArrayCopyWithinHelper(fixedLength, 0, 2); + assert.compareArray(ToNumbers(fixedLength), [ + 2, + 3, + 2, + 3 + ]); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + ArrayCopyWithinHelper(fixedLengthWithOffset, 0, 1); + assert.compareArray(ToNumbers(fixedLengthWithOffset), [ + 3, + 3 + ]); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + ArrayCopyWithinHelper(lengthTracking, 0, 2); + assert.compareArray(ToNumbers(lengthTracking), [ + 2, + 3, + 2, + 3 + ]); + ArrayCopyWithinHelper(lengthTrackingWithOffset, 0, 1); + assert.compareArray(ToNumbers(lengthTrackingWithOffset), [ + 3, + 3 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 3; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + // Orig. array: [0, 1, 2] + // [0, 1, 2, ...] << lengthTracking + // [2, ...] << lengthTrackingWithOffset + + assert.compareArray(ToNumbers(fixedLength), []); + assert.compareArray(ToNumbers(fixedLengthWithOffset), []); + + ArrayCopyWithinHelper(fixedLength, 0, 1); + ArrayCopyWithinHelper(fixedLengthWithOffset, 0, 1); + // We'll check below that these were no-op. + assert.compareArray(ToNumbers(fixedLength), []); + assert.compareArray(ToNumbers(fixedLengthWithOffset), []); + assert.compareArray(ToNumbers(lengthTracking), [ + 0, + 1, + 2 + ]); + ArrayCopyWithinHelper(lengthTracking, 0, 1); + assert.compareArray(ToNumbers(lengthTracking), [ + 1, + 2, + 2 + ]); + ArrayCopyWithinHelper(lengthTrackingWithOffset, 0, 1); + assert.compareArray(ToNumbers(lengthTrackingWithOffset), [2]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + taWrite[0] = MayNeedBigInt(taWrite, 0); + ArrayCopyWithinHelper(fixedLength, 0, 1, 1); + ArrayCopyWithinHelper(fixedLengthWithOffset, 0, 1, 1); + ArrayCopyWithinHelper(lengthTrackingWithOffset, 0, 1, 1); + assert.compareArray(ToNumbers(lengthTracking), [0]); + ArrayCopyWithinHelper(lengthTracking, 0, 0, 1); + assert.compareArray(ToNumbers(lengthTracking), [0]); + // Shrink to zero. + rab.resize(0); + ArrayCopyWithinHelper(fixedLength, 0, 1, 1); + ArrayCopyWithinHelper(fixedLengthWithOffset, 0, 1, 1); + ArrayCopyWithinHelper(lengthTrackingWithOffset, 0, 1, 1); + assert.compareArray(ToNumbers(lengthTracking), []); + ArrayCopyWithinHelper(lengthTracking, 0, 0, 1); + assert.compareArray(ToNumbers(lengthTracking), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + // Orig. array: [0, 1, 2, 3, 4, 5] + // [0, 1, 2, 3] << fixedLength + // [2, 3] << fixedLengthWithOffset + // [0, 1, 2, 3, 4, 5, ...] << lengthTracking + // [2, 3, 4, 5, ...] << lengthTrackingWithOffset + ArrayCopyWithinHelper(fixedLength, 0, 2); + assert.compareArray(ToNumbers(fixedLength), [ + 2, + 3, + 2, + 3 + ]); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + ArrayCopyWithinHelper(fixedLengthWithOffset, 0, 1); + assert.compareArray(ToNumbers(fixedLengthWithOffset), [ + 3, + 3 + ]); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + // [0, 1, 2, 3, 4, 5, ...] << lengthTracking + // target ^ ^ start + ArrayCopyWithinHelper(lengthTracking, 0, 2); + assert.compareArray(ToNumbers(lengthTracking), [ + 2, + 3, + 4, + 5, + 4, + 5 + ]); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + // [2, 3, 4, 5, ...] << lengthTrackingWithOffset + // target ^ ^ start + ArrayCopyWithinHelper(lengthTrackingWithOffset, 0, 1); + assert.compareArray(ToNumbers(lengthTrackingWithOffset), [ + 3, + 4, + 5, + 5 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.js new file mode 100644 index 0000000000000000000000000000000000000000..7d4c8d648b719fa483696aad37093a38141f1b39 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from deleting property value - using Proxy +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 17. Repeat, while count > 0 + a. Let fromKey be ToString(from). + b. Let toKey be ToString(to). + c. Let fromPresent be HasProperty(O, fromKey). + f. Else fromPresent is false, + i. Let deleteStatus be DeletePropertyOrThrow(O, toKey). + ii. ReturnIfAbrupt(deleteStatus). +features: [Proxy] +---*/ + +var o = { + '42': true, + length: 43 +}; +var p = new Proxy(o, { + deleteProperty: function(t, prop) { + if (prop === '42') { + throw new Test262Error(); + } + } +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.copyWithin.call(p, 42, 0); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js new file mode 100644 index 0000000000000000000000000000000000000000..fd9fa51f9dee1953f9c6e84f88ab826da8702146 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from deleting property value on DeletePropertyOrThrow(O, toKey). +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 17. Repeat, while count > 0 + a. Let fromKey be ToString(from). + b. Let toKey be ToString(to). + c. Let fromPresent be HasProperty(O, fromKey). + f. Else fromPresent is false, + i. Let deleteStatus be DeletePropertyOrThrow(O, toKey). + ii. ReturnIfAbrupt(deleteStatus). +---*/ + +var o = { + length: 43 +}; +Object.defineProperty(o, '42', { + configurable: false, + writable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.copyWithin.call(o, 42, 0); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..37e5cbbb6ee946fea0f740c31b6823fb6d0f454f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from end as a Symbol. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 11. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 12. ReturnIfAbrupt(relativeEnd). +features: [Symbol] +---*/ + +var s = Symbol(1); +assert.throws(TypeError, function() { + [].copyWithin(0, 0, s); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-end.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-end.js new file mode 100644 index 0000000000000000000000000000000000000000..69335b1fb8321d830db194799f0e92a7e0674a99 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-end.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from ToInteger(end). +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 11. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 12. ReturnIfAbrupt(relativeEnd). +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; +assert.throws(Test262Error, function() { + [].copyWithin(0, 0, o1); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js new file mode 100644 index 0000000000000000000000000000000000000000..432b3c195d1bbd35b21fcda20466a84301f1e045 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from getting property value - Get(O, fromKey). +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 8. Let relativeStart be ToInteger(start). + 9. ReturnIfAbrupt(relativeStart). + 10. If relativeStart < 0, let from be max((len + relativeStart),0); else let + from be min(relativeStart, len). + 17. Repeat, while count > 0 + a. Let fromKey be ToString(from). + b. Let toKey be ToString(to). + c. Let fromPresent be HasProperty(O, fromKey). + d. ReturnIfAbrupt(fromPresent). + e. If fromPresent is true, then + i. Let fromVal be Get(O, fromKey). + ii. ReturnIfAbrupt(fromVal). +---*/ + +var o = { + length: 1 +}; +Object.defineProperty(o, '0', { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.copyWithin.call(o, 0, 0); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-has-start.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-has-start.js new file mode 100644 index 0000000000000000000000000000000000000000..355e362c7f1c1bec9dfadff01a6984c73be743e7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-has-start.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from HasProperty(O, fromKey). +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 8. Let relativeStart be ToInteger(start). + 9. ReturnIfAbrupt(relativeStart). + 10. If relativeStart < 0, let from be max((len + relativeStart),0); else let + from be min(relativeStart, len). + 17. Repeat, while count > 0 + a. Let fromKey be ToString(from). + b. Let toKey be ToString(to). + c. Let fromPresent be HasProperty(O, fromKey). + d. ReturnIfAbrupt(fromPresent). +features: [Proxy] +---*/ + +var o = { + '0': 42, + length: 1 +}; +var p = new Proxy(o, { + has: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.copyWithin.call(p, 0, 0); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.js new file mode 100644 index 0000000000000000000000000000000000000000..60eb00022351b01f0156052cbb6eaf9c1583ba7c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from setting property value - Set(O, toKey, fromVal, true). +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 5. Let relativeTarget be ToInteger(target). + 6. ReturnIfAbrupt(relativeTarget). + 7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to + be min(relativeTarget, len). + 17. Repeat, while count > 0 + a. Let fromKey be ToString(from). + b. Let toKey be ToString(to). + e. If fromPresent is true, then + iii. Let setStatus be Set(O, toKey, fromVal, true). + iv. ReturnIfAbrupt(setStatus). +---*/ + +var o = { + '0': true, + length: 43 +}; +Object.defineProperty(o, '42', { + set: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.copyWithin.call(o, 42, 0); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..c4e762b6c03571f7f8b97414dac0845d89ce3557 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from start as a Symbol. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 8. Let relativeStart be ToInteger(start). + 9. ReturnIfAbrupt(relativeStart). +features: [Symbol] +---*/ + +var s = Symbol(1); +assert.throws(TypeError, function() { + [].copyWithin(0, s); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-start.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-start.js new file mode 100644 index 0000000000000000000000000000000000000000..8dde6149dd78b6907a9ea3aac179ae2b5b991fc1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-start.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from ToInteger(start). +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 8. Let relativeStart be ToInteger(start). + 9. ReturnIfAbrupt(relativeStart). +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; +assert.throws(Test262Error, function() { + [].copyWithin(0, o1); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..3811276777b193cc4502399eb1877f437282e9b8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from target as a Symbol. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 5. Let relativeTarget be ToInteger(target). + 6. ReturnIfAbrupt(relativeTarget). +features: [Symbol] +---*/ + +var s = Symbol(1); +assert.throws(TypeError, function() { + [].copyWithin(s, 0); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-target.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-target.js new file mode 100644 index 0000000000000000000000000000000000000000..b7c6938c246741368efb65788d07236c551d6b16 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-target.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from ToInteger(target). +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 5. Let relativeTarget be ToInteger(target). + 6. ReturnIfAbrupt(relativeTarget). +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; +assert.throws(Test262Error, function() { + [].copyWithin(o1); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..00632a63cd97306696b1320e61db01f391391492 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from ToLength(Get(O, "length")) where length is a Symbol. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let len be ToLength(Get(O, "length")). + 4. ReturnIfAbrupt(len). +features: [Symbol] +---*/ + +var o = {}; +o.length = Symbol(1); +// value argument is given to avoid false positives +assert.throws(TypeError, function() { + [].copyWithin.call(o, 0, 0); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-this-length.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-this-length.js new file mode 100644 index 0000000000000000000000000000000000000000..34bf17a0f6e9b081e0410f64b196fefdf4e00e6e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-this-length.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from ToLength(Get(O, "length")). +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let len be ToLength(Get(O, "length")). + 4. ReturnIfAbrupt(len). +---*/ + +var o1 = {}; +Object.defineProperty(o1, 'length', { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + [].copyWithin.call(o1); +}); +var o2 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; +assert.throws(Test262Error, function() { + [].copyWithin.call(o2); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-this.js b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-this.js new file mode 100644 index 0000000000000000000000000000000000000000..80b63dd1632ac80478aa705321a329f3565e8ceb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-abrupt-from-this.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Return abrupt from ToObject(this value). +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.copyWithin.call(undefined, 0, 0); +}); +assert.throws(TypeError, function() { + SendableArray.prototype.copyWithin.call(null, 0, 0); +}); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/return-this.js b/test/sendable/builtins/Array/prototype/copyWithin/return-this.js new file mode 100644 index 0000000000000000000000000000000000000000..24190bdf40afb682778d7543d7d0a5b595eb9343 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/return-this.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + Returns `this`. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 18. Return O. +---*/ + +var arr = []; +var result = arr.copyWithin(0, 0); +assert.sameValue(result, arr); +var o = { + length: 0 +}; +result = SendableArray.prototype.copyWithin.call(o, 0, 0); +assert.sameValue(result, o); diff --git a/test/sendable/builtins/Array/prototype/copyWithin/undefined-end.js b/test/sendable/builtins/Array/prototype/copyWithin/undefined-end.js new file mode 100644 index 0000000000000000000000000000000000000000..52d8c0329e5744ab19f118a507ba65b158de6080 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/copyWithin/undefined-end.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.copywithin +description: > + If `end` is undefined, set final position to `this.length`. +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + 11. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 1, undefined), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, 1, undefined) must return [1, 2, 3, 3]' +); +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, 1) must return [1, 2, 3, 3]' +); diff --git a/test/sendable/builtins/Array/prototype/entries/iteration-mutable.js b/test/sendable/builtins/Array/prototype/entries/iteration-mutable.js new file mode 100644 index 0000000000000000000000000000000000000000..a3c5d1bdf467553a9cc9717c5201f74af56f9c4e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/iteration-mutable.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.entries +description: > + New items in the array are accessible via iteration until iterator is "done". +info: | + The method should return a valid iterator with the context as the + IteratedObject. When an item is added to the array after the iterator is + created but before the iterator is "done" (as defined by 22.1.5.2.1) the + new item should be accessible via iteration. +---*/ + +var SendableArray = []; +var iterator = SendableArray.entries(); +var result; +SendableArray.push('a'); +result = iterator.next(); +assert.sameValue(result.done, false, 'First result `done` flag'); +assert.sameValue(result.value[0], 0, 'First result `value` (array key)'); +assert.sameValue(result.value[1], 'a', 'First result `value (array value)'); +assert.sameValue(result.value.length, 2, 'First result `value` (length)'); +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +SendableArray.push('b'); +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag (after push)'); +assert.sameValue(result.value, undefined, 'Exhausted result `value` (after push)'); diff --git a/test/sendable/builtins/Array/prototype/entries/iteration.js b/test/sendable/builtins/Array/prototype/entries/iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..51550e925fbcc10445957bd5634d5b9d41efc520 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/iteration.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.entries +description: > + The return is a valid iterator with the array's numeric properties. +info: | + 22.1.3.4 Array.prototype.entries ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "key+value"). +---*/ + +var SendableArray = ['a', 'b', 'c']; +var iterator = array.entries(); +var result; +result = iterator.next(); +assert.sameValue(result.done, false, 'First result `done` flag'); +assert.sameValue(result.value[0], 0, 'First result `value` (array key)'); +assert.sameValue(result.value[1], 'a', 'First result `value` (array value)'); +assert.sameValue(result.value.length, 2, 'First result `value` (length)'); +result = iterator.next(); +assert.sameValue(result.done, false, 'Second result `done` flag'); +assert.sameValue(result.value[0], 1, 'Second result `value` (array key)'); +assert.sameValue(result.value[1], 'b', 'Second result `value` (array value)'); +assert.sameValue(result.value.length, 2, 'Second result `value` (length)'); +result = iterator.next(); +assert.sameValue(result.done, false, 'Third result `done` flag'); +assert.sameValue(result.value[0], 2, 'Third result `value` (array key)'); +assert.sameValue(result.value[1], 'c', 'Third result `value` (array value)'); +assert.sameValue(result.value.length, 2, 'Third result `value` (length)'); +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); diff --git a/test/sendable/builtins/Array/prototype/entries/length.js b/test/sendable/builtins/Array/prototype/entries/length.js new file mode 100644 index 0000000000000000000000000000000000000000..b1bbef984ad3d09eae8b65ad392add4566c1905c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/length.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.entries +description: > + Array.prototype.entries.length value and descriptor. +info: | + 22.1.3.4 Array.prototype.entries ( ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.entries, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/entries/name.js b/test/sendable/builtins/Array/prototype/entries/name.js new file mode 100644 index 0000000000000000000000000000000000000000..5974eb0e6d380d8f5e666d4d6c8d3c2baa4e145b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/name.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.entries +description: > + Array.prototype.entries.name value and descriptor. +info: | + 22.1.3.4 Array.prototype.entries ( ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.entries, "name", { + value: "entries", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/entries/not-a-constructor.js b/test/sendable/builtins/Array/prototype/entries/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..7af70e6e1e5709ff786678ba1b4d5faf09a4c329 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.entries does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.entries), + false, + 'isConstructor(SendableArray.prototype.entries) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.entries(); +}); + diff --git a/test/sendable/builtins/Array/prototype/entries/prop-desc.js b/test/sendable/builtins/Array/prototype/entries/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..f2be3e34459566eb5145958166ac9aa7fe7c310c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/prop-desc.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.entries +description: > + Property type and descriptor. +info: | + 22.1.3.4 Array.prototype.entries ( ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.entries, + 'function', + '`typeof SendableArray.prototype.entries` is `function`' +); +verifyProperty(SendableArray.prototype, "entries", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/entries/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/entries/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..3910e9821b9ce625210258ea5a3bacd28fffadf1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.entries +description: > + Array.p.entries behaves correctly when receiver is backed by a resizable + buffer and resized mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function ArrayEntriesHelper(ta) { + return SendableArray.prototype.entries.call(ta); +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +// Iterating with entries() (the 4 loops below). +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + // The fixed length array is not affected by resizing. + TestIterationAndResize(ArrayEntriesHelper(fixedLength), [ + [ + 0, + 0 + ], + [ + 1, + 2 + ], + [ + 2, + 4 + ], + [ + 3, + 6 + ] + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + // The fixed length array is not affected by resizing. + TestIterationAndResize(ArrayEntriesHelper(fixedLengthWithOffset), [ + [ + 0, + 4 + ], + [ + 1, + 6 + ] + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(ArrayEntriesHelper(lengthTracking), [ + [ + 0, + 0 + ], + [ + 1, + 2 + ], + [ + 2, + 4 + ], + [ + 3, + 6 + ], + [ + 4, + 0 + ], + [ + 5, + 0 + ] + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + TestIterationAndResize(ArrayEntriesHelper(lengthTrackingWithOffset), [ + [ + 0, + 4 + ], + [ + 1, + 6 + ], + [ + 2, + 0 + ], + [ + 3, + 0 + ] + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/Array/prototype/entries/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/entries/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..0eaefe36c5e71366fd24173afaff5eb5645276a5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.entries +description: > + Array.p.entries behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function ArrayEntriesHelper(ta) { + return SendableArray.prototype.entries.call(ta); +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +// Iterating with entries() (the 4 loops below). +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + // The fixed length array goes out of bounds when the RAB is resized. + assert.throws(TypeError, () => { + TestIterationAndResize(ArrayEntriesHelper(fixedLength), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + // The fixed length array goes out of bounds when the RAB is resized. + assert.throws(TypeError, () => { + TestIterationAndResize(ArrayEntriesHelper(fixedLengthWithOffset), null, rab, 1, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(ArrayEntriesHelper(lengthTracking), [ + [ + 0, + 0 + ], + [ + 1, + 2 + ], + [ + 2, + 4 + ] + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + TestIterationAndResize(ArrayEntriesHelper(lengthTrackingWithOffset), [ + [ + 0, + 4 + ], + [ + 1, + 6 + ] + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/Array/prototype/entries/resizable-buffer.js b/test/sendable/builtins/Array/prototype/entries/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..01fb36fc07458d70081e05cbfb2973d355ec5ac5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/resizable-buffer.js @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.entries +description: > + Array.p.entries behaves correctly when receiver is backed by resizable + buffer +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function ArrayEntriesHelper(ta) { + return SendableArray.prototype.entries.call(ta); +} +function ValuesFromArrayEntries(ta) { + let result = []; + let expectedKey = 0; + for (let [key, value] of Array.prototype.entries.call(ta)) { + assert.sameValue(key, expectedKey, 'TypedArray method .entries should return `expectedKey`.'); + ++expectedKey; + result.push(Number(value)); + } + return result; +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + assert.compareArray(ValuesFromArrayEntries(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ValuesFromArrayEntries(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ValuesFromArrayEntries(lengthTracking), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ValuesFromArrayEntries(lengthTrackingWithOffset), [ + 4, + 6 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + // TypedArray.prototype.{entries, keys, values} throw right away when + // called. Array.prototype.{entries, keys, values} don't throw, but when + // we try to iterate the returned ArrayIterator, that throws. + ArrayEntriesHelper(fixedLength); + ArrayEntriesHelper(fixedLengthWithOffset); + assert.throws(TypeError, () => { + SendableArray.from(ArrayEntriesHelper(fixedLength)); + }); + assert.throws(TypeError, () => { + SendableArray.from(ArrayEntriesHelper(fixedLengthWithOffset)); + }); + assert.compareArray(ValuesFromArrayEntries(lengthTracking), [ + 0, + 2, + 4 + ]); + assert.compareArray(ValuesFromArrayEntries(lengthTrackingWithOffset), [4]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + ArrayEntriesHelper(fixedLength); + ArrayEntriesHelper(fixedLengthWithOffset); + ArrayEntriesHelper(lengthTrackingWithOffset); + assert.throws(TypeError, () => { + SendableArray.from(ArrayEntriesHelper(fixedLength)); + }); + assert.throws(TypeError, () => { + SendableArray.from(ArrayEntriesHelper(fixedLengthWithOffset)); + }); + assert.throws(TypeError, () => { + SendableArray.from(ArrayEntriesHelper(lengthTrackingWithOffset)); + }); + assert.compareArray(ValuesFromArrayEntries(lengthTracking), [0]); + + // Shrink to zero. + rab.resize(0); + ArrayEntriesHelper(fixedLength); + ArrayEntriesHelper(fixedLengthWithOffset); + ArrayEntriesHelper(lengthTrackingWithOffset); + assert.throws(TypeError, () => { + SendableArray.from(ArrayEntriesHelper(fixedLength)); + }); + assert.throws(TypeError, () => { + SendableArray.from(ArrayEntriesHelper(fixedLengthWithOffset)); + }); + assert.throws(TypeError, () => { + SendableArray.from(ArrayEntriesHelper(lengthTrackingWithOffset)); + }); + assert.compareArray(ValuesFromArrayEntries(lengthTracking), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.compareArray(ValuesFromArrayEntries(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ValuesFromArrayEntries(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ValuesFromArrayEntries(lengthTracking), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(ValuesFromArrayEntries(lengthTrackingWithOffset), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/entries/return-abrupt-from-this.js b/test/sendable/builtins/Array/prototype/entries/return-abrupt-from-this.js new file mode 100644 index 0000000000000000000000000000000000000000..600d36eff73011f6d1bde56d5ae1048e285907c2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/return-abrupt-from-this.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.entries +description: > + Return abrupt from ToObject(this value). +info: | + 22.1.3.4 Array.prototype.entries ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.entries.call(undefined); +}); +assert.throws(TypeError, function() { + SendableArray.prototype.entries.call(null); +}); diff --git a/test/sendable/builtins/Array/prototype/entries/returns-iterator-from-object.js b/test/sendable/builtins/Array/prototype/entries/returns-iterator-from-object.js new file mode 100644 index 0000000000000000000000000000000000000000..267ea9709f8cd8b33dd7ac474da1b6739935b919 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/returns-iterator-from-object.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.entries +description: > + Creates an iterator from a custom object. +info: | + 22.1.3.4 Array.prototype.entries ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "key+value"). +features: [Symbol.iterator] +---*/ + +var obj = { + length: 2 +}; +var iter = SendableArray.prototype.entries.call(obj); +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].entries() is %ArrayIteratorPrototype%' +); diff --git a/test/sendable/builtins/Array/prototype/entries/returns-iterator.js b/test/sendable/builtins/Array/prototype/entries/returns-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..3c846c3e76f50299ce5e582f0e044cc45194fedd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/entries/returns-iterator.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.entries +description: > + The method should return an Iterator instance. +info: | + 22.1.3.4 Array.prototype.entries ( ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "key+value"). + 22.1.5.1 CreateArrayIterator Abstract Operation + 2. Let iterator be ObjectCreate(%ArrayIteratorPrototype%, «‍[[IteratedObject]], + [[ArrayIteratorNextIndex]], [[ArrayIterationKind]]»). + 6. Return iterator. +features: [Symbol.iterator] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); +var iter = [].entries(); +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].entries() is %ArrayIteratorPrototype%' +); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-0-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-0-1.js new file mode 100644 index 0000000000000000000000000000000000000000..c46aaacba4056ce96584f2614d49a50149ea5da7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-0-1.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every must exist as a function +---*/ + +var f = SendableArray.prototype.every; +assert.sameValue(typeof(f), "function", 'typeof(f)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..ba60ef9995320d5e3a320f16a9604f614001f087 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to undefined throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.every.call(undefined); // TypeError is thrown if value is undefined +}); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-10.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..3d0ba9ed0c5429a209ad311ea589ab56d4383925 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-10.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to the Math object +---*/ + +function callbackfn(val, idx, obj) { + return ('[object Math]' !== Object.prototype.toString.call(obj)); +} +Math.length = 1; +Math[0] = 1; +assert.sameValue(SendableArray.prototype.every.call(Math, callbackfn), false, 'SendableArray.prototype.every.call(Math, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-11.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..a5c44af33d412879a1888fcf1b4efdbab2165138 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-11.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to Date object +---*/ + +function callbackfn(val, idx, obj) { + return !(obj instanceof Date); +} +var obj = new Date(0); +obj.length = 1; +obj[0] = 1; +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-12.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..82743960cd820edbaf471fd8dfacb839e89d4f21 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-12.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to RegExp object +---*/ + +function callbackfn(val, idx, obj) { + return !(obj instanceof RegExp); +} +var obj = new RegExp(); +obj.length = 1; +obj[0] = 1; +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-13.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..3e034e084c566f15101bffacba35aa0c801ae116 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-13.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to the JSON object +---*/ + +function callbackfn(val, idx, obj) { + return ('[object JSON]' !== Object.prototype.toString.call(obj)); +} +JSON.length = 1; +JSON[0] = 1; +assert.sameValue(SendableArray.prototype.every.call(JSON, callbackfn), false, 'SendableArray.prototype.every.call(JSON, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-14.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-14.js new file mode 100644 index 0000000000000000000000000000000000000000..f311195cf901c9890b7da4d742cfc7ff75763d51 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-14.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to Error object +---*/ + +function callbackfn(val, idx, obj) { + return !(obj instanceof Error); +} +var obj = new Error(); +obj.length = 1; +obj[0] = 1; +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-15.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..534c0d3785d23fe6f6cc99cba5892fe5715f9090 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-15.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to the Arguments object +---*/ + +function callbackfn(val, idx, obj) { + return ('[object Arguments]' !== Object.prototype.toString.call(obj)); +} +var obj = (function fun() { + return arguments; +}("a", "b")); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-2.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..cd035218d29938fe6d1267dd1d23317cdc2bbe6b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to null throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.every.call(null); // TypeError is thrown if value is null +}); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-3.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..887d05ba8bfb97c32c0193dac3fcacec63c54243 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-3.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to boolean primitive +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return obj instanceof Boolean; +} +Boolean.prototype[0] = 1; +Boolean.prototype.length = 1; +assert(SendableArray.prototype.every.call(false, callbackfn), 'SendableArray.prototype.every.call(false, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-4.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..54d0bc0cd4199bbb618795834c8cf1f58fb3709c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to Boolean object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return obj instanceof Boolean; +} +var obj = new Boolean(true); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-5.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..f1bfdbf5c32d69478bb11d2b224ee6d114aa9fa6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-5.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to number primitive +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return obj instanceof Number; +} +Number.prototype[0] = 1; +Number.prototype.length = 1; +assert(SendableArray.prototype.every.call(2.5, callbackfn), 'SendableArray.prototype.every.call(2.5, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-6.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..8778d458961a898bb00f933618a660546df0a374 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-6.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to Number object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return obj instanceof Number; +} +var obj = new Number(-128); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-7.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..58d772af7376b36772ee196a725505344473e072 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-7.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to string primitive +---*/ + +function callbackfn(val, idx, obj) { + return !(obj instanceof String); +} +assert.sameValue(SendableArray.prototype.every.call("hello\nworld\\!", callbackfn), false, 'SendableArray.prototype.every.call("hello\nworld\\!", callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-8.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..973b3cb7749efdd4897fae1003109d7259b25c5e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-8.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to String object +---*/ + +function callbackfn(val, idx, obj) { + return !(obj instanceof String); +} +var obj = new String("hello\nworld\\!"); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-9.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..a8c5b3060427eb498db5d8bf074ead979a4134c6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-1-9.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to Function object +---*/ + +function callbackfn(val, idx, obj) { + return !(obj instanceof Function); +} +var obj = function(a, b) { + return a + b; +}; +obj[0] = 11; +obj[1] = 9; +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..1abf1b0b35262613345916fdefd82e8471079491 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-1.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to Array-like object, 'length' is an + own data property +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: 2 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-10.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-10.js new file mode 100644 index 0000000000000000000000000000000000000000..ba25d501848ca9861fbb1312520a58424092d41f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-10.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to Array-like object, 'length' is an + inherited accessor property +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert(SendableArray.prototype.every.call(child, callbackfn1), 'SendableArray.prototype.every.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn2), false, 'SendableArray.prototype.every.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-11.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-11.js new file mode 100644 index 0000000000000000000000000000000000000000..e9bf86c7d8c9c89964ea08122d25cee16465a5b9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-11.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to Array-like object, 'length' is an + own accessor property without a get function +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 9, + 1: 8 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-12.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-12.js new file mode 100644 index 0000000000000000000000000000000000000000..5b0d898f01c333fc317085aab10863567c923b1a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-12.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - 'length' is own accessor property without + a get function that overrides an inherited accessor property +---*/ +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +Object.defineProperty(Object.prototype, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var obj = { + 0: 9, + 1: 8 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-13.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-13.js new file mode 100644 index 0000000000000000000000000000000000000000..5207799f3110ca26475d601eacc97b07832aee30 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-13.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to the Array-like object that + 'length' is inherited accessor property without a get function +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var proto = {}; +Object.defineProperty(proto, "length", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 9; +child[1] = 8; +assert(SendableArray.prototype.every.call(child, callbackfn), 'SendableArray.prototype.every.call(child, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-14.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-14.js new file mode 100644 index 0000000000000000000000000000000000000000..237e480e23202c76a84028302117eae6737b4f4f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-14.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to the Array-like object that + 'length' property doesn't exist +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + 1: 12 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-17.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-17.js new file mode 100644 index 0000000000000000000000000000000000000000..bc9ff5fead8bc35d5dc192935be80df6ac546af1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-17.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to the Arguments object, which + implements its own property get method +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var func = function(a, b) { + arguments[2] = 9; + return SendableArray.prototype.every.call(arguments, callbackfn1) && + !SendableArray.prototype.every.call(arguments, callbackfn2); +}; +assert(func(12, 11), 'func(12, 11) !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-18.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-18.js new file mode 100644 index 0000000000000000000000000000000000000000..d30dfb474dab84e2f2e53d1f9593aac476c35e00 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-18.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to String object, which implements + its own property get method +---*/ + +function callbackfn1(val, idx, obj) { + return parseInt(val, 10) > 1; +} +function callbackfn2(val, idx, obj) { + return parseInt(val, 10) > 2; +} +var str = new String("432"); +String.prototype[3] = "1"; +assert(SendableArray.prototype.every.call(str, callbackfn1), 'SendableArray.prototype.every.call(str, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(str, callbackfn2), false, 'SendableArray.prototype.every.call(str, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-19.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-19.js new file mode 100644 index 0000000000000000000000000000000000000000..5cf0571999c9cedd6f56110d6be681e326781148 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-19.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to Function object, which implements + its own property get method +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var fun = function(a, b) { + return a + b; +}; +fun[0] = 12; +fun[1] = 11; +fun[2] = 9; +assert(SendableArray.prototype.every.call(fun, callbackfn1), 'SendableArray.prototype.every.call(fun, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(fun, callbackfn2), false, 'SendableArray.prototype.every.call(fun, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-2.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..8de1cec4d08b9b04020613881aee5698fecc55bf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - 'length' is own data property on an Array +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +SendableArray.prototype[2] = 9; +assert([12, 11].every(callbackfn1), '[12, 11].every(callbackfn1) !== true'); +assert.sameValue([12, 11].every(callbackfn2), false, '[12, 11].every(callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-3.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..cecbbc3747da1bcf0e71df168ec671171da22d33 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-3.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to Array-like object, 'length' is an + own data property that overrides an inherited data property +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert(SendableArray.prototype.every.call(child, callbackfn1), 'SendableArray.prototype.every.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn2), false, 'SendableArray.prototype.every.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-4.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..77ced97130d78cccaf23409cc753f3e26a084d11 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-4.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - 'length' is own data property that + overrides an inherited data property on an Array +---*/ + +var arrProtoLen = 0; +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +arrProtoLen = Array.prototype.length; +SendableArray.prototype.length = 0; +SendableArray.prototype[2] = 9; +assert([12, 11].every(callbackfn1), '[12, 11].every(callbackfn1) !== true'); +assert.sameValue([12, 11].every(callbackfn2), false, '[12, 11].every(callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-5.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..5655481d3d672eaaee93f480513dbd41fe2d01ab --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-5.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to Array-like object, 'length' is an + own data property that overrides an inherited accessor property +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +Object.defineProperty(child, "length", { + value: 2, + configurable: true +}); +assert(SendableArray.prototype.every.call(child, callbackfn1), 'SendableArray.prototype.every.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn2), false, 'SendableArray.prototype.every.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-6.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-6.js new file mode 100644 index 0000000000000000000000000000000000000000..7fd9ea554c08ddacac6ab215e459b8211fb3739e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-6.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to Array-like object, 'length' is an + inherited data property +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = { + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert(SendableArray.prototype.every.call(child, callbackfn1), 'SendableArray.prototype.every.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn2), false, 'SendableArray.prototype.every.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-7.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-7.js new file mode 100644 index 0000000000000000000000000000000000000000..146ef2a59205850ed5d8973864ef5f6dae5691f5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-7.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to Array-like object, 'length' is an + own accessor property +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return 2; + }, + configurable: true +}); +obj[0] = 12; +obj[1] = 11; +obj[2] = 9; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-8.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-8.js new file mode 100644 index 0000000000000000000000000000000000000000..2060a80b5599a7c969d3a96e8794250e4053c643 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-8.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to Array-like object, 'length' is an + own accessor property that overrides an inherited data property +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert(SendableArray.prototype.every.call(child, callbackfn1), 'SendableArray.prototype.every.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn2), false, 'SendableArray.prototype.every.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-9.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-9.js new file mode 100644 index 0000000000000000000000000000000000000000..a9444f754c7b7a21e8cb2c409cf7127ce50d0811 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-2-9.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every applied to Array-like object, 'length' is an + own accessor property that overrides an inherited accessor property +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert(SendableArray.prototype.every.call(child, callbackfn1), 'SendableArray.prototype.every.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn2), false, 'SendableArray.prototype.every.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-1.js new file mode 100644 index 0000000000000000000000000000000000000000..5eec5b797c36d24909c7d7e89676410b3e62dade --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - value of 'length' is undefined +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 9, + length: undefined +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-10.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-10.js new file mode 100644 index 0000000000000000000000000000000000000000..b913be3a20ca8737b9ea720b14730ac2724af1c5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-10.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - value of 'length' is a number (value is + NaN) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 9, + length: NaN +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-11.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-11.js new file mode 100644 index 0000000000000000000000000000000000000000..a570bd79f0b783439cb6a061c527d7012dbaac0d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-11.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - 'length' is a string containing a positive + number +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: "2" +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-12.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-12.js new file mode 100644 index 0000000000000000000000000000000000000000..8b1bbcfbfecdcb52ceff3ac0e6a2d2e2d52ca7fe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-12.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - 'length' is a string containing a negative + number +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 11, + 1: 12, + 2: 9, + length: "-4294967294" +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert(SendableArray.prototype.every.call(obj, callbackfn2), 'SendableArray.prototype.every.call(obj, callbackfn2) !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-13.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-13.js new file mode 100644 index 0000000000000000000000000000000000000000..10ce67576f3255922166ddfa35c9357e9b2fdc2e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-13.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - 'length' is a string containing a decimal + number +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: "2.5" +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-14.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-14.js new file mode 100644 index 0000000000000000000000000000000000000000..1ece97444af5a6a71eac429484395b9c0dc35fd1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-14.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - 'length' is a string containing +/-Infinity +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var objOne = { + 0: 9, + length: "Infinity" +}; +var objTwo = { + 0: 9, + length: "+Infinity" +}; +var objThree = { + 0: 9, + length: "-Infinity" +}; +assert.sameValue(SendableArray.prototype.every.call(objOne, callbackfn), false, 'SendableArray.prototype.every.call(objOne, callbackfn)'); +assert.sameValue(SendableArray.prototype.every.call(objTwo, callbackfn), false, 'SendableArray.prototype.every.call(objTwo, callbackfn)'); +assert(SendableArray.prototype.every.call(objThree, callbackfn), 'SendableArray.prototype.every.call(objThree, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-15.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-15.js new file mode 100644 index 0000000000000000000000000000000000000000..d58408398c6f1a508572f246d5528fe012e0f0c4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-15.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - 'length' is a string containing an + exponential number +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: "2E0" +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-16.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-16.js new file mode 100644 index 0000000000000000000000000000000000000000..251bf527660344144d33b5ff0bc0d8f36e86bb8f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-16.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - 'length' is a string containing a hex + number +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: "0x0002" +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-17.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-17.js new file mode 100644 index 0000000000000000000000000000000000000000..2f3b8d73462cc1f6de285ca2d46f15d6a6f0bb93 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-17.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - 'length' is a string containing a number + with leading zeros +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: "0002.00" +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-18.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-18.js new file mode 100644 index 0000000000000000000000000000000000000000..8130416582e967135df78d169a9e0a919ab607ea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-18.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - value of 'length' is a string that can't + convert to a number +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 9, + 1: 8, + length: "two" +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-19.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-19.js new file mode 100644 index 0000000000000000000000000000000000000000..d8ae9b91c9d98aff464939eb3a269fd6571dd4d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-19.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - value of 'length' is an Object which has + an own toString method +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var toStringAccessed = false; +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: { + toString: function() { + toStringAccessed = true; + return '2'; + } + } +}; +// objects inherit the default valueOf() method from Object +// that simply returns itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); +assert(toStringAccessed, 'toStringAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-2.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-2.js new file mode 100644 index 0000000000000000000000000000000000000000..d1e3f257838d66c3a16a8c19fced8edfabafddc8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-2.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every on an Array-like object if 'length' is 1 + (length overridden to true(type conversion)) +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 11, + 1: 9, + length: true +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-20.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-20.js new file mode 100644 index 0000000000000000000000000000000000000000..74e4d6e908b08bb5e51cc2dc3c51a75416bf1820 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-20.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - value of 'length' is an Object which has + an own valueOf method +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var valueOfAccessed = false; +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: { + valueOf: function() { + valueOfAccessed = true; + return 2; + } + } +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-21.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-21.js new file mode 100644 index 0000000000000000000000000000000000000000..f248a9af35bc5d1ad49e37ea3518100614af668e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-21.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - 'length' is an object that has an own + valueOf method that returns an object and toString method that + returns a string +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var toStringAccessed = false; +var valueOfAccessed = false; +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: { + valueOf: function() { + valueOfAccessed = true; + return {}; + }, + toString: function() { + toStringAccessed = true; + return '2'; + } + } +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert(toStringAccessed, 'toStringAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-22.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-22.js new file mode 100644 index 0000000000000000000000000000000000000000..41b48f75d9535f96ca60aa280a9210c4bfea24b8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-22.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every throws TypeError exception when 'length' is + an object with toString and valueOf methods that don�t return + primitive values +---*/ + +var callbackfnAccessed = false; +var toStringAccessed = false; +var valueOfAccessed = false; +function callbackfn(val, idx, obj) { + callbackfnAccessed = true; + return val > 10; +} +var obj = { + 0: 11, + 1: 12, + + length: { + valueOf: function() { + valueOfAccessed = true; + return {}; + }, + toString: function() { + toStringAccessed = true; + return {}; + } + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.every.call(obj, callbackfn); +}); +assert(toStringAccessed, 'toStringAccessed !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(callbackfnAccessed, false, 'callbackfnAccessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-23.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-23.js new file mode 100644 index 0000000000000000000000000000000000000000..2002231d343ceead717de7232e82ea39b6925b1e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-23.js @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every uses inherited valueOf method when 'length' + is an object with an own toString and inherited valueOf methods +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var valueOfAccessed = false; +var toStringAccessed = false; +var proto = { + valueOf: function() { + valueOfAccessed = true; + return 2; + } +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "toString", { + value: function() { + toStringAccessed = true; + return '1'; + } +}); +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: child +}; + +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(toStringAccessed, false, 'toStringAccessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-24.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-24.js new file mode 100644 index 0000000000000000000000000000000000000000..0cdd168ba7d28546d9495fc6ec87b27787b767ee --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-24.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - value of 'length' is a positive + non-integer, ensure truncation occurs in the proper direction +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: 2.685 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-25.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-25.js new file mode 100644 index 0000000000000000000000000000000000000000..c1860668eef047195864669a1e4007bf2903f79f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-25.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - value of 'length' is a negative non-integer +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: -4294967294.5 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert(SendableArray.prototype.every.call(obj, callbackfn2), 'SendableArray.prototype.every.call(obj, callbackfn2) !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-29.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-29.js new file mode 100644 index 0000000000000000000000000000000000000000..33dc9e7a7e6b8bdbbe243829254c09808eaaf3a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-29.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - value of 'length' is boundary value (2^32 + + 1) +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 11, + 1: 9, + length: 4294967297 +}; +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn1), false, 'SendableArray.prototype.every.call(obj, callbackfn1)'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-3.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-3.js new file mode 100644 index 0000000000000000000000000000000000000000..81372e82e32a75bbc2894404df4a2d8f7e0bfa0b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-3.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - value of 'length' is a number (value is 0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 9, + length: 0 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-4.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-4.js new file mode 100644 index 0000000000000000000000000000000000000000..fb8f5160463880dc6c9e4a8e8549c73b7d5aab0a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - value of 'length' is a number (value is +0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 9, + length: +0 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-5.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-5.js new file mode 100644 index 0000000000000000000000000000000000000000..8436f04dead87c64a40d9cbd7e7e28ddad5a77d2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-5.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - value of 'length' is a number (value is -0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 9, + length: -0 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-6.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-6.js new file mode 100644 index 0000000000000000000000000000000000000000..178fd93fc269b011725c85c3a5a611cb7bcd7823 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - value of 'length' is a number (value is + positive) +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: 2 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn2), false, 'SendableArray.prototype.every.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-7.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-7.js new file mode 100644 index 0000000000000000000000000000000000000000..4c90d2d364936316b2f276f69a9254e7a839d3f7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-7.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - value of 'length' is a number (value is + negative) +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: -4294967294 +}; //length used to exec while loop is 0 +assert(SendableArray.prototype.every.call(obj, callbackfn1), 'SendableArray.prototype.every.call(obj, callbackfn1) !== true'); +assert(SendableArray.prototype.every.call(obj, callbackfn2), 'SendableArray.prototype.every.call(obj, callbackfn2) !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-8.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-8.js new file mode 100644 index 0000000000000000000000000000000000000000..166009d930aaf6d358d19bf672c8767c688de409 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-8.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-3-8 +description: > + Array.prototype.every - value of 'length' is a number (value is + Infinity) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 9, + length: Infinity +}; +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-9.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-9.js new file mode 100644 index 0000000000000000000000000000000000000000..9ba6ffea92214863231a849d9cd39564c4d7f9fb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-3-9.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-3-9 +description: > + Array.prototype.every - value of 'length' is a number (value is + -Infinity) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 9, + length: -Infinity +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..888e824d3f39ed3ae836a7b2ca9deea7cc7f5cd5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-1.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-1 +description: Array.prototype.every throws TypeError if callbackfn is undefined +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.every(); +}); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-10.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-10.js new file mode 100644 index 0000000000000000000000000000000000000000..5594665fd81c2ecbfe9198c74afb64a25bd43310 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-10.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-10 +description: > + Array.prototype.every - the exception is not thrown if exception + was thrown by step 2 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.every.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-11.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-11.js new file mode 100644 index 0000000000000000000000000000000000000000..f2890e13f79095ef41e8f9bd59e1aad54b96ba35 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-11.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-11 +description: > + Array.prototype.every - the exception is not thrown if exception + was thrown by step 3 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + throw new Test262Error(); + } + }; + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.every.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-12.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-12.js new file mode 100644 index 0000000000000000000000000000000000000000..2622b95fe1d171396b10c7d41831462545881d5b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-12.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-12 +description: Array.prototype.every - 'callbackfn' is a function +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +assert.sameValue([11, 9].every(callbackfn), false, '[11, 9].every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-15.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-15.js new file mode 100644 index 0000000000000000000000000000000000000000..5ff333ffc6fc0fef65409844fb326fe74adae1b1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-15.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-15 +description: > + Array.prototype.every - calling with no callbackfn is the same as + passing undefined for callbackfn +---*/ + +var obj = { + 10: 10 +}; +var lengthAccessed = false; +var loopAccessed = false; +Object.defineProperty(obj, "length", { + get: function() { + lengthAccessed = true; + return 20; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + loopAccessed = true; + return 10; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.every.call(obj); +}); +assert(lengthAccessed, 'lengthAccessed !== true'); +assert.sameValue(loopAccessed, false, 'loopAccessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-3.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..901357ecd2fdce6e84022e3ea6e572bc5d6f05e4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-3.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-3 +description: Array.prototype.every throws TypeError if callbackfn is null +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.every(null); +}); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-4.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..3c927147c70361458dda0e65ad1f7581078d356c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-4.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-4 +description: Array.prototype.every throws TypeError if callbackfn is boolean +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.every(true); +}); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-5.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-5.js new file mode 100644 index 0000000000000000000000000000000000000000..b473c5dd65601b34e5f9c8a0c7cc5893c9fdda29 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-5.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-5 +description: Array.prototype.every throws TypeError if callbackfn is number +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.every(5); +}); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-6.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-6.js new file mode 100644 index 0000000000000000000000000000000000000000..1366b99bf62d5860247ebdc37ead3494e7fd18e3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-6.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-6 +description: Array.prototype.every throws TypeError if callbackfn is string +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.every("abc"); +}); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-7.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-7.js new file mode 100644 index 0000000000000000000000000000000000000000..f8460cec1f9069598795aa3582173a89a18ce61b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-7.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-7 +description: > + Array.prototype.every throws TypeError if callbackfn is Object + without a Call internal method +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.every({}); +}); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-8.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-8.js new file mode 100644 index 0000000000000000000000000000000000000000..81e2599774051395e49ecaee43793744e746c217 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-8.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-8 +description: > + Array.prototype.every - side effects produced by step 2 are + visible when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + accessed = true; + return 2; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.every.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-9.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-9.js new file mode 100644 index 0000000000000000000000000000000000000000..8c93a50df240c938b901bcfe3ce6568e686a4906 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-4-9.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-4-9 +description: > + Array.prototype.every - side effects produced by step 3 are + visible when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + accessed = true; + return "2"; + } + }; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.every.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-1-s.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-1-s.js new file mode 100644 index 0000000000000000000000000000000000000000..5da287c99595f3158d2fdc370fc13e6e431240c8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-1-s.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-1-s +description: Array.prototype.every - thisArg not passed to strict callbackfn +flags: [noStrict] +---*/ + +var innerThisCorrect = false; +function callbackfn(val, idx, obj) { + "use strict"; + innerThisCorrect = this === undefined; + return true; +} +[1].every(callbackfn); +assert(innerThisCorrect, 'innerThisCorrect !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..a1ec4b918413fcadea2c932805cbf131a68dfb49 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-1.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-1 +description: Array.prototype.every - thisArg not passed +flags: [noStrict] +---*/ + +var global = this; +function callbackfn(val, idx, obj) +{ + return this === global; +} +var arr = [1]; +assert.sameValue(arr.every(callbackfn), true, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-10.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-10.js new file mode 100644 index 0000000000000000000000000000000000000000..38da0b5e9b35f33eea6f3503738f2bdf5b04820d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-10.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-10 +description: Array.prototype.every - Array Object can be used as thisArg +---*/ + +var accessed = false; +var objArray = []; +function callbackfn(val, idx, obj) { + accessed = true; + return this === objArray; +} +assert([11].every(callbackfn, objArray), '[11].every(callbackfn, objArray) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-11.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-11.js new file mode 100644 index 0000000000000000000000000000000000000000..8aabe58a92826fc3d6cfac28a7029fd1e0f96ed0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-11.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-11 +description: Array.prototype.every - String Object can be used as thisArg +---*/ + +var accessed = false; +var objString = new String(); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objString; +} +assert([11].every(callbackfn, objString), '[11].every(callbackfn, objString) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-12.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-12.js new file mode 100644 index 0000000000000000000000000000000000000000..31dd7a4843fced017238ce0d7e1f68caff2bf929 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-12.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-12 +description: Array.prototype.every - Boolean Object can be used as thisArg +---*/ + +var accessed = false; +var objBoolean = new Boolean(); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objBoolean; +} +assert([11].every(callbackfn, objBoolean), '[11].every(callbackfn, objBoolean) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-13.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-13.js new file mode 100644 index 0000000000000000000000000000000000000000..63962fa18770e8dd43be7aef579317f76428fc03 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-13.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-13 +description: Array.prototype.every - Number Object can be used as thisArg +---*/ + +var accessed = false; +var objNumber = new Number(); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objNumber; +} +assert([11].every(callbackfn, objNumber), '[11].every(callbackfn, objNumber) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-14.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-14.js new file mode 100644 index 0000000000000000000000000000000000000000..6ef23469d00d7e39c21ff816e48e3279f265e71a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-14.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-14 +description: Array.prototype.every - the Math object can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this === Math; +} +assert([11].every(callbackfn, Math), '[11].every(callbackfn, Math) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-15.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-15.js new file mode 100644 index 0000000000000000000000000000000000000000..42ed2f75c7114481bc543ee9e7d27c831136b149 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-15.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-15 +description: Array.prototype.every - Date Object can be used as thisArg +---*/ + +var accessed = false; +var objDate = new Date(0); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objDate; +} +assert([11].every(callbackfn, objDate), '[11].every(callbackfn, objDate) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-16.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-16.js new file mode 100644 index 0000000000000000000000000000000000000000..5c56dc047ce63abca335521eb9d8d21ad38f261c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-16.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-16 +description: Array.prototype.every - RegExp Object can be used as thisArg +---*/ + +var accessed = false; +var objRegExp = new RegExp(); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objRegExp; +} +assert([11].every(callbackfn, objRegExp), '[11].every(callbackfn, objRegExp) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-17.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-17.js new file mode 100644 index 0000000000000000000000000000000000000000..15ec234416df8b9fa4c02029dc60f61450af4ea1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-17.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-17 +description: Array.prototype.every - the JSON object can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this === JSON; +} +assert([11].every(callbackfn, JSON), '[11].every(callbackfn, JSON) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-18.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-18.js new file mode 100644 index 0000000000000000000000000000000000000000..428bc99670a7de5ff622dcf59dcf4fa9a6e31008 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-18.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-18 +description: Array.prototype.every - Error Object can be used as thisArg +---*/ + +var accessed = false; +var objError = new RangeError(); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objError; +} +assert([11].every(callbackfn, objError), '[11].every(callbackfn, objError) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-19.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-19.js new file mode 100644 index 0000000000000000000000000000000000000000..e1e33cb527ba0b593941f082ce996a9641918685 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-19.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-19 +description: Array.prototype.every - the Arguments object can be used as thisArg +---*/ + +var accessed = false; +var arg; +function callbackfn(val, idx, obj) { + accessed = true; + return this === arg; +} +(function fun() { + arg = arguments; +}(1, 2, 3)); +assert([11].every(callbackfn, arg), '[11].every(callbackfn, arg) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-2.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-2.js new file mode 100644 index 0000000000000000000000000000000000000000..fe61fcc15cdb24fba1845aebe6f0becb6dff3b4c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-2 +description: Array.prototype.every - thisArg is Object +---*/ + +var res = false; +var o = new Object(); +o.res = true; +function callbackfn(val, idx, obj) +{ + return this.res; +} +var arr = [1]; +assert.sameValue(arr.every(callbackfn, o), true, 'arr.every(callbackfn, o)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-21.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-21.js new file mode 100644 index 0000000000000000000000000000000000000000..d445022e64ab338e9b8472d807111e38b08d0fed --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-21.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-21 +description: Array.prototype.every - the global object can be used as thisArg +---*/ + +var global = this; +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this === global; +} +assert([11].every(callbackfn, global), '[11].every(callbackfn, global) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-22.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-22.js new file mode 100644 index 0000000000000000000000000000000000000000..fea3054f7e1808bb002cc7ce9a393f846ebde5cc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-22.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-22 +description: Array.prototype.every - boolean primitive can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this.valueOf() === false; +} +assert([11].every(callbackfn, false), '[11].every(callbackfn, false) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-23.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-23.js new file mode 100644 index 0000000000000000000000000000000000000000..290cf08ad436146f935fcc24afb99f1c378c83b1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-23.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-23 +description: Array.prototype.every - number primitive can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this.valueOf() === 101; +} +assert([11].every(callbackfn, 101), '[11].every(callbackfn, 101) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-24.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-24.js new file mode 100644 index 0000000000000000000000000000000000000000..87c9c942cd4c77742a60960b2fb583cba77490d6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-24.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-24 +description: Array.prototype.every - string primitive can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this.valueOf() === "abc"; +} +assert([11].every(callbackfn, "abc"), '[11].every(callbackfn, "abc") !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-3.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-3.js new file mode 100644 index 0000000000000000000000000000000000000000..75f0b9d3ad19bf3f7722a13deb70b5356b1f5c05 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-3.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +es5id: 15.4.4.16-5-3 +description: Array.prototype.every - thisArg is Array +---*/ + +var res = false; +var a = new Array(); +a.res = true; +function callbackfn(val, idx, obj) +{ + return this.res; +} +var arr = [1]; +assert.sameValue(arr.every(callbackfn, a), true, 'arr.every(callbackfn, a)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-4.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-4.js new file mode 100644 index 0000000000000000000000000000000000000000..442862faa896e3101888f94f5c077841c22bba09 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-4.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - thisArg is object from object + template(prototype) +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +foo.prototype.res = true; +var f = new foo(); +var arr = [1]; +assert.sameValue(arr.every(callbackfn, f), true, 'arr.every(callbackfn,f)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-5.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-5.js new file mode 100644 index 0000000000000000000000000000000000000000..d809a83fbeab682ced77c9c7772cb56ca965b63f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-5.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - thisArg is object from object template +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +var f = new foo(); +f.res = true; +var arr = [1]; +assert.sameValue(arr.every(callbackfn, f), true, 'arr.every(callbackfn,f)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-6.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-6.js new file mode 100644 index 0000000000000000000000000000000000000000..61e9a38d6fb27b6f9316a00fa950c85010d0ef6d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-6.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - thisArg is function +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +foo.res = true; +var arr = [1]; +assert.sameValue(arr.every(callbackfn, foo), true, 'arr.every(callbackfn,foo)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-7.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-7.js new file mode 100644 index 0000000000000000000000000000000000000000..7d9f06db89753de2a2b3e90e9f0f4f5b48ca8117 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-7.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - built-in functions can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this === eval; +} +assert([11].every(callbackfn, eval), '[11].every(callbackfn, eval) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-9.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-9.js new file mode 100644 index 0000000000000000000000000000000000000000..9c3be55d9fec08ad4bf3dfdd0509eebe44e37a78 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-5-9.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - Function Object can be used as thisArg +---*/ + +var accessed = false; +var objFunction = function() {}; +function callbackfn(val, idx, obj) { + accessed = true; + return this === objFunction; +} +assert([11].every(callbackfn, objFunction), '[11].every(callbackfn, objFunction) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-1.js new file mode 100644 index 0000000000000000000000000000000000000000..bcc861daec5b4e5be0d7850f1cd1563ceff6415d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every considers new elements added to array after + the call +---*/ + +var calledForThree = false; +function callbackfn(val, Idx, obj) +{ + arr[2] = 3; + if (val == 3) + calledForThree = true; + return true; +} +var arr = [1, 2, , 4, 5]; +var res = arr.every(callbackfn); +assert(calledForThree, 'calledForThree !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-2.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-2.js new file mode 100644 index 0000000000000000000000000000000000000000..e709ff7f6e74e770b450582928d33b027b122aa0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every considers new value of elements in array + after the call +---*/ + +function callbackfn(val, Idx, obj) +{ + arr[4] = 6; + if (val < 6) + return true; + else + return false; +} +var arr = [1, 2, 3, 4, 5]; +assert.sameValue(arr.every(callbackfn), false, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-3.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-3.js new file mode 100644 index 0000000000000000000000000000000000000000..ae4bf4e0ff55cdb038aa4f678fc7fe94d756b430 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every doesn't visit deleted elements in array + after the call +---*/ + +function callbackfn(val, Idx, obj) +{ + delete arr[2]; + if (val == 3) + return false; + else + return true; +} +var arr = [1, 2, 3, 4, 5]; +assert.sameValue(arr.every(callbackfn), true, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-4.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-4.js new file mode 100644 index 0000000000000000000000000000000000000000..0bfff155eca05b25f9dee11cc9e586fa574c9f11 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-4.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every doesn't visit deleted elements when + Array.length is decreased +---*/ + +function callbackfn(val, Idx, obj) +{ + arr.length = 3; + if (val < 4) + return true; + else + return false; +} +var arr = [1, 2, 3, 4, 6]; +assert.sameValue(arr.every(callbackfn), true, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-5.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-5.js new file mode 100644 index 0000000000000000000000000000000000000000..bf320ffd53f76630a0a92be0d322c65ae6988733 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-5.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every doesn't consider newly added elements in + sparse array +---*/ + +function callbackfn(val, Idx, obj) +{ + arr[1000] = 3; + if (val < 3) + return true; + else + return false; +} +var arr = new SendableArray(10); +arr[1] = 1; +arr[2] = 2; +assert.sameValue(arr.every(callbackfn), true, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-6.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-6.js new file mode 100644 index 0000000000000000000000000000000000000000..36fe62987389319c60754aa77af2db396d746ff0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-6.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every visits deleted element in array after the + call when same index is also present in prototype +---*/ + +function callbackfn(val, Idx, obj) +{ + delete arr[2]; + if (val == 3) + return false; + else + return true; +} +SendableArray.prototype[2] = 3; +var arr = [1, 2, 3, 4, 5]; +var res = arr.every(callbackfn); +delete SendableArray.prototype[2]; +assert.sameValue(res, false, 'res'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-7.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-7.js new file mode 100644 index 0000000000000000000000000000000000000000..8030d563fc530c37f06cfb0c5d441be6b1131b2e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-7.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - Deleting the array itself within the + callbackfn of Array.prototype.every is successful once + Array.prototype.every is called for all elements +---*/ + +var o = new Object(); +o.arr = [1, 2, 3, 4, 5]; +function callbackfn(val, Idx, obj) { + delete o.arr; + if (val === Idx + 1) + return true; + else + return false; +} +assert(o.arr.every(callbackfn), 'o.arr.every(callbackfn) !== true'); +assert.sameValue(o.hasOwnProperty("arr"), false, 'o.hasOwnProperty("arr")'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-8.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-8.js new file mode 100644 index 0000000000000000000000000000000000000000..d169054880bae1c09101569578b5a95d80d305f1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-8.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - no observable effects occur if len is 0 +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + 1: 12, + length: 0 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-9.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-9.js new file mode 100644 index 0000000000000000000000000000000000000000..6219d33b1af7e170ed919c563210c58ac66c0c6d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-9.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - modifications to length don't change + number of iterations +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + return val > 10; +} +var obj = { + 1: 12, + 2: 9, + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + obj.length = 3; + return 11; + }, + configurable: true +}); +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..65d6d9ed258751472bd4c1d7b198bbab6646877a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - callbackfn not called for indexes never + been assigned values +---*/ + +var callCnt = 0.; +function callbackfn(val, Idx, obj) +{ + callCnt++; + return true; +} +var arr = new SendableArray(10); +arr[1] = undefined; +arr.every(callbackfn); +assert.sameValue(callCnt, 1, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-10.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-10.js new file mode 100644 index 0000000000000000000000000000000000000000..197f335693eb0e92c8d24f5b5e24fc8a1cd18126 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-10.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - deleting property of prototype causes + prototype index property not to be visited on an Array-like Object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx !== 1; +} +var arr = { + 2: 2, + length: 20 +}; +Object.defineProperty(arr, "0", { + get: function() { + delete Object.prototype[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +assert(SendableArray.prototype.every.call(arr, callbackfn), 'SendableArray.prototype.every.call(arr, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-11.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-11.js new file mode 100644 index 0000000000000000000000000000000000000000..6a2faff2d46560f0b6dd0d75ea89b7415f0ab1e9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-11.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - deleting property of prototype causes + prototype index property not to be visited on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx !== 1; +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + delete Array.prototype[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +assert(arr.every(callbackfn), 'arr.every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-12.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-12.js new file mode 100644 index 0000000000000000000000000000000000000000..df5b10b4681a789692c55e2c5778b1ebafec1cd9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-12.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - deleting own property with prototype + property causes prototype index property to be visited on an + Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + return false; + } else { + return true; + } +} +var arr = { + 0: 0, + 1: 111, + 2: 2, + length: 10 +}; +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +assert.sameValue(SendableArray.prototype.every.call(arr, callbackfn), false, 'SendableArray.prototype.every.call(arr, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-13.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-13.js new file mode 100644 index 0000000000000000000000000000000000000000..31bc700e9f8403b240e5ea705e90cd7e72c47c4c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-13.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - deleting own property with prototype + property causes prototype index property to be visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + return false; + } else { + return true; + } +} +var arr = [0, 111, 2]; + +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +assert.sameValue(arr.every(callbackfn), false, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-14.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-14.js new file mode 100644 index 0000000000000000000000000000000000000000..1bda458c197f7b86e0d7a04bb94f34844de51d99 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-14.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - decreasing length of array causes index + property not to be visited +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx !== 3; +} +var arr = [0, 1, 2, "last"]; +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 3; + return 0; + }, + configurable: true +}); +assert(arr.every(callbackfn), 'arr.every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-15.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-15.js new file mode 100644 index 0000000000000000000000000000000000000000..892c99c2c55e8c26bb8c6f136b371f52cbecf164 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-15.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - decreasing length of array with prototype + property causes prototype index property to be visited +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "prototype") { + return false; + } else { + return true; + } +} +var arr = [0, 1, 2]; +Object.defineProperty(Array.prototype, "2", { + get: function() { + return "prototype"; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +assert.sameValue(arr.every(callbackfn), false, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-16.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-16.js new file mode 100644 index 0000000000000000000000000000000000000000..d2ae124cb86664f34c6f01a9d0c6c03bec1044a6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-16.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - decreasing length of array does not delete + non-configurable properties +flags: [noStrict] +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "unconfigurable") { + return false; + } else { + return true; + } +} +var arr = [0, 1, 2]; +Object.defineProperty(arr, "2", { + get: function() { + return "unconfigurable"; + }, + configurable: false +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +assert.sameValue(arr.every(callbackfn), false, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-2.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-2.js new file mode 100644 index 0000000000000000000000000000000000000000..256c24912a9e4b152bbd660b0cb4f2ed315b8455 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-2.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - added properties in step 2 are visible here +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "length") { + return false; + } else { + return true; + } +} +var arr = {}; +Object.defineProperty(arr, "length", { + get: function() { + arr[2] = "length"; + return 3; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.every.call(arr, callbackfn), false, 'SendableArray.prototype.every.call(arr, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-3.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-3.js new file mode 100644 index 0000000000000000000000000000000000000000..66eae653b644c05ec978e7f9e3ada117b6175c67 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-3.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - deleted properties in step 2 are visible + here +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx !== 2; +} +var arr = { + 2: 6.99, + 8: 19 +}; +Object.defineProperty(arr, "length", { + get: function() { + delete arr[2]; + return 10; + }, + configurable: true +}); +assert(SendableArray.prototype.every.call(arr, callbackfn), 'SendableArray.prototype.every.call(arr, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-4.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-4.js new file mode 100644 index 0000000000000000000000000000000000000000..9ef30bc9ac1683ce53f07256945f76af0382a077 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-4.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - properties added into own object after + current position are visited on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + return false; + } else { + return true; + } +} +var arr = { + length: 2 +}; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.every.call(arr, callbackfn), false, 'SendableArray.prototype.every.call(arr, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-5.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-5.js new file mode 100644 index 0000000000000000000000000000000000000000..cf9b24c5e2408f65025033b7d8694bb107927d0f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-5.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - properties added into own object after + current position are visited on an Array +---*/ +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + return false; + } else { + return true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(arr.every(callbackfn), false, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-6.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-6.js new file mode 100644 index 0000000000000000000000000000000000000000..a7bfded0f792a4a07850d3482c81ca68b2dc97aa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-6.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - properties can be added to prototype after + current position are visited on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 6.99) { + return false; + } else { + return true; + } +} +var arr = { + length: 2 +}; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(Object.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.every.call(arr, callbackfn), false, 'SendableArray.prototype.every.call(arr, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-7.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-7.js new file mode 100644 index 0000000000000000000000000000000000000000..fc6b368cd0665306b1e025a03d5d55160192cd71 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-7.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - properties can be added to prototype after + current position are visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 6.99) { + return false; + } else { + return true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(arr.every(callbackfn), false, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-8.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-8.js new file mode 100644 index 0000000000000000000000000000000000000000..ca00b666f097ac2de85b853264d07ae3f1a3f7fd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-8.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - deleting own property causes index + property not to be visited on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx !== 1; +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + get: function() { + return 6.99; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-9.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-9.js new file mode 100644 index 0000000000000000000000000000000000000000..f85470478f3a3dcec9373a6d4efb47bd2203daeb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-b-9.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - deleting own property causes index + property not to be visited on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx !== 1; +} +var arr = [1, 2]; +Object.defineProperty(arr, "1", { + get: function() { + return "6.99"; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +assert(arr.every(callbackfn), 'arr.every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-1.js new file mode 100644 index 0000000000000000000000000000000000000000..5bd647c77423beac1846bbfd6340e3b295a705b9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-1.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own data + property on an Array-like object +---*/ + +var kValue = {}; +function callbackfn(val, idx, obj) { + if (idx === 5) { + return val !== kValue; + } else { + return true; + } +} +var obj = { + 5: kValue, + length: 100 +}; +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-10.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-10.js new file mode 100644 index 0000000000000000000000000000000000000000..fe3d88da61c45a577269b47c1f8452e7ca3db02f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-10.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own accessor + property on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 2) { + return val !== 12; + } else { + return true; + } +} +var arr = []; +Object.defineProperty(arr, "2", { + get: function() { + return 12; + }, + configurable: true +}); +assert.sameValue(arr.every(callbackfn), false, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-11.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-11.js new file mode 100644 index 0000000000000000000000000000000000000000..0bb3b44ef449f7afdaa4b349ef26168dd3372d0a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-11.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own accessor + property that overrides an inherited data property on an + Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 5; + } else { + return true; + } +} +var proto = { + 0: 5, + 1: 6 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +Object.defineProperty(child, "0", { + get: function() { + return 11; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn), false, 'SendableArray.prototype.every.call(child, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-12.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-12.js new file mode 100644 index 0000000000000000000000000000000000000000..97db543d9b0b795dc14388d0e7e7a541c3224737 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-12.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own accessor + property that overrides an inherited data property on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 10; + } else { + return true; + } +} +var arr = []; +SendableArray.prototype[0] = 10; +Object.defineProperty(arr, "0", { + get: function() { + return 111; + }, + configurable: true +}); +assert.sameValue(arr.every(callbackfn), false, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-13.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-13.js new file mode 100644 index 0000000000000000000000000000000000000000..5c1a50fc99e0416dcf7e8316acee7b0888c36592 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-13.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own accessor + property that overrides an inherited accessor property on an + Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val === 6; + } else { + return true; + } +} +var proto = {}; +Object.defineProperty(proto, "1", { + get: function() { + return 6; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +Object.defineProperty(child, "1", { + get: function() { + return 12; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn), false, 'SendableArray.prototype.every.call(child, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-14.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-14.js new file mode 100644 index 0000000000000000000000000000000000000000..58e21ad67c43520951b559fc27045f6e412d6aa5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-14.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own accessor + property that overrides an inherited accessor property on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 5; + } else { + return true; + } +} +var arr = []; +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 5; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + return 11; + }, + configurable: true +}); +assert.sameValue(arr.every(callbackfn), false, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-15.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-15.js new file mode 100644 index 0000000000000000000000000000000000000000..6f96b7080b85984d77ac60478d588e4fb66b8277 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-15.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is inherited + accessor property on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val !== 11; + } else { + return true; + } +} +var proto = {}; +Object.defineProperty(proto, "1", { + get: function() { + return 11; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 20; +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn), false, 'SendableArray.prototype.every.call(child, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-16.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-16.js new file mode 100644 index 0000000000000000000000000000000000000000..75c84edcca1224b31c79568a9cb0dcc0332d9905 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-16.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is inherited + accessor property on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val !== 11; + } else { + return true; + } +} +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 11; + }, + configurable: true +}); +assert.sameValue([, , , ].every(callbackfn), false, '[, , , ].every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-17.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-17.js new file mode 100644 index 0000000000000000000000000000000000000000..adfe68419fef171a8c283949a84faff6c631574d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-17.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own accessor + property without a get function on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return typeof val === "undefined"; +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-18.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-18.js new file mode 100644 index 0000000000000000000000000000000000000000..71d83854c0a6d9c930e8e4fc9bc9717b96a7026f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-18.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own accessor + property without a get function on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return typeof val === "undefined"; +} +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +assert(arr.every(callbackfn), 'arr.every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-19.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-19.js new file mode 100644 index 0000000000000000000000000000000000000000..bcb8d30cb1d54d806682136a13066c1a9f000744 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-19.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return typeof val === "undefined"; +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +Object.prototype[1] = 10; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-2.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-2.js new file mode 100644 index 0000000000000000000000000000000000000000..f3d2d2d6faf53ad7d79b42a81aedec707e4ef44d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own data + property on an Array +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + return val === 11; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert.sameValue(called, 1, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-20.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-20.js new file mode 100644 index 0000000000000000000000000000000000000000..2fd8e1483f8dfa1c5e8190ce6f08a3abc9cb8868 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-20.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return typeof val === "undefined"; +} +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +SendableArray.prototype[0] = 100; +assert(arr.every(callbackfn), 'arr.every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-21.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-21.js new file mode 100644 index 0000000000000000000000000000000000000000..6670a239027ae5037f6f5157d2252f73989d5a34 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-21.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is inherited + accessor property without a get function on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return typeof val === "undefined"; +} +var proto = {}; +Object.defineProperty(proto, "1", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +assert(SendableArray.prototype.every.call(child, callbackfn), 'SendableArray.prototype.every.call(child, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-22.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-22.js new file mode 100644 index 0000000000000000000000000000000000000000..cab59cad96a1c2833fb958a2b0698ae2fd96db37 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-22.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is inherited + accessor property without a get function on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return typeof val === "undefined"; +} +Object.defineProperty(SendableArray.prototype, "0", { + set: function() {}, + configurable: true +}); +assert([, ].every(callbackfn), '[, ].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-25.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-25.js new file mode 100644 index 0000000000000000000000000000000000000000..355c129f47f8291317b4214c340d5d1180c226fc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-25.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - This object is the Arguments object which + implements its own property get method (number of arguments is + less than number of parameters) +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + return val === 11; +} +var func = function(a, b) { + return SendableArray.prototype.every.call(arguments, callbackfn); +}; +assert(func(11), 'func(11) !== true'); +assert.sameValue(called, 1, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-26.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-26.js new file mode 100644 index 0000000000000000000000000000000000000000..7ca8c28a42a2d384097e4b50dca1a57b826df23f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-26.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - This object is the Arguments object which + implements its own property get method (number of arguments equals + number of parameters) +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + if (idx === 0) { + return val === 11; + } else if (idx === 1) { + return val === 9; + } else { + return false; + } +} +var func = function(a, b) { + return SendableArray.prototype.every.call(arguments, callbackfn); +}; +assert(func(11, 9), 'func(11, 9) !== true'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-27.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-27.js new file mode 100644 index 0000000000000000000000000000000000000000..d21dbb5d2310de81a4c62a63373aa62a39f75d60 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-27.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - This object is the Arguments object which + implements its own property get method (number of arguments is + greater than number of parameters) +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + if (idx < 2) { + return val > 10; + } else if (idx === 2) { + return val < 10; + } else { + return false; + } +} +var func = function(a, b) { + return SendableArray.prototype.every.call(arguments, callbackfn); +}; +assert(func(11, 12, 9), 'func(11, 12, 9) !== true'); +assert.sameValue(called, 3, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-28.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-28.js new file mode 100644 index 0000000000000000000000000000000000000000..d3d62c07bf6ab18ecac9b1dc805a2311ca1027ef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-28.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element changed by getter on previous + iterations is observed on an Array +---*/ + +var preIterVisible = false; +var arr = []; +function callbackfn(val, idx, obj) { + return val > 10; +} +Object.defineProperty(arr, "0", { + get: function() { + preIterVisible = true; + return 11; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + if (preIterVisible) { + return 9; + } else { + return 11; + } + }, + configurable: true +}); +assert.sameValue(arr.every(callbackfn), false, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-29.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-29.js new file mode 100644 index 0000000000000000000000000000000000000000..c1b101a37a2c1f670322d612a7239bad6726d7cb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-29.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element changed by getter on previous + iterations is observed on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var preIterVisible = false; +var obj = { + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + preIterVisible = true; + return 11; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + if (preIterVisible) { + return 9; + } else { + return 13; + } + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-3.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-3.js new file mode 100644 index 0000000000000000000000000000000000000000..23fb5adb751d64206193bc2e81d91bfadf2fcacc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-3.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 5) { + return val === 100; + } else { + return true; + } +} +var proto = { + 0: 11, + 5: 100 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[5] = "abc"; +child.length = 10; +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn), false, 'SendableArray.prototype.every.call(child, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-30.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-30.js new file mode 100644 index 0000000000000000000000000000000000000000..65e71989fd4b088f0fe511a754b11eea31e1b8a9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-30.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - unnhandled exceptions happened in getter + terminate iteration on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 1) { + accessed = true; + } + return true; +} +var obj = { + 0: 11, + 5: 10, + 10: 8, + length: 20 +}; +Object.defineProperty(obj, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + SendableArray.prototype.every.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-31.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-31.js new file mode 100644 index 0000000000000000000000000000000000000000..ea06edfb2b785417ff1a2afd7cb7875ce652ba13 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-31.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - unhandled exceptions happened in getter + terminate iteration on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 1) { + accessed = true; + } + return true; +} +var arr = []; +arr[5] = 10; +arr[10] = 100; +Object.defineProperty(arr, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + arr.every(callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-4.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-4.js new file mode 100644 index 0000000000000000000000000000000000000000..3efec07535d5a898cf6a3bebf485aa5af78dafd8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + return val === 12; +} +SendableArray.prototype[0] = 11; +SendableArray.prototype[1] = 11; +assert([12, 12].every(callbackfn), '[12, 12].every(callbackfn) !== true'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-5.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-5.js new file mode 100644 index 0000000000000000000000000000000000000000..1cbe342439a8568e245ea2f01efba243a101a3c6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-5.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own data + property that overrides an inherited accessor property on an + Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 5; + } else { + return true; + } +} +var proto = {}; +Object.defineProperty(proto, "0", { + get: function() { + return 5; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +Object.defineProperty(child, "0", { + value: 11, + configurable: true +}); +child[1] = 12; +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn), false, 'SendableArray.prototype.every.call(child, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-6.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-6.js new file mode 100644 index 0000000000000000000000000000000000000000..82f67eeec9550fe33c0862b4c27416c72a417606 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-6.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own data + property that overrides an inherited accessor property on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val === 11; +} +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 9; + }, + configurable: true +}); +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-7.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-7.js new file mode 100644 index 0000000000000000000000000000000000000000..8691e989e961ec0b40cfbf37d5585f7254621b7c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-7.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is inherited data + property on an Array-like object +---*/ + +var kValue = 'abc'; +function callbackfn(val, idx, obj) { + if (idx === 5) { + return val !== kValue; + } else { + return true; + } +} +var proto = { + 5: kValue +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +assert.sameValue(SendableArray.prototype.every.call(child, callbackfn), false, 'SendableArray.prototype.every.call(child, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-8.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-8.js new file mode 100644 index 0000000000000000000000000000000000000000..fd37043f8502fddae2c1215c4416474dc8a01e00 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-8.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is inherited data + property on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val !== 13; + } else { + return true; + } +} +SendableArray.prototype[1] = 13; +assert.sameValue([, , , ].every(callbackfn), false, '[, , , ].every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-9.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-9.js new file mode 100644 index 0000000000000000000000000000000000000000..5e0b14b04ca0f25a37f64576f219fabc9cf2d702 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-i-9.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element to be retrieved is own accessor + property on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val !== 11; + } else { + return true; + } +} +var obj = { + 10: 10, + length: 20 +}; +Object.defineProperty(obj, "0", { + get: function() { + return 11; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..5eace82d008bd0b26335938415378cfd9657f485 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-1.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - callbackfn called with correct parameters +---*/ + +function callbackfn(val, Idx, obj) +{ + if (obj[Idx] === val) + return true; +} +var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +assert.sameValue(arr.every(callbackfn), true, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-10.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..1feb4cc4605f4a31f89eb52f4e14fd6037af913a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-10.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - callbackfn is called with 1 formal + parameter +---*/ + +var called = 0; +function callbackfn(val) { + called++; + return val > 10; +} +assert([11, 12].every(callbackfn), '[11, 12].every(callbackfn) !== true'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-11.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..17d1fd6034b4edc4eab0098c68b3e921e372ad92 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-11.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - callbackfn is called with 2 formal + parameter +---*/ + +var called = 0; +function callbackfn(val, idx) { + called++; + return val > 10 && arguments[2][idx] === val; +} +assert([11, 12].every(callbackfn), '[11, 12].every(callbackfn) !== true'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-12.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-12.js new file mode 100644 index 0000000000000000000000000000000000000000..f77a2a3293ae2cbf094a81fe6af3bce24fb8020b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-12.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - callbackfn is called with 3 formal + parameter +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + return val > 10 && obj[idx] === val; +} +assert([11, 12, 13].every(callbackfn), '[11, 12, 13].every(callbackfn) !== true'); +assert.sameValue(called, 3, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-13.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-13.js new file mode 100644 index 0000000000000000000000000000000000000000..1ae7d87a49b7c6fc010533c90893d74b5a3436e6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-13.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - callbackfn that uses arguments object to + get parameter value +---*/ + +var called = 0; +function callbackfn() { + called++; + return arguments[2][arguments[1]] === arguments[0]; +} +assert([11, 12].every(callbackfn), '[11, 12].every(callbackfn) !== true'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-16.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-16.js new file mode 100644 index 0000000000000000000000000000000000000000..6f4942b52b4edeb13c8be2fb2a991eb2fe275afb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-16.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - 'this' of 'callbackfn' is a Boolean object + when T is not an object (T is a boolean primitive) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this.valueOf() !== false; +} +var obj = { + 0: 11, + length: 2 +}; +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn, false), false, 'SendableArray.prototype.every.call(obj, callbackfn, false)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-17.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-17.js new file mode 100644 index 0000000000000000000000000000000000000000..5698cf207642baec00b4b98016ef90b087d89981 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-17.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every -'this' of 'callbackfn' is a Number object + when T is not an object (T is a number primitive) +---*/ + +var accessed = false; +function callbackfn(val, idx, o) { + accessed = true; + return 5 === this.valueOf(); +} +var obj = { + 0: 11, + length: 2 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn, 5), 'SendableArray.prototype.every.call(obj, callbackfn, 5) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-18.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-18.js new file mode 100644 index 0000000000000000000000000000000000000000..f35d1ad44d94cf2e0adac7183889450527fd7bfd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-18.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - 'this' of 'callbackfn' is an String object + when T is not an object (T is a string primitive) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return 'hello' === this.valueOf(); +} +var obj = { + 0: 11, + length: 2 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn, "hello"), 'SendableArray.prototype.every.call(obj, callbackfn, "hello") !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-19.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-19.js new file mode 100644 index 0000000000000000000000000000000000000000..d0733969731f16b448e863def37a9f2a26a41211 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-19.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - non-indexed properties are not called +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + return val !== 8; +} +var obj = { + 0: 11, + 10: 12, + non_index_property: 8, + length: 20 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-2.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..8a3c72d1be6b4a8436095f75df34ef863c425524 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-2.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - callbackfn takes 3 arguments +---*/ + +function callbackfn(val, Idx, obj) +{ + if (arguments.length === 3) //verify if callbackfn was called with 3 parameters + return true; +} +var arr = [0, 1, true, null, new Object(), "five"]; +arr[999999] = -6.6; +assert.sameValue(arr.every(callbackfn), true, 'arr.every(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-20.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-20.js new file mode 100644 index 0000000000000000000000000000000000000000..bd312b72dffd140b15f8521e9e8bd4f1206d0636 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-20.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - callbackfn called with correct parameters + (thisArg is correct) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return 10 === this.threshold; +} +var thisArg = { + threshold: 10 +}; +var obj = { + 0: 11, + length: 1 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn, thisArg), 'SendableArray.prototype.every.call(obj, callbackfn, thisArg) !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-21.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-21.js new file mode 100644 index 0000000000000000000000000000000000000000..744155995177e004a2e730bf343806a6e83e4769 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-21.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - callbackfn called with correct parameters + (kValue is correct) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + if (idx === 0) { + return val === 11; + } + + if (idx === 1) { + return val === 12; + } + +} +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-22.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-22.js new file mode 100644 index 0000000000000000000000000000000000000000..ae16199330d105258da1b08e74b2f28647bfc2b0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-22.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - callbackfn called with correct parameters + (the index k is correct) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + if (val === 11) { + return idx === 0; + } + + if (val === 12) { + return idx === 1; + } + +} +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-23.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-23.js new file mode 100644 index 0000000000000000000000000000000000000000..f5e1bbcab088ec3789998f292528b84bc5d3f9b8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-23.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - callbackfn called with correct parameters + (this object O is correct) +---*/ + +var called = 0; +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +function callbackfn(val, idx, o) { + called++; + return obj === o; +} +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-3.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-3.js new file mode 100644 index 0000000000000000000000000000000000000000..f1770d84355f5288b755f18ac9e44738fd97c3f0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-3.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every immediately returns false if callbackfn + returns false +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; + if (idx > 5) + return false; + else + return true; +} +var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +assert.sameValue(arr.every(callbackfn), false, 'arr.every(callbackfn)'); +assert.sameValue(callCnt, 7, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-4.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..42e19095dc0a5504e0dca58cd6a81740a5eb5a3c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-4.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - k values are passed in ascending numeric + order +---*/ + +var arr = [0, 1, 2, 3, 4, 5]; +var lastIdx = 0; +var called = 0; +function callbackfn(val, idx, o) { + called++; + if (lastIdx !== idx) { + return false; + } else { + lastIdx++; + return true; + } +} +assert(arr.every(callbackfn), 'arr.every(callbackfn) !== true'); +assert.sameValue(arr.length, called, 'arr.length'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-5.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..520584fbe36d04678f5de4b5ca14a962447e55f0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-5.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - k values are accessed during each + iteration and not prior to starting the loop on an Array +---*/ + +var called = 0; +var kIndex = []; +//By below way, we could verify that k would be setted as 0, 1, ..., length - 1 in order, and each value will be setted one time. +function callbackfn(val, idx, obj) { + called++; + //Each position should be visited one time, which means k is accessed one time during iterations. + if (typeof kIndex[idx] === "undefined") { + //when current position is visited, its previous index should has been visited. + if (idx !== 0 && typeof kIndex[idx - 1] === "undefined") { + return false; + } + kIndex[idx] = 1; + return true; + } else { + return false; + } +} +assert([11, 12, 13, 14].every(callbackfn, undefined), '[11, 12, 13, 14].every(callbackfn, undefined) !== true'); +assert.sameValue(called, 4, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-6.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-6.js new file mode 100644 index 0000000000000000000000000000000000000000..57c4782d1286421d3a80ae33bac8ff619040f814 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-6.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - arguments to callbackfn are self consistent +---*/ + +var accessed = false; +var thisArg = {}; +var obj = { + 0: 11, + length: 1 +}; +function callbackfn() { + accessed = true; + return this === thisArg && + arguments[0] === 11 && + arguments[1] === 0 && + arguments[2] === obj; +} +assert(SendableArray.prototype.every.call(obj, callbackfn, thisArg), 'SendableArray.prototype.every.call(obj, callbackfn, thisArg) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-7.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..62a7a74f9d6609e8e85c5b9df9c7381dbb40f180 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-7.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - unhandled exceptions happened in + callbackfn terminate iteration +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + if (called === 1) { + throw new Test262Error("Exception occurred in callbackfn"); + } + return true; +} +var obj = { + 0: 11, + 4: 10, + 10: 8, + length: 20 +}; +assert.throws(Test262Error, function() { + SendableArray.prototype.every.call(obj, callbackfn); +}); +assert.sameValue(called, 1, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-8.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..727c7ecd58da09fcbb609a4994ee7b787917da78 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-8.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - element changed by callbackfn on previous + iterations is observed +---*/ + +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +function callbackfn(val, idx, o) { + if (idx === 0) { + obj[idx + 1] = 8; + } + return val > 10; +} +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-9.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..0749d08359141773d410f7ecefacd3a2ea6bf7d5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-ii-9.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - callbackfn is called with 0 formal + parameter +---*/ + +var called = 0; +function callbackfn() { + called++; + return true; +} +assert([11, 12].every(callbackfn), '[11, 12].every(callbackfn) !== true'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..25fe5b613ff446dfc70dd87c3178aba27859d20d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - return value of callbackfn is undefined +---*/ + +var accessed = false; +var obj = { + 0: 11, + length: 1 +}; +function callbackfn(val, idx, o) { + accessed = true; + return undefined; +} +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-10.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..8acc61f79e7aa39a3403d8ad3dd14d6d2fa504b9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-10.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a number + (value is Infinity) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return Infinity; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-11.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..4f9c82afba4a897434e8ce19205866089499a4dd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-11.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a number + (value is -Infinity) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return -Infinity; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-12.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-12.js new file mode 100644 index 0000000000000000000000000000000000000000..2b250c1ba1e16a22878f3290c06af11c6163b8d6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-12.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a number + (value is NaN) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return NaN; +} +assert.sameValue([11].every(callbackfn), false, '[11].every(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-13.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-13.js new file mode 100644 index 0000000000000000000000000000000000000000..1eaa419819c9ef32494c43285d672fb31aa4127a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-13.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is an empty + string +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return ""; +} +assert.sameValue([11].every(callbackfn), false, '[11].every(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-14.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-14.js new file mode 100644 index 0000000000000000000000000000000000000000..0de62153ffe30e611a4efd6019edf2ec8adeb34d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-14.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a non-empty + string +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return "non-empty string"; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-15.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-15.js new file mode 100644 index 0000000000000000000000000000000000000000..27de673dd70730042e684709fadbcf70827e2d25 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-15.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a Function + object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return function() {}; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-16.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-16.js new file mode 100644 index 0000000000000000000000000000000000000000..eee23a4da7bcc4c92577528e288bd98d5a0ef225 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-16.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is an Array + object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return []; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-17.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-17.js new file mode 100644 index 0000000000000000000000000000000000000000..cfba6f598036a2f8eda61f378e7280100e603066 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-17.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a String + object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return new String(); +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-18.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-18.js new file mode 100644 index 0000000000000000000000000000000000000000..6196bced8cdce068e04031e356feeae642457735 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-18.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a Boolean + object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return new Boolean(); +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-19.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-19.js new file mode 100644 index 0000000000000000000000000000000000000000..2adc8eb49a4cde678949c23e2449be8c2fc388e6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-19.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a Number + object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return new Number(); +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-2.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..2453981ea15c6c1274b3a17f44ff75e52d3bd45e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - return value of callbackfn is null +---*/ + +var accessed = false; +var obj = { + 0: 11, + length: 1 +}; +function callbackfn(val, idx, obj) { + accessed = true; + return null; +} +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-20.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-20.js new file mode 100644 index 0000000000000000000000000000000000000000..d5e1a532dae910b55af8430862ed0ce711543b75 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-20.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is the Math + object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return Math; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-21.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-21.js new file mode 100644 index 0000000000000000000000000000000000000000..08c4e30fcd67193add76c1da9dd6f07ac0a75d5c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-21.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - return value of callbackfn is a Date object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return new Date(0); +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-22.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-22.js new file mode 100644 index 0000000000000000000000000000000000000000..e9a533b266dca7c6908bab3f995ccb6a475c2232 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-22.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a RegExp + object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return new RegExp(); +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-23.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-23.js new file mode 100644 index 0000000000000000000000000000000000000000..1a4bfc56473b0be085cf5fffcd382d0d61471a17 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-23.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is the JSON + object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return JSON; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-24.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-24.js new file mode 100644 index 0000000000000000000000000000000000000000..bcd84e22880042e908105b3178d11f6b3189d465 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-24.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is an Error + object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return new EvalError(); +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-25.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-25.js new file mode 100644 index 0000000000000000000000000000000000000000..6b73fa423ae2927a4de95546e8931515573f8518 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-25.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is the + Arguments object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return arguments; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-27.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-27.js new file mode 100644 index 0000000000000000000000000000000000000000..127aecab8eeb518931805cc24d451925d3e2fe1a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-27.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is the global + object +---*/ + +var global = this; +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return global; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-28.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-28.js new file mode 100644 index 0000000000000000000000000000000000000000..3bb13b761fee2123b40326aac169133b8a49db7e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-28.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - false prevents further side effects +---*/ + +var result = false; +var obj = { + length: 20 +}; +function callbackfn(val, idx, obj) { + if (idx > 1) { + result = true; + } + return val > 10; +} +Object.defineProperty(obj, "0", { + get: function() { + return 11; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + return 8; + }, + configurable: true +}); +Object.defineProperty(obj, "2", { + get: function() { + result = true; + return 8; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); +assert.sameValue(result, false, 'result'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-29.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-29.js new file mode 100644 index 0000000000000000000000000000000000000000..a1fc50ba8cf9565982291cb8e8bc28bb57510b0e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-29.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value (new Boolean(false)) of + callbackfn is treated as true value +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return new Boolean(false); +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-3.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-3.js new file mode 100644 index 0000000000000000000000000000000000000000..24a118873634f75b7a2c690d601e12172d8780d5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-3.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a boolean + (value is false) +---*/ + +var accessed = false; +var obj = { + 0: 11, + length: 1 +}; +function callbackfn(val, idx, obj) { + accessed = true; + return false; +} +assert.sameValue(SendableArray.prototype.every.call(obj, callbackfn), false, 'SendableArray.prototype.every.call(obj, callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-4.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..deda81e6e19780cb39bcab4228f359ec7117e972 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-4.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a boolean + (value is true) +---*/ + +var accessed = false; +var obj = { + 0: 11, + length: 1 +}; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +assert(SendableArray.prototype.every.call(obj, callbackfn), 'SendableArray.prototype.every.call(obj, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-5.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..ba3ad76aeb75a29ff40ccfd66d51214da5f9d858 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-5.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a number + (value is 0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return 0; +} +assert.sameValue([11].every(callbackfn), false, '[11].every(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-6.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-6.js new file mode 100644 index 0000000000000000000000000000000000000000..306f9b4400067dad7a9ffc84a0804071a9e679ba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-6.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a number + (value is +0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return +0; +} +assert.sameValue([11].every(callbackfn), false, '[11].every(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-7.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..74163ff732fa9d5ebf8f04f9d6f7e7a7a4ca1cf8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-7.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a nunmber + (value is -0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return -0; +} +assert.sameValue([11].every(callbackfn), false, '[11].every(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-8.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..d30fa7a924e3dba6623bb224b43233c4fd1dda7c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-8.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a number + (value is positive number) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return 5; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-9.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..aa0ab248204ca2d267dce92ac05c3666664ef948 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-7-c-iii-9.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every - return value of callbackfn is a number + (value is negative number) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return -5; +} +assert([11].every(callbackfn), '[11].every(callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-1.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-1.js new file mode 100644 index 0000000000000000000000000000000000000000..c2d0891229d60cdb0c2ba77be4a1e710545cc9e8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every returns true if 'length' is 0 (empty array) +---*/ + +function cb() {} +var i = [].every(cb); +assert.sameValue(i, true, 'i'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-10.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-10.js new file mode 100644 index 0000000000000000000000000000000000000000..29794292320b75cbc98b0d7db92118bde7361761 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-10.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every - subclassed array when length is reduced +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 2; +function cb(val) +{ + if (val > 2) + return false; + else + return true; +} +var i = f.every(cb); +assert.sameValue(i, true, 'i'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-11.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-11.js new file mode 100644 index 0000000000000000000000000000000000000000..0d429ecc1dd2677bb9631e0a09afe89a51099b89 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-11.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every returns true when all calls to callbackfn + return true +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; + return true; +} +var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +assert.sameValue(arr.every(callbackfn), true, 'arr.every(callbackfn)'); +assert.sameValue(callCnt, 10, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-12.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-12.js new file mode 100644 index 0000000000000000000000000000000000000000..ceb0a285439c8d47941867f5f3979a8c962908e9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-12.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every doesn't mutate the array on which it is + called on +---*/ + +function callbackfn(val, idx, obj) +{ + return true; +} +var arr = [1, 2, 3, 4, 5]; +arr.every(callbackfn); +assert.sameValue(arr[0], 1, 'arr[0]'); +assert.sameValue(arr[1], 2, 'arr[1]'); +assert.sameValue(arr[2], 3, 'arr[2]'); +assert.sameValue(arr[3], 4, 'arr[3]'); +assert.sameValue(arr[4], 5, 'arr[4]'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-13.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-13.js new file mode 100644 index 0000000000000000000000000000000000000000..cad0a5a5fe461a810a3bee79c4a35f0bef554c2b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-13.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every doesn't visit expandos +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; + return true; +} +var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +arr["i"] = 10; +arr[true] = 11; +assert.sameValue(arr.every(callbackfn), true, 'arr.every(callbackfn)'); +assert.sameValue(callCnt, 10, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-2.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-2.js new file mode 100644 index 0000000000000000000000000000000000000000..f4df250fda7f23c59b546ffde1032b2764532967 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every returns true if 'length' is 0 (subclassed + Array, length overridden to null (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = null; +function cb() {} +var i = f.every(cb); +assert.sameValue(i, true, 'i'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-3.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-3.js new file mode 100644 index 0000000000000000000000000000000000000000..7a948d8fde070198f1571bfb846e93e09db105ed --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-3.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every returns true if 'length' is 0 (subclassed + Array, length overridden to false (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = false; +function cb() {} +var i = f.every(cb); +assert.sameValue(i, true, 'i'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-4.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-4.js new file mode 100644 index 0000000000000000000000000000000000000000..beaf4be5ae146448442e8fa0fe82071fee0cabe1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every returns true if 'length' is 0 (subclassed + Array, length overridden to 0 (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 0; +function cb() {} +var i = f.every(cb); +assert.sameValue(i, true, 'i'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-5.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-5.js new file mode 100644 index 0000000000000000000000000000000000000000..0fcbe639fa31aa928713c78c0e99137e9831a1f0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-5.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every returns true if 'length' is 0 (subclassed + Array, length overridden to '0' (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = '0'; +function cb() {} +var i = f.every(cb); +assert.sameValue(i, true, 'i'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-6.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-6.js new file mode 100644 index 0000000000000000000000000000000000000000..a5ab8b25758df3b16497cc7c2c1bb9ca8abd275b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-6.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every returns true if 'length' is 0 (subclassed + Array, length overridden with obj with valueOf) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + valueOf: function() { + return 0; + } +}; +f.length = o; +function cb() {} +var i = f.every(cb); +assert.sameValue(i, true, 'i'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-7.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-7.js new file mode 100644 index 0000000000000000000000000000000000000000..83962972827e29632d0b78900eb7ae0c2defc718 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-7.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every returns true if 'length' is 0 (subclassed + Array, length overridden with obj w/o valueOf (toString)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + toString: function() { + return '0'; + } +}; +f.length = o; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +function cb() {} +var i = f.every(cb); +assert.sameValue(i, true, 'i'); diff --git a/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-8.js b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-8.js new file mode 100644 index 0000000000000000000000000000000000000000..18302434c89d08c366ef01599124af04264b52a5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/15.4.4.16-8-8.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every returns true if 'length' is 0 (subclassed + Array, length overridden with [] +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = []; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +function cb() {} +var i = f.every(cb); +assert.sameValue(i, true, 'i'); diff --git a/test/sendable/builtins/Array/prototype/every/call-with-boolean.js b/test/sendable/builtins/Array/prototype/every/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..1a1db10090ff546d9c3a22897f81ff661b775397 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: Array.prototype.every applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.every.call(true, () => {}), + true, + 'SendableArray.prototype.every.call(true, () => {}) must return true' +); +assert.sameValue( + SendableArray.prototype.every.call(false, () => {}), + true, + 'SendableArray.prototype.every.call(false, () => {}) must return true' +); diff --git a/test/sendable/builtins/Array/prototype/every/callbackfn-resize-arraybuffer.js b/test/sendable/builtins/Array/prototype/every/callbackfn-resize-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..b18129bf2dcba94f85ff4fa9a7f4cf19f97baa3a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/callbackfn-resize-arraybuffer.js @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: TypedArray instance buffer can be resized during iteration +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.every.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + elements.push(element); + indices.push(index); + arrays.push(array); + return true; + }); + assert.compareArray(elements, expectedElements, 'elements (shrink)'); + assert.compareArray(indices, expectedIndices, 'indices (shrink)'); + assert.compareArray(arrays, expectedArrays, 'arrays (shrink)'); + assert.sameValue(result, true, 'result (shrink)'); + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.every.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + elements.push(element); + indices.push(index); + arrays.push(array); + return true; + }); + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, true, 'result (grow)'); +}); diff --git a/test/sendable/builtins/Array/prototype/every/length.js b/test/sendable/builtins/Array/prototype/every/length.js new file mode 100644 index 0000000000000000000000000000000000000000..06dea31d019276b4dcf94edfb31162ab61a9aa26 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/length.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every.length value and property descriptor +info: | + Array.prototype.every ( callbackfn [ , thisArg] ) + The length property of the of function is 1. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.every, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/every/name.js b/test/sendable/builtins/Array/prototype/every/name.js new file mode 100644 index 0000000000000000000000000000000000000000..2c263624f7abd4932715b4d7ea7df7a597bf89a9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.prototype.every.name is "every". +info: | + Array.prototype.every ( callbackfn [ , thisArg] ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.every, "name", { + value: "every", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/every/not-a-constructor.js b/test/sendable/builtins/Array/prototype/every/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..8783fca3a6d6abd2cbf72f2a2e7796295c2220e0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/not-a-constructor.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.every does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.every), + false, + 'isConstructor(SendableArray.prototype.every) must return false' +); + +assert.throws(TypeError, () => { + new SendableArray.prototype.every(() => {}); +}); + diff --git a/test/sendable/builtins/Array/prototype/every/prop-desc.js b/test/sendable/builtins/Array/prototype/every/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..3bff712187689e9d73a408e06d8df827a658047a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + "every" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.every, 'function', 'typeof'); +verifyPrimordialProperty(SendableArray.prototype, "every", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/every/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/every/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..966a3ff6dbc87672e2b7896996d53182613e9022 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.p.every behaves correctly when receiver is backed by resizable + buffer that is grown mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + // Returns true by default. + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(SendableArray.prototype.every.call(fixedLength, ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(SendableArray.prototype.every.call(fixedLengthWithOffset, ResizeMidIteration)); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(SendableArray.prototype.every.call(lengthTracking, ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(SendableArray.prototype.every.call(lengthTrackingWithOffset, ResizeMidIteration)); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/every/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/every/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..52ebc890af5759f074cc8cfa193930af4a59c896 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.p.every behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + // Returns true by default. + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(SendableArray.prototype.every.call(fixedLength, ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(SendableArray.prototype.every.call(fixedLengthWithOffset, ResizeMidIteration)); + assert.compareArray(values, [4]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(SendableArray.prototype.every.call(lengthTracking, ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(SendableArray.prototype.every.call(lengthTrackingWithOffset, ResizeMidIteration)); + assert.compareArray(values, [4]); +} diff --git a/test/sendable/builtins/Array/prototype/every/resizable-buffer.js b/test/sendable/builtins/Array/prototype/every/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..a56db539af81542c8c04188f360e99f8cb88a491 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/every/resizable-buffer.js @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.every +description: > + Array.p.every behaves correctly when the receiver is backed by + resizable buffer +includes: [resizableArrayBufferUtils.js ] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + function div3(n) { + return Number(n) % 3 == 0; + } + function even(n) { + return Number(n) % 2 == 0; + } + function over10(n) { + return Number(n) > 10; + } + assert(!Array.prototype.every.call(fixedLength, div3)); + assert(Array.prototype.every.call(fixedLength, even)); + assert(!Array.prototype.every.call(fixedLengthWithOffset, div3)); + assert(Array.prototype.every.call(fixedLengthWithOffset, even)); + assert(!Array.prototype.every.call(lengthTracking, div3)); + assert(Array.prototype.every.call(lengthTracking, even)); + assert(!Array.prototype.every.call(lengthTrackingWithOffset, div3)); + assert(Array.prototype.every.call(lengthTrackingWithOffset, even)); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + // Calling .every on an out of bounds TA doesn't throw. + assert(Array.prototype.every.call(fixedLength, div3)); + assert(Array.prototype.every.call(fixedLengthWithOffset, div3)); + assert(!Array.prototype.every.call(lengthTracking, div3)); + assert(Array.prototype.every.call(lengthTracking, even)); + assert(!Array.prototype.every.call(lengthTrackingWithOffset, div3)); + assert(Array.prototype.every.call(lengthTrackingWithOffset, even)); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + // Calling .every on an out of bounds TA doesn't throw. + assert(Array.prototype.every.call(fixedLength, div3)); + assert(Array.prototype.every.call(fixedLengthWithOffset, div3)); + assert(Array.prototype.every.call(lengthTrackingWithOffset, div3)); + assert(Array.prototype.every.call(lengthTracking, div3)); + assert(Array.prototype.every.call(lengthTracking, even)); + // Shrink to zero. + rab.resize(0); + // Calling .every on an out of bounds TA doesn't throw. + assert(Array.prototype.every.call(fixedLength, div3)); + assert(Array.prototype.every.call(fixedLengthWithOffset, div3)); + assert(Array.prototype.every.call(lengthTrackingWithOffset, div3)); + assert(Array.prototype.every.call(lengthTracking, div3)); + assert(Array.prototype.every.call(lengthTracking, even)); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + assert(!Array.prototype.every.call(fixedLength, div3)); + assert(Array.prototype.every.call(fixedLength, even)); + assert(!Array.prototype.every.call(fixedLengthWithOffset, div3)); + assert(Array.prototype.every.call(fixedLengthWithOffset, even)); + assert(!Array.prototype.every.call(lengthTracking, div3)); + assert(Array.prototype.every.call(lengthTracking, even)); + assert(!Array.prototype.every.call(lengthTrackingWithOffset, div3)); + assert(Array.prototype.every.call(lengthTrackingWithOffset, even)); +} diff --git a/test/sendable/builtins/Array/prototype/exotic-array.js b/test/sendable/builtins/Array/prototype/exotic-array.js new file mode 100644 index 0000000000000000000000000000000000000000..aef0dae61e69b591e7c8824fd58199e0c66bac6f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/exotic-array.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-properties-of-the-array-prototype-object +description: > + Array.prototype is an exoctic array object +info: | + 22.1.3 Properties of the Array Prototype Object + + (...) + The Array prototype object is an Array exotic object and has the internal + methods specified for such objects. +---*/ + +SendableArray.prototype[2] = 42; +assert.sameValue(SendableArray.prototype.length, 3); +assert.sameValue(SendableArray.prototype[0], undefined, 'SendableArray.prototype[0]'); +assert.sameValue(SendableArray.prototype[1], undefined, 'SendableArray.prototype[1]'); +assert.sameValue(SendableArray.prototype[2], 42, 'SendableArray.prototype[2]'); +assert.sameValue({}.toString.call(SendableArray.prototype), '[object SendableArray]'); diff --git a/test/sendable/builtins/Array/prototype/fill/call-with-boolean.js b/test/sendable/builtins/Array/prototype/fill/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..1b8ff7ce353d39f69a3975b576e5b2fc4a969517 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: Array.prototype.fill applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.fill.call(true) instanceof Boolean, + true, + 'The result of `(SendableArray.prototype.fill.call(true) instanceof Boolean)` is true' +); +assert.sameValue( + SendableArray.prototype.fill.call(false) instanceof Boolean, + true, + 'The result of `(SendableArray.prototype.fill.call(false) instanceof Boolean)` is true' +); diff --git a/test/sendable/builtins/Array/prototype/fill/coerced-indexes.js b/test/sendable/builtins/Array/prototype/fill/coerced-indexes.js new file mode 100644 index 0000000000000000000000000000000000000000..0a0f78fbbd8fafd332dd06d74968791c33eb05fb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/coerced-indexes.js @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Fills elements from coerced to Integer `start` and `end` values +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 7. Let relativeStart be ToInteger(start). + 8. ReturnIfAbrupt(relativeStart). + 9. If relativeStart < 0, let k be max((len + relativeStart),0); else let k be + min(relativeStart, len). + 10. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). +includes: [compareArray.js] +---*/ + +assert.compareArray([0, 0].fill(1, undefined), [1, 1], + '[0, 0].fill(1, undefined) must return [1, 1]' +); +assert.compareArray([0, 0].fill(1, 0, undefined), [1, 1], + '[0, 0].fill(1, 0, undefined) must return [1, 1]' +); +assert.compareArray([0, 0].fill(1, null), [1, 1], + '[0, 0].fill(1, null) must return [1, 1]' +); +assert.compareArray([0, 0].fill(1, 0, null), [0, 0], + '[0, 0].fill(1, 0, null) must return [0, 0]' +); +assert.compareArray([0, 0].fill(1, true), [0, 1], + '[0, 0].fill(1, true) must return [0, 1]' +); +assert.compareArray([0, 0].fill(1, 0, true), [1, 0], + '[0, 0].fill(1, 0, true) must return [1, 0]' +); +assert.compareArray([0, 0].fill(1, false), [1, 1], + '[0, 0].fill(1, false) must return [1, 1]' +); +assert.compareArray([0, 0].fill(1, 0, false), [0, 0], + '[0, 0].fill(1, 0, false) must return [0, 0]' +); +assert.compareArray([0, 0].fill(1, NaN), [1, 1], + '[0, 0].fill(1, NaN) must return [1, 1]' +); +assert.compareArray([0, 0].fill(1, 0, NaN), [0, 0], + '[0, 0].fill(1, 0, NaN) must return [0, 0]' +); +assert.compareArray([0, 0].fill(1, '1'), [0, 1], + '[0, 0].fill(1, "1") must return [0, 1]' +); +assert.compareArray([0, 0].fill(1, 0, '1'), [1, 0], + '[0, 0].fill(1, 0, "1") must return [1, 0]' +); +assert.compareArray([0, 0].fill(1, 1.5), [0, 1], + '[0, 0].fill(1, 1.5) must return [0, 1]' +); +assert.compareArray([0, 0].fill(1, 0, 1.5), [1, 0], + '[0, 0].fill(1, 0, 1.5) must return [1, 0]' +); diff --git a/test/sendable/builtins/Array/prototype/fill/fill-values-custom-start-and-end.js b/test/sendable/builtins/Array/prototype/fill/fill-values-custom-start-and-end.js new file mode 100644 index 0000000000000000000000000000000000000000..94b445df1715a12d09419543d6e4367f32ff406c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/fill-values-custom-start-and-end.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Fills all the elements from a with a custom start and end indexes. +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 7. If relativeStart < 0, let k be max((len + relativeStart),0); else let k be + min(relativeStart, len). + 8. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 9. ReturnIfAbrupt(relativeEnd). + 10. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let + final be min(relativeEnd, len). +includes: [compareArray.js] +---*/ + +assert.compareArray([0, 0, 0].fill(8, 1, 2), [0, 8, 0], '[0, 0, 0].fill(8, 1, 2) must return [0, 8, 0]'); +assert.compareArray( + [0, 0, 0, 0, 0].fill(8, -3, 4), + [0, 0, 8, 8, 0], + '[0, 0, 0, 0, 0].fill(8, -3, 4) must return [0, 0, 8, 8, 0]' +); +assert.compareArray( + [0, 0, 0, 0, 0].fill(8, -2, -1), + [0, 0, 0, 8, 0], + '[0, 0, 0, 0, 0].fill(8, -2, -1) must return [0, 0, 0, 8, 0]' +); +assert.compareArray( + [0, 0, 0, 0, 0].fill(8, -1, -3), + [0, 0, 0, 0, 0], + '[0, 0, 0, 0, 0].fill(8, -1, -3) must return [0, 0, 0, 0, 0]' +); +assert.compareArray([, , , , 0].fill(8, 1, 3), [, 8, 8, , 0], '[, , , , 0].fill(8, 1, 3) must return [, 8, 8, , 0]'); diff --git a/test/sendable/builtins/Array/prototype/fill/fill-values-relative-end.js b/test/sendable/builtins/Array/prototype/fill/fill-values-relative-end.js new file mode 100644 index 0000000000000000000000000000000000000000..7945d7b620821c954b4420370e3092e5b00fcc19 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/fill-values-relative-end.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Fills all the elements from a with a custom start index. +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 8. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 9. ReturnIfAbrupt(relativeEnd). + 10. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let + final be min(relativeEnd, len). +includes: [compareArray.js] +---*/ + +assert.compareArray([0, 0, 0].fill(8, 0, 1), [8, 0, 0], + '[0, 0, 0].fill(8, 0, 1) must return [8, 0, 0]' +); +assert.compareArray([0, 0, 0].fill(8, 0, -1), [8, 8, 0], + '[0, 0, 0].fill(8, 0, -1) must return [8, 8, 0]' +); +assert.compareArray([0, 0, 0].fill(8, 0, 5), [8, 8, 8], + '[0, 0, 0].fill(8, 0, 5) must return [8, 8, 8]' +); diff --git a/test/sendable/builtins/Array/prototype/fill/fill-values-relative-start.js b/test/sendable/builtins/Array/prototype/fill/fill-values-relative-start.js new file mode 100644 index 0000000000000000000000000000000000000000..5d292d0375384f6ba0d8f1e66596b872116f0995 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/fill-values-relative-start.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Fills all the elements from a with a custom start index. +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 7. If relativeStart < 0, let k be max((len + relativeStart),0); else let k be + min(relativeStart, len). +includes: [compareArray.js] +---*/ + +assert.compareArray([0, 0, 0].fill(8, 1), [0, 8, 8], + '[0, 0, 0].fill(8, 1) must return [0, 8, 8]' +); +assert.compareArray([0, 0, 0].fill(8, 4), [0, 0, 0], + '[0, 0, 0].fill(8, 4) must return [0, 0, 0]' +); +assert.compareArray([0, 0, 0].fill(8, -1), [0, 0, 8], + '[0, 0, 0].fill(8, -1) must return [0, 0, 8]' +); diff --git a/test/sendable/builtins/Array/prototype/fill/fill-values.js b/test/sendable/builtins/Array/prototype/fill/fill-values.js new file mode 100644 index 0000000000000000000000000000000000000000..4ce84e6b982e8f5702a0b0aae3f445c8a1b67c8a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/fill-values.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Fills all the elements with `value` from a defaul start and index. +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 7. If relativeStart < 0, let k be max((len + relativeStart),0); else let k be + min(relativeStart, len). + 8. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 9. ReturnIfAbrupt(relativeEnd). + 10. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let + final be min(relativeEnd, len). + 11. Repeat, while k < final + a. Let Pk be ToString(k). + b. Let setStatus be Set(O, Pk, value, true). + c. ReturnIfAbrupt(setStatus). + d. Increase k by 1. + 12. Return O. +includes: [compareArray.js] +---*/ + +assert.compareArray([].fill(8), [], '[].fill(8) must return []'); +assert.compareArray([0, 0].fill(), [undefined, undefined], '[0, 0].fill() must return [undefined, undefined]'); +assert.compareArray([0, 0, 0].fill(8), [8, 8, 8], + '[0, 0, 0].fill(8) must return [8, 8, 8]' +); diff --git a/test/sendable/builtins/Array/prototype/fill/length-near-integer-limit.js b/test/sendable/builtins/Array/prototype/fill/length-near-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..39114158cbe270595bd8774898a2b1316d50d5e7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/length-near-integer-limit.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.fill +description: > + Elements are filled in an array-like object + whose "length" property is near the integer limit. +info: | + Array.prototype.fill ( value [ , start [ , end ] ] ) + 1. Let O be ? ToObject(this value). + 2. Let len be ? LengthOfArrayLike(O). + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). +---*/ + +var value = {}; +var startIndex = Number.MAX_SAFE_INTEGER - 3; +var arrayLike = { + length: Number.MAX_SAFE_INTEGER, +}; +SendableArray.prototype.fill.call(arrayLike, value, startIndex, startIndex + 3); +assert.sameValue(arrayLike[startIndex], value); +assert.sameValue(arrayLike[startIndex + 1], value); +assert.sameValue(arrayLike[startIndex + 2], value); diff --git a/test/sendable/builtins/Array/prototype/fill/length.js b/test/sendable/builtins/Array/prototype/fill/length.js new file mode 100644 index 0000000000000000000000000000000000000000..41804705e2881759bb0139245f037133a61742d5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/length.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: Array.prototype.fill.length value and descriptor. +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.fill, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/fill/name.js b/test/sendable/builtins/Array/prototype/fill/name.js new file mode 100644 index 0000000000000000000000000000000000000000..4a9493211039d5390b9c5f224b52b16d6aa093fc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/name.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Array.prototype.fill.name value and descriptor. +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.fill, "name", { + value: "fill", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/fill/not-a-constructor.js b/test/sendable/builtins/Array/prototype/fill/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..ec9cba43055b37a05d31eb3e47b4bee2b4b05124 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.fill does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.prototype.fill), false, 'isConstructor(SendableArray.prototype.fill) must return false'); +assert.throws(TypeError, () => { + new SendableArray.prototype.fill(); +}); + diff --git a/test/sendable/builtins/Array/prototype/fill/prop-desc.js b/test/sendable/builtins/Array/prototype/fill/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..da501932b36acee24b535c5c3ae5ba95ed0fec9c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: Property type and descriptor. +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.fill, + 'function', + '`typeof SendableArray.prototype.fill` is `function`' +); +verifyProperty(SendableArray.prototype, "fill", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/fill/resizable-buffer.js b/test/sendable/builtins/Array/prototype/fill/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..980e1553935ce05bad68842b2048e712559fe4a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/resizable-buffer.js @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Array.p.fill behaves correctly when the receiver is backed by + resizable buffer +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function ReadDataFromBuffer(ab, ctor) { + let result = []; + const ta = new ctor(ab, 0, ab.byteLength / ctor.BYTES_PER_ELEMENT); + for (let item of ta) { + result.push(Number(item)); + } + return result; +} +function ArrayFillHelper(ta, n, start, end) { + if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) { + SendableArray.prototype.fill.call(ta, BigInt(n), start, end); + } else { + SendableArray.prototype.fill.call(ta, n, start, end); + } +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 0, + 0, + 0, + 0 + ]); + ArrayFillHelper(fixedLength, 1); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 1, + 1, + 1, + 1 + ]); + ArrayFillHelper(fixedLengthWithOffset, 2); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 1, + 1, + 2, + 2 + ]); + ArrayFillHelper(lengthTracking, 3); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 3, + 3, + 3, + 3 + ]); + ArrayFillHelper(lengthTrackingWithOffset, 4); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 3, + 3, + 4, + 4 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + ArrayFillHelper(fixedLength, 5); + ArrayFillHelper(fixedLengthWithOffset, 6); + // We'll check below that these were no-op. + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 3, + 3, + 4 + ]); + ArrayFillHelper(lengthTracking, 7); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 7, + 7, + 7 + ]); + ArrayFillHelper(lengthTrackingWithOffset, 8); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 7, + 7, + 8 + ]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + // We'll check below that these were no-op. + ArrayFillHelper(fixedLength, 9); + ArrayFillHelper(fixedLengthWithOffset, 10); + ArrayFillHelper(lengthTrackingWithOffset, 11); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [7]); + ArrayFillHelper(lengthTracking, 12); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [12]); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + ArrayFillHelper(fixedLength, 13); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 13, + 13, + 13, + 13, + 0, + 0 + ]); + ArrayFillHelper(fixedLengthWithOffset, 14); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 13, + 13, + 14, + 14, + 0, + 0 + ]); + ArrayFillHelper(lengthTracking, 15); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 15, + 15, + 15, + 15, + 15 + ]); + ArrayFillHelper(lengthTrackingWithOffset, 16); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 15, + 16, + 16, + 16, + 16 + ]); + // Filling with non-undefined start & end. + ArrayFillHelper(fixedLength, 17, 1, 3); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 17, + 17, + 16, + 16, + 16 + ]); + ArrayFillHelper(fixedLengthWithOffset, 18, 1, 2); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 17, + 17, + 18, + 16, + 16 + ]); + ArrayFillHelper(lengthTracking, 19, 1, 3); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 19, + 19, + 18, + 16, + 16 + ]); + ArrayFillHelper(lengthTrackingWithOffset, 20, 1, 2); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 19, + 19, + 20, + 16, + 16 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-end-as-symbol.js b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-end-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..aaf70cbf48d9256097ed31dc67ce2c217a194c3a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-end-as-symbol.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Return abrupt from ToInteger(end) as a Symbol. +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 8. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 9. ReturnIfAbrupt(relativeEnd). +features: [Symbol] +---*/ + +var end = Symbol(1); +assert.throws(TypeError, function() { + [].fill(1, 0, end); +}); diff --git a/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-end.js b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-end.js new file mode 100644 index 0000000000000000000000000000000000000000..78a2faf59aceedb93304772d2ebf063b267ad79b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-end.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Return abrupt from ToInteger(end). +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 8. If end is undefined, let relativeEnd be len; else let relativeEnd be + ToInteger(end). + 9. ReturnIfAbrupt(relativeEnd). +---*/ + +var end = { + valueOf: function() { + throw new Test262Error(); + } +}; +assert.throws(Test262Error, function() { + [].fill(1, 0, end); +}); diff --git a/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-setting-property-value.js b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-setting-property-value.js new file mode 100644 index 0000000000000000000000000000000000000000..0263e0880cebe72eb463a9850f0ff5ab0f636bbc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-setting-property-value.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Return abrupt from setting a property value. +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 11. Repeat, while k < final + a. Let Pk be ToString(k). + b. Let setStatus be Set(O, Pk, value, true). + c. ReturnIfAbrupt(setStatus). +---*/ + +var a1 = []; +Object.freeze(a1); +// won't break on an empty array. +a1.fill(1); +var a2 = { + length: 1 +}; +Object.defineProperty(a2, '0', { + set: function() { + throw new Test262Error(); + } +}) +assert.throws(Test262Error, function() { + SendableArray.prototype.fill.call(a2); +}); diff --git a/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-start-as-symbol.js b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-start-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..a4aeda89e9ad6fbb36025796b612d717ce7e0b08 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-start-as-symbol.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Return abrupt from ToInteger(start) as a Symbol. +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 5. Let relativeStart be ToInteger(start). + 6. ReturnIfAbrupt(relativeStart). +features: [Symbol] +---*/ + +var start = Symbol(1); +assert.throws(TypeError, function() { + [].fill(1, start); +}); diff --git a/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-start.js b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-start.js new file mode 100644 index 0000000000000000000000000000000000000000..cda4a75596bc759e816254f892d9faa622e41b9b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-start.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Return abrupt from ToInteger(start). +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 5. Let relativeStart be ToInteger(start). + 6. ReturnIfAbrupt(relativeStart). +---*/ + +var start = { + valueOf: function() { + throw new Test262Error(); + } +}; +assert.throws(Test262Error, function() { + [].fill(1, start); +}); diff --git a/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-this-length-as-symbol.js b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-this-length-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..f7f03cfb8fdfc48978ab3863b69a053f5103495b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-this-length-as-symbol.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Return abrupt from ToLength(Get(O, "length")) where length is a Symbol. +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let len be ToLength(Get(O, "length")). + 4. ReturnIfAbrupt(len). +features: [Symbol] +---*/ + +var o = {}; +o.length = Symbol(1); +// value argument is given to avoid false positives +assert.throws(TypeError, function() { + [].fill.call(o, 1); +}); diff --git a/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-this-length.js b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-this-length.js new file mode 100644 index 0000000000000000000000000000000000000000..02c6f2b2a4510f5ad27796db23f28f7dd87ba04b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-this-length.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Return abrupt from ToLength(Get(O, "length")). +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let len be ToLength(Get(O, "length")). + 4. ReturnIfAbrupt(len). +---*/ + +var o1 = {}; +Object.defineProperty(o1, 'length', { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + [].fill.call(o1, 1); +}); +var o2 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; +assert.throws(Test262Error, function() { + [].fill.call(o2, 1); +}); diff --git a/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-this.js b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-this.js new file mode 100644 index 0000000000000000000000000000000000000000..1ac2e3d806e23efc80e4448147cf5d7937cb79ea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/return-abrupt-from-this.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Return abrupt from ToObject(this value). +info: | + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.fill.call(undefined, 1); +}); +assert.throws(TypeError, function() { + SendableArray.prototype.fill.call(null, 1); +}); diff --git a/test/sendable/builtins/Array/prototype/fill/return-this.js b/test/sendable/builtins/Array/prototype/fill/return-this.js new file mode 100644 index 0000000000000000000000000000000000000000..e228540f6e68dfd1c385cc4e2f52ae5762ee086d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/return-this.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Returns `this`. +info: | + 12. Return O. +---*/ + +var arr = []; +var result = arr.fill(1); +assert.sameValue(result, arr); +var o = { + length: 0 +}; +result = SendableArray.prototype.fill.call(o); +assert.sameValue(result, o); diff --git a/test/sendable/builtins/Array/prototype/fill/typed-array-resize.js b/test/sendable/builtins/Array/prototype/fill/typed-array-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..28b0cc79831936c56546932be0c960e709d7bbdf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/fill/typed-array-resize.js @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.fill +description: > + Array.p.fill called on a TypedArray backed by a resizable buffer + that goes out of bounds during evaluation of the arguments +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function ReadDataFromBuffer(ab, ctor) { + let result = []; + const ta = new ctor(ab, 0, ab.byteLength / ctor.BYTES_PER_ELEMENT); + for (let item of ta) { + result.push(Number(item)); + } + return result; +} +function ArrayFillHelper(ta, n, start, end) { + if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) { + SendableArray.prototype.fill.call(ta, BigInt(n), start, end); + } else { + SendableArray.prototype.fill.call(ta, n, start, end); + } +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 3; + } + }; + ArrayFillHelper(fixedLength, evil, 1, 2); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 0, + 0 + ]); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 1; + } + }; + ArrayFillHelper(fixedLength, 3, evil, 2); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 0, + 0 + ]); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 2; + } + }; + ArrayFillHelper(fixedLength, 3, 1, evil); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 0, + 0 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..fb50996a1465279887a6d8e3fc58d86b42ddfab1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to undefined throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.filter.call(undefined); // TypeError is thrown if value is undefined +}); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-10.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..bdc533dafb6ef33b66d05c0c5d2cd47a474d656d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-10.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to the Math object +---*/ + +function callbackfn(val, idx, obj) { + return '[object Math]' === Object.prototype.toString.call(obj); +} +Math.length = 1; +Math[0] = 1; +var newArr = SendableArray.prototype.filter.call(Math, callbackfn); +assert.sameValue(newArr[0], 1, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-11.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..eab3c61683e1fb880f5e30137a7669303d3c648c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-11.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to Date object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Date; +} +var obj = new Date(0); +obj.length = 1; +obj[0] = 1; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr[0], 1, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-12.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..19c40c45c99e2c425522f0f61e3973b80f6c3fb1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-12.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to RegExp object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof RegExp; +} +var obj = new RegExp(); +obj.length = 2; +obj[1] = true; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr[0], true, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-13.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..b1cd285cfa9853ce1b417a4f0b5ac951424df016 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-13.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to the JSON object +---*/ + +function callbackfn(val, idx, obj) { + return '[object JSON]' === Object.prototype.toString.call(JSON); +} +JSON.length = 1; +JSON[0] = 1; +var newArr = SendableArray.prototype.filter.call(JSON, callbackfn); +assert.sameValue(newArr[0], 1, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-14.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-14.js new file mode 100644 index 0000000000000000000000000000000000000000..be7ffb9e11693e0e4480108dedcb17225c4e6523 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-14.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to Error object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Error; +} +var obj = new Error(); +obj.length = 1; +obj[0] = 1; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr[0], 1, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-15.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..2c466dfd77a34b357f75607aa4206e00d8e4b341 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-15.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to the Arguments object +---*/ + +function callbackfn(val, idx, obj) { + return '[object Arguments]' === Object.prototype.toString.call(obj); +} +var obj = (function() { + return arguments; +}("a", "b")); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr[0], "a", 'newArr[0]'); +assert.sameValue(newArr[1], "b", 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..bd38b042c74efb881021af9d6ce0664970e5f083 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to null throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.filter.call(null); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..9ce975bb620615862d3bcfd2425630903b394d91 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-3.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to boolean primitive +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Boolean; +} +Boolean.prototype[0] = true; +Boolean.prototype.length = 1; +var newArr = SendableArray.prototype.filter.call(false, callbackfn); +assert.sameValue(newArr[0], true, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..bb2eb80bd44261d43b896157bc1c60eaf9232c6f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-4.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to Boolean Object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Boolean; +} +var obj = new Boolean(true); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert.sameValue(newArr[1], 12, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..4a45a6eb5f73787a4678c43cb010d82b4e887f33 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-5.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to number primitive +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Number; +} +Number.prototype[0] = 1; +Number.prototype.length = 1; +var newArr = SendableArray.prototype.filter.call(2.5, callbackfn); +assert.sameValue(newArr[0], 1, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..2eb53fe9d49507e6fbe370962b87421fdc87891e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-6.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to Number object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Number; +} +var obj = new Number(-128); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert.sameValue(newArr[1], 12, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-7.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..8e61bc6d4bfbedb71e34193e9fc9457b9979b314 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-7.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to string primitive +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof String; +} +var newArr = SendableArray.prototype.filter.call("abc", callbackfn); +assert.sameValue(newArr[0], "a", 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-8.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..c0002227c34caec57ddb3e3fdc9889d5585c4ff2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-8.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to String object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof String; +} +var obj = new String("abc"); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr[0], "a", 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-9.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..0cf847efa76a4c7e18780ab25890be7a6f789cb5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-1-9.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to Function object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Function; +} +var obj = function(a, b) { + return a + b; +}; +obj[0] = 11; +obj[1] = 9; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert.sameValue(newArr[1], 9, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-1.js new file mode 100644 index 0000000000000000000000000000000000000000..04bf45827220f9810c427d2a4dc89acde8d63034 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter doesn't mutate the Array on which it is + called on +---*/ + +function callbackfn(val, idx, obj) +{ + return true; +} +var srcArr = [1, 2, 3, 4, 5]; +srcArr.filter(callbackfn); +assert.sameValue(srcArr[0], 1, 'srcArr[0]'); +assert.sameValue(srcArr[1], 2, 'srcArr[1]'); +assert.sameValue(srcArr[2], 3, 'srcArr[2]'); +assert.sameValue(srcArr[3], 4, 'srcArr[3]'); +assert.sameValue(srcArr[4], 5, 'srcArr[4]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-2.js new file mode 100644 index 0000000000000000000000000000000000000000..509e2156123190d321ad74fbf415d35acc47f926 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-2.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter returns new Array with length equal to + number of true returned by callbackfn +---*/ + +function callbackfn(val, idx, obj) +{ + if (val % 2) + return true; + else + return false; +} +var srcArr = [1, 2, 3, 4, 5]; +var resArr = srcArr.filter(callbackfn); +assert.sameValue(resArr.length, 3, 'resArr.length'); +assert.sameValue(resArr[0], 1, 'resArr[0]'); +assert.sameValue(resArr[1], 3, 'resArr[1]'); +assert.sameValue(resArr[2], 5, 'resArr[2]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-3.js new file mode 100644 index 0000000000000000000000000000000000000000..f249899088a13fb94f00bb9d33f1ac162f3adad8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-3.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - subclassed array when length is reduced +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 1; +function cb() { + return true; +} +var a = f.filter(cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 1, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-4.js new file mode 100644 index 0000000000000000000000000000000000000000..b9b9bd251482477b2b010a6f7303cfa5717173b5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-10-4.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter doesn't visit expandos +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; +} +var srcArr = [1, 2, 3, 4, 5]; +srcArr["i"] = 10; +srcArr[true] = 11; +var resArr = srcArr.filter(callbackfn); +assert.sameValue(callCnt, 5, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..cd62a13c01f726f124102aea283bac6e8f9893b0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to Array-like object, 'length' is + own data property +---*/ + +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: 2 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-10.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-10.js new file mode 100644 index 0000000000000000000000000000000000000000..665b41d8fb6eb73ddb46ae93ee1eba7b52203599 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-10.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to Array-like object, 'length' is + inherited accessor property +---*/ + +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-11.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-11.js new file mode 100644 index 0000000000000000000000000000000000000000..fa5895a0d28540919f74a01cf6286555da25af06 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-11.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to Array-like object, 'length' is + own accessor property without a get function +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-12.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-12.js new file mode 100644 index 0000000000000000000000000000000000000000..360fb8cf550dcc5c975a38f6d3c561c50360f87c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-12.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - 'length' is own accessor property without + a get function that overrides an inherited accessor property +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +Object.defineProperty(Object.prototype, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var obj = { + 0: 12, + 1: 11 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-13.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-13.js new file mode 100644 index 0000000000000000000000000000000000000000..10950470e5613a7f573750e370c857b670ceea7c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-13.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to the Array-like object that + 'length' is inherited accessor property without a get function +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +var proto = {}; +Object.defineProperty(proto, "length", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 11; +child[1] = 12; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-14.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-14.js new file mode 100644 index 0000000000000000000000000000000000000000..42e2a551fe292f366bb6aed7a3a85d26a9ea7490 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-14.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to the Array-like object that + 'length property doesn't exist +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +var obj = { + 0: 11, + 1: 12 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-17.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-17.js new file mode 100644 index 0000000000000000000000000000000000000000..df98cae944aa373a8bd42f3d56f428dc660a2469 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-17.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to the Arguments object, which + implements its own property get method +---*/ + +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +var func = function(a, b) { + var newArr = SendableArray.prototype.filter.call(arguments, callbackfn); + return newArr.length === 2; +}; +assert(func(12, 11), 'func(12, 11) !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-18.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-18.js new file mode 100644 index 0000000000000000000000000000000000000000..57a4aca97c6010e5672dad4cd8c04638afafab3c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-18.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to String object, which implements + its own property get method +---*/ + +function callbackfn(val, idx, obj) { + return obj.length === 3; +} +var str = new String("012"); +var newArr = SendableArray.prototype.filter.call(str, callbackfn); +assert.sameValue(newArr.length, 3, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-19.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-19.js new file mode 100644 index 0000000000000000000000000000000000000000..09ee29ae0d617792ba83fab075017b11ebc860a6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-19.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to Function object, which + implements its own property get method +---*/ + +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +var fun = function(a, b) { + return a + b; +}; +fun[0] = 12; +fun[1] = 11; +fun[2] = 9; +var newArr = SendableArray.prototype.filter.call(fun, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..1c4d23720acca4c755873f52cf5e8366d70f95eb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-2.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - 'length' is own data property on an Array +---*/ +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +var newArr = [12, 11].filter(callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..3e0853a7e380e51ba043866a2d7322b0e9a8e731 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-3.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to Array-like object, 'length' is + an own data property that overrides an inherited data property +---*/ + +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +child[0] = 12; +child[1] = 11; +child[2] = 9; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..3c8d5dfec3eb2bb2f6c913eeaab3ca1245953255 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-4.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - 'length' is own data property that + overrides an inherited data property on an Array +---*/ + +var arrProtoLen; +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +arrProtoLen = SendableArray.prototype.length; +SendableArray.prototype.length = 0; +var newArr = [12, 11].filter(callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..79995d767f93c88900f81ebe1525e076859364e8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-5.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter to Array-like object, 'length' is an own + data property that overrides an inherited accessor property +---*/ + +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + value: 2, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-6.js new file mode 100644 index 0000000000000000000000000000000000000000..29c0ec3c594ba9695aa40c96bc073e0d8f0566e6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to Array-like object, 'length' is + an inherited data property +---*/ + +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +var proto = { + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-7.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-7.js new file mode 100644 index 0000000000000000000000000000000000000000..fbb529c91aef5f768fd6fd2e30ae687c8f9202b8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-7.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to Array-like object, 'length' is + an own accessor property +---*/ + +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return 2; + }, + configurable: true +}); +obj[0] = 12; +obj[1] = 11; +obj[2] = 9; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-8.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-8.js new file mode 100644 index 0000000000000000000000000000000000000000..8e669ff57184337d3325b7f7a70fea1bca791bb8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-8.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to Array-like object, 'length' is + own accessor property that overrides an inherited data property +---*/ + +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-9.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-9.js new file mode 100644 index 0000000000000000000000000000000000000000..c1127354e9ac6e864332f6e843f5d85dc6a26be7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-2-9.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied to Array-like object, 'length' is + an own accessor property that overrides an inherited accessor + property +---*/ + +function callbackfn(val, idx, obj) { + return obj.length === 2; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-1.js new file mode 100644 index 0000000000000000000000000000000000000000..7dd05a513d8cefa05fc0cf5e66635f9baa93cb06 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - value of 'length' is undefined +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +var obj = { + 0: 0, + 1: 1, + length: undefined +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-10.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-10.js new file mode 100644 index 0000000000000000000000000000000000000000..f5881ae85c76944d93b4d5ea6e49b4eeb5c0bc69 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-10.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of 'length' is a number (value is + NaN) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +var obj = { + 0: 9, + length: NaN +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-11.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-11.js new file mode 100644 index 0000000000000000000000000000000000000000..b7baf3ad82772c7d40d84d388f6afd7e06a0d081 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-11.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - 'length' is a string containing a + positive number +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: "2" +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-12.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-12.js new file mode 100644 index 0000000000000000000000000000000000000000..89680608af0c44800f63c050b90b645bb3f93075 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-12.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - 'length' is a string containing a + negative number +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: "-4294967294" +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(newArr[0], undefined, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-13.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-13.js new file mode 100644 index 0000000000000000000000000000000000000000..01b1533aac98316d7b91d4f50bfaf2795f838652 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-13.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - 'length' is a string containing a decimal + number +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: "2.5" +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-14.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-14.js new file mode 100644 index 0000000000000000000000000000000000000000..75e5724120c22ebb219e281834d5effddda3c25b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-14.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - 'length' is a string containing -Infinity +---*/ + +var accessed2 = false; +function callbackfn2(val, idx, obj) { + accessed2 = true; + return true; +} +var obj2 = { + 0: 9, + length: "-Infinity" +}; +var newArr2 = SendableArray.prototype.filter.call(obj2, callbackfn2); +assert.sameValue(accessed2, false, 'accessed2'); +assert.sameValue(newArr2.length, 0, 'newArr2.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-15.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-15.js new file mode 100644 index 0000000000000000000000000000000000000000..281b511263b79d298157467debf06457df9bc3c6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-15.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - 'length' is a string containing an + exponential number +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: "2E0" +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-16.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-16.js new file mode 100644 index 0000000000000000000000000000000000000000..e147cdd353124b80985138a3525f017aa0165e7e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-16.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - 'length' is a string containing a hex + number +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: "0x0002" +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-17.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-17.js new file mode 100644 index 0000000000000000000000000000000000000000..588d3cdee1320cae238590a5012b233ed12fa037 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-17.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - 'length' is a string containing a number + with leading zeros +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: "0002.00" +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-18.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-18.js new file mode 100644 index 0000000000000000000000000000000000000000..77d706360ddf8544b85f57dd2530d980b866579f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-18.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of 'length' is a string that can't + convert to a number +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +var obj = { + 0: 9, + length: "asdf!_" +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-19.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-19.js new file mode 100644 index 0000000000000000000000000000000000000000..55da68a8325108a8f62cdf596c483e8134da55d4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-19.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of 'length' is an Object which has + an own toString method. +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: { + toString: function() { + return '2'; + } + } +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-2.js new file mode 100644 index 0000000000000000000000000000000000000000..1d279f9c4bf70afca4e77531247d145d37f94809 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-2.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter applied on an Array-like object if 'length' + is 1 (length overridden to true(type conversion)) +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 0: 11, + 1: 9, + length: true +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-20.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-20.js new file mode 100644 index 0000000000000000000000000000000000000000..0e214059dee80ec3b5121a65306739301708666d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-20.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of 'length' is an Object which has + an own valueOf method. +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: { + valueOf: function() { + return 2; + } + } +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-21.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-21.js new file mode 100644 index 0000000000000000000000000000000000000000..c82570227082fa906bbf3474c5981add4401d7eb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-21.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - 'length' is an object that has an own + valueOf method that returns an object and toString method that + returns a string +---*/ + +var firstStepOccured = false; +var secondStepOccured = false; +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: { + valueOf: function() { + firstStepOccured = true; + return {}; + }, + toString: function() { + secondStepOccured = true; + return '2'; + } + } +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(firstStepOccured, 'firstStepOccured !== true'); +assert(secondStepOccured, 'secondStepOccured !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-22.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-22.js new file mode 100644 index 0000000000000000000000000000000000000000..ab1bb622ef4f674a5465f8c4a000a20500f8b2a3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-22.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter throws TypeError exception when 'length' is + an object with toString and valueOf methods that don�t return + primitive values +---*/ + +var accessed = false; +var firstStepOccured = false; +var secondStepOccured = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +var obj = { + 1: 11, + 2: 12, + + length: { + valueOf: function() { + firstStepOccured = true; + return {}; + }, + toString: function() { + secondStepOccured = true; + return {}; + } + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.filter.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); +assert(firstStepOccured, 'firstStepOccured !== true'); +assert(secondStepOccured, 'secondStepOccured !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-23.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-23.js new file mode 100644 index 0000000000000000000000000000000000000000..e8dfd3a0b02dad24dae839c84b2778c835f9e9f8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-23.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter uses inherited valueOf method when 'length' + is an object with an own toString and inherited valueOf methods +---*/ + +var valueOfAccessed = false; +var toStringAccessed = false; +function callbackfn(val, idx, obj) { + return true; +} +var proto = { + valueOf: function() { + valueOfAccessed = true; + return 2; + } +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.toString = function() { + toStringAccessed = true; + return '1'; +}; +var obj = { + 1: 11, + 2: 9, + length: child +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(toStringAccessed, false, 'toStringAccessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-24.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-24.js new file mode 100644 index 0000000000000000000000000000000000000000..60a78a7d5f0a307acd9d00b7f73f1c34a1312100 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-24.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of 'length' is a positive + non-integer, ensure truncation occurs in the proper direction +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: 2.685 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-25.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-25.js new file mode 100644 index 0000000000000000000000000000000000000000..4bda6a0ef9e122619b1b3fbab9b201d5467ebb6d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-25.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of 'length' is a negative + non-integer +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: -4294967294.5 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(newArr[0], undefined, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-3.js new file mode 100644 index 0000000000000000000000000000000000000000..b7cbddc7de9d6c99b976cd169177519fc32a683d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - value of 'length' is a number (value is 0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +var obj = { + 0: 11, + length: 0 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-4.js new file mode 100644 index 0000000000000000000000000000000000000000..53dbbaa1e529d012514ea55c2c8d29f15832dd37 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-4.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of 'length' is a number (value is + +0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +var obj = { + 0: 11, + length: +0 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-5.js new file mode 100644 index 0000000000000000000000000000000000000000..c69c8f5714ad465874f3e8ce5b99f5baea9ea1ac --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-5.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of 'length' is a number (value is + -0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +var obj = { + 0: 11, + length: -0 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-6.js new file mode 100644 index 0000000000000000000000000000000000000000..5678cdd80cc679555cb897b16e70cbfa709d61d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-6.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of 'length' is a number (value is + positive) +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: 2 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-7.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-7.js new file mode 100644 index 0000000000000000000000000000000000000000..97d83a508f7824c6c094490c4b9d7fb7647a294d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-7.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of 'length' is a number (value is + negative) +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 1: 11, + 2: 9, + length: -4294967294 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(newArr[0], undefined, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-9.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-9.js new file mode 100644 index 0000000000000000000000000000000000000000..bbac55190ebd58fc9aa739621294ffc51320bf8c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-3-9.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of 'length' is a number (value is + -Infinity) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return true; +} +var obj = { + 0: 9, + length: -Infinity +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..e505e0daa4665d269bdf3266d2162078b9bc0cfd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter throws TypeError if callbackfn is undefined +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.filter(); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-10.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-10.js new file mode 100644 index 0000000000000000000000000000000000000000..286cecd0c023069f2754ed09579293e61a27dbb3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-10.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - the exception is not thrown if exception + was thrown by step 2 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.filter.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-11.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-11.js new file mode 100644 index 0000000000000000000000000000000000000000..0f71ff8c79640a28ddbcc21b4db2892f9a9d53e1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-11.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - the exception is not thrown if exception + was thrown by step 3 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + throw new Test262Error(); + } + }; + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.filter.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-12.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-12.js new file mode 100644 index 0000000000000000000000000000000000000000..97251811fdc02e2a2c9db7c3e02c8326e2148150 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-12.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - 'callbackfn' is a function +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val === 9; + } + return false; +} +var newArr = [11, 9].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 9, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-15.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-15.js new file mode 100644 index 0000000000000000000000000000000000000000..12a6acfff6ef57a19d72576dd5a0c9560af726a4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-15.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - calling with no callbackfn is the same as + passing undefined for callbackfn +---*/ + +var obj = { + 10: 10 +}; +var lengthAccessed = false; +var loopAccessed = false; +Object.defineProperty(obj, "length", { + get: function() { + lengthAccessed = true; + return 20; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + loopAccessed = true; + return 10; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.filter.call(obj); +}); +assert(lengthAccessed, 'lengthAccessed !== true'); +assert.sameValue(loopAccessed, false, 'loopAccessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-2.js new file mode 100644 index 0000000000000000000000000000000000000000..b2eae252193cc7670000a1ec5989762237c4ddc2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter throws ReferenceError if callbackfn is + unreferenced +---*/ + +var arr = new SendableArray(10); +assert.throws(ReferenceError, function() { + arr.filter(foo); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..b55ea90649f506dca5c1a2f144220c2f800af250 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-3.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter throws TypeError if callbackfn is null +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.filter(null); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..268064847cb6319d879b8c9e641526e7c86d5871 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-4.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter throws TypeError if callbackfn is boolean +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.filter(true); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-5.js new file mode 100644 index 0000000000000000000000000000000000000000..69079bfd98404464bebc6cd056a24b14eddf477f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-5.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter throws TypeError if callbackfn is number +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.filter(5); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-6.js new file mode 100644 index 0000000000000000000000000000000000000000..b52445d43e4e65925d1f5c0c107dbdffcacf1c88 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-6.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter throws TypeError if callbackfn is string +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.filter("abc"); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-7.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-7.js new file mode 100644 index 0000000000000000000000000000000000000000..271e76b6ef719d1a48f400d1be2884100f488eb4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-7.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter throws TypeError if callbackfn is Object + without [[Call]] internal method +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.filter(new Object()); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-8.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-8.js new file mode 100644 index 0000000000000000000000000000000000000000..654437ead58d6816efc127ee1b44bba1cca30203 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-8.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - side effects produced by step 2 are + visible when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + accessed = true; + return 2; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.filter.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-9.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-9.js new file mode 100644 index 0000000000000000000000000000000000000000..d017ec0b36d227d6d0124aee750f90c7a73ffb5f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-4-9.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - side effects produced by step 3 are + visible when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + accessed = true; + return "2"; + } + }; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.filter.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-1-s.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-1-s.js new file mode 100644 index 0000000000000000000000000000000000000000..b1364628e87ba22288e19614b1670674851d2155 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-1-s.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - thisArg not passed to strict callbackfn +flags: [noStrict] +---*/ + +var innerThisCorrect = false; +function callbackfn(val, idx, obj) { + "use strict"; + innerThisCorrect = this === undefined; + return true; +} +[1].filter(callbackfn); +assert(innerThisCorrect, 'innerThisCorrect !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..5114938989812dfe8c4d90cebe249e6100a95dc3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - thisArg is passed +flags: [noStrict] +---*/ + +(function() { + this._15_4_4_20_5_1 = false; + var _15_4_4_20_5_1 = true; + function callbackfn(val, idx, obj) { + return this._15_4_4_20_5_1; + } + var srcArr = [1]; + var resArr = srcArr.filter(callbackfn); + assert.sameValue(resArr.length, 0, 'resArr.length'); +})(); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-10.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-10.js new file mode 100644 index 0000000000000000000000000000000000000000..f9aa9c605969a2a90d1b51ff2ffe3598b7d498ad --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-10.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - Array Object can be used as thisArg +---*/ + +var accessed = false; +var objArray = new SendableArray(10); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objArray; +} +var newArr = [11].filter(callbackfn, objArray); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-11.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-11.js new file mode 100644 index 0000000000000000000000000000000000000000..ca73b00aa18bfdc026d2cd7272f5ea44c915c26c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-11.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - String Object can be used as thisArg +---*/ + +var accessed = false; +var objString = new String(); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objString; +} +var newArr = [11].filter(callbackfn, objString); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-12.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-12.js new file mode 100644 index 0000000000000000000000000000000000000000..43fb5f857ae22de456b569d475824a652d836977 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-12.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - Boolean Object can be used as thisArg +---*/ + +var accessed = false; +var objBoolean = new Boolean(); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objBoolean; +} +var newArr = [11].filter(callbackfn, objBoolean); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-13.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-13.js new file mode 100644 index 0000000000000000000000000000000000000000..257df599fbdf0bce42148f4a8e6b91c9ad0c95af --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-13.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - Number Object can be used as thisArg +---*/ + +var accessed = false; +var objNumber = new Number(); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objNumber; +} +var newArr = [11].filter(callbackfn, objNumber); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-14.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-14.js new file mode 100644 index 0000000000000000000000000000000000000000..272a2046632c76549ccd516fcc20dc10b1a72c83 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-14.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - the Math object can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this === Math; +} +var newArr = [11].filter(callbackfn, Math); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-15.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-15.js new file mode 100644 index 0000000000000000000000000000000000000000..e107b363f4231f5221f24c5bd1b24e2f0c51713b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-15.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - Date Object can be used as thisArg +---*/ + +var accessed = false; +var objDate = new Date(0); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objDate; +} +var newArr = [11].filter(callbackfn, objDate); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-16.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-16.js new file mode 100644 index 0000000000000000000000000000000000000000..898d6c215f1b4b4668ad36c9eb11a9b3ff0af09c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-16.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - RegExp Object can be used as thisArg +---*/ + +var accessed = false; +var objRegExp = new RegExp(); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objRegExp; +} +var newArr = [11].filter(callbackfn, objRegExp); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-17.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-17.js new file mode 100644 index 0000000000000000000000000000000000000000..d13320316c3275f238ebcd1b0daf101356f4bb99 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-17.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - the JSON object can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this === JSON; +} +var newArr = [11].filter(callbackfn, JSON); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-18.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-18.js new file mode 100644 index 0000000000000000000000000000000000000000..9637dc6f180f5dd9a91ad08e2c0c263a0d244dca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-18.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - Error Object can be used as thisArg +---*/ + +var accessed = false; +var objError = new RangeError(); +function callbackfn(val, idx, obj) { + accessed = true; + return this === objError; +} +var newArr = [11].filter(callbackfn, objError); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-19.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-19.js new file mode 100644 index 0000000000000000000000000000000000000000..5483ed46574669127343f1852fb0bd902d17921d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-19.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - the Arguments object can be used as + thisArg +---*/ + +var accessed = false; +var arg; +function callbackfn(val, idx, obj) { + accessed = true; + return this === arg; +} +(function fun() { + arg = arguments; +}(1, 2, 3)); +var newArr = [11].filter(callbackfn, arg); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-2.js new file mode 100644 index 0000000000000000000000000000000000000000..8058025cf8a7fbb5479979ee6c4e72cd0c563b93 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - thisArg is Object +---*/ + +var res = false; +var o = new Object(); +o.res = true; +function callbackfn(val, idx, obj) +{ + return this.res; +} +var srcArr = [1]; +var resArr = srcArr.filter(callbackfn, o); +assert.sameValue(resArr.length, 1, 'resArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-21.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-21.js new file mode 100644 index 0000000000000000000000000000000000000000..7aa47c2a2b945b786fe6813fa3771f75f11fdfed --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-21.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - the global object can be used as thisArg +---*/ + +var global = this; +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this === global; +} +var newArr = [11].filter(callbackfn, global); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-22.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-22.js new file mode 100644 index 0000000000000000000000000000000000000000..604ad3ebd9c797116dc8dddb8246b8bfc961d00f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-22.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - boolean primitive can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this.valueOf() === false; +} +var newArr = [11].filter(callbackfn, false); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-23.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-23.js new file mode 100644 index 0000000000000000000000000000000000000000..fd034ab78215bbebaf8a7ebaccef86636bdd2a0b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-23.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - number primitive can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this.valueOf() === 101; +} +var newArr = [11].filter(callbackfn, 101); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-24.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-24.js new file mode 100644 index 0000000000000000000000000000000000000000..56c5b180faf629d3b99596cab3a961a2a771eb92 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-24.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - string primitive can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this.valueOf() === "abc"; +} +var newArr = [11].filter(callbackfn, "abc"); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-27.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-27.js new file mode 100644 index 0000000000000000000000000000000000000000..9e5043af775f6930b98c7d0e70970c7deac6dbb4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-27.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - Array.isArray(arg) returns true when arg + is the returned array +---*/ + +var newArr = [11].filter(function() {}); +assert(SendableArray.isArray(newArr), 'SendableArray.isArray(newArr) !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-28.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-28.js new file mode 100644 index 0000000000000000000000000000000000000000..0c648c544496142277df6211ff8fa94ef5f1b788 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-28.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - the returned array is instanceof Array +---*/ + +var newArr = [11].filter(function() {}); +assert(newArr instanceof SendableArray, 'newArr instanceof SendableArray !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-29.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-29.js new file mode 100644 index 0000000000000000000000000000000000000000..bf37ff3a48ea1a632281e06029e1fe34cbb78266 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-29.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - returns an array whose length is 0 +---*/ + +var newArr = [11].filter(function() {}); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-3.js new file mode 100644 index 0000000000000000000000000000000000000000..9fe58a74786add0992263485bbf96c0a5ea3a023 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-3.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - thisArg is Array +---*/ + +var res = false; +var a = new Array(); +a.res = true; +function callbackfn(val, idx, obj) +{ + return this.res; +} +var srcArr = [1]; +var resArr = srcArr.filter(callbackfn, a); +assert.sameValue(resArr.length, 1, 'resArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-30.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-30.js new file mode 100644 index 0000000000000000000000000000000000000000..1bf4c45d498a0136eb7912b68d2ad7c8963a5abf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-30.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - thisArg not passed +flags: [noStrict] +---*/ + +function innerObj() { + this._15_4_4_20_5_30 = true; + var _15_4_4_20_5_30 = false; + function callbackfn(val, idx, obj) { + return this._15_4_4_20_5_30; + } + var srcArr = [1]; + var resArr = srcArr.filter(callbackfn); + this.retVal = resArr.length === 0; +} +assert(new innerObj().retVal, 'new innerObj().retVal !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-4.js new file mode 100644 index 0000000000000000000000000000000000000000..bd6c371e06e59fe074f9c77e56d26744ccd55674 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-4.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-5-4 +description: > + Array.prototype.filter - thisArg is object from object + template(prototype) +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +foo.prototype.res = true; +var f = new foo(); +var srcArr = [1]; +var resArr = srcArr.filter(callbackfn, f); +assert.sameValue(resArr.length, 1, 'resArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-5.js new file mode 100644 index 0000000000000000000000000000000000000000..77f9cdb2564de472c1197f7e09742fa69d71b5ae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-5.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-5-5 +description: Array.prototype.filter - thisArg is object from object template +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +var f = new foo(); +f.res = true; +var srcArr = [1]; +var resArr = srcArr.filter(callbackfn, f); +assert.sameValue(resArr.length, 1, 'resArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-6.js new file mode 100644 index 0000000000000000000000000000000000000000..8be09ba84a8521a010b8a083e3560b54cec14ae2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-6.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-5-6 +description: Array.prototype.filter - thisArg is function +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +foo.res = true; +var srcArr = [1]; +var resArr = srcArr.filter(callbackfn, foo); +assert.sameValue(resArr.length, 1, 'resArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-7.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-7.js new file mode 100644 index 0000000000000000000000000000000000000000..68cb455cbb65748f87f25a04c4696661822bfbdf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-7.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-5-7 +description: Array.prototype.filter - built-in functions can be used as thisArg +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return this === eval; +} +var newArr = [11].filter(callbackfn, eval); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-9.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-9.js new file mode 100644 index 0000000000000000000000000000000000000000..725689b0c27f45d42f1121fb1de449bc6f39676d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-5-9.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-5-9 +description: Array.prototype.filter - Function Object can be used as thisArg +---*/ + +var accessed = false; +var objFunction = function() {}; +function callbackfn(val, idx, obj) { + accessed = true; + return this === objFunction; +} +var newArr = [11].filter(callbackfn, objFunction); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-1.js new file mode 100644 index 0000000000000000000000000000000000000000..9b49983a2527124fbdc7bdb3314aef36631cc8b0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-1.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-6-1 +description: > + Array.prototype.filter returns an empty array if 'length' is 0 + (empty array) +---*/ + +function cb() {} +var a = [].filter(cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 0, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-2.js new file mode 100644 index 0000000000000000000000000000000000000000..5f1fb081d5dd02940263ca1f83db85fdb4e8c69a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-6-2 +description: > + Array.prototype.filter returns an empty array if 'length' is 0 + (subclassed Array, length overridden to null (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = null; +function cb() {} +var a = f.filter(cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 0, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-3.js new file mode 100644 index 0000000000000000000000000000000000000000..53d778236ff7dbde3177f4b4c9c92d4c9f25b932 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-3.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-6-3 +description: > + Array.prototype.filter returns an empty array if 'length' is 0 + (subclassed Array, length overridden to false (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = false; +function cb() {} +var a = f.filter(cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 0, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-4.js new file mode 100644 index 0000000000000000000000000000000000000000..ea3926ca0e9beb3bfd5aa7884cbc95c61bd6b409 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-6-4 +description: > + Array.prototype.filter returns an empty array if 'length' is 0 + (subclassed Array, length overridden to 0 (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 0; +function cb() {} +var a = f.filter(cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 0, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-5.js new file mode 100644 index 0000000000000000000000000000000000000000..bc700459c6b54e0e329a23c0d73d3251e1988717 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-5.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-6-5 +description: > + Array.prototype.filter returns an empty array if 'length' is 0 + (subclassed Array, length overridden to '0' (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = '0'; +function cb() {} +var a = f.filter(cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 0, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-6.js new file mode 100644 index 0000000000000000000000000000000000000000..09ec0af3c09432d5020f6796d0665e41133766ee --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-6-6 +description: > + Array.prototype.filter returns an empty array if 'length' is 0 + (subclassed Array, length overridden with obj with valueOf) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + valueOf: function() { + return 0; + } +}; +f.length = o; +function cb() {} +var a = f.filter(cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 0, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-7.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-7.js new file mode 100644 index 0000000000000000000000000000000000000000..e579846e800c0b39d108fe65bd70fe42f0a180e8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-7.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-6-7 +description: > + Array.prototype.filter returns an empty array if 'length' is 0 + (subclassed Array, length overridden with obj w/o valueOf + (toString)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + toString: function() { + return '0'; + } +}; +f.length = o; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +function cb() {} +var a = f.filter(cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 0, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-8.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-8.js new file mode 100644 index 0000000000000000000000000000000000000000..0c431a654eb786fc8e999043ac44cb558dded5ed --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-6-8.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-6-8 +description: > + Array.prototype.filter returns an empty array if 'length' is 0 + (subclassed Array, length overridden with [] +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = []; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +function cb() {} +var a = f.filter(cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 0, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-1.js new file mode 100644 index 0000000000000000000000000000000000000000..c1c5c93ecc82504db877cdaf4a98f60c53703c78 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-1 +description: > + Array.prototype.filter doesn't consider new elements added to + array after it is called +---*/ + +function callbackfn(val, idx, obj) { + srcArr[2] = 3; + srcArr[5] = 6; + return true; +} +var srcArr = [1, 2, , 4, 5]; +var resArr = srcArr.filter(callbackfn); +assert.sameValue(resArr.length, 5, 'resArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-2.js new file mode 100644 index 0000000000000000000000000000000000000000..5fae0f6080fd9d994beccb15c325cf43444bdaa2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-2.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-2 +description: > + Array.prototype.filter considers new value of elements in array + after it is called +---*/ + +function callbackfn(val, idx, obj) +{ + srcArr[2] = -1; + srcArr[4] = -1; + if (val > 0) + return true; + else + return false; +} +var srcArr = [1, 2, 3, 4, 5]; +var resArr = srcArr.filter(callbackfn); +assert.sameValue(resArr.length, 3, 'resArr.length'); +assert.sameValue(resArr[0], 1, 'resArr[0]'); +assert.sameValue(resArr[2], 4, 'resArr[2]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-3.js new file mode 100644 index 0000000000000000000000000000000000000000..184f623e22619e3117a7433e45f3b8393a5a45e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-3.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-3 +description: > + Array.prototype.filter doesn't visit deleted elements in array + after the call +---*/ + +function callbackfn(val, idx, obj) +{ + delete srcArr[2]; + delete srcArr[4]; + if (val > 0) + return true; + else + return false; +} +var srcArr = [1, 2, 3, 4, 5]; +var resArr = srcArr.filter(callbackfn); +// two elements deleted +assert.sameValue(resArr.length, 3, 'resArr.length'); +assert.sameValue(resArr[0], 1, 'resArr[0]'); +assert.sameValue(resArr[2], 4, 'resArr[2]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-4.js new file mode 100644 index 0000000000000000000000000000000000000000..b5ba735997b46cfe054b013c45663b0a3c8d66db --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-4 +description: > + Array.prototype.filter doesn't visit deleted elements when + Array.length is decreased +---*/ + +function callbackfn(val, idx, obj) +{ + srcArr.length = 2; + return true; +} +var srcArr = [1, 2, 3, 4, 6]; +var resArr = srcArr.filter(callbackfn); +assert.sameValue(resArr.length, 2, 'resArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-5.js new file mode 100644 index 0000000000000000000000000000000000000000..36ed5f0f5401a3f6fc53fed87e0bc0fe4b2201c2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-5.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-5 +description: > + Array.prototype.filter doesn't consider newly added elements in + sparse array +---*/ + +function callbackfn(val, idx, obj) +{ + srcArr[1000] = 3; + return true; +} +var srcArr = new SendableArray(10); +srcArr[1] = 1; +srcArr[2] = 2; +var resArr = srcArr.filter(callbackfn); +assert.sameValue(resArr.length, 2, 'resArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-6.js new file mode 100644 index 0000000000000000000000000000000000000000..cac2c91376e711a7e58e664893f38b2ef05433d9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-6.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-6 +description: > + Array.prototype.filter visits deleted element in array after the + call when same index is also present in prototype +---*/ + +function callbackfn(val, idx, obj) +{ + delete srcArr[2]; + delete srcArr[4]; + if (val > 0) + return true; + else + return false; +} +SendableArray.prototype[4] = 5; +var srcArr = [1, 2, 3, 4, 5]; +var resArr = srcArr.filter(callbackfn); +delete SendableArray.prototype[4]; +// only one element deleted +assert.sameValue(resArr.length, 4, 'resArr.length'); +assert.sameValue(resArr[0], 1, 'resArr[0]'); +assert.sameValue(resArr[3], 5, 'resArr[3]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-7.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-7.js new file mode 100644 index 0000000000000000000000000000000000000000..9a1050e7675cd6042911a681f3ed24f24201c036 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-7.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-7 +description: > + Array.prototype.filter stops calling callbackfn once the array is + deleted during the call +---*/ + +var o = new Object(); +o.srcArr = [1, 2, 3, 4, 5]; +function callbackfn(val, idx, obj) { + delete o.srcArr; + if (val > 0) + return true; + else + return false; +} +var resArr = o.srcArr.filter(callbackfn); +assert.sameValue(resArr.length, 5, 'resArr.length'); +assert.sameValue(typeof o.srcArr, "undefined", 'typeof o.srcArr'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-8.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-8.js new file mode 100644 index 0000000000000000000000000000000000000000..05b856affbbdbfb26e80010220dfa5c3e6896ab9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-8.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-8 +description: Array.prototype.filter - no observable effects occur if len is 0 +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + 1: 12, + length: 0 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); +assert.sameValue(obj.length, 0, 'obj.length'); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-9.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-9.js new file mode 100644 index 0000000000000000000000000000000000000000..7e1fd49d83e15cb042a2593af980294e5fbaab88 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-9.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-9 +description: > + Array.prototype.filter - modifications to length don't change + number of iterations +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + return true; +} +var obj = { + 1: 12, + 2: 9, + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + obj.length = 3; + return 11; + }, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..468a516df516b4000d09b3e522042efa5dd1a367 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-1 +description: > + Array.prototype.filter - callbackfn not called for indexes never + been assigned values +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; + return false; +} +var srcArr = new SendableArray(10); +srcArr[1] = undefined; //explicitly assigning a value +var resArr = srcArr.filter(callbackfn); +assert.sameValue(resArr.length, 0, 'resArr.length'); +assert.sameValue(callCnt, 1, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-10.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-10.js new file mode 100644 index 0000000000000000000000000000000000000000..f4c32c1ef9a65440233a7ae35fb100e8810055a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-10.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-10 +description: > + Array.prototype.filter - deleting property of prototype causes + prototype index property not to be visited on an Array-like Object +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 2: 2, + length: 20 +}; +Object.defineProperty(obj, "0", { + get: function() { + delete Object.prototype[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); +assert.notSameValue(newArr[1], 1, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-11.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-11.js new file mode 100644 index 0000000000000000000000000000000000000000..2bb7c85c91b508a7cfeac7ff407f9981bca35147 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-11.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-11 +description: > + Array.prototype.filter - deleting property of prototype causes + prototype index property not to be visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + delete SendableArray.prototype[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); +assert.notSameValue(newArr[1], 1, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-12.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-12.js new file mode 100644 index 0000000000000000000000000000000000000000..7b1c5db8d2dece80b1c8e108c5c882ee06ef774e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-12.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-12 +description: > + Array.prototype.filter - deleting own property with prototype + property causes prototype index property to be visited on an + Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 0: 0, + 1: 111, + 2: 2, + length: 10 +}; +Object.defineProperty(obj, "0", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 3, 'newArr.length'); +assert.sameValue(newArr[1], 1, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-13.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-13.js new file mode 100644 index 0000000000000000000000000000000000000000..a1bc50aba9f692490c1b6fb63e526cf511b52021 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-13.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-13 +description: > + Array.prototype.filter - deleting own property with prototype + property causes prototype index property to be visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + return val < 3 ? true : false; +} +var arr = [0, 111, 2]; +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 3, 'newArr.length'); +assert.sameValue(newArr[1], 1, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-14.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-14.js new file mode 100644 index 0000000000000000000000000000000000000000..7d586d07cc5c2ad8b0a2580d3676c29700df8b6e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-14.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-14 +description: > + Array.prototype.filter - decreasing length of array causes index + property not to be visited +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var arr = [0, 1, 2, "last"]; +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 3; + return 0; + }, + configurable: true +}); +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 3, 'newArr.length'); +assert.sameValue(newArr[2], 2, 'newArr[2]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-15.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-15.js new file mode 100644 index 0000000000000000000000000000000000000000..caa81fd156c1849cb4d46ca1197ced763fd764f4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-15.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-15 +description: > + Array.prototype.filter - decreasing length of array with prototype + property causes prototype index property to be visited +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var arr = [0, 1, 2]; +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return "prototype"; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 3, 'newArr.length'); +assert.sameValue(newArr[2], "prototype", 'newArr[2]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-16.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-16.js new file mode 100644 index 0000000000000000000000000000000000000000..b6660fd295426b2c488ee579dc9af34b14d2fb40 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-16.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-16 +description: > + Array.prototype.filter - decreasing length of array does not + delete non-configurable properties +flags: [noStrict] +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var arr = [0, 1, 2]; +Object.defineProperty(arr, "2", { + get: function() { + return "unconfigurable"; + }, + configurable: false +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 3, 'newArr.length'); +assert.sameValue(newArr[2], "unconfigurable", 'newArr[2]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-2.js new file mode 100644 index 0000000000000000000000000000000000000000..8a1390f3c9596b7e8f0fff13de3ad85b250ab589 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-2.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-2 +description: > + Array.prototype.filter - added properties in step 2 are visible + here +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + obj[2] = "length"; + return 3; + }, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], "length", 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-3.js new file mode 100644 index 0000000000000000000000000000000000000000..69f01f103311fba15b1ff8813b5ce3a1df88eefa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-3.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-3 +description: > + Array.prototype.filter - deleted properties in step 2 are visible + here +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 2: 6.99, + 8: 19 +}; +Object.defineProperty(obj, "length", { + get: function() { + delete obj[2]; + return 10; + }, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.notSameValue(newArr[0], 6.99, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-4.js new file mode 100644 index 0000000000000000000000000000000000000000..e0d446ce45d553d405749671bd6c124e139da381 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-4.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-4 +description: > + Array.prototype.filter - properties added into own object after + current position are visited on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + Object.defineProperty(obj, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); +assert.sameValue(newArr[1], 6.99, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-5.js new file mode 100644 index 0000000000000000000000000000000000000000..3545628a78b7bab569ce457747d6fa08f999f476 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-5.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-5 +description: > + Array.prototype.filter - properties added into own object after + current position are visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 3, 'newArr.length'); +assert.sameValue(newArr[1], 6.99, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-6.js new file mode 100644 index 0000000000000000000000000000000000000000..fc31d392ad0913a9b615dc7f6c9d6a012137cc1f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-6.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-6 +description: > + Array.prototype.filter - properties can be added to prototype + after current position are visited on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + Object.defineProperty(Object.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); +assert.sameValue(SendableArray[1], 6.99, 'SendableArray[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-7.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-7.js new file mode 100644 index 0000000000000000000000000000000000000000..c05229be5517319fb9dc1262375988e056731bfb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-7.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-7 +description: > + Array.prototype.filter - properties can be added to prototype + after current position are visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 3, 'newArr.length'); +assert.sameValue(newArr[1], 6.99, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-8.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-8.js new file mode 100644 index 0000000000000000000000000000000000000000..dae2774efe0cb0be0dd3d9b4609308d3aef83473 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-8.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-8 +description: > + Array.prototype.filter - deleting own property causes index + property not to be visited on an Array-like object +---*/ + +var accessed = false; +var obj = { + length: 2 +}; +function callbackfn(val, idx, o) { + accessed = true; + return true; +} +Object.defineProperty(obj, "1", { + get: function() { + return 6.99; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 0, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-9.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-9.js new file mode 100644 index 0000000000000000000000000000000000000000..49c522fc606a3f73d01a5e5b24ae055bdc4cafdf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-b-9.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-b-9 +description: > + Array.prototype.filter - deleting own property causes index + property not to be visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var arr = [1, 2]; +Object.defineProperty(arr, "1", { + get: function() { + return "6.99"; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 0, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-1.js new file mode 100644 index 0000000000000000000000000000000000000000..5d04e1e45e75aba210298b8ff905910f6410229c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-c-i-1 +description: > + Array.prototype.filter - element to be retrieved is own data + property on an Array-like object +---*/ + +var kValue = {}; +function callbackfn(val, idx, obj) { + return (idx === 5) && (val === kValue); +} +var obj = { + 5: kValue, + length: 100 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], kValue, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-10.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-10.js new file mode 100644 index 0000000000000000000000000000000000000000..becd3b164824f457fe69de5ba7b1ca38b82d96ea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-10.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-c-i-10 +description: > + Array.prototype.filter - element to be retrieved is own accessor + property on an Array +---*/ + +function callbackfn(val, idx, obj) { + return idx === 2 && val === 12; +} +var arr = []; +Object.defineProperty(arr, "2", { + get: function() { + return 12; + }, + configurable: true +}); +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 12, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-11.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-11.js new file mode 100644 index 0000000000000000000000000000000000000000..b661d713d6d630f27de83fe926d80853cd43e1f7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-11.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-c-i-11 +description: > + Array.prototype.filter - element to be retrieved is own accessor + property that overrides an inherited data property on an + Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return idx === 0 && val === 11; +} +var proto = { + 0: 5, + 1: 6 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +Object.defineProperty(child, "0", { + get: function() { + return 11; + }, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-12.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-12.js new file mode 100644 index 0000000000000000000000000000000000000000..35d1a398ff208a1c4313f876249d1cbc4978f21f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-12.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-c-i-12 +description: > + Array.prototype.filter - element to be retrieved is own accessor + property that overrides an inherited data property on an Array +---*/ + +function callbackfn(val, idx, obj) { + return val === 111 && idx === 0; +} +var arr = []; +SendableArray.prototype[0] = 10; +Object.defineProperty(arr, "0", { + get: function() { + return 111; + }, + configurable: true +}); +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 111, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-13.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-13.js new file mode 100644 index 0000000000000000000000000000000000000000..d4f9733eaaf0a9a1b2be841a3a65150c6de6a169 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-13.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-c-i-13 +description: > + Array.prototype.filter - element to be retrieved is own accessor + property that overrides an inherited accessor property on an + Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return idx === 1 && val === 12; +} +var proto = {}; +Object.defineProperty(proto, "1", { + get: function() { + return 6; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +Object.defineProperty(child, "1", { + get: function() { + return 12; + }, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 12, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-14.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-14.js new file mode 100644 index 0000000000000000000000000000000000000000..866271d5d2a6d4248a2c3632634d9dc5acb22ce0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-14.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +es5id: 15.4.4.20-9-c-i-14 +description: > + Array.prototype.filter - element to be retrieved is own accessor + property that overrides an inherited accessor property on an Array +---*/ + +function callbackfn(val, idx, obj) { + return idx === 0 && val === 11; +} +var arr = []; +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 5; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + return 11; + }, + configurable: true +}); +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-15.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-15.js new file mode 100644 index 0000000000000000000000000000000000000000..161178c6809a0ff3c106e3da304f43fa64ca5df0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-15.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is inherited + accessor property on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return val === 11 && idx === 1; +} +var proto = {}; +Object.defineProperty(proto, "1", { + get: function() { + return 11; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 20; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-16.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-16.js new file mode 100644 index 0000000000000000000000000000000000000000..51dd0638c8e395abba66ddca5c5c294f627880e8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-16.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is inherited + accessor property on an Array +---*/ + +function callbackfn(val, idx, obj) { + return idx === 0 && val === 11; +} +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 11; + }, + configurable: true +}); +var newArr = [, , , ].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-17.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-17.js new file mode 100644 index 0000000000000000000000000000000000000000..ab2ca4eb8a9c3e09d8512ff7247b4ec5d22e9e7c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-17.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is own accessor + property without a get function on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return undefined === val && idx === 1; +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], undefined, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-18.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-18.js new file mode 100644 index 0000000000000000000000000000000000000000..0967977ac772d6c7d5a3f416c7ebee28cd1a5e7d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-18.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is own accessor + property without a get function on an Array +---*/ + +function callbackfn(val, idx, obj) { + return undefined === val && idx === 0; +} +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], undefined, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-19.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-19.js new file mode 100644 index 0000000000000000000000000000000000000000..c56717572ebe58e9fef50ec906a2aed9543579a4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-19.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return undefined === val && idx === 1; +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +Object.prototype[1] = 10; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], undefined, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-2.js new file mode 100644 index 0000000000000000000000000000000000000000..49db2ca0cb16b9428a69b443136af2f470fd91e3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is own data + property on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 11; + } +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-20.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-20.js new file mode 100644 index 0000000000000000000000000000000000000000..1c2abd9f7368fd422d326067db6c82c919e84097 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-20.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array +---*/ + +function callbackfn(val, idx, obj) { + return undefined === val && idx === 0; +} +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +SendableArray.prototype[0] = 100; +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], undefined, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-21.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-21.js new file mode 100644 index 0000000000000000000000000000000000000000..8687a4570e8d0ffccca7101491f0277d879c5430 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-21.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is inherited + accessor property without a get function on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return val === undefined && idx === 1; +} +var proto = {}; +Object.defineProperty(proto, "1", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], undefined, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-22.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-22.js new file mode 100644 index 0000000000000000000000000000000000000000..e08050b33e13d409e887e40fbede441ac1968c8e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-22.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is inherited + accessor property without a get function on an Array +---*/ + +function callbackfn(val, idx, obj) { + return undefined === val && idx === 0; +} +Object.defineProperty(SendableArray.prototype, "0", { + set: function() {}, + configurable: true +}); +var newArr = [, ].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], undefined, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-25.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-25.js new file mode 100644 index 0000000000000000000000000000000000000000..8e3f551d786ff96f39c45b54f1f96a139d4f495f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-25.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - This object is the Arguments object which + implements its own property get method (number of arguments is + less than number of parameters) +---*/ + +function callbackfn(val, idx, obj) { + return val === 11 && idx === 0; +} +var func = function(a, b) { + return SendableArray.prototype.filter.call(arguments, callbackfn); +}; +var newArr = func(11); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-26.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-26.js new file mode 100644 index 0000000000000000000000000000000000000000..9b71d72c29ebab5765c875e679177aab9684b46d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-26.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - This object is the Arguments object which + implements its own property get method (number of arguments equals + number of parameters) +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 11; + } else if (idx === 1) { + return val === 9; + } else { + return false; + } +} +var func = function(a, b) { + return SendableArray.prototype.filter.call(arguments, callbackfn); +}; +var newArr = func(11, 9); +assert.sameValue(newArr.length, 2, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert.sameValue(newArr[1], 9, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-27.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-27.js new file mode 100644 index 0000000000000000000000000000000000000000..967c64de7e04f57373666aacae58f23e84ab53a8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-27.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - This object is the Arguments object which + implements its own property get method (number of arguments is + greater than number of parameters) +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 11; + } else if (idx === 1) { + return val === 12; + } else if (idx === 2) { + return val === 9; + } else { + return false; + } +} +var func = function(a, b) { + return SendableArray.prototype.filter.call(arguments, callbackfn); +}; +var newArr = func(11, 12, 9); +assert.sameValue(newArr.length, 3, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert.sameValue(newArr[1], 12, 'newArr[1]'); +assert.sameValue(newArr[2], 9, 'newArr[2]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-28.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-28.js new file mode 100644 index 0000000000000000000000000000000000000000..289704031dda219c4e3c8deeb71423eed037b300 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-28.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element changed by getter on previous + iterations is observed on an Array +---*/ + +var preIterVisible = false; +var arr = []; +function callbackfn(val, idx, obj) { + return idx === 1 && val === 9; +} +Object.defineProperty(arr, "0", { + get: function() { + preIterVisible = true; + return 11; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + if (preIterVisible) { + return 9; + } else { + return 11; + } + }, + configurable: true +}); +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 9, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-29.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-29.js new file mode 100644 index 0000000000000000000000000000000000000000..c29c0c68fa0bcb582ca66c2f05d3645648efb007 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-29.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element changed by getter on previous + iterations is observed on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return val === 9 && idx === 1; +} +var preIterVisible = false; +var obj = { + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + preIterVisible = true; + return 11; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + if (preIterVisible) { + return 9; + } else { + return 13; + } + }, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 9, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-3.js new file mode 100644 index 0000000000000000000000000000000000000000..d2822bc6fb7511eb45c95cb3029a46846566d0d5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-3.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is own data + property that overrides an inherited data property on an + Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return (idx === 5) && (val === "abc"); +} +var proto = { + 0: 11, + 5: 100 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[5] = "abc"; +child.length = 10; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], "abc", 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-30.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-30.js new file mode 100644 index 0000000000000000000000000000000000000000..3b752636158ee7544ca52131b087b5c430bd5836 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-30.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - unnhandled exceptions happened in getter + terminate iteration on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 1) { + accessed = true; + } + return true; +} +var obj = { + 0: 11, + 5: 10, + 10: 8, + length: 20 +}; +Object.defineProperty(obj, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + SendableArray.prototype.filter.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-31.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-31.js new file mode 100644 index 0000000000000000000000000000000000000000..0c7719ffae0ca5db166d0a9bb163db38fa34fee6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-31.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - unnhandled exceptions happened in getter + terminate iteration on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 1) { + accessed = true; + } + return true; +} +var arr = []; +arr[5] = 10; +arr[10] = 100; +Object.defineProperty(arr, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + arr.filter(callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-4.js new file mode 100644 index 0000000000000000000000000000000000000000..39cade273e469611501385608c6d43b094733c1c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +function callbackfn(val, idx, obj) { + return (idx === 0) && (val === 12); +} +SendableArray.prototype[0] = 11; +var newArr = [12].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 12, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-5.js new file mode 100644 index 0000000000000000000000000000000000000000..a73215ce05f357944fb4fd12a5cbd51873c47b1e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-5.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is own data + property that overrides an inherited accessor property on an + Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return idx === 0 && val === 11; +} +var proto = {}; +Object.defineProperty(proto, "0", { + get: function() { + return 5; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +Object.defineProperty(child, "0", { + value: 11, + configurable: true +}); +child[1] = 12; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-6.js new file mode 100644 index 0000000000000000000000000000000000000000..5fdc342657d069b2683579c42e4660336af78a43 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-6.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is own data + property that overrides an inherited accessor property on an Array +---*/ + +function callbackfn(val, idx, obj) { + return val === 11; +} +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 9; + }, + configurable: true +}); +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-7.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-7.js new file mode 100644 index 0000000000000000000000000000000000000000..40be865701a8d3b4ff5280c5bc1ef81b67c92452 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-7.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is inherited data + property on an Array-like object +---*/ + +var kValue = 'abc'; +function callbackfn(val, idx, obj) { + return (idx === 5) && (val === kValue); +} +var proto = { + 5: kValue +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +var newArr = SendableArray.prototype.filter.call(child, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], kValue, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-8.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-8.js new file mode 100644 index 0000000000000000000000000000000000000000..6134bb6481fafacf0e32c312e78312a7da8b7028 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-8.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is inherited data + property on an Array +---*/ + +function callbackfn(val, idx, obj) { + return (idx === 1) && (val === 13); +} +SendableArray.prototype[1] = 13; +var newArr = [, , , ].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 13, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-9.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-9.js new file mode 100644 index 0000000000000000000000000000000000000000..3dd1ef80a8790b6c5864df06c8236ded19b036f8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-i-9.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element to be retrieved is own accessor + property on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + return (idx === 0) && (val === 11); +} +var obj = { + 10: 10, + length: 20 +}; +Object.defineProperty(obj, "0", { + get: function() { + return 11; + }, + configurable: true +}); +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..e1c47754ae6d6908baeb64805cee3b498af21fb4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - callbackfn called with correct parameters +---*/ + +var bPar = true; +var bCalled = false; +function callbackfn(val, idx, obj) +{ + bCalled = true; + if (obj[idx] !== val) + bPar = false; +} +var srcArr = [0, 1, true, null, new Object(), "five"]; +srcArr[999999] = -6.6; +var resArr = srcArr.filter(callbackfn); +assert.sameValue(bCalled, true, 'bCalled'); +assert.sameValue(bPar, true, 'bPar'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-10.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..b316c52ccd3606c7fab351514d37c7cc22967200 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-10.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - callbackfn is called with 1 formal + parameter +---*/ + +function callbackfn(val) { + return val > 10; +} +var newArr = [12].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 12, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-11.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..fede2a41576f18c0e7ff768cdb4a78cb47a99b90 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-11.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - callbackfn is called with 2 formal + parameter +---*/ + +function callbackfn(val, idx) { + return val > 10 && arguments[2][idx] === val; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-12.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-12.js new file mode 100644 index 0000000000000000000000000000000000000000..5b64600126a0d287fd0a0728debe8f9a1ad79beb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-12.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - callbackfn is called with 3 formal + parameter +---*/ + +function callbackfn(val, idx, obj) { + return val > 10 && obj[idx] === val; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-13.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-13.js new file mode 100644 index 0000000000000000000000000000000000000000..a5849e8c4e980bc99a12a6c06d6b729e1bd29d40 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-13.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - callbackfn that uses arguments object to + get parameter value +---*/ + +function callbackfn() { + return arguments[2][arguments[1]] === arguments[0]; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-16.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-16.js new file mode 100644 index 0000000000000000000000000000000000000000..71b3d0763fda2ee5017715f821d6ad7baf6778cb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-16.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - 'this' of 'callbackfn' is a Boolean + object when T is not an object (T is a boolean) +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === false; +} +var obj = { + 0: 11, + length: 2 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn, false); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-17.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-17.js new file mode 100644 index 0000000000000000000000000000000000000000..e13ea2c476aeef0c6c42b5d1656bd66fce9f0917 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-17.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter -'this' of 'callbackfn' is a Number object + when T is not an object (T is a number) +---*/ + +function callbackfn(val, idx, o) { + return 5 === this.valueOf(); +} +var obj = { + 0: 11, + length: 2 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn, 5); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-18.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-18.js new file mode 100644 index 0000000000000000000000000000000000000000..22dba59637d86304242866b0b3deee9f581311ae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-18.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - 'this' of 'callbackfn' is an String + object when T is not an object (T is a string) +---*/ + +function callbackfn(val, idx, obj) { + return 'hello' === this.valueOf(); +} +var obj = { + 0: 11, + length: 2 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn, "hello"); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-19.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-19.js new file mode 100644 index 0000000000000000000000000000000000000000..126251432e1f585407947bf63d83e8bcc0a7e2d7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-19.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - non-indexed properties are not called +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val === 8; +} +var obj = { + 0: 11, + non_index_property: 8, + 2: 5, + length: 20 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..1c33d6ec569897153fdd03e19299caf6f6b138ef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - callbackfn takes 3 arguments +---*/ + +var parCnt = 3; +var bCalled = false +function callbackfn(val, idx, obj) +{ + bCalled = true; + if (arguments.length !== 3) + parCnt = arguments.length; //verify if callbackfn was called with 3 parameters +} +var srcArr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +var resArr = srcArr.filter(callbackfn); +assert.sameValue(bCalled, true, 'bCalled'); +assert.sameValue(parCnt, 3, 'parCnt'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-20.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-20.js new file mode 100644 index 0000000000000000000000000000000000000000..3984512ccad456b1a07a221fbdce40d65f9a7d5c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-20.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - callbackfn called with correct parameters + (thisArg is correct) +---*/ + +var thisArg = { + threshold: 10 +}; +function callbackfn(val, idx, obj) { + return this === thisArg; +} +var obj = { + 0: 11, + length: 1 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn, thisArg); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-21.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-21.js new file mode 100644 index 0000000000000000000000000000000000000000..619a36e9a1a8136cc5480c7dd5ff3ddd3545d80b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-21.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - callbackfn called with correct parameters + (kValue is correct) +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 11; + } + if (idx === 1) { + return val === 12; + } + return false; +} +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert.sameValue(newArr[1], 12, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-22.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-22.js new file mode 100644 index 0000000000000000000000000000000000000000..e97d8bbd7b2e5bf71cb317628c5eb501733b9260 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-22.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - callbackfn called with correct parameters + (the index k is correct) +---*/ + +function callbackfn(val, idx, obj) { + if (val === 11) { + return idx === 0; + } + if (val === 12) { + return idx === 1; + } + return false; +} +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); +assert.sameValue(newArr[1], 12, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-23.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-23.js new file mode 100644 index 0000000000000000000000000000000000000000..758971d5f5bd26c40cc2a809a7e7d7105a8a3d13 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-23.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - callbackfn called with correct parameters + (this object O is correct) +---*/ + +var obj = { + 0: 11, + length: 2 +}; +function callbackfn(val, idx, o) { + return obj === o; +} +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..68068d2ab77931043aa216792aee0af1c3eb97e0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-4.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - k values are passed in ascending numeric + order +---*/ + +var arr = [0, 1, 2, 3, 4, 5]; +var lastIdx = 0; +var called = 0; +function callbackfn(val, idx, o) { + called++; + if (lastIdx !== idx) { + return false; + } else { + lastIdx++; + return true; + } +} +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, called, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..df97f3e31105962a97fc92d142fd9c6950ed33a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-5.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - k values are accessed during each + iteration and not prior to starting the loop on an Array +---*/ + +var kIndex = []; +var called = 0; +//By below way, we could verify that k would be setted as 0, 1, ..., length - 1 in order, and each value will be setted one time. +function callbackfn(val, idx, obj) { + called++; + //Each position should be visited one time, which means k is accessed one time during iterations. + if (kIndex[idx] === undefined) { + //when current position is visited, its previous index should has been visited. + if (idx !== 0 && kIndex[idx - 1] === undefined) { + return true; + } + kIndex[idx] = 1; + return false; + } else { + return true; + } +} +var newArr = [11, 12, 13, 14].filter(callbackfn, undefined); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert.sameValue(called, 4, 'called'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-6.js new file mode 100644 index 0000000000000000000000000000000000000000..82487ed60795348655a5b8f7bcf11a4c23e1a36c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - arguments to callbackfn are self + consistent +---*/ + +var obj = { + 0: 11, + length: 1 +}; +var thisArg = {}; +function callbackfn() { + return this === thisArg && + arguments[0] === 11 && + arguments[1] === 0 && + arguments[2] === obj; +} +var newArr = SendableArray.prototype.filter.call(obj, callbackfn, thisArg); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-7.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..44599443633a88c4c4cdbac129d7ac56c5a38329 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-7.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - unhandled exceptions happened in + callbackfn terminate iteration +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + if (called === 1) { + throw new Error("Exception occurred in callbackfn"); + } + return true; +} +var obj = { + 0: 11, + 4: 10, + 10: 8, + length: 20 +}; +assert.throws(Error, function() { + SendableArray.prototype.filter.call(obj, callbackfn); +}); +assert.sameValue(called, 1, 'called'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-8.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..d0b58ee1d9744ac782a798caa7fc1eef6da717e6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-8.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - element changed by callbackfn on previous + iterations is observed +---*/ + +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +function callbackfn(val, idx, o) { + if (idx === 0) { + obj[idx + 1] = 8; + } + return val > 10; +} +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-9.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..7ae9704fa993de190fc52a1b3c80ebea2eaba2ed --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-ii-9.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - callbackfn is called with 0 formal + parameter +---*/ + +function callbackfn() { + return true; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..052c6b8a76610b8050431551af0c1e036060a699 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of returned array element equals to + 'kValue' +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 0: 11, + 1: 9, + length: 2 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr[0], obj[0], 'newArr[0]'); +assert.sameValue(newArr[1], obj[1], 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..92da69325d05c9663e15c7e50a64a1dfc9e102ea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-2.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of returned array element can be + overwritten +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 0: 11, + 1: 9, + length: 2 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +var tempVal = newArr[1]; +newArr[1] += 1; +assert.notSameValue(newArr[1], tempVal, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..60188bdc80350526f646362edc3ffac15a63287c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-3.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of returned array element can be + enumerated +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 0: 11, + length: 2 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +var prop; +var enumerable = false; +for (prop in newArr) { + if (newArr.hasOwnProperty(prop)) { + if (prop === "0") { + enumerable = true; + } + } +} +assert(enumerable, 'enumerable !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..f6e96181c7bc763e1071e748aceec1a9eca3896f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-4.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - value of returned array element can be + changed or deleted +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 0: 11, + 1: 9, + length: 2 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +var tempVal = newArr[1]; +delete newArr[1]; +assert.notSameValue(tempVal, undefined, 'tempVal'); +assert.sameValue(newArr[1], undefined, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..75eff04fde501a147de9cda0360dab17667bbadd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-5.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - values of 'to' are passed in acending + numeric order +---*/ + +var arr = [0, 1, 2, 3, 4]; +var lastToIdx = 0; +var called = 0; +function callbackfn(val, idx, obj) { + called++; + if (lastToIdx !== idx) { + return false; + } else { + lastToIdx++; + return true; + } +} +var newArr = arr.filter(callbackfn); +assert.sameValue(newArr.length, 5, 'newArr.length'); +assert.sameValue(called, 5, 'called'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..d53a0c8507064e47a02b92da5dfb4e2d4c744810 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1-6.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - values of 'to' are accessed during each + iteration when 'selected' is converted to true and not prior to + starting the loop +---*/ + +var toIndex = []; +var called = 0; +//By below way, we could verify that 'to' would be setted as 0, 1, ..., length - 1 in order, and each value will be setted one time. +function callbackfn(val, idx, obj) { + called++; + //Each position should be visited one time, which means 'to' is accessed one time during iterations. + if (toIndex[idx] === undefined) { + //when current position is visited, its previous index should has been visited. + if (idx !== 0 && toIndex[idx - 1] === undefined) { + return false; + } + toIndex[idx] = 1; + return true; + } else { + return false; + } +} +var newArr = [11, 12, 13, 14].filter(callbackfn, undefined); +assert.sameValue(newArr.length, 4, 'newArr.length'); +assert.sameValue(called, 4, 'called'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..8086bc7141097cb0a7d6bef1ffa330ec72f7eddd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-1.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - getOwnPropertyDescriptor(all true) of + returned array element +---*/ + +function callbackfn(val, idx, obj) { + if (val % 2) + return true; + else + return false; +} +var srcArr = [0, 1, 2, 3, 4]; +var resArr = srcArr.filter(callbackfn); +assert(resArr.length > 0, 'resArr.length > 0'); +var desc = Object.getOwnPropertyDescriptor(resArr, 1); +assert.sameValue(desc.value, 3, 'desc.value'); //srcArr[1] = true +assert.sameValue(desc.writable, true, 'desc.writable'); +assert.sameValue(desc.enumerable, true, 'desc.enumerable'); +assert.sameValue(desc.configurable, true, 'desc.configurable'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-10.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..d904830b83a271292a51621c389bbcb15935eb3c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-10.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter return value of callbackfn is a number + (value is negative number) +---*/ + +function callbackfn(val, idx, obj) { + return -5; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-11.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..90204e24139728665f6a95b02719961bda2cec72 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-11.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter return value of callbackfn is a number + (value is Infinity) +---*/ + +function callbackfn(val, idx, obj) { + return Infinity; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-12.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-12.js new file mode 100644 index 0000000000000000000000000000000000000000..940e02bbfd394688d28528b0a030811eb81d63d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-12.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter return value of callbackfn is a number + (value is -Infinity) +---*/ + +function callbackfn(val, idx, obj) { + return -Infinity; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-13.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-13.js new file mode 100644 index 0000000000000000000000000000000000000000..552f21c2fbc2a6b74d6df44b2bb55a7ba2b7106e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-13.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter return value of callbackfn is a number + (value is NaN) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return NaN; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-14.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-14.js new file mode 100644 index 0000000000000000000000000000000000000000..4c9daeb01782838a428f5d87b5141b1828b662c3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-14.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter return value of callbackfn is an empty + string +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return ""; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-15.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-15.js new file mode 100644 index 0000000000000000000000000000000000000000..a781b2d2cf4348bbb0141c3324897ddff6642949 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-15.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter return value of callbackfn is a non-empty + string +---*/ + +function callbackfn(val, idx, obj) { + return "non-empty string"; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-16.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-16.js new file mode 100644 index 0000000000000000000000000000000000000000..acc89ca0b14c7cd4fc6d74ec521ad481a2d42723 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-16.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter return value of callbackfn is a Function + object +---*/ + +function callbackfn(val, idx, obj) { + return function() {}; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-17.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-17.js new file mode 100644 index 0000000000000000000000000000000000000000..aa650e9fb0887a82186fafb6667abcc311a67b56 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-17.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter return value of callbackfn is an Array + object +---*/ + +function callbackfn(val, idx, obj) { + return new Array(10); +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-18.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-18.js new file mode 100644 index 0000000000000000000000000000000000000000..6f44e5d1aa7d96b879ad317399d8670fcf60f4dd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-18.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter return value of callbackfn is a String + object +---*/ + +function callbackfn(val, idx, obj) { + return new String(); +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-19.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-19.js new file mode 100644 index 0000000000000000000000000000000000000000..95fb2e0b161c33fa37e491444c41243a0687a3f3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-19.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter return value of callbackfn is a Boolean + object +---*/ + +function callbackfn(val, idx, obj) { + return new Boolean(); +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-2.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..53c448f73deed8e9ffa3c09951e695da0b0ecb9d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-2.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - return value of callbackfn is undefined +---*/ + +var accessed = false; +function callbackfn(val, idx, o) { + accessed = true; + return undefined; +} + +var obj = { + 0: 11, + length: 1 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-20.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-20.js new file mode 100644 index 0000000000000000000000000000000000000000..8133789f13a5637716e2e9b4eecaff3a609f48ce --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-20.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is a Number + object +---*/ + +function callbackfn(val, idx, obj) { + return new Number(); +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-21.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-21.js new file mode 100644 index 0000000000000000000000000000000000000000..5f1b6e8dc2f20af294d4a4370682f801366089a3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-21.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is the Math + object +---*/ + +function callbackfn(val, idx, obj) { + return Math; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-22.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-22.js new file mode 100644 index 0000000000000000000000000000000000000000..bd4aa2350784be385c4e6c2ff037f8fa32aecf25 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-22.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is a Date + object +---*/ + +function callbackfn(val, idx, obj) { + return new Date(0); +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-23.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-23.js new file mode 100644 index 0000000000000000000000000000000000000000..e770273dce82a3e54a1b86b2a3e5a52f2743fd83 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-23.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is a RegExp + object +---*/ + +function callbackfn(val, idx, obj) { + return new RegExp(); +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-24.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-24.js new file mode 100644 index 0000000000000000000000000000000000000000..23985e9a487f82811d515e99c02dba5c6126bea7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-24.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is the JSON + object +---*/ + +function callbackfn(val, idx, obj) { + return JSON; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-25.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-25.js new file mode 100644 index 0000000000000000000000000000000000000000..5cf04f4998c975b1048e0fb51d2eafcca19f7ff4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-25.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is an Error + object +---*/ + +function callbackfn(val, idx, obj) { + return new EvalError(); +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-26.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-26.js new file mode 100644 index 0000000000000000000000000000000000000000..b446b9905f9cdd57fb1d5d5fbab61d4b48c1b4c4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-26.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is the + Arguments object +---*/ + +function callbackfn(val, idx, obj) { + return arguments; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-28.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-28.js new file mode 100644 index 0000000000000000000000000000000000000000..836bb182d63e7d1b051402a250eb2d591ac3e84a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-28.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is the global + object +---*/ + +var global = this; + +function callbackfn(val, idx, obj) { + return global; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-29.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-29.js new file mode 100644 index 0000000000000000000000000000000000000000..dbbdee45caca8f1529ce0f55a22521600dc2302b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-29.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - false prevents element added to output + Array +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + return val > 10; +} +var obj = { + 0: 11, + 1: 8, + length: 20 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.notSameValue(newArr[0], 8, 'newArr[0]'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-3.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-3.js new file mode 100644 index 0000000000000000000000000000000000000000..c113735982d124bcfe45d2d4f185297bda12db34 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter - return value of callbackfn is null +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return null; +} +var obj = { + 0: 11, + length: 1 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-30.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-30.js new file mode 100644 index 0000000000000000000000000000000000000000..f36952566fc2f7d8c240763db7957e84f224ed1c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-30.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value (new Boolean(false)) of + callbackfn is treated as true value +---*/ + +function callbackfn(val, idx, obj) { + return new Boolean(false); +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-4.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..82c7ddfe10d2606c4fb82c726754d1873c68385e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-4.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is a boolean + (value is false) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return false; +} +var obj = { + 0: 11, + length: 1 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-5.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..719c3f7a93573281e11f73898422357ccb94f78a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-5.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is a boolean + (value is true) +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 0: 11, + length: 1 +}; +var newArr = SendableArray.prototype.filter.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-6.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-6.js new file mode 100644 index 0000000000000000000000000000000000000000..d71d0d46ff2dceff527f7c71327c8ac469b0e045 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-6.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is a number + (value is 0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return 0; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-7.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..fef3580b1e40c20baf6f8f823cfcc89dc6892829 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-7.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is a number + (value is +0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return +0; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-8.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..a7bf9c370261459ee9eb5029b47cb8c21f27c79f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-8.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is a nunmber + (value is -0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return -0; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-9.js b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..baae8633b3c189ffbd9cf1b58e2ec09720ff5a04 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/15.4.4.20-9-c-iii-9.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter - return value of callbackfn is a number + (value is positive number) +---*/ + +function callbackfn(val, idx, obj) { + return 5; +} +var newArr = [11].filter(callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); +assert.sameValue(newArr[0], 11, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/filter/call-with-boolean.js b/test/sendable/builtins/Array/prototype/filter/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..8b0172fdc3841710e8be5a625d75c9c2b063881b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/call-with-boolean.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Array.prototype.filter applied to boolean primitive +includes: [compareArray.js] +---*/ + +assert.compareArray( + SendableArray.prototype.filter.call(true, () => {}), + [], + 'SendableArray.prototype.filter.call(true, () => {}) must return []' +); +assert.compareArray( + SendableArray.prototype.filter.call(false, () => {}), + [], + 'SendableArray.prototype.filter.call(false, () => {}) must return []' +); diff --git a/test/sendable/builtins/Array/prototype/filter/callbackfn-resize-arraybuffer.js b/test/sendable/builtins/Array/prototype/filter/callbackfn-resize-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..70ae9741a759b7c4ad644fca28352be1c2e9f69c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/callbackfn-resize-arraybuffer.js @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: TypedArray instance buffer can be resized during iteration +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.filter.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + elements.push(element); + indices.push(index); + arrays.push(array); + return true; + }); + assert.compareArray(elements, expectedElements, 'elements (shrink)'); + assert.compareArray(indices, expectedIndices, 'indices (shrink)'); + assert.compareArray(arrays, expectedArrays, 'arrays (shrink)'); + assert.compareArray(result, expectedElements, 'result (shrink)'); + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.filter.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return true; + }); + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.compareArray(result, expectedElements, 'result (grow)'); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/create-ctor-non-object.js b/test/sendable/builtins/Array/prototype/filter/create-ctor-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..88cd95b4b274386e1f98cb77ee9914e06d7cddac --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-ctor-non-object.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Behavior when `constructor` property is neither an Object nor undefined +---*/ + +var a = []; +var callCount = 0; +var cb = function() { + callCount += 0; +}; +a.constructor = null; +assert.throws(TypeError, function() { + a.filter(cb); +}, 'null value'); +assert.sameValue(callCount, 0, 'callback not invoked (null value)'); +a = []; +a.constructor = 1; +assert.throws(TypeError, function() { + a.filter(cb); +}, 'number value'); +assert.sameValue(callCount, 0, 'callback not invoked (number value)'); +a = []; +a.constructor = 'string'; +assert.throws(TypeError, function() { + a.filter(cb); +}, 'string value'); +assert.sameValue(callCount, 0, 'callback not invoked (string value)'); +a = []; +a.constructor = true; +assert.throws(TypeError, function() { + a.filter(cb); +}, 'boolean value'); +assert.sameValue(callCount, 0, 'callback not invoked (boolean value)'); diff --git a/test/sendable/builtins/Array/prototype/filter/create-ctor-poisoned.js b/test/sendable/builtins/Array/prototype/filter/create-ctor-poisoned.js new file mode 100644 index 0000000000000000000000000000000000000000..abb5f502c1495e62dd93b5dbbd3064ccd171c4e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-ctor-poisoned.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Abrupt completion from `constructor` property access +---*/ + +var a = []; +var callCount = 0; +var cb = function() { + callCount += 1; +}; +Object.defineProperty(a, 'constructor', { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + a.filter(cb); +}); +assert.sameValue(callCount, 0); diff --git a/test/sendable/builtins/Array/prototype/filter/create-non-array.js b/test/sendable/builtins/Array/prototype/filter/create-non-array.js new file mode 100644 index 0000000000000000000000000000000000000000..7128ab3e54b18df6aa5456709b09c9fe6aedc6ec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-non-array.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Constructor is ignored for non-Array values +---*/ + +var obj = { + length: 0 +}; +var callCount = 0; +var result; +Object.defineProperty(obj, 'constructor', { + get: function() { + callCount += 1; + } +}); +result = SendableArray.prototype.filter.call(obj, function() {}); +assert.sameValue(callCount, 0, '`constructor` property not accessed'); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert(SendableArray.isArray(result), 'result is an Array exotic object'); +assert.sameValue(result.length, 0, 'array created with appropriate length'); diff --git a/test/sendable/builtins/Array/prototype/filter/create-proto-from-ctor-realm-array.js b/test/sendable/builtins/Array/prototype/filter/create-proto-from-ctor-realm-array.js new file mode 100644 index 0000000000000000000000000000000000000000..c2f57ebc402aa8d8d9fb3b627f425240be9fd3a8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-proto-from-ctor-realm-array.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Prefer Array constructor of current realm record +features: [cross-realm, Symbol.species] +---*/ + +var SendableArray = []; +var callCount = 0; +var OArray = $262.createRealm().global.SendableArray; +var speciesDesc = { + get: function() { + callCount += 1; + } +}; +var result; +SendableArray.constructor = OArray; +Object.defineProperty(SendableArray, Symbol.species, speciesDesc); +Object.defineProperty(OArray, Symbol.species, speciesDesc); +result = SendableArray.filter(function() {}); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert.sameValue(callCount, 0, 'Species constructor is not referenced'); diff --git a/test/sendable/builtins/Array/prototype/filter/create-proto-from-ctor-realm-non-array.js b/test/sendable/builtins/Array/prototype/filter/create-proto-from-ctor-realm-non-array.js new file mode 100644 index 0000000000000000000000000000000000000000..696bee824db0a4aff8bc0c3e2baf2f4171204f87 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-proto-from-ctor-realm-non-array.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Accept non-Array constructors from other realms +features: [cross-realm, Symbol.species] +---*/ + +var SendableArray = []; +var callCount = 0; +var CustomCtor = function() {}; +var OObject = $262.createRealm().global.Object; +var speciesDesc = { + get: function() { + callCount += 1; + } +}; +var result; +SendableArray.constructor = OObject; +OObject[Symbol.species] = CustomCtor; + +Object.defineProperty(SendableArray, Symbol.species, speciesDesc); +result = SendableArray.filter(function() {}); +assert.sameValue(Object.getPrototypeOf(result), CustomCtor.prototype); +assert.sameValue(callCount, 0, 'SendableArray species constructor is not referenced'); diff --git a/test/sendable/builtins/Array/prototype/filter/create-proxy.js b/test/sendable/builtins/Array/prototype/filter/create-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..dbaf65e99cd51bb090ac8e3479b20ea8373e3a7a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-proxy.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Species constructor of a Proxy object whose target is an array +features: [Proxy, Symbol.species] +---*/ + +var SendableArray = []; +var proxy = new Proxy(new Proxy(SendableArray, {}), {}); +var Ctor = function() {}; +var result; +SendableArray.constructor = function() {}; +SendableArray.constructor[Symbol.species] = Ctor; +result = SendableArray.prototype.filter.call(proxy, function() {}); +assert.sameValue(Object.getPrototypeOf(result), Ctor.prototype); diff --git a/test/sendable/builtins/Array/prototype/filter/create-revoked-proxy.js b/test/sendable/builtins/Array/prototype/filter/create-revoked-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..0c60b5ed38ae07037a868998ea251221b60d0f2b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-revoked-proxy.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Abrupt completion from constructor that is a revoked Proxy object +features: [Proxy] +---*/ + +var o = Proxy.revocable([], {}); +var ctorCount = 0; +var cbCount = 0; +var cb = function() { + cbCount += 1; +}; +Object.defineProperty(o.proxy, 'constructor', { + get: function() { + ctorCount += 1; + } +}); +o.revoke(); +assert.throws(TypeError, function() { + SendableArray.prototype.filter.call(o.proxy, cb); +}); +assert.sameValue(ctorCount, 0, '`constructor` property not accessed'); +assert.sameValue(cbCount, 0, 'callback not invoked'); diff --git a/test/sendable/builtins/Array/prototype/filter/create-species-abrupt.js b/test/sendable/builtins/Array/prototype/filter/create-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..155b6fcc314b922eb8bc8b8f56a82b33e6cc01d2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-species-abrupt.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Species constructor returns an abrupt completion +features: [Symbol.species] +---*/ + +var Ctor = function() { + throw new Test262Error(); +}; +var callCount = 0; +var cb = function() { + callCount += 1; +}; +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; +assert.throws(Test262Error, function() { + a.filter(cb); +}); +assert.sameValue(callCount, 0); diff --git a/test/sendable/builtins/Array/prototype/filter/create-species-non-ctor.js b/test/sendable/builtins/Array/prototype/filter/create-species-non-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..47886fb3e91f7451ba9ec5fc90cc4c972ce6dfaf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-species-non-ctor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Behavior when the @@species attribute is a non-constructor object +includes: [isConstructor.js] +features: [Symbol.species, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(parseInt), + false, + 'precondition: isConstructor(parseInt) must return false' +); +var a = []; +var callCount = 0; +var cb = function() { + callCount += 1; +}; +a.constructor = {}; +a.constructor[Symbol.species] = parseInt; +assert.throws(TypeError, function() { + a.filter(cb); +}, 'a.filter(cb) throws a TypeError exception'); +assert.sameValue(callCount, 0); diff --git a/test/sendable/builtins/Array/prototype/filter/create-species-null.js b/test/sendable/builtins/Array/prototype/filter/create-species-null.js new file mode 100644 index 0000000000000000000000000000000000000000..6abdc347ef47e250a0c2f04d5ec51992c5f4ca00 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-species-null.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + A null value for the @@species constructor is interpreted as `undefined` +features: [Symbol.species] +---*/ + +var a = []; +var result; +a.constructor = {}; +a.constructor[Symbol.species] = null; +result = a.filter(function() {}); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert(SendableArray.isArray(result), 'result is an Array exotic object'); diff --git a/test/sendable/builtins/Array/prototype/filter/create-species-poisoned.js b/test/sendable/builtins/Array/prototype/filter/create-species-poisoned.js new file mode 100644 index 0000000000000000000000000000000000000000..23ef097558c510c78c41a4bc0b66a29f2a71e558 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-species-poisoned.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Abrupt completion from `@@species` property access +features: [Symbol.species] +---*/ + +var a = []; +var callCount = 0; +var cb = function() { + callCount += 1; +}; +a.constructor = {}; + +Object.defineProperty(a.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + a.filter(cb); +}); +assert.sameValue(callCount, 0); diff --git a/test/sendable/builtins/Array/prototype/filter/create-species-undef.js b/test/sendable/builtins/Array/prototype/filter/create-species-undef.js new file mode 100644 index 0000000000000000000000000000000000000000..0f10c846d7d9eabacf35f35265a415f65b12224a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-species-undef.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + An undefined value for the @@species constructor triggers the creation of + an Array exotic object +features: [Symbol.species] +---*/ + +var a = []; +var result; + +a.constructor = {}; +a.constructor[Symbol.species] = undefined; + +result = a.filter(function() {}); + +assert.sameValue(Object.getPrototypeOf(result), Array.prototype); +assert(Array.isArray(result), 'result is an Array exotic object'); diff --git a/test/sendable/builtins/Array/prototype/filter/create-species.js b/test/sendable/builtins/Array/prototype/filter/create-species.js new file mode 100644 index 0000000000000000000000000000000000000000..da4e1ba51a6c092e618b262fd3a0132f944e1ff7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/create-species.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: Species constructor is used to create a new instance +features: [Symbol.species] +---*/ + +var thisValue, args, result; +var callCount = 0; +var instance = []; +var Ctor = function() { + callCount += 1; + thisValue = this; + args = arguments; + return instance; +}; +var a = [1, 2, 3, 4, 5, 6, 7]; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; + +result = a.filter(function() {}); + +assert.sameValue(callCount, 1, 'Constructor invoked exactly once'); +assert.sameValue(Object.getPrototypeOf(thisValue), Ctor.prototype); +assert.sameValue(args.length, 1, 'Constructor invoked with a single argument'); +assert.sameValue(args[0], 0); +assert.sameValue(result, instance); diff --git a/test/sendable/builtins/Array/prototype/filter/length.js b/test/sendable/builtins/Array/prototype/filter/length.js new file mode 100644 index 0000000000000000000000000000000000000000..8d0e174d39d11388b3cb352d2d3f4ac9565edc2a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/length.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.filter +description: > + The "length" property of Array.prototype.filter +info: | + 22.1.3.7 Array.prototype.filter ( callbackfn [ , thisArg ] ) + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.filter, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/filter/name.js b/test/sendable/builtins/Array/prototype/filter/name.js new file mode 100644 index 0000000000000000000000000000000000000000..6009f8f92b4ddbc41cf87e44b1223981db296d3f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.prototype.filter.name is "filter". +info: | + Array.prototype.filter ( callbackfn [ , thisArg ] ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.filter, "name", { + value: "filter", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/filter/not-a-constructor.js b/test/sendable/builtins/Array/prototype/filter/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..70051077fab69c64ce30bffc93a5cf8ce789e035 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.filter does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.filter), + false, + 'isConstructor(SendableArray.prototype.filter) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.filter(() => {}); +}); + diff --git a/test/sendable/builtins/Array/prototype/filter/prop-desc.js b/test/sendable/builtins/Array/prototype/filter/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..5be5d11e8ff40cca4e4d11afce26925e101b99c4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + "filter" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.filter, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "filter", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/filter/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/filter/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..4ea14c04b21228e16dcfe2eeccd99d308a4093aa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.p.filter behaves correctly on TypedArrays backed by resizable buffers + that grow mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(fixedLength, ResizeMidIteration)), []); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(fixedLengthWithOffset, ResizeMidIteration)), []); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTracking, ResizeMidIteration)), []); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTrackingWithOffset, ResizeMidIteration)), []); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/filter/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/filter/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..cf7c000d6eedba936796ff3ec29d88bcadb88195 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-%array%.prototype.filter +description: > + Array.p.filter behaves correctly on TypedArrays backed by resizable buffers + that shrink mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(fixedLength, ResizeMidIteration)),[]); + assert.compareArray(values, [ + 0, + 2 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(fixedLengthWithOffset, ResizeMidIteration)),[]); + assert.compareArray(values, [ + 4 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTracking, ResizeMidIteration)),[]); + assert.compareArray(values, [ + 0, + 2, + 4 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTrackingWithOffset, ResizeMidIteration)),[]); + assert.compareArray(values, [ + 4 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/filter/resizable-buffer.js b/test/sendable/builtins/Array/prototype/filter/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..50fbe05034860019392a972edc8bb9890890de62 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/resizable-buffer.js @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Array.p.filter behaves correctly on TypedArrays backed by resizable buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + // Orig. array: [0, 1, 2, 3] + // [0, 1, 2, 3] << fixedLength + // [2, 3] << fixedLengthWithOffset + // [0, 1, 2, 3, ...] << lengthTracking + // [2, 3, ...] << lengthTrackingWithOffset + function isEven(n) { + return n != undefined && Number(n) % 2 == 0; + } + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(fixedLength, isEven)), [ + 0, + 2 + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(fixedLengthWithOffset, isEven)), [2]); + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTracking, isEven)), [ + 0, + 2 + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTrackingWithOffset, isEven)), [2]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 1, 2] + // [0, 1, 2, ...] << lengthTracking + // [2, ...] << lengthTrackingWithOffset + + assert.compareArray(SendableArray.prototype.filter.call(fixedLength, isEven), []); + assert.compareArray(SendableArray.prototype.filter.call(fixedLengthWithOffset, isEven), []); + + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTracking, isEven)), [ + 0, + 2 + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTrackingWithOffset, isEven)), [2]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(SendableArray.prototype.filter.call(fixedLength, isEven), []); + assert.compareArray(SendableArray.prototype.filter.call(fixedLengthWithOffset, isEven), []); + assert.compareArray(SendableArray.prototype.filter.call(lengthTrackingWithOffset, isEven), []); + + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTracking, isEven)), [0]); + + // Shrink to zero. + rab.resize(0); + assert.compareArray(SendableArray.prototype.filter.call(fixedLength, isEven), []); + assert.compareArray(SendableArray.prototype.filter.call(fixedLengthWithOffset, isEven), []); + assert.compareArray(SendableArray.prototype.filter.call(lengthTrackingWithOffset, isEven), []); + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTracking, isEven)), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + // Orig. array: [0, 1, 2, 3, 4, 5] + // [0, 1, 2, 3] << fixedLength + // [2, 3] << fixedLengthWithOffset + // [0, 1, 2, 3, 4, 5, ...] << lengthTracking + // [2, 3, 4, 5, ...] << lengthTrackingWithOffset + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(fixedLength, isEven)), [ + 0, + 2 + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(fixedLengthWithOffset, isEven)), [2]); + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTracking, isEven)), [ + 0, + 2, + 4 + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.filter.call(lengthTrackingWithOffset, isEven)), [ + 2, + 4 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/filter/target-array-non-extensible.js b/test/sendable/builtins/Array/prototype/filter/target-array-non-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..9afd9853851bd5d92b1346417915a61cc7b1a321 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/target-array-non-extensible.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + TypeError is thrown if CreateDataProperty fails. + (result object is non-extensible) +features: [Symbol.species] +---*/ + +var A = function(_length) { + this.length = 0; + Object.preventExtensions(this); +}; +var arr = [1]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.filter(function() { + return true; + }); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/target-array-with-non-configurable-property.js b/test/sendable/builtins/Array/prototype/filter/target-array-with-non-configurable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..599ec4a03815e949bb9dd2fe00f197026df4a89d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/target-array-with-non-configurable-property.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + TypeError is thrown if CreateDataProperty fails. + (result object's "0" is non-configurable) +features: [Symbol.species] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + writable: true, + configurable: false, + }); +}; +var arr = [1]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.filter(function() { + return true; + }); +}); diff --git a/test/sendable/builtins/Array/prototype/filter/target-array-with-non-writable-property.js b/test/sendable/builtins/Array/prototype/filter/target-array-with-non-writable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..6b00e245431dfb808d7c188ec2dfd719c4f08b2e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/filter/target-array-with-non-writable-property.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.filter +description: > + Non-writable properties are overwritten by CreateDataPropertyOrThrow. +features: [Symbol.species] +includes: [propertyHelper.js] +---*/ + +var a = [1]; +a.constructor = {}; +a.constructor[Symbol.species] = function(len) { + var q = new SendableArray(0); + Object.defineProperty(q, 0, { + value: 0, writable: false, configurable: true, enumerable: false, + }); + return q; +}; +var r = a.filter(function(){ return true; }); +verifyProperty(r, 0, { + value: 1, writable: true, configurable: true, enumerable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/find/array-altered-during-loop.js b/test/sendable/builtins/Array/prototype/find/array-altered-during-loop.js new file mode 100644 index 0000000000000000000000000000000000000000..50f3a1c090ab7017175060a914b7e88d32bcd757 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/array-altered-during-loop.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + The range of elements processed is set before the first call to `predicate`. +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var results = []; +arr.find(function(kValue) { + if (results.length === 0) { + arr.splice(1, 1); + } + results.push(kValue); +}); +assert.sameValue(results.length, 3, 'predicate called three times'); +assert.sameValue(results[0], 'Shoes'); +assert.sameValue(results[1], 'Bike'); +assert.sameValue(results[2], undefined); +results = []; +arr = ['Skateboard', 'Barefoot']; +arr.find(function(kValue) { + if (results.length === 0) { + arr.push('Motorcycle'); + arr[1] = 'Magic Carpet'; + } + results.push(kValue); +}); +assert.sameValue(results.length, 2, 'predicate called twice'); +assert.sameValue(results[0], 'Skateboard'); +assert.sameValue(results[1], 'Magic Carpet'); diff --git a/test/sendable/builtins/Array/prototype/find/call-with-boolean.js b/test/sendable/builtins/Array/prototype/find/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..79d61ec3da460e35d1935efd3e731a6e46d141d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: Array.prototype.find applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.find.call(true, () => {}), + undefined, + 'SendableArray.prototype.find.call(true, () => {}) must return undefined' +); +assert.sameValue( + SendableArray.prototype.find.call(false, () => {}), + undefined, + 'SendableArray.prototype.find.call(false, () => {}) must return undefined' +); diff --git a/test/sendable/builtins/Array/prototype/find/callbackfn-resize-arraybuffer.js b/test/sendable/builtins/Array/prototype/find/callbackfn-resize-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..23810c950e42ff037c84c46e54aeb8e9f8dffdbc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/callbackfn-resize-arraybuffer.js @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: TypedArray instance buffer can be resized during iteration +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var finalElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + elements = []; + indices = []; + arrays = []; + result = Array.prototype.find.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + finalElement = undefined; + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + finalElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + assert.compareArray(elements, [0, 0, finalElement], 'elements (shrink)'); + assert.compareArray(indices, [0, 1, 2], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, undefined, 'result (shrink)'); + elements = []; + indices = []; + arrays = []; + result = Array.prototype.find.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, undefined, 'result (grow)'); +}); diff --git a/test/sendable/builtins/Array/prototype/find/length.js b/test/sendable/builtins/Array/prototype/find/length.js new file mode 100644 index 0000000000000000000000000000000000000000..8128b9adfe89333e377f3dbbbd34bdb85503b680 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/length.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: Array.prototype.find.length value and descriptor. +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.find, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/find/name.js b/test/sendable/builtins/Array/prototype/find/name.js new file mode 100644 index 0000000000000000000000000000000000000000..95c75c34af1f660afee0d050b35d429664dee2bc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/name.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Array.prototype.find.name value and descriptor. +info: | + 22.1.3.8 Array.prototype.find ( predicate [ , thisArg ] ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.find, "name", { + value: "find", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/find/not-a-constructor.js b/test/sendable/builtins/Array/prototype/find/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..dc6a84867554873f86a5248b0a1b2465af2ad41b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/not-a-constructor.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.find does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.prototype.find), false, 'isConstructor(SendableArray.prototype.find) must return false'); +assert.throws(TypeError, () => { + new SendableArray.prototype.find(() => {}); +}); + diff --git a/test/sendable/builtins/Array/prototype/find/predicate-call-parameters.js b/test/sendable/builtins/Array/prototype/find/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..9ee90e11d9c6d3be5dc18034338aee8a73b87c4f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/predicate-call-parameters.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var arr = ['Mike', 'Rick', 'Leo']; +var results = []; +arr.find(function(kValue, k, O) { + results.push(arguments); +}); +assert.sameValue(results.length, 3); +var result = results[0]; +assert.sameValue(result[0], 'Mike'); +assert.sameValue(result[1], 0); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); +result = results[1]; +assert.sameValue(result[0], 'Rick'); +assert.sameValue(result[1], 1); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); +result = results[2]; +assert.sameValue(result[0], 'Leo'); +assert.sameValue(result[1], 2); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); diff --git a/test/sendable/builtins/Array/prototype/find/predicate-call-this-non-strict.js b/test/sendable/builtins/Array/prototype/find/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..0de5019cc891e02dfdc7f20a4bd62644e85b21b8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/predicate-call-this-non-strict.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var result; +[1].find(function(kValue, k, O) { + result = this; +}); +assert.sameValue(result, this); +var o = {}; +[1].find(function() { + result = this; +}, o); +assert.sameValue(result, o); diff --git a/test/sendable/builtins/Array/prototype/find/predicate-call-this-strict.js b/test/sendable/builtins/Array/prototype/find/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..a6465dede9abaf535afe7a52e3658d97b8b4d4db --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/predicate-call-this-strict.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var result; +[1].find(function(kValue, k, O) { + result = this; +}); +assert.sameValue(result, undefined); +var o = {}; +[1].find(function() { + result = this; +}, o); +assert.sameValue(result, o); diff --git a/test/sendable/builtins/Array/prototype/find/predicate-called-for-each-array-property.js b/test/sendable/builtins/Array/prototype/find/predicate-called-for-each-array-property.js new file mode 100644 index 0000000000000000000000000000000000000000..f847b926f6bcb59c1003b7b99749629170e2ddf9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/predicate-called-for-each-array-property.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Predicate is called for each array property. +---*/ + +var arr = [undefined, , , 'foo']; +var called = 0; +arr.find(function() { + called++; +}); +assert.sameValue(called, 4); diff --git a/test/sendable/builtins/Array/prototype/find/predicate-is-not-callable-throws.js b/test/sendable/builtins/Array/prototype/find/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..605e7075a4fe0d0d0dce104b5f2d710ee1047d29 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/predicate-is-not-callable-throws.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Throws a TypeError exception if predicate is not callable. +---*/ + +assert.throws(TypeError, function() { + [].find({}); +}); +assert.throws(TypeError, function() { + [].find(null); +}); +assert.throws(TypeError, function() { + [].find(undefined); +}); +assert.throws(TypeError, function() { + [].find(true); +}); +assert.throws(TypeError, function() { + [].find(1); +}); +assert.throws(TypeError, function() { + [].find(''); +}); +assert.throws(TypeError, function() { + [].find(1); +}); +assert.throws(TypeError, function() { + [].find([]); +}); +assert.throws(TypeError, function() { + [].find(/./); +}); diff --git a/test/sendable/builtins/Array/prototype/find/predicate-not-called-on-empty-array.js b/test/sendable/builtins/Array/prototype/find/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..88bd9a356d7baa548f12164bf830bdf8215f45c5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/predicate-not-called-on-empty-array.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Predicate is only called if this.length is > 0. +---*/ + +var called = false; +var predicate = function() { + called = true; + return true; +}; +var result = [].find(predicate); +assert.sameValue(called, false, '[].find(predicate) does not call predicate'); +assert.sameValue(result, undefined, '[].find(predicate) returned undefined'); diff --git a/test/sendable/builtins/Array/prototype/find/prop-desc.js b/test/sendable/builtins/Array/prototype/find/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..de33068e7386c1add3c716ec6f40ad0ce1755849 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: Property type and descriptor. +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.find, + 'function', + '`typeof SendableArray.prototype.find` is `function`' +); +verifyProperty(SendableArray.prototype, "find", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/find/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/find/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..873acec4fdfc8f1aec82492409793401b75ac5b5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.find +description: > + Array.p.find behaves correctly when receiver is backed by resizable + buffer that is grown mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.find.call(fixedLength, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.find.call(fixedLengthWithOffset, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.find.call(lengthTracking, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.find.call(lengthTrackingWithOffset, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/find/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/find/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..38b891c3671cffbfb64b9aa442ea21a82cff0642 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.find +description: > + Array.p.find behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function ArrayFindHelper(ta, p) { + return SendableArray.prototype.find.call(ta, p); +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + const values = []; + const resizeAfter = 2; + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + function CollectResize(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; + } + assert.sameValue(ArrayFindHelper(fixedLength, CollectResize), undefined); + assert.compareArray(values, [ + 0, + 2, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const values = []; + const resizeAfter = 1; + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + function CollectResize(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; + } + assert.sameValue(ArrayFindHelper(fixedLengthWithOffset, CollectResize), undefined); + assert.compareArray(values, [ + 4, + undefined + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + const values = []; + const resizeAfter = 2; + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + function CollectResize(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; + } + assert.sameValue(ArrayFindHelper(lengthTracking, CollectResize), undefined); + assert.compareArray(values, [ + 0, + 2, + 4, + undefined + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const values = []; + const resizeAfter = 1; + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + function CollectResize(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; + } + assert.sameValue(ArrayFindHelper(lengthTrackingWithOffset, CollectResize), undefined); + assert.compareArray(values, [ + 4, + undefined + ]); +} diff --git a/test/sendable/builtins/Array/prototype/find/resizable-buffer.js b/test/sendable/builtins/Array/prototype/find/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..6e42560ecb7e7fb2a8656f71e183e110a6396ccf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/resizable-buffer.js @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.find +description: > + Array.p.find behaves correctly when receiver is backed by resizable + buffer +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function isTwoOrFour(n) { + return n == 2 || n == 4; + } + assert.sameValue(Number(SendableArray.prototype.find.call(fixedLength, isTwoOrFour)), 2); + assert.sameValue(Number(SendableArray.prototype.find.call(fixedLengthWithOffset, isTwoOrFour)), 4); + assert.sameValue(Number(SendableArray.prototype.find.call(lengthTracking, isTwoOrFour)), 2); + assert.sameValue(Number(SendableArray.prototype.find.call(lengthTrackingWithOffset, isTwoOrFour)), 4); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.sameValue(SendableArray.prototype.find.call(fixedLength, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.find.call(fixedLengthWithOffset, isTwoOrFour), undefined); + assert.sameValue(Number(SendableArray.prototype.find.call(lengthTracking, isTwoOrFour)), 2); + assert.sameValue(Number(SendableArray.prototype.find.call(lengthTrackingWithOffset, isTwoOrFour)), 4); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(SendableArray.prototype.find.call(fixedLength, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.find.call(fixedLengthWithOffset, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.find.call(lengthTrackingWithOffset, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.find.call(lengthTracking, isTwoOrFour), undefined); + // Shrink to zero. + rab.resize(0); + assert.sameValue(SendableArray.prototype.find.call(fixedLength, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.find.call(fixedLengthWithOffset, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.find.call(lengthTrackingWithOffset, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.find.call(lengthTracking, isTwoOrFour), undefined); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 0); + } + taWrite[4] = MayNeedBigInt(taWrite, 2); + taWrite[5] = MayNeedBigInt(taWrite, 4); + // Orig. array: [0, 0, 0, 0, 2, 4] + // [0, 0, 0, 0] << fixedLength + // [0, 0] << fixedLengthWithOffset + // [0, 0, 0, 0, 2, 4, ...] << lengthTracking + // [0, 0, 2, 4, ...] << lengthTrackingWithOffset + assert.sameValue(SendableArray.prototype.find.call(fixedLength, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.find.call(fixedLengthWithOffset, isTwoOrFour), undefined); + assert.sameValue(Number(SendableArray.prototype.find.call(lengthTracking, isTwoOrFour)), 2); + assert.sameValue(Number(SendableArray.prototype.find.call(lengthTrackingWithOffset, isTwoOrFour)), 2); +} diff --git a/test/sendable/builtins/Array/prototype/find/return-abrupt-from-predicate-call.js b/test/sendable/builtins/Array/prototype/find/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..44051819e7b3bbb0346d37fb8f99331b80a3830b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/return-abrupt-from-predicate-call.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Return abrupt from predicate call. +---*/ + +var predicate = function() { + throw new Test262Error(); +}; +assert.throws(Test262Error, function() { + [1].find(predicate); +}); diff --git a/test/sendable/builtins/Array/prototype/find/return-abrupt-from-property.js b/test/sendable/builtins/Array/prototype/find/return-abrupt-from-property.js new file mode 100644 index 0000000000000000000000000000000000000000..f5964bcb25ff1367ad1e5104aa7165a389a87391 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/return-abrupt-from-property.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Returns abrupt from getting property value from `this`. +---*/ + +var o = { + length: 1 +}; +Object.defineProperty(o, 0, { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + [].find.call(o, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/find/return-abrupt-from-this-length-as-symbol.js b/test/sendable/builtins/Array/prototype/find/return-abrupt-from-this-length-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..5cd7938a13abf04c9505cb9981f586da73eb8175 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/return-abrupt-from-this-length-as-symbol.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Return abrupt from ToLength(Get(O, "length")) where length is a Symbol. +---*/ + +var o = {}; + +o.length = Symbol(1); +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + [].find.call(o, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/find/return-abrupt-from-this-length.js b/test/sendable/builtins/Array/prototype/find/return-abrupt-from-this-length.js new file mode 100644 index 0000000000000000000000000000000000000000..f0600a57f87f0040a8cc1b3bfd7f334f5a6c7887 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/return-abrupt-from-this-length.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Return abrupt from ToLength(Get(O, "length")). +---*/ + +var o1 = {}; +Object.defineProperty(o1, 'length', { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + [].find.call(o1); +}); +var o2 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; +assert.throws(Test262Error, function() { + [].find.call(o2); +}); diff --git a/test/sendable/builtins/Array/prototype/find/return-abrupt-from-this.js b/test/sendable/builtins/Array/prototype/find/return-abrupt-from-this.js new file mode 100644 index 0000000000000000000000000000000000000000..fed39282784f23dd0cc5f4e60bed5876fb1686eb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/return-abrupt-from-this.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Return abrupt from ToObject(this value). +info: | + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + SendableArray.prototype.find.call(undefined, function() {}); +}); +assert.throws(TypeError, function() { + SendableArray.prototype.find.call(null, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/find/return-found-value-predicate-result-is-true.js b/test/sendable/builtins/Array/prototype/find/return-found-value-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..17c0495594ad5d3c2951c0a4f1e43000ea85a942 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/return-found-value-predicate-result-is-true.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Return found value if predicate return a boolean true value. +features: [Symbol] +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; +var result = arr.find(function(val) { + called++; + return true; +}); +assert.sameValue(result, 'Shoes'); +assert.sameValue(called, 1, 'predicate was called once'); +called = 0; +result = arr.find(function(val) { + called++; + return val === 'Bike'; +}); +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, 'Bike'); +result = arr.find(function(val) { + return 'string'; +}); +assert.sameValue(result, 'Shoes', 'coerced string'); +result = arr.find(function(val) { + return {}; +}); +assert.sameValue(result, 'Shoes', 'coerced object'); +result = arr.find(function(val) { + return Symbol(''); +}); +assert.sameValue(result, 'Shoes', 'coerced Symbol'); +result = arr.find(function(val) { + return 1; +}); +assert.sameValue(result, 'Shoes', 'coerced number'); +result = arr.find(function(val) { + return -1; +}); +assert.sameValue(result, 'Shoes', 'coerced negative number'); diff --git a/test/sendable/builtins/Array/prototype/find/return-undefined-if-predicate-returns-false-value.js b/test/sendable/builtins/Array/prototype/find/return-undefined-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..d35d512c6d965fefad85dc07e11b61a3c0ca272d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/find/return-undefined-if-predicate-returns-false-value.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.find +description: > + Return undefined if predicate always returns a boolean false value. +features: [Symbol] +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; +var result = arr.find(function(val) { + called++; + return false; +}); +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, undefined); +result = arr.find(function(val) { + return ''; +}); +assert.sameValue(result, undefined, 'coerced string'); +result = arr.find(function(val) { + return undefined; +}); +assert.sameValue(result, undefined, 'coerced undefined'); +result = arr.find(function(val) { + return null; +}); +assert.sameValue(result, undefined, 'coerced null'); +result = arr.find(function(val) { + return 0; +}); +assert.sameValue(result, undefined, 'coerced 0'); +result = arr.find(function(val) { + return NaN; +}); +assert.sameValue(result, undefined, 'coerced NaN'); diff --git a/test/sendable/builtins/Array/prototype/findIndex/array-altered-during-loop.js b/test/sendable/builtins/Array/prototype/findIndex/array-altered-during-loop.js new file mode 100644 index 0000000000000000000000000000000000000000..f8f23bb90efa75256fcf829402b9a96928fe0bb4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/array-altered-during-loop.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + The range of elements processed is set before the first call to `predicate`. +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var results = []; +arr.findIndex(function(kValue) { + if (results.length === 0) { + arr.splice(1, 1); + } + results.push(kValue); +}); +assert.sameValue(results.length, 3, 'predicate called three times'); +assert.sameValue(results[0], 'Shoes'); +assert.sameValue(results[1], 'Bike'); +assert.sameValue(results[2], undefined); +results = []; +arr = ['Skateboard', 'Barefoot']; +arr.findIndex(function(kValue) { + if (results.length === 0) { + arr.push('Motorcycle'); + arr[1] = 'Magic Carpet'; + } + results.push(kValue); +}); +assert.sameValue(results.length, 2, 'predicate called twice'); +assert.sameValue(results[0], 'Skateboard'); +assert.sameValue(results[1], 'Magic Carpet'); diff --git a/test/sendable/builtins/Array/prototype/findIndex/call-with-boolean.js b/test/sendable/builtins/Array/prototype/findIndex/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..bd1266a7b15a9ada49dfadd677f82941f700fdfa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findIndex +description: Array.prototype.findIndex applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.findIndex.call(true, () => {}), + -1, + 'SendableArray.prototype.findIndex.call(true, () => {}) must return -1' +); +assert.sameValue( + SendableArray.prototype.findIndex.call(false, () => {}), + -1, + 'SendableArray.prototype.findIndex.call(false, () => {}) must return -1' +); diff --git a/test/sendable/builtins/Array/prototype/findIndex/callbackfn-resize-arraybuffer.js b/test/sendable/builtins/Array/prototype/findIndex/callbackfn-resize-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9d7d2ada667471cc902da7c5f5c61c19507cc8dc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/callbackfn-resize-arraybuffer.js @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: TypedArray instance buffer can be resized during iteration +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var finalElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.findIndex.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + finalElement = undefined; + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + finalElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + assert.compareArray(elements, [0, 0, finalElement], 'elements (shrink)'); + assert.compareArray(indices, [0, 1, 2], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, -1, 'result (shrink)'); + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.findIndex.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, -1, 'result (grow)'); +}); diff --git a/test/sendable/builtins/Array/prototype/findIndex/length.js b/test/sendable/builtins/Array/prototype/findIndex/length.js new file mode 100644 index 0000000000000000000000000000000000000000..d3d9fa8c28669a1317a128430a7271c701794799 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/length.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: Array.prototype.findIndex.length value and descriptor. +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.findIndex, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/findIndex/name.js b/test/sendable/builtins/Array/prototype/findIndex/name.js new file mode 100644 index 0000000000000000000000000000000000000000..83b18d6e984ca991c04ce90aa244caf1b67191b6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/name.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Array.prototype.findIndex.name value and descriptor. +info: | + 22.1.3.9 Array.prototype.findIndex ( predicate [ , thisArg ] ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.findIndex, "name", { + value: "findIndex", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/findIndex/not-a-constructor.js b/test/sendable/builtins/Array/prototype/findIndex/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..f28309bf599b0ded5890a7bd2c9c9d95d3a44d6b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/not-a-constructor.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.findIndex does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.findIndex), + false, + 'isConstructor(SendableArray.prototype.findIndex) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.findIndex(() => {}); +}); + diff --git a/test/sendable/builtins/Array/prototype/findIndex/predicate-call-parameters.js b/test/sendable/builtins/Array/prototype/findIndex/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..014dfd8ba91740874c40247700511b5e700afca2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/predicate-call-parameters.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var arr = ['Mike', 'Rick', 'Leo']; +var results = []; +arr.findIndex(function(kValue, k, O) { + results.push(arguments); +}); +assert.sameValue(results.length, 3); +var result = results[0]; +assert.sameValue(result[0], 'Mike'); +assert.sameValue(result[1], 0); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); +result = results[1]; +assert.sameValue(result[0], 'Rick'); +assert.sameValue(result[1], 1); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); +result = results[2]; +assert.sameValue(result[0], 'Leo'); +assert.sameValue(result[1], 2); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); diff --git a/test/sendable/builtins/Array/prototype/findIndex/predicate-call-this-non-strict.js b/test/sendable/builtins/Array/prototype/findIndex/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..b70aec2789ffbdcb27b53b065c4f8e223f6fa5f1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/predicate-call-this-non-strict.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var result; +[1].find(function(kValue, k, O) { + result = this; +}); +assert.sameValue(result, this); +var o = {}; +[1].find(function() { + result = this; +}, o); +assert.sameValue(result, o); diff --git a/test/sendable/builtins/Array/prototype/findIndex/predicate-call-this-strict.js b/test/sendable/builtins/Array/prototype/findIndex/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..16076b46c96d2d0d5eab26fa534aeb6df9a1793e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/predicate-call-this-strict.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var result; +[1].find(function(kValue, k, O) { + result = this; +}); +assert.sameValue(result, undefined); +var o = {}; +[1].find(function() { + result = this; +}, o); +assert.sameValue(result, o); diff --git a/test/sendable/builtins/Array/prototype/findIndex/predicate-called-for-each-array-property.js b/test/sendable/builtins/Array/prototype/findIndex/predicate-called-for-each-array-property.js new file mode 100644 index 0000000000000000000000000000000000000000..50e602e080e0def250186b820c5a90dac4ff7516 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/predicate-called-for-each-array-property.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Predicate is called for each array property. +---*/ + +var arr = [undefined, , , 'foo']; +var called = 0; +arr.findIndex(function() { + called++; +}); +assert.sameValue(called, 4); diff --git a/test/sendable/builtins/Array/prototype/findIndex/predicate-is-not-callable-throws.js b/test/sendable/builtins/Array/prototype/findIndex/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..c14d3ec8e1aaaf9d1630d0fdd448cd0b20195018 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/predicate-is-not-callable-throws.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Throws a TypeError exception if predicate is not callable. +---*/ + +assert.throws(TypeError, function() { + [].findIndex({}); +}); +assert.throws(TypeError, function() { + [].findIndex(null); +}); +assert.throws(TypeError, function() { + [].findIndex(undefined); +}); +assert.throws(TypeError, function() { + [].findIndex(true); +}); +assert.throws(TypeError, function() { + [].findIndex(1); +}); +assert.throws(TypeError, function() { + [].findIndex(''); +}); +assert.throws(TypeError, function() { + [].findIndex(1); +}); +assert.throws(TypeError, function() { + [].findIndex([]); +}); +assert.throws(TypeError, function() { + [].findIndex(/./); +}); diff --git a/test/sendable/builtins/Array/prototype/findIndex/predicate-not-called-on-empty-array.js b/test/sendable/builtins/Array/prototype/findIndex/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..e79f8380b9dcec92131845b154a3ab0ca3c5d759 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/predicate-not-called-on-empty-array.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Predicate is only called if this.length is > 0. +---*/ + +var called = false; +var predicate = function() { + called = true; + return true; +}; +var result = [].findIndex(predicate); +assert.sameValue( + called, false, + '[].findIndex(predicate) does not call predicate' +); +assert.sameValue( + result, -1, + '[].findIndex(predicate) returned undefined' +); diff --git a/test/sendable/builtins/Array/prototype/findIndex/prop-desc.js b/test/sendable/builtins/Array/prototype/findIndex/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..a55703890cf60acf4e43c8fa000a2db69feb88ac --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: Property type and descriptor. +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.findIndex, + 'function', + '`typeof SendableArray.prototype.findIndex` is `function`' +); +verifyProperty(SendableArray.prototype, "findIndex", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/findIndex/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/findIndex/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..16a35f167bbcc5e70d49a417456046d6bc98a4a0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.findindex +description: > + Array.p.findIndex behaves correctly when receiver is backed by resizable + buffer that is grown mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLength, ResizeMidIteration), -1); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLengthWithOffset, ResizeMidIteration), -1); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTracking, ResizeMidIteration), -1); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTrackingWithOffset, ResizeMidIteration), -1); + assert.compareArray(values, [ + 4, + 6 + ]); +} + diff --git a/test/sendable/builtins/Array/prototype/findIndex/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/findIndex/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..1a6c9e5f89967c3c21eff82ec6c30935ab89070a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Array.p.findIndex behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLength, ResizeMidIteration), -1); + assert.compareArray(values, [ + 0, + 2, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLengthWithOffset, ResizeMidIteration), -1); + assert.compareArray(values, [ + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTracking, ResizeMidIteration), -1); + assert.compareArray(values, [ + 0, + 2, + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTrackingWithOffset, ResizeMidIteration), -1); + assert.compareArray(values, [ + 4, + undefined + ]); +} diff --git a/test/sendable/builtins/Array/prototype/findIndex/resizable-buffer.js b/test/sendable/builtins/Array/prototype/findIndex/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9c3c075be5ba0cc751c3511819c93e49ec5c96bb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/resizable-buffer.js @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Array.p.findIndex behaves correctly when receiver is backed by resizable + buffer +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + function isTwoOrFour(n) { + return n == 2 || n == 4; + } + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLength, isTwoOrFour), 1); + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLengthWithOffset, isTwoOrFour), 0); + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTracking, isTwoOrFour), 1); + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTrackingWithOffset, isTwoOrFour), 0); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLength, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLengthWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTracking, isTwoOrFour), 1); + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTrackingWithOffset, isTwoOrFour), 0); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLength, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLengthWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTrackingWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTracking, isTwoOrFour), -1); + // Shrink to zero. + rab.resize(0); + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLength, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLengthWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTrackingWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTracking, isTwoOrFour), -1); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 0); + } + taWrite[4] = MayNeedBigInt(taWrite, 2); + taWrite[5] = MayNeedBigInt(taWrite, 4); + // Orig. array: [0, 0, 0, 0, 2, 4] + // [0, 0, 0, 0] << fixedLength + // [0, 0] << fixedLengthWithOffset + // [0, 0, 0, 0, 2, 4, ...] << lengthTracking + // [0, 0, 2, 4, ...] << lengthTrackingWithOffset + + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLength, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findIndex.call(fixedLengthWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTracking, isTwoOrFour), 4); + assert.sameValue(SendableArray.prototype.findIndex.call(lengthTrackingWithOffset, isTwoOrFour), 2); +} diff --git a/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-predicate-call.js b/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..13b5464dbf60555e7345b6003e71b0829becc1fb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-predicate-call.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Return abrupt from predicate call. +---*/ + +var predicate = function() { + throw new Test262Error(); +}; +assert.throws(Test262Error, function() { + [1].findIndex(predicate); +}); diff --git a/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-property.js b/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-property.js new file mode 100644 index 0000000000000000000000000000000000000000..ef315feb159fbb59497c8c22e1b3a22d18da3e29 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-property.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Returns abrupt from getting property value from `this`. +---*/ + +var o = { + length: 1 +}; +Object.defineProperty(o, 0, { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + [].findIndex.call(o, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-this-length-as-symbol.js b/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-this-length-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..af109491f5eb108bfed3675240fe4c825ffd1562 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-this-length-as-symbol.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Return abrupt from ToLength(Get(O, "length")) where length is a Symbol. +---*/ + +var o = {}; +o.length = Symbol(1); +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + [].findIndex.call(o, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-this-length.js b/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-this-length.js new file mode 100644 index 0000000000000000000000000000000000000000..24b10e78ca51150649c1e45b8887ffa69132889b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-this-length.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Return abrupt from ToLength(Get(O, "length")). +info: | + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Let len be ToLength(Get(O, "length")). + 4. ReturnIfAbrupt(len). +---*/ + +var o1 = {}; +Object.defineProperty(o1, 'length', { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +// predicate fn is given to avoid false positives +assert.throws(Test262Error, function() { + [].findIndex.call(o1, function() {}); +}); +var o2 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; +assert.throws(Test262Error, function() { + [].findIndex.call(o2, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-this.js b/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-this.js new file mode 100644 index 0000000000000000000000000000000000000000..d86318274d05633686f454de45be070c6be8ee66 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/return-abrupt-from-this.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Return abrupt from ToObject(this value). +info: | + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + SendableArray.prototype.findIndex.call(undefined, function() {}); +}); +assert.throws(TypeError, function() { + SendableArray.prototype.findIndex.call(null, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/findIndex/return-index-predicate-result-is-true.js b/test/sendable/builtins/Array/prototype/findIndex/return-index-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..60e89111ddcff97970d541ed05830212af5aef93 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/return-index-predicate-result-is-true.js @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Return index if predicate return a boolean true value. +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; +var result = arr.findIndex(function(val) { + called++; + return true; +}); +assert.sameValue(result, 0); +assert.sameValue(called, 1, 'predicate was called once'); +called = 0; +result = arr.findIndex(function(val) { + called++; + return val === 'Bike'; +}); +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, 2); +result = arr.findIndex(function(val) { + return 'string'; +}); +assert.sameValue(result, 0, 'coerced string'); +result = arr.findIndex(function(val) { + return {}; +}); +assert.sameValue(result, 0, 'coerced object'); +result = arr.findIndex(function(val) { + return Symbol(''); +}); +assert.sameValue(result, 0, 'coerced Symbol'); +result = arr.findIndex(function(val) { + return 1; +}); +assert.sameValue(result, 0, 'coerced number'); +result = arr.findIndex(function(val) { + return -1; +}); +assert.sameValue(result, 0, 'coerced negative number'); diff --git a/test/sendable/builtins/Array/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js b/test/sendable/builtins/Array/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..e1fe2b7ad65f1bbaea8f1ddc28c8279b7c188c23 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findindex +description: > + Return -1 if predicate always returns a boolean false value. +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; +var result = arr.findIndex(function(val) { + called++; + return false; +}); +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, -1); +result = arr.findIndex(function(val) { + return ''; +}); +assert.sameValue(result, -1, 'coerced string'); +result = arr.findIndex(function(val) { + return undefined; +}); +assert.sameValue(result, -1, 'coerced undefined'); +result = arr.findIndex(function(val) { + return null; +}); +assert.sameValue(result, -1, 'coerced null'); +result = arr.findIndex(function(val) { + return 0; +}); +assert.sameValue(result, -1, 'coerced 0'); +result = arr.findIndex(function(val) { + return NaN; +}); +assert.sameValue(result, -1, 'coerced NaN'); diff --git a/test/sendable/builtins/Array/prototype/findLast/array-altered-during-loop.js b/test/sendable/builtins/Array/prototype/findLast/array-altered-during-loop.js new file mode 100644 index 0000000000000000000000000000000000000000..c46602e2a1dd2dafc43ae09a8d2e764789ef1a99 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/array-altered-during-loop.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + The range of elements processed is set before the first call to `predicate`. +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var results = []; +arr.findLast(function(kValue) { + if (results.length === 0) { + arr.splice(1, 1); + } + results.push(kValue); +}); +assert.sameValue(results.length, 3, 'predicate called three times'); +assert.sameValue(results[0], 'Bike'); +assert.sameValue(results[1], 'Bike'); +assert.sameValue(results[2], 'Shoes'); +results = []; +arr = ['Skateboard', 'Barefoot']; +arr.findLast(function(kValue) { + if (results.length === 0) { + arr.push('Motorcycle'); + arr[0] = 'Magic Carpet'; + } + results.push(kValue); +}); +assert.sameValue(results.length, 2, 'predicate called twice'); +assert.sameValue(results[0], 'Barefoot'); +assert.sameValue(results[1], 'Magic Carpet'); diff --git a/test/sendable/builtins/Array/prototype/findLast/call-with-boolean.js b/test/sendable/builtins/Array/prototype/findLast/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..85d7278cfb22bada95b57902573d94db95caf0df --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/call-with-boolean.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: Array.prototype.findLast applied to boolean primitive. +features: [array-find-from-last] +---*/ + +assert.sameValue( + SendableArray.prototype.findLast.call(true, () => {}), + undefined, + 'SendableArray.prototype.findLast.call(true, () => {}) must return undefined' +); +assert.sameValue( + SendableArray.prototype.findLast.call(false, () => {}), + undefined, + 'SendableArray.prototype.findLast.call(false, () => {}) must return undefined' +); diff --git a/test/sendable/builtins/Array/prototype/findLast/callbackfn-resize-arraybuffer.js b/test/sendable/builtins/Array/prototype/findLast/callbackfn-resize-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..7955e548fcace30a2b8844b80bd25ba53010506d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/callbackfn-resize-arraybuffer.js @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: TypedArray instance buffer can be resized during iteration +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var secondElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.findLast.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(BPE); + secondElement = undefined; + expectedElements = [0]; + expectedIndices = [0]; + expectedArrays = [sample]; + } catch (_) { + secondElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [2, 1, 0]; + expectedArrays = [sample, sample, sample]; + } + } + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + assert.compareArray(elements, [0, secondElement, 0], 'elements (shrink)'); + assert.compareArray(indices, [2, 1, 0], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, undefined, 'result (shrink)'); + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.findLast.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, undefined, 'result (grow)'); +}); diff --git a/test/sendable/builtins/Array/prototype/findLast/length.js b/test/sendable/builtins/Array/prototype/findLast/length.js new file mode 100644 index 0000000000000000000000000000000000000000..40b7d968efedca2e175ea43e2faf360039f2da59 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/length.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: Array.prototype.findLast.length value and descriptor. +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [array-find-from-last] +---*/ + +assert.sameValue( + SendableArray.prototype.findLast.length, 1, + 'The value of `SendableArray.prototype.findLast.length` is `1`' +); +verifyProperty(SendableArray.prototype.findLast, "length", { + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/findLast/maximum-index.js b/test/sendable/builtins/Array/prototype/findLast/maximum-index.js new file mode 100644 index 0000000000000000000000000000000000000000..a55cbfaac79f82a01684fefca80f3b769cd9076e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/maximum-index.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Support the maximum valid integer index. +---*/ + +var tooBigLength = Number.MAX_VALUE; +var maxExpectedIndex = 9007199254740990; +var arrayLike = { length: tooBigLength }; +var calledWithIndex = []; +SendableArray.prototype.findLast.call(arrayLike, function(_value, index) { + calledWithIndex.push(index); + return true; +}); +assert.sameValue(calledWithIndex.length, 1, 'predicate invoked once'); +assert.sameValue(calledWithIndex[0], maxExpectedIndex); diff --git a/test/sendable/builtins/Array/prototype/findLast/name.js b/test/sendable/builtins/Array/prototype/findLast/name.js new file mode 100644 index 0000000000000000000000000000000000000000..0e8618c51edd5ebda79c50035a122d4447162c0b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/name.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Array.prototype.findLast.name value and descriptor. +info: | + Array.prototype.findLast ( predicate [ , thisArg ] ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [array-find-from-last] +---*/ + +assert.sameValue( + SendableArray.prototype.findLast.name, 'findLast', + 'The value of `SendableArray.prototype.findLast.name` is `"findLast"`' +); +verifyProperty(SendableArray.prototype.findLast, "name", { + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/findLast/not-a-constructor.js b/test/sendable/builtins/Array/prototype/findLast/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..6b871d01fc39eb031041b1123078e24291e8287b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.findLast does not implement [[Construct]], is not new-able. +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function, array-find-from-last] +---*/ + +assert.sameValue(isConstructor(SendableArray.prototype.findLast), false, 'isConstructor(SendableArray.prototype.findLast) must return false'); +assert.throws(TypeError, () => { + new SendableArray.prototype.findLast(() => {}); +}); + diff --git a/test/sendable/builtins/Array/prototype/findLast/predicate-call-parameters.js b/test/sendable/builtins/Array/prototype/findLast/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..5b03a2899462468a4ad24b19f6b680e2df295322 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/predicate-call-parameters.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var arr = ['Mike', 'Rick', 'Leo']; +var results = []; +arr.findLast(function() { + results.push(arguments); +}); +assert.sameValue(results.length, 3); +var result = results[0]; +assert.sameValue(result[0], 'Leo'); +assert.sameValue(result[1], 2); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); +result = results[1]; +assert.sameValue(result[0], 'Rick'); +assert.sameValue(result[1], 1); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); +result = results[2]; +assert.sameValue(result[0], 'Mike'); +assert.sameValue(result[1], 0); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); diff --git a/test/sendable/builtins/Array/prototype/findLast/predicate-call-this-non-strict.js b/test/sendable/builtins/Array/prototype/findLast/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..e4d7a76520044807125d0bf5eb2caa22105155bf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/predicate-call-this-non-strict.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var result; +[1].findLast(function() { + result = this; +}); +assert.sameValue(result, this); +var o = {}; +[1].findLast(function() { + result = this; +}, o); +assert.sameValue(result, o); diff --git a/test/sendable/builtins/Array/prototype/findLast/predicate-call-this-strict.js b/test/sendable/builtins/Array/prototype/findLast/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..ab75a815e5d76c0a307ea95dc8dd7e459559cd5b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/predicate-call-this-strict.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var result; +[1].findLast(function() { + result = this; +}); +assert.sameValue(result, undefined); +var o = {}; +[1].findLast(function() { + result = this; +}, o); +assert.sameValue(result, o); diff --git a/test/sendable/builtins/Array/prototype/findLast/predicate-called-for-each-array-property.js b/test/sendable/builtins/Array/prototype/findLast/predicate-called-for-each-array-property.js new file mode 100644 index 0000000000000000000000000000000000000000..b857318f1e21cab987d8e72d25acf1880fe9327d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/predicate-called-for-each-array-property.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Predicate is called for each array property. +---*/ + +var arr = [undefined, , , 'foo']; +var called = 0; +arr.findLast(function() { + called++; +}); +assert.sameValue(called, 4); diff --git a/test/sendable/builtins/Array/prototype/findLast/predicate-is-not-callable-throws.js b/test/sendable/builtins/Array/prototype/findLast/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..10160bdc3f9421f4db7084387eaa7544c61f46fa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/predicate-is-not-callable-throws.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Throws a TypeError exception if predicate is not callable. +---*/ + +assert.throws(TypeError, function() { + [].findLast({}); +}); +assert.throws(TypeError, function() { + [].findLast(null); +}); +assert.throws(TypeError, function() { + [].findLast(undefined); +}); +assert.throws(TypeError, function() { + [].findLast(true); +}); +assert.throws(TypeError, function() { + [].findLast(1); +}); +assert.throws(TypeError, function() { + [].findLast(''); +}); +assert.throws(TypeError, function() { + [].findLast(1); +}); +assert.throws(TypeError, function() { + [].findLast([]); +}); +assert.throws(TypeError, function() { + [].findLast(/./); +}); diff --git a/test/sendable/builtins/Array/prototype/findLast/predicate-not-called-on-empty-array.js b/test/sendable/builtins/Array/prototype/findLast/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..d46a83a23cadcb3e02c492b51b11da7b9ff9a45c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/predicate-not-called-on-empty-array.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Predicate is only called if this.length is > 0. +---*/ + +var called = false; +var predicate = function() { + called = true; + return true; +}; +var result = [].findLast(predicate); +assert.sameValue(called, false, '[].findLast(predicate) does not call predicate'); +assert.sameValue(result, undefined, '[].findLast(predicate) returned undefined'); diff --git a/test/sendable/builtins/Array/prototype/findLast/prop-desc.js b/test/sendable/builtins/Array/prototype/findLast/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..7c249855ca643cf32dc9fa5c01bb1293bc2d89bb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/prop-desc.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: Property type and descriptor. +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [array-find-from-last] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.findLast, + 'function', + '`typeof SendableArray.prototype.findLast` is `function`' +); +verifyProperty(SendableArray.prototype, "findLast", { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/findLast/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/findLast/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..35180743bceeb01f7375b9a022f18d9559fc4ad8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Array.p.findLast behaves correctly when receiver is backed by resizable + buffer that is grown mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLast.call(fixedLength, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLast.call(fixedLengthWithOffset, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLast.call(lengthTracking, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLast.call(lengthTrackingWithOffset, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/findLast/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/findLast/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..fd142e0a9b2bb1033de581e1d7cf3a5472697802 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Array.p.findLast behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLast.call(fixedLength, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLast.call(fixedLengthWithOffset, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLast.call(lengthTracking, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLast.call(lengthTrackingWithOffset, ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/findLast/resizable-buffer.js b/test/sendable/builtins/Array/prototype/findLast/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..df080f6fe2efa663e5d425fc8e5f1c94f9f11ff9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/resizable-buffer.js @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.findLast +description: > + Array.p.findLast behaves correctly when receiver is backed by resizable + buffer +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function isTwoOrFour(n) { + return n == 2 || n == 4; + } + assert.sameValue(Number(SendableArray.prototype.findLast.call(fixedLength, isTwoOrFour)), 4); + assert.sameValue(Number(SendableArray.prototype.findLast.call(fixedLengthWithOffset, isTwoOrFour)), 4); + assert.sameValue(Number(SendableArray.prototype.findLast.call(lengthTracking, isTwoOrFour)), 4); + assert.sameValue(Number(SendableArray.prototype.findLast.call(lengthTrackingWithOffset, isTwoOrFour)), 4); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.sameValue(SendableArray.prototype.findLast.call(fixedLength, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.findLast.call(fixedLengthWithOffset, isTwoOrFour), undefined); + assert.sameValue(Number(SendableArray.prototype.findLast.call(lengthTracking, isTwoOrFour)), 4); + assert.sameValue(Number(SendableArray.prototype.findLast.call(lengthTrackingWithOffset, isTwoOrFour)), 4); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(SendableArray.prototype.findLast.call(fixedLength, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.findLast.call(fixedLengthWithOffset, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.findLast.call(lengthTrackingWithOffset, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.findLast.call(lengthTracking, isTwoOrFour), undefined); + // Shrink to zero. + rab.resize(0); + assert.sameValue(SendableArray.prototype.findLast.call(fixedLength, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.findLast.call(fixedLengthWithOffset, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.findLast.call(lengthTrackingWithOffset, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.findLast.call(lengthTracking, isTwoOrFour), undefined); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 0); + } + taWrite[4] = MayNeedBigInt(taWrite, 2); + taWrite[5] = MayNeedBigInt(taWrite, 4); + // Orig. array: [0, 0, 0, 0, 2, 4] + // [0, 0, 0, 0] << fixedLength + // [0, 0] << fixedLengthWithOffset + // [0, 0, 0, 0, 2, 4, ...] << lengthTracking + // [0, 0, 2, 4, ...] << lengthTrackingWithOffset + assert.sameValue(SendableArray.prototype.findLast.call(fixedLength, isTwoOrFour), undefined); + assert.sameValue(SendableArray.prototype.findLast.call(fixedLengthWithOffset, isTwoOrFour), undefined); + assert.sameValue(Number(SendableArray.prototype.findLast.call(lengthTracking, isTwoOrFour)), 4); + assert.sameValue(Number(SendableArray.prototype.findLast.call(lengthTrackingWithOffset, isTwoOrFour)), 4); +} diff --git a/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-predicate-call.js b/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..e0361196fd4229f5aea003c731d08f33a1f78471 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-predicate-call.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Return abrupt from predicate call. +---*/ + +var predicate = function() { + throw new Test262Error(); +}; +assert.throws(Test262Error, function() { + [1].findLast(predicate); +}); diff --git a/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-property.js b/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-property.js new file mode 100644 index 0000000000000000000000000000000000000000..28dd94e0235d21aafae49e7d23238cf04c4980f7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-property.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Returns abrupt from getting property value from `this`. +---*/ + +var o = { + length: 1 +}; +Object.defineProperty(o, 0, { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + [].findLast.call(o, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-this-length-as-symbol.js b/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-this-length-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..d12da64393e96aecd4705f1333d37bc9ed1e1d11 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-this-length-as-symbol.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Return abrupt from ToLength(Get(O, "length")) where length is a Symbol. +---*/ + +var o = {}; +o.length = Symbol(1); +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + [].findLast.call(o, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-this-length.js b/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-this-length.js new file mode 100644 index 0000000000000000000000000000000000000000..86581010884204f4770ccfa4ba6444877f58e1b5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-this-length.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Return abrupt from ToLength(Get(O, "length")). +---*/ + +var o1 = {}; +Object.defineProperty(o1, 'length', { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + [].findLast.call(o1); +}); +var o2 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; +assert.throws(Test262Error, function() { + [].findLast.call(o2); +}); diff --git a/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-this.js b/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-this.js new file mode 100644 index 0000000000000000000000000000000000000000..cfb0bc507081aa811e6cca6524a1f198085d3f3b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/return-abrupt-from-this.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Return abrupt from ToObject(this value). +---*/ + +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + SendableArray.prototype.findLast.call(undefined, function() {}); +}); +assert.throws(TypeError, function() { + SendableArray.prototype.findLast.call(null, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/findLast/return-found-value-predicate-result-is-true.js b/test/sendable/builtins/Array/prototype/findLast/return-found-value-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..b48170a5a420f93c631d22f767a6d3e8b2382363 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/return-found-value-predicate-result-is-true.js @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Return found value if predicate return a boolean true value. +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; +var result = arr.findLast(function() { + called++; + return true; +}); +assert.sameValue(result, 'Bike'); +assert.sameValue(called, 1, 'predicate was called once'); +called = 0; +result = arr.findLast(function(val) { + called++; + return val === 'Shoes'; +}); +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, 'Shoes'); +result = arr.findLast(function() { + return 'string'; +}); +assert.sameValue(result, 'Bike', 'coerced string'); +result = arr.findLast(function() { + return {}; +}); +assert.sameValue(result, 'Bike', 'coerced object'); +result = arr.findLast(function() { + return Symbol(''); +}); +assert.sameValue(result, 'Bike', 'coerced Symbol'); +result = arr.findLast(function() { + return 1; +}); +assert.sameValue(result, 'Bike', 'coerced number'); +result = arr.findLast(function() { + return -1; +}); +assert.sameValue(result, 'Bike', 'coerced negative number'); diff --git a/test/sendable/builtins/Array/prototype/findLast/return-undefined-if-predicate-returns-false-value.js b/test/sendable/builtins/Array/prototype/findLast/return-undefined-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..e4b43ea2d2aaed312732758e41eab0caee1a9ee0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLast/return-undefined-if-predicate-returns-false-value.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlast +description: > + Return undefined if predicate always returns a boolean false value. +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; +var result = arr.findLast(function() { + called++; + return false; +}); +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, undefined); +result = arr.findLast(function() { + return ''; +}); +assert.sameValue(result, undefined, 'coerced string'); +result = arr.findLast(function() { + return undefined; +}); +assert.sameValue(result, undefined, 'coerced undefined'); +result = arr.findLast(function() { + return null; +}); +assert.sameValue(result, undefined, 'coerced null'); +result = arr.findLast(function() { + return 0; +}); +assert.sameValue(result, undefined, 'coerced 0'); +result = arr.findLast(function() { + return NaN; +}); +assert.sameValue(result, undefined, 'coerced NaN'); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/array-altered-during-loop.js b/test/sendable/builtins/Array/prototype/findLastIndex/array-altered-during-loop.js new file mode 100644 index 0000000000000000000000000000000000000000..b3bc630f8a2da9dafa5690ca98dc4363a52eb633 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/array-altered-during-loop.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + The range of elements processed is set before the first call to `predicate`. +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var results = []; +arr.findLastIndex(function(kValue) { + if (results.length === 0) { + arr.splice(1, 1); + } + results.push(kValue); +}); +assert.sameValue(results.length, 3, 'predicate called three times'); +assert.sameValue(results[0], 'Bike'); +assert.sameValue(results[1], 'Bike'); +assert.sameValue(results[2], 'Shoes'); +results = []; +arr = ['Skateboard', 'Barefoot']; +arr.findLastIndex(function(kValue) { + if (results.length === 0) { + arr.push('Motorcycle'); + arr[0] = 'Magic Carpet'; + } + results.push(kValue); +}); +assert.sameValue(results.length, 2, 'predicate called twice'); +assert.sameValue(results[0], 'Barefoot'); +assert.sameValue(results[1], 'Magic Carpet'); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/call-with-boolean.js b/test/sendable/builtins/Array/prototype/findLastIndex/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..b53d7cfa6c78e4a42eb03df155a2982b9129076c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/call-with-boolean.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: Array.prototype.findLastIndex applied to boolean primitive. +features: [array-find-from-last] +---*/ + +assert.sameValue( + SendableArray.prototype.findLastIndex.call(true, () => {}), + -1, + 'SendableArray.prototype.findLastIndex.call(true, () => {}) must return -1' +); +assert.sameValue( + SendableArray.prototype.findLastIndex.call(false, () => {}), + -1, + 'SendableArray.prototype.findLastIndex.call(false, () => {}) must return -1' +); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/callbackfn-resize-arraybuffer.js b/test/sendable/builtins/Array/prototype/findLastIndex/callbackfn-resize-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..900a3c4c9a9d44cc473405184bada13a33a27903 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/callbackfn-resize-arraybuffer.js @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: TypedArray instance buffer can be resized during iteration +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var secondElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.findLastIndex.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(BPE); + secondElement = undefined; + expectedElements = [0]; + expectedIndices = [0]; + expectedArrays = [sample]; + } catch (_) { + secondElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [2, 1, 0]; + expectedArrays = [sample, sample, sample]; + } + } + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + assert.compareArray(elements, [0, secondElement, 0], 'elements (shrink)'); + assert.compareArray(indices, [2, 1, 0], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, -1, 'result (shrink)'); + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.findLastIndex.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, -1, 'result (grow)'); +}); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/length.js b/test/sendable/builtins/Array/prototype/findLastIndex/length.js new file mode 100644 index 0000000000000000000000000000000000000000..875b9287a65af568ce1e7fbba5d21c27fee30f46 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/length.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: Array.prototype.findLastIndex.length value and descriptor. +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [array-find-from-last] +---*/ + +assert.sameValue( + SendableArray.prototype.findLastIndex.length, 1, + 'The value of `SendableArray.prototype.findLastIndex.length` is `1`' +); +verifyProperty(SendableArray.prototype.findLastIndex, "length", { + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/maximum-index.js b/test/sendable/builtins/Array/prototype/findLastIndex/maximum-index.js new file mode 100644 index 0000000000000000000000000000000000000000..1fa3f74429654eb09c15876928bcfb68e50563ca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/maximum-index.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Support the maximum valid integer index. +---*/ + +var tooBigLength = Number.MAX_VALUE; +var maxExpectedIndex = 9007199254740990; +var arrayLike = { length: tooBigLength }; +var calledWithIndex = []; +SendableArray.prototype.findLastIndex.call(arrayLike, function(_value, index) { + calledWithIndex.push(index); + return true; +}); +assert.sameValue(calledWithIndex.length, 1, 'predicate invoked once'); +assert.sameValue(calledWithIndex[0], maxExpectedIndex); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/name.js b/test/sendable/builtins/Array/prototype/findLastIndex/name.js new file mode 100644 index 0000000000000000000000000000000000000000..82fb455a6272fc8c447040d00d11ca0c3d1d3f64 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Array.prototype.findLastIndex.name value and descriptor. +info: | + Array.prototype.findLastIndex ( predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [array-find-from-last] +---*/ + +assert.sameValue( + SendableArray.prototype.findLastIndex.name, 'findLastIndex', + 'The value of `SendableArray.prototype.findLastIndex.name` is `"findLastIndex"`' +); +verifyProperty(SendableArray.prototype.findLastIndex, "name", { + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/not-a-constructor.js b/test/sendable/builtins/Array/prototype/findLastIndex/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..cb3551da5509aaa2e9e327d9e43b83446152c6dc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/not-a-constructor.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.findLastIndex does not implement [[Construct]], is not new-able. +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function, array-find-from-last] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.findLastIndex), + false, + 'isConstructor(SendableArray.prototype.findLastIndex) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.findLastIndex(() => {}); +}); + diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/predicate-call-parameters.js b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..5c4d363c008cfad3b87027723aad348c9cfd35bb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-call-parameters.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var arr = ['Mike', 'Rick', 'Leo']; +var results = []; +arr.findLastIndex(function() { + results.push(arguments); +}); +assert.sameValue(results.length, 3); +var result = results[0]; +assert.sameValue(result[0], 'Leo'); +assert.sameValue(result[1], 2); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); +result = results[1]; +assert.sameValue(result[0], 'Rick'); +assert.sameValue(result[1], 1); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); +result = results[2]; +assert.sameValue(result[0], 'Mike'); +assert.sameValue(result[1], 0); +assert.sameValue(result[2], arr); +assert.sameValue(result.length, 3); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/predicate-call-this-non-strict.js b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..4dc54eee0a1a137f48b2c7063edb3850d03eb5f8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-call-this-non-strict.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var result; +[1].findLastIndex(function() { + result = this; +}); +assert.sameValue(result, this); +var o = {}; +[1].findLastIndex(function() { + result = this; +}, o); +assert.sameValue(result, o); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/predicate-call-this-strict.js b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..15bb11056b46f9cde7dc811c5723110b74f5e60e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-call-this-strict.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +---*/ + +var result; +[1].findLastIndex(function() { + result = this; +}); +assert.sameValue(result, undefined); +var o = {}; +[1].findLastIndex(function() { + result = this; +}, o); +assert.sameValue(result, o); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/predicate-called-for-each-array-property.js b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-called-for-each-array-property.js new file mode 100644 index 0000000000000000000000000000000000000000..47c0e1a3897a607ffda9e57e4d2778ad15bbaeee --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-called-for-each-array-property.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Predicate is called for each array property. +---*/ + +var arr = [undefined, , , 'foo']; +var called = 0; +arr.findLastIndex(function() { + called++; +}); +assert.sameValue(called, 4); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/predicate-is-not-callable-throws.js b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9acca53ea8f4229d8240ad9bca32fd1462bf6095 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-is-not-callable-throws.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Throws a TypeError exception if predicate is not callable. +---*/ + +assert.throws(TypeError, function() { + [].findLastIndex({}); +}); +assert.throws(TypeError, function() { + [].findLastIndex(null); +}); +assert.throws(TypeError, function() { + [].findLastIndex(undefined); +}); +assert.throws(TypeError, function() { + [].findLastIndex(true); +}); +assert.throws(TypeError, function() { + [].findLastIndex(1); +}); +assert.throws(TypeError, function() { + [].findLastIndex(''); +}); +assert.throws(TypeError, function() { + [].findLastIndex(1); +}); +assert.throws(TypeError, function() { + [].findLastIndex([]); +}); +assert.throws(TypeError, function() { + [].findLastIndex(/./); +}); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/predicate-not-called-on-empty-array.js b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..079253fe201ecc7425e604b4a4891fa722a54760 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/predicate-not-called-on-empty-array.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Predicate is only called if this.length is > 0. +---*/ + +var called = false; +var predicate = function() { + called = true; + return true; +}; +var result = [].findLastIndex(predicate); +assert.sameValue( + called, false, + '[].findLastIndex(predicate) does not call predicate' +); +assert.sameValue( + result, -1, + '[].findLastIndex(predicate) returned undefined' +); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/prop-desc.js b/test/sendable/builtins/Array/prototype/findLastIndex/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..4bbe20fdda2f4c5df554244a2b7e28f490dc586b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/prop-desc.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: Property type and descriptor. +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [array-find-from-last] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.findLastIndex, + 'function', + '`typeof SendableArray.prototype.findLastIndex` is `function`' +); +verifyProperty(SendableArray.prototype, "findLastIndex", { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/findLastIndex/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..83f60270f582dc01adf2a53f7323e56c48fcc23f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Array.p.findLastIndex behaves correctly when receiver is backed by resizable + buffer that is grown mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLength, ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLengthWithOffset, ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTracking, ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTrackingWithOffset, ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/findLastIndex/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..94535d1df83474519c68043424aa5f448772867f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Array.p.findLastIndex behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLength, ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLengthWithOffset, ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTracking, ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 1; + resizeTo = 2 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTracking, ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + undefined, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTrackingWithOffset, ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/resizable-buffer.js b/test/sendable/builtins/Array/prototype/findLastIndex/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..74d14d77ac12a4b7c95c7bcb50a95b05017ed367 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/resizable-buffer.js @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Array.p.findLastIndex behaves correctly when receiver is backed by resizable + buffer +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + function isTwoOrFour(n) { + return n == 2 || n == 4; + } + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLength, isTwoOrFour), 2); + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLengthWithOffset, isTwoOrFour), 0); + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTracking, isTwoOrFour), 2); + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTrackingWithOffset, isTwoOrFour), 0); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLength, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLengthWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTracking, isTwoOrFour), 2); + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTrackingWithOffset, isTwoOrFour), 0); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLength, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLengthWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTrackingWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTracking, isTwoOrFour), -1); + // Shrink to zero. + rab.resize(0); + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLength, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLengthWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTrackingWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTracking, isTwoOrFour), -1); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 0); + } + taWrite[4] = MayNeedBigInt(taWrite, 2); + taWrite[5] = MayNeedBigInt(taWrite, 4); + // Orig. array: [0, 0, 0, 0, 2, 4] + // [0, 0, 0, 0] << fixedLength + // [0, 0] << fixedLengthWithOffset + // [0, 0, 0, 0, 2, 4, ...] << lengthTracking + // [0, 0, 2, 4, ...] << lengthTrackingWithOffset + + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLength, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findLastIndex.call(fixedLengthWithOffset, isTwoOrFour), -1); + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTracking, isTwoOrFour), 5); + assert.sameValue(SendableArray.prototype.findLastIndex.call(lengthTrackingWithOffset, isTwoOrFour), 3); +} + diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-predicate-call.js b/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..20731759593b372a7041c90b98cee59e857a0a85 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-predicate-call.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Return abrupt from predicate call. +---*/ + +var predicate = function() { + throw new Test262Error(); +}; +assert.throws(Test262Error, function() { + [1].findLastIndex(predicate); +}); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-property.js b/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-property.js new file mode 100644 index 0000000000000000000000000000000000000000..8edfe39f2cf57952ba31fa61b4c02c371d909acd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-property.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Returns abrupt from getting property value from `this`. +---*/ + +var o = { + length: 1 +}; +Object.defineProperty(o, 0, { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + [].findLastIndex.call(o, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-this-length-as-symbol.js b/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-this-length-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..8462a7a603c3cf97e44e3b76b98c827a4f01db1f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-this-length-as-symbol.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Return abrupt from ToLength(Get(O, "length")) where length is a Symbol. +---*/ + +var o = {}; +o.length = Symbol(1); +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + [].findLastIndex.call(o, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-this-length.js b/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-this-length.js new file mode 100644 index 0000000000000000000000000000000000000000..0f078afdcffde4b6131a50d5c004f49b06a28665 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-this-length.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Return abrupt from ToLength(Get(O, "length")). +---*/ + +var o1 = {}; +Object.defineProperty(o1, 'length', { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +// predicate fn is given to avoid false positives +assert.throws(Test262Error, function() { + [].findLastIndex.call(o1, function() {}); +}); +var o2 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; +assert.throws(Test262Error, function() { + [].findLastIndex.call(o2, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-this.js b/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-this.js new file mode 100644 index 0000000000000000000000000000000000000000..60d96dedc2d3eedc7b137b879b21664923fce115 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/return-abrupt-from-this.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Return abrupt from ToObject(this value). +---*/ + +// predicate fn is given to avoid false positives +assert.throws(TypeError, function() { + SendableArray.prototype.findLastIndex.call(undefined, function() {}); +}); +assert.throws(TypeError, function() { + SendableArray.prototype.findLastIndex.call(null, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/return-index-predicate-result-is-true.js b/test/sendable/builtins/Array/prototype/findLastIndex/return-index-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..3b89ac4305cc56849fa8630a16a24637f343116b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/return-index-predicate-result-is-true.js @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Return index if predicate return a boolean true value. +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; +var result = arr.findLastIndex(function() { + called++; + return true; +}); +assert.sameValue(result, 2); +assert.sameValue(called, 1, 'predicate was called once'); +called = 0; +result = arr.findLastIndex(function(val) { + called++; + return val === 'Shoes'; +}); +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, 0); +result = arr.findLastIndex(function() { + return 'string'; +}); +assert.sameValue(result, 2, 'coerced string'); +result = arr.findLastIndex(function() { + return {}; +}); +assert.sameValue(result, 2, 'coerced object'); +result = arr.findLastIndex(function() { + return Symbol(''); +}); +assert.sameValue(result, 2, 'coerced Symbol'); +result = arr.findLastIndex(function() { + return 1; +}); +assert.sameValue(result, 2, 'coerced number'); +result = arr.findLastIndex(function() { + return -1; +}); +assert.sameValue(result, 2, 'coerced negative number'); diff --git a/test/sendable/builtins/Array/prototype/findLastIndex/return-negative-one-if-predicate-returns-false-value.js b/test/sendable/builtins/Array/prototype/findLastIndex/return-negative-one-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..82adaee8dd47db678e93414d3bb46c92ff88c3fb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/findLastIndex/return-negative-one-if-predicate-returns-false-value.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.findlastindex +description: > + Return -1 if predicate always returns a boolean false value. +---*/ + +var arr = ['Shoes', 'Car', 'Bike']; +var called = 0; +var result = arr.findLastIndex(function() { + called++; + return false; +}); +assert.sameValue(called, 3, 'predicate was called three times'); +assert.sameValue(result, -1); +result = arr.findLastIndex(function() { + return ''; +}); +assert.sameValue(result, -1, 'coerced string'); +result = arr.findLastIndex(function() { + return undefined; +}); +assert.sameValue(result, -1, 'coerced undefined'); +result = arr.findLastIndex(function() { + return null; +}); +assert.sameValue(result, -1, 'coerced null'); +result = arr.findLastIndex(function() { + return 0; +}); +assert.sameValue(result, -1, 'coerced 0'); +result = arr.findLastIndex(function() { + return NaN; +}); +assert.sameValue(result, -1, 'coerced NaN'); diff --git a/test/sendable/builtins/Array/prototype/flat/array-like-objects.js b/test/sendable/builtins/Array/prototype/flat/array-like-objects.js new file mode 100644 index 0000000000000000000000000000000000000000..e9ddc643e62c9c78030e8f29fe6f2b78fc0c27e6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/array-like-objects.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + array-like objects can be flattened +includes: [compareArray.js] +features: [Array.prototype.flat] +---*/ + +function getArgumentsObject() { + return arguments; +} +var a = getArgumentsObject([1], [2]); +var actual = [].flat.call(a); +assert.compareArray(actual, [1, 2], 'The value of actual is expected to be [1, 2]'); +a = { + length: 1, + 0: [1], +}; +actual = [].flat.call(a); +assert.compareArray(actual, [1], 'The value of actual is expected to be [1]'); +a = { + length: undefined, + 0: [1], +}; +actual = [].flat.call(a); +assert.compareArray(actual, [], 'The value of actual is expected to be []'); diff --git a/test/sendable/builtins/Array/prototype/flat/bound-function-call.js b/test/sendable/builtins/Array/prototype/flat/bound-function-call.js new file mode 100644 index 0000000000000000000000000000000000000000..197eea675c11d529981ddeee8afc940968444a73 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/bound-function-call.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + using bound functions +includes: [compareArray.js] +features: [Array.prototype.flat] +---*/ + +var a = [ + [0], + [1] +]; +var actual = [].flat.bind(a)(); +assert.compareArray(actual, [0, 1], 'The value of actual is expected to be [0, 1]'); diff --git a/test/sendable/builtins/Array/prototype/flat/call-with-boolean.js b/test/sendable/builtins/Array/prototype/flat/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..d409cc4bcf1f281184df70453beebbd9460f5dca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/call-with-boolean.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.flat +description: Array.prototype.flat applied to boolean primitive +includes: [compareArray.js] +---*/ +assert.compareArray(SendableArray.prototype.flat.call(true), [], 'SendableArray.prototype.flat.call(true) must return []'); +assert.compareArray(SendableArray.prototype.flat.call(false), [], 'SendableArray.prototype.flat.call(false) must return []'); diff --git a/test/sendable/builtins/Array/prototype/flat/empty-array-elements.js b/test/sendable/builtins/Array/prototype/flat/empty-array-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..e6b7be57f3971030e7f1d5020fef26de8662b66a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/empty-array-elements.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + arrays with empty arrays elements +includes: [compareArray.js] +features: [Array.prototype.flat] +---*/ + +var a = {}; +assert.compareArray([].flat(), [], '[].flat() must return []'); +assert.compareArray([ + [], + [] +].flat(), [], '[ [], [] ].flat() must return []'); +assert.compareArray([ + [], + [1] +].flat(), [1], '[ [], [1] ].flat() must return [1]'); +assert.compareArray([ + [], + [1, a] +].flat(), [1, a], '[ [], [1, a] ].flat() must return [1, a]'); diff --git a/test/sendable/builtins/Array/prototype/flat/empty-object-elements.js b/test/sendable/builtins/Array/prototype/flat/empty-object-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..6b999e3981c2264b94b99304db6fbb28c3a8a07e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/empty-object-elements.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + arrays with empty object elements +includes: [compareArray.js] +features: [Array.prototype.flat] +---*/ + +var a = {}, + b = {}; +assert.compareArray([a].flat(), [a], '[a].flat() must return [a]'); +assert.compareArray([a, [b]].flat(), [a, b], '[a, [b]].flat() must return [a, b]'); +assert.compareArray([ + [a], b +].flat(), [a, b], '[ [a], b ].flat() must return [a, b]'); +assert.compareArray([ + [a], + [b] +].flat(), [a, b], '[ [a], [b] ].flat() must return [a, b]'); diff --git a/test/sendable/builtins/Array/prototype/flat/length.js b/test/sendable/builtins/Array/prototype/flat/length.js new file mode 100644 index 0000000000000000000000000000000000000000..8ad3aae5bbc1d48cf51c57abe52394b7567e5370 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/length.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: Array.prototype.flat.length value and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [Array.prototype.flat] +---*/ + +assert.sameValue( + SendableArray.prototype.flat.length, 0, + 'The value of `SendableArray.prototype.flat.length` is `0`' +); +verifyProperty(SendableArray.prototype.flat, 'length', { + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/flat/name.js b/test/sendable/builtins/Array/prototype/flat/name.js new file mode 100644 index 0000000000000000000000000000000000000000..784af39f54e26dce1aab8c453b9907926a56b1ee --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/name.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + Array.prototype.flat.name value and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [Array.prototype.flat] +---*/ + +assert.sameValue( + SendableArray.prototype.flat.name, 'flat', + 'The value of `SendableArray.prototype.flat.name` is `"flat"`' +); +verifyProperty(SendableArray.prototype.flat, 'name', { + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/flat/non-numeric-depth-should-not-throw.js b/test/sendable/builtins/Array/prototype/flat/non-numeric-depth-should-not-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..f8d54d787888d9a585185cf8db67426ee22a52d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/non-numeric-depth-should-not-throw.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + if the argument is a string or object, the depthNum is 0 +includes: [compareArray.js] +features: [Array.prototype.flat] +---*/ + +var a = [1, [2]]; +var expected = a; +// non integral string depthNum is converted to 0 +var depthNum = 'TestString'; +var actual = a.flat(depthNum); +assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected'); +// object type depthNum is converted to 0 +depthNum = {}; +actual = a.flat(depthNum); +assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected'); +// negative infinity depthNum is converted to 0 +depthNum = Number.NEGATIVE_INFINITY; +actual = a.flat(depthNum); +assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected'); +// positive zero depthNum is converted to 0 +depthNum = +0; +actual = a.flat(depthNum); +assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected'); +// negative zero depthNum is converted to 0 +depthNum = -0; +actual = a.flat(depthNum); +assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected'); +// integral string depthNum is converted to an integer +depthNum = '1'; +actual = a.flat(depthNum); +expected = [1, 2] +assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected'); diff --git a/test/sendable/builtins/Array/prototype/flat/non-object-ctor-throws.js b/test/sendable/builtins/Array/prototype/flat/non-object-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..e45103baf0f02eac36493939a2abf4ebed2daca8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/non-object-ctor-throws.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + Behavior when `constructor` property is neither an Object nor undefined + - if IsConstructor(C) is false, throw a TypeError exception. +features: [Array.prototype.flat] +---*/ + +assert.sameValue(typeof Array.prototype.flat, 'function'); +var a = []; +a.constructor = null; +assert.throws(TypeError, function() { + a.flat(); +}, 'null value'); +a = []; +a.constructor = 1; +assert.throws(TypeError, function() { + a.flat(); +}, 'number value'); +a = []; +a.constructor = 'string'; +assert.throws(TypeError, function() { + a.flat(); +}, 'string value'); +a = []; +a.constructor = true; +assert.throws(TypeError, function() { + a.flat(); +}, 'boolean value'); diff --git a/test/sendable/builtins/Array/prototype/flat/not-a-constructor.js b/test/sendable/builtins/Array/prototype/flat/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..7b74befd17bc1c2d9702c21e49272218142f2706 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.flat does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.prototype.flat), false, 'isConstructor(SendableArray.prototype.flat) must return false'); +assert.throws(TypeError, () => { + new SendableArray.prototype.flat(); +}); + diff --git a/test/sendable/builtins/Array/prototype/flat/null-undefined-elements.js b/test/sendable/builtins/Array/prototype/flat/null-undefined-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..cc0a4f59e3d89b1ff8bc7a198349c4899a1ce33f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/null-undefined-elements.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + arrays with null, and undefined +includes: [compareArray.js] +features: [Array.prototype.flat] +---*/ + +var a = [void 0]; +assert.compareArray( + [1, null, void 0].flat(), + [1, null, undefined], + '[1, null, void 0].flat() must return [1, null, undefined]' +); +assert.compareArray( + [1, [null, void 0]].flat(), + [1, null, undefined], + '[1, [null, void 0]].flat() must return [1, null, undefined]' +); +assert.compareArray([ + [null, void 0], + [null, void 0] +].flat(), [null, undefined, null, undefined], '[ [null, void 0], [null, void 0] ].flat() must return [null, undefined, null, undefined]'); +assert.compareArray([1, [null, a]].flat(1), [1, null, a], '[1, [null, a]].flat(1) must return [1, null, a]'); +assert.compareArray( + [1, [null, a]].flat(2), + [1, null, undefined], + '[1, [null, a]].flat(2) must return [1, null, undefined]' +); diff --git a/test/sendable/builtins/Array/prototype/flat/null-undefined-input-throws.js b/test/sendable/builtins/Array/prototype/flat/null-undefined-input-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..252811b1103397c197b0efa6caeb4ad3fe544d25 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/null-undefined-input-throws.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + null or undefined should throw TypeError Exception +features: [Array.prototype.flat] +---*/ + +assert.sameValue(typeof SendableArray.prototype.flat, 'function'); +assert.throws(TypeError, function() { + [].flat.call(null); +}, 'null value'); +assert.throws(TypeError, function() { + [].flat.call(); +}, 'missing'); +assert.throws(TypeError, function() { + [].flat.call(void 0); +}, 'undefined'); diff --git a/test/sendable/builtins/Array/prototype/flat/positive-infinity.js b/test/sendable/builtins/Array/prototype/flat/positive-infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..8ae46aeeaa98e2a52b0dbdd4ffbfe68604a1a378 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/positive-infinity.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + if the argument is a positive infinity, the depthNum is max depth of the array +includes: [compareArray.js] +features: [Array.prototype.flat] +---*/ + +var a = [1, [2, [3, [4]]]] +assert.compareArray(a.flat(Number.POSITIVE_INFINITY), [1, 2, 3, 4], 'a.flat(Number.POSITIVE_INFINITY) must return [1, 2, 3, 4]'); diff --git a/test/sendable/builtins/Array/prototype/flat/prop-desc.js b/test/sendable/builtins/Array/prototype/flat/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..da34914d27d0363f6fc0c859d53073125732c386 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/prop-desc.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: Property type and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [Array.prototype.flat] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.flat, + 'function', + '`typeof SendableArray.prototype.flat` is `function`' +); +verifyProperty(SendableArray.prototype, 'flat', { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/flat/proxy-access-count.js b/test/sendable/builtins/Array/prototype/flat/proxy-access-count.js new file mode 100644 index 0000000000000000000000000000000000000000..3bd684b8982597117819d3aa0dbb6bfe1e967af1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/proxy-access-count.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + properties are accessed correct number of times by .flat +info: | + Array.prototype.flat( [ depth ] ) + ... + 6. Perform ? FlattenIntoArray(A, O, sourceLen, 0, depthNum). + FlattenIntoArray (target, source, sourceLen, start, depth [ , mapperFunction, thisArg ]) + 3. Repeat, while sourceIndex < sourceLen + a. Let P be ! ToString(sourceIndex). + b. Let exists be ? HasProperty(source, P). + c. If exists is true, then + i. Let element be ? Get(source, P). +features: [Array.prototype.flat] +includes: [compareArray.js] +---*/ + +const getCalls = [], hasCalls = []; +const handler = { + get : function (t, p, r) { getCalls.push(p); return Reflect.get(t, p, r); }, + has : function (t, p, r) { hasCalls.push(p); return Reflect.has(t, p, r); } +} +const tier2 = new Proxy([4, 3], handler); +const tier1 = new Proxy([2, [3, [4, 2], 2], 5, tier2, 6], handler); +SendableArray.prototype.flat.call(tier1, 3); +assert.compareArray(getCalls, ["length", "constructor", "0", "1", "2", "3", "length", "0", "1", "4"], 'The value of getCalls is expected to be ["length", "constructor", "0", "1", "2", "3", "length", "0", "1", "4"]'); +assert.compareArray(hasCalls, ["0", "1", "2", "3", "0", "1", "4"], 'The value of hasCalls is expected to be ["0", "1", "2", "3", "0", "1", "4"]'); diff --git a/test/sendable/builtins/Array/prototype/flat/symbol-object-create-null-depth-throws.js b/test/sendable/builtins/Array/prototype/flat/symbol-object-create-null-depth-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..7cc30864a39a7744ac6fd9a8f4f5b2198c55d7f2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/symbol-object-create-null-depth-throws.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + if the argument is a Symbol or Object null, it throws exception +features: [Array.prototype.flat] +---*/ + +assert.sameValue(typeof SendableArray.prototype.flat, 'function'); +assert.throws(TypeError, function() { + [].flat(Symbol()); +}, 'symbol value'); +assert.throws(TypeError, function() { + [].flat(Object.create(null)); +}, 'object create null'); diff --git a/test/sendable/builtins/Array/prototype/flat/target-array-non-extensible.js b/test/sendable/builtins/Array/prototype/flat/target-array-non-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..f52627ab2bfce138dbc5d7cbaf5473fe6c493956 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/target-array-non-extensible.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.flat +description: > + TypeError is thrown if CreateDataProperty fails. + (result object is non-extensible, source array is not flattened) +---*/ + +var A = function(_length) { + this.length = 0; + Object.preventExtensions(this); +}; +var arr = [1]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.flat(1); +}); diff --git a/test/sendable/builtins/Array/prototype/flat/target-array-with-non-configurable-property.js b/test/sendable/builtins/Array/prototype/flat/target-array-with-non-configurable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..46459485fad38d7ca1804ab55713760dcbb845c9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/target-array-with-non-configurable-property.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.flat +description: > + TypeError is thrown if CreateDataProperty fails. + (result object's "0" is non-configurable, source array gets flattened) +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + set: function(_value) {}, + configurable: false, + }); +}; +var arr = [[1]]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.flat(1); +}); diff --git a/test/sendable/builtins/Array/prototype/flat/target-array-with-non-writable-property.js b/test/sendable/builtins/Array/prototype/flat/target-array-with-non-writable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..ffd82a634114716e4d05daf778d290e453104671 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flat/target-array-with-non-writable-property.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flat +description: > + Non-writable properties are overwritten by CreateDataProperty. + (result object's "0" is non-writable, source array gets flattened) +features: [Symbol.species] +includes: [propertyHelper.js] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + value: 1, + writable: false, + enumerable: false, + configurable: true, + }); +}; +var arr = [[2]]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +var res = arr.flat(1); +verifyProperty(res, "0", { + value: 2, + writable: true, + enumerable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/flatMap/array-like-objects-nested.js b/test/sendable/builtins/Array/prototype/flatMap/array-like-objects-nested.js new file mode 100644 index 0000000000000000000000000000000000000000..1273d4847b69556ab76ce5a3b6ba11015ad19b78 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/array-like-objects-nested.js @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + Does not flatten array-like objects nested into the main array +info: | + FlattenIntoArray(target, source, sourceLen, start, depth [ , mapperFunction, thisArg ]) +includes: [compareArray.js] +features: [Array.prototype.flatMap, Int32Array] +---*/ + +function fn(e) { + return e; +} +var obj1 = { + length: 1, + 0: 'a', + toString() { return 'obj1'; } +}; +var obj2 = new Int32Array(2); +var obj3 = { + get length() { throw "should not even consider the length property" }, + toString() { return 'obj3'; } +}; +var arr = [obj1, obj2, obj3]; +var actual = arr.flatMap(fn); +assert.compareArray(actual, arr, 'The value of actual is expected to equal the value of arr'); +assert.notSameValue(actual, arr, 'The value of actual is expected to not equal the value of `arr`'); +var arrLike = { + length: 4, + 0: obj1, + 1: obj2, + 2: obj3, + get 3() { return arrLike }, + toString() { return 'obj4'; } +}; +actual = [].flatMap.call(arrLike, fn); +assert.compareArray(actual, [obj1, obj2, obj3, arrLike], 'The value of actual is expected to be [obj1, obj2, obj3, arrLike]'); +assert.notSameValue(actual, arrLike, 'The value of actual is expected to not equal the value of `arrLike`'); +assert.sameValue( + Object.getPrototypeOf(actual), + SendableArray.prototype, + 'Object.getPrototypeOf([].flatMap.call(arrLike, fn)") returns SendableArray.prototype' +); diff --git a/test/sendable/builtins/Array/prototype/flatMap/array-like-objects-poisoned-length.js b/test/sendable/builtins/Array/prototype/flatMap/array-like-objects-poisoned-length.js new file mode 100644 index 0000000000000000000000000000000000000000..dbd3e0818b0f184747fea9b86a9172f42071b70d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/array-like-objects-poisoned-length.js @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + Observe abrupt completion in poisoned lengths of array-like objects +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) + 1. Let O be ? ToObject(this value). + 2. Let sourceLen be ? ToLength(? Get(O, "length")). +features: [Array.prototype.flatMap, Symbol.toPrimitive] +---*/ + +assert.sameValue(typeof SendableArray.prototype.flatMap, 'function'); +function fn(e) { + return e; +} +var arr = { + length: Symbol(), +}; +assert.throws(TypeError, function() { + [].flatMap.call(arr, fn); +}, 'length is a symbol'); +arr = { + get length() { throw new Test262Error() } +}; +assert.throws(Test262Error, function() { + [].flatMap.call(arr, fn); +}, 'custom get error'); +arr = { + length: { + valueOf() { throw new Test262Error() } + } +}; +assert.throws(Test262Error, function() { + [].flatMap.call(arr, fn); +}, 'custom valueOf error'); +arr = { + length: { + toString() { throw new Test262Error() } + } +}; +assert.throws(Test262Error, function() { + [].flatMap.call(arr, fn); +}, 'custom toString error'); +arr = { + length: { + [Symbol.toPrimitive]() { throw new Test262Error() } + } +}; +assert.throws(Test262Error, function() { + [].flatMap.call(arr, fn); +}, 'custom Symbol.toPrimitive error'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/array-like-objects-typedarrays.js b/test/sendable/builtins/Array/prototype/flatMap/array-like-objects-typedarrays.js new file mode 100644 index 0000000000000000000000000000000000000000..32f6e01ba1e3d4a0b794f71e1115f7294600bc9c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/array-like-objects-typedarrays.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + array-like objects can be flattened (typedArrays) +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +includes: [compareArray.js] +features: [Array.prototype.flatMap, Int32Array] +---*/ + +function same(e) { + return e; +} +var ta; +var actual; +ta = new Int32Array([1, 0, 42]); +Object.defineProperty(ta, 'constructor', { + get() { throw "it should not object the typedarray ctor"; } +}); +actual = [].flatMap.call(ta, same); +assert.compareArray(actual, [1, 0, 42], 'The value of actual is expected to be [1, 0, 42]'); +assert.sameValue(Object.getPrototypeOf(actual), SendableArray.prototype, 'Object.getPrototypeOf([].flatMap.call(ta, same)") returns SendableArray.prototype'); +assert.sameValue(actual instanceof Int32Array, false, 'The result of evaluating (actual instanceof Int32Array) is expected to be false'); +ta = new Int32Array(0); +Object.defineProperty(ta, 'constructor', { + get() { throw "it should not object the typedarray ctor"; } +}); +actual = [].flatMap.call(ta, same); +assert.compareArray(actual, [], 'The value of actual is expected to be []'); +assert.sameValue(Object.getPrototypeOf(actual), SendableArray.prototype, 'Object.getPrototypeOf([].flatMap.call(ta, same)") returns SendableArray.prototype'); +assert.sameValue(actual instanceof Int32Array, false, 'The result of evaluating (actual instanceof Int32Array) is expected to be false'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/array-like-objects.js b/test/sendable/builtins/Array/prototype/flatMap/array-like-objects.js new file mode 100644 index 0000000000000000000000000000000000000000..f6d75a47eaa52d43977ceabc1a8e7efa1804d466 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/array-like-objects.js @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + array-like objects can be flattened +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +includes: [compareArray.js] +features: [Array.prototype.flatMap] +---*/ + +function fn(e) { + return [39, e * 2]; // returns an array to observe it being flattened after +} +var a; +var actual; +a = { + length: 3, + 0: 1, + // property 1 will be fully skipped + 2: 21, + get 3() { throw 'it should not get this property'; } +}; +actual = [].flatMap.call(a, fn); +assert.compareArray(actual, [39, 2, 39, 42], 'The value of actual is expected to be [39, 2, 39, 42]'); +assert.sameValue(Object.getPrototypeOf(actual), SendableArray.prototype, 'Object.getPrototypeOf([].flatMap.call(a, fn)") returns SendableArray.prototype'); +a = { + length: undefined, + get 0() { throw 'it should not get this property'; }, +}; +actual = [].flatMap.call(a, fn); +assert.compareArray(actual, [], 'The value of actual is expected to be []'); +assert.sameValue(Object.getPrototypeOf(actual), SendableArray.prototype, 'Object.getPrototypeOf([].flatMap.call(a, fn)") returns SendableArray.prototype'); +var called = false; +a = { + get length() { + if (!called) { + called = true; + return 2; + } else { + throw 'is should get the length only once'; + } + }, + 0: 21, + 1: 19.5, + get 2() { throw 'it should not get this property'; }, +}; +actual = [].flatMap.call(a, fn); +assert.compareArray(actual, [39, 42, 39, 39], 'The value of actual is expected to be [39, 42, 39, 39]'); +assert.sameValue(Object.getPrototypeOf(actual), SendableArray.prototype, 'Object.getPrototypeOf([].flatMap.call(a, fn)") returns SendableArray.prototype'); +a = { + length: 10001, + [10000]: 7, +}; +actual = [].flatMap.call(a, fn); +assert.compareArray(actual, [39, 14], 'The value of actual is expected to be [39, 14]'); +assert.sameValue(Object.getPrototypeOf(actual), SendableArray.prototype, 'Object.getPrototypeOf([].flatMap.call(a, fn)") returns SendableArray.prototype'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/bound-function-argument.js b/test/sendable/builtins/Array/prototype/flatMap/bound-function-argument.js new file mode 100644 index 0000000000000000000000000000000000000000..371ac5778f6fd1cdf2f4e9c205c3f33c2ed4d279 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/bound-function-argument.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + Behavior when given a bound function +includes: [compareArray.js] +features: [Array.prototype.flatMap] +---*/ + +var a = [0, 0]; +assert.compareArray(a.flatMap(function() { + return this; +}.bind([1, 2])), [1, 2, 1, 2], 'a.flatMap(function() {return this;}.bind([1, 2])) must return [1, 2, 1, 2]'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/call-with-boolean.js b/test/sendable/builtins/Array/prototype/flatMap/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..b81636074b404bed23295f47e22be032a46699ae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/call-with-boolean.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: Array.prototype.flatMap applied to boolean primitive +includes: [compareArray.js] +---*/ + +assert.compareArray( + SendableArray.prototype.flatMap.call(true, () => {}), + [], + 'SendableArray.prototype.flatMap.call(true, () => {}) must return []' +); +assert.compareArray( + SendableArray.prototype.flatMap.call(false, () => {}), + [], + 'Array.prototype.flatMap.call(false, () => {}) must return []' +); diff --git a/test/sendable/builtins/Array/prototype/flatMap/depth-always-one.js b/test/sendable/builtins/Array/prototype/flatMap/depth-always-one.js new file mode 100644 index 0000000000000000000000000000000000000000..b88d0ba80a21b75c456597ace2a54f9584d2e27b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/depth-always-one.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + Behavior when array is depth more than 1 +includes: [compareArray.js] +features: [Array.prototype.flatMap] +---*/ + +assert.compareArray([1, 2].flatMap(function(e) { + return [e, e * 2]; +}), [1, 2, 2, 4], '[1, 2].flatMap(function(e) {return [e, e * 2];}) must return [1, 2, 2, 4]'); +var result = [1, 2, 3].flatMap(function(ele) { + return [ + [ele * 2] + ]; +}); +assert.sameValue(result.length, 3, 'The value of result.length is expected to be 3'); +assert.compareArray(result[0], [2], 'The value of result[0] is expected to be [2]'); +assert.compareArray(result[1], [4], 'The value of result[1] is expected to be [4]'); +assert.compareArray(result[2], [6], 'The value of result[2] is expected to be [6]'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/length.js b/test/sendable/builtins/Array/prototype/flatMap/length.js new file mode 100644 index 0000000000000000000000000000000000000000..84c3521c821d4909ce3aed9bee0775d71f4ba4c0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/length.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: Array.prototype.flatMap.length value and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [Array.prototype.flatMap] +---*/ + +assert.sameValue( + SendableArray.prototype.flatMap.length, 1, + 'The value of `SendableArray.prototype.flatmap.length` is `1`' +); +verifyProperty(SendableArray.prototype.flatMap, 'length', { + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/flatMap/name.js b/test/sendable/builtins/Array/prototype/flatMap/name.js new file mode 100644 index 0000000000000000000000000000000000000000..d97f65100986db6e880b1a27f9bf7eb3551ca6e6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/name.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatmap +description: Array.prototype.flatmap name value and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [Array.prototype.flatMap] +---*/ + +assert.sameValue( + SendableArray.prototype.flatMap.name, 'flatMap', + 'The value of `SendableArray.prototype.flatMap.name` is `"flatMap"`' +); +verifyProperty(SendableArray.prototype.flatMap, 'name', { + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/flatMap/non-callable-argument-throws.js b/test/sendable/builtins/Array/prototype/flatMap/non-callable-argument-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..2fe0ae5ced1b0c37540c8eb5e214b1a011036283 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/non-callable-argument-throws.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + non callable argument should throw TypeError Exception +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +---*/ + +assert.sameValue(typeof SendableArray.prototype.flatMap, "function"); +assert.throws(TypeError, function() { + [].flatMap({}); +}, 'non callable argument, object'); +assert.throws(TypeError, function() { + [].flatMap(0); +}, 'non callable argument, number'); +assert.throws(TypeError, function() { + [].flatMap(); +}, 'non callable argument, implict undefined'); +assert.throws(TypeError, function() { + [].flatMap(undefined); +}, 'non callable argument, undefined'); +assert.throws(TypeError, function() { + [].flatMap(null); +}, 'non callable argument, null'); +assert.throws(TypeError, function() { + [].flatMap(false); +}, 'non callable argument, boolean'); +assert.throws(TypeError, function() { + [].flatMap(''); +}, 'non callable argument, string'); +var s = Symbol(); +assert.throws(TypeError, function() { + [].flatMap(s); +}, 'non callable argument, symbol'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/not-a-constructor.js b/test/sendable/builtins/Array/prototype/flatMap/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..4ed2204f4a0d4d0df9a809a8f88c9b27adaf3142 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.flatMap does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects +includes: [isConstructor.js] +features: [Reflect.construct, Array.prototype.flatMap, arrow-function] + ---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.flatMap), + false, + 'isConstructor(SendableArray.prototype.flatMap) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.flatMap(() => {}); +}); + diff --git a/test/sendable/builtins/Array/prototype/flatMap/prop-desc.js b/test/sendable/builtins/Array/prototype/flatMap/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..72e65fd0bc840e51398842672926d99d8218eba4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/prop-desc.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.flatMap +description: Property type and descriptor. +info: > + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [Array.prototype.flatMap] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.flatMap, + 'function', + '`typeof SendableArray.prototype.flatMap` is `function`' +); +verifyProperty(SendableArray.prototype, 'flatMap', { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/flatMap/proxy-access-count.js b/test/sendable/builtins/Array/prototype/flatMap/proxy-access-count.js new file mode 100644 index 0000000000000000000000000000000000000000..01695a6afc5e4098c43502972c574e3bc72b3703 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/proxy-access-count.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + properties are accessed correct number of times by .flatMap +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) + 6. Perform ? FlattenIntoArray(A, O, sourceLen, 0, 1, mapperFunction, T). + FlattenIntoArray (target, source, sourceLen, start, depth [ , mapperFunction, thisArg ]) + 3. Repeat, while sourceIndex < sourceLen + a. Let P be ! ToString(sourceIndex). + b. Let exists be ? HasProperty(source, P). + c. If exists is true, then + i. Let element be ? Get(source, P). +features: [Array.prototype.flatMap] +includes: [compareArray.js] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.flatMap, + 'function', + 'The value of `typeof SendableArray.prototype.flatMap` is expected to be "function"' +); +const getCalls = [], hasCalls = []; +const handler = { + get : function (t, p, r) { getCalls.push(p); return Reflect.get(t, p, r); }, + has : function (t, p, r) { hasCalls.push(p); return Reflect.has(t, p, r); } +} +const tier2 = new Proxy([4, 3], handler); +const tier1 = new Proxy([2, [3, 4, 2, 2], 5, tier2, 6], handler); +SendableArray.prototype.flatMap.call(tier1, function(a){ return a; }); +assert.compareArray(getCalls, ["length", "constructor", "0", "1", "2", "3", "length", "0", "1", "4"], 'The value of getCalls is expected to be ["length", "constructor", "0", "1", "2", "3", "length", "0", "1", "4"]'); +assert.compareArray(hasCalls, ["0", "1", "2", "3", "0", "1", "4"], 'The value of hasCalls is expected to be ["0", "1", "2", "3", "0", "1", "4"]'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/target-array-non-extensible.js b/test/sendable/builtins/Array/prototype/flatMap/target-array-non-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..79c3911513ca88e895c3060c91e216dcaf97cd9d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/target-array-non-extensible.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatmap +description: > + TypeError is thrown if CreateDataProperty fails. + (result object is non-extensible, source array gets flattened) +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +features: [Symbol.species] + ---*/ + +var A = function(_length) { + this.length = 0; + Object.preventExtensions(this); +}; +var arr = [[1]]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.flatMap(function(item) { + return item; + }); +}); diff --git a/test/sendable/builtins/Array/prototype/flatMap/target-array-with-non-configurable-property.js b/test/sendable/builtins/Array/prototype/flatMap/target-array-with-non-configurable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..bc9d0ab028e93a463a5e53e797a89b6a53d3670b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/target-array-with-non-configurable-property.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatmap +description: > + TypeError is thrown if CreateDataProperty fails. + (result object's "0" is non-configurable, source array is not flattened) +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +features: [Symbol.species] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + writable: true, + configurable: false, + }); +}; +var arr = [1]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.flatMap(function(item) { + return item; + }); +}); diff --git a/test/sendable/builtins/Array/prototype/flatMap/target-array-with-non-writable-property.js b/test/sendable/builtins/Array/prototype/flatMap/target-array-with-non-writable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..392de43207f8876c8482fc461f2edc43dfcf5cd6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/target-array-with-non-writable-property.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.flatmap +description: > + Non-writable properties are overwritten by CreateDataProperty. + (result object's "0" is non-writable, source array is not flattened) +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +features: [Symbol.species] +includes: [propertyHelper.js] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + value: 1, + writable: false, + enumerable: false, + configurable: true, + }); +}; +var arr = [2]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +var res = arr.flatMap(function(item) { + return item; +}); +verifyProperty(res, "0", { + value: 2, + writable: true, + enumerable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-non-object.js b/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..2993c9b59f9334f814230ce962d711f81ff1160b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-non-object.js @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + Assert behavior if this value has a custom non-object constructor property +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +features: [Array.prototype.flatMap, Symbol] +includes: [compareArray.js] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.flatMap, + 'function', + 'The value of `typeof SendableArray.prototype.flatMap` is expected to be "function"' +); +var a = []; +var mapperFn = function() {}; +a.constructor = null; +assert.throws(TypeError, function() { + a.flatMap(mapperFn); +}, 'a.flatMap(mapperFn) throws a TypeError exception'); +a = []; +a.constructor = 1; +assert.throws(TypeError, function() { + a.flatMap(mapperFn); +}, 'a.flatMap(mapperFn) throws a TypeError exception'); +a = []; +a.constructor = 'string'; +assert.throws(TypeError, function() { + a.flatMap(mapperFn); +}, 'a.flatMap(mapperFn) throws a TypeError exception'); +a = []; +a.constructor = true; +assert.throws(TypeError, function() { + a.flatMap(mapperFn); +}, 'a.flatMap(mapperFn) throws a TypeError exception'); +a = []; +a.constructor = Symbol(); +assert.throws(TypeError, function() { + a.flatMap(mapperFn); +}, 'a.flatMap(mapperFn) throws a TypeError exception'); +a = []; +a.constructor = undefined; +var actual = a.flatMap(mapperFn); +assert.compareArray(actual, [], 'The value of actual is expected to be []'); +assert.sameValue( + Object.getPrototypeOf(actual), + SendableArray.prototype, + 'Object.getPrototypeOf(a.flatMap(mapperFn)) returns SendableArray.prototype' +); +assert.notSameValue(actual, a, 'The value of actual is expected to not equal the value of `a`'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species-bad-throws.js b/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species-bad-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..06f0117c70db2823d10082c7d99c075c92978936 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species-bad-throws.js @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + Assert behavior if this value has a custom object constructor property species +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +features: [Array.prototype.flatMap, Symbol, Symbol.species] +includes: [compareArray.js] + ---*/ + +assert.sameValue( + typeof SendableArray.prototype.flatMap, + 'function', + 'The value of `typeof Array.prototype.flatMap` is expected to be "function"' +); +var arr = [[42, 1], [42, 2]]; +var mapperFn = function(e) { return e; }; +arr.constructor = {}; +var actual = arr.flatMap(mapperFn); +assert.compareArray(actual, [42, 1, 42, 2], 'The value of actual is expected to be [42, 1, 42, 2]'); +assert.sameValue( + Object.getPrototypeOf(actual), + SendableArray.prototype, + 'Object.getPrototypeOf(arr.flatMap(mapperFn)) returns SendableArray.prototype' +); +var called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return 0; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return ''; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return false; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return {}; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return []; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return Symbol(); + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + throw new Test262Error + } +}; +assert.throws(Test262Error, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a Test262Error exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species-custom-ctor-poisoned-throws.js b/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species-custom-ctor-poisoned-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..63576dd4c8e1a051b991e153ff4314bddbaffe7e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species-custom-ctor-poisoned-throws.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + Assert behavior if this value has a poisoned custom species constructor +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +features: [Array.prototype.flatMap, Symbol, Symbol.species] +---*/ + +assert.sameValue(typeof SendableArray.prototype.flatMap, 'function'); +var arr = []; +var mapperFn = function(e) { return e; }; +var called = 0; +var ctorCalled = 0; +function ctor(len) { + assert.sameValue(new.target, ctor, 'new target is defined'); + assert.sameValue(len, 0, 'first argument is always 0'); + ctorCalled++; + throw new Test262Error(); +} +arr.constructor = { + get [Symbol.species]() { + called++; + return ctor; + } +}; +assert.throws(Test262Error, function() { + arr.flatMap(mapperFn); +}, 'Return abrupt completion from species custom ctor'); +assert.sameValue(called, 1, 'got species once'); +assert.sameValue(ctorCalled, 1, 'called custom ctor once'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species-custom-ctor.js b/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species-custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..cebda7d8d8ccceeb133490fb5f8ca7615eda1d6b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species-custom-ctor.js @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + Assert behavior if this value has a custom species constructor +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +features: [Array.prototype.flatMap, Symbol, Symbol.species] +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.flatMap, 'function'); +var arr = [[42, 1], [42, 2]]; +var mapperFn = function(e) { return e; }; +var called = 0; +var ctorCalled = 0; +function ctor(len) { + assert.sameValue(new.target, ctor, 'new target is defined'); + assert.sameValue(len, 0, 'first argument is always 0'); + ctorCalled++; +} +arr.constructor = { + get [Symbol.species]() { + called++; + return ctor; + } +}; +var actual = arr.flatMap(mapperFn); +assert(actual instanceof ctor, 'returned value is an instance of custom ctor'); +assert.sameValue(called, 1, 'got species once'); +assert.sameValue(ctorCalled, 1, 'called custom ctor once'); +assert.sameValue(Object.prototype.hasOwnProperty.call(actual, 'length'), false, 'it does not define an own length property'); +verifyProperty(actual, '0', { + configurable: true, + writable: true, + enumerable: true, + value: 42 +}); +verifyProperty(actual, '1', { + configurable: true, + writable: true, + enumerable: true, + value: 1 +}); +verifyProperty(actual, '2', { + configurable: true, + writable: true, + enumerable: true, + value: 42 +}); +verifyProperty(actual, '3', { + configurable: true, + writable: true, + enumerable: true, + value: 2 +}); diff --git a/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species.js b/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species.js new file mode 100644 index 0000000000000000000000000000000000000000..eb8790905452348153552693884b964cd33b08f5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/this-value-ctor-object-species.js @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.flatMap +description: > + Assert behavior if this value has a custom object constructor property +info: | + SendableArray.prototype.flatMap ( mapperFunction [ , thisArg ] ) +features: [Array.prototype.flatMap, Symbol, Symbol.species] +includes: [compareArray.js] + ---*/ + +assert.sameValue( + typeof SendableArray.prototype.flatMap, + 'function', + 'The value of `typeof SendableArray.prototype.flatMap` is expected to be "function"' +); +var arr = [[42, 1], [42, 2]]; +var mapperFn = function(e) { return e; }; +arr.constructor = {}; +var actual = arr.flatMap(mapperFn); +assert.compareArray(actual, [42, 1, 42, 2], 'The value of actual is expected to be [42, 1, 42, 2]'); +assert.sameValue( + Object.getPrototypeOf(actual), + SendableArray.prototype, + 'Object.getPrototypeOf(arr.flatMap(mapperFn)) returns SendableArray.prototype' +); +var called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return null; + } +}; +actual = arr.flatMap(mapperFn); +assert.compareArray(actual, [42, 1, 42, 2], 'The value of actual is expected to be [42, 1, 42, 2]'); +assert.sameValue( + Object.getPrototypeOf(actual), + SendableArray.prototype, + 'Object.getPrototypeOf(arr.flatMap(mapperFn)) returns SendableArray.prototype' +); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return undefined; + } +}; +actual = arr.flatMap(mapperFn); +assert.compareArray(actual, [42, 1, 42, 2], 'The value of actual is expected to be [42, 1, 42, 2]'); +assert.sameValue( + Object.getPrototypeOf(actual), + SendableArray.prototype, + 'Object.getPrototypeOf(arr.flatMap(mapperFn)) returns SendableArray.prototype' +); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return 0; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return ''; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return false; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return {}; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return []; + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); +called = 0; +arr.constructor = { + get [Symbol.species]() { + called++; + return Symbol(); + } +}; +assert.throws(TypeError, function() { + arr.flatMap(mapperFn); +}, 'arr.flatMap(mapperFn) throws a TypeError exception'); +assert.sameValue(called, 1, 'The value of called is expected to be 1'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/this-value-null-undefined-throws.js b/test/sendable/builtins/Array/prototype/flatMap/this-value-null-undefined-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..8967485fbaa1f043f0aeceb1464c6fd811630b3c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/this-value-null-undefined-throws.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + Throw a TypeError if this value is null or undefined +info: | + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) + 1. Let O be ? ToObject(this value). +features: [Array.prototype.flatMap] +---*/ + +assert.sameValue(typeof SendableArray.prototype.flatMap, 'function'); +var mapperFn = function() {}; +assert.throws(TypeError, function() { + [].flatMap.call(null, mapperFn); +}, 'null value'); +assert.throws(TypeError, function() { + [].flatMap.call(undefined, mapperFn); +}, 'undefined'); diff --git a/test/sendable/builtins/Array/prototype/flatMap/thisArg-argument.js b/test/sendable/builtins/Array/prototype/flatMap/thisArg-argument.js new file mode 100644 index 0000000000000000000000000000000000000000..8f39ad21bf835486a024e5cc41371b9e8c2c5acc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/flatMap/thisArg-argument.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.flatMap +description: > + Behavior when thisArg is provided + Array.prototype.flatMap ( mapperFunction [ , thisArg ] ) +flags: [onlyStrict] +includes: [compareArray.js] +features: [Array.prototype.flatMap] +---*/ + +var a = {}; +var actual; +actual = [1].flatMap(function() { + return [this]; +}, "TestString"); +assert.compareArray(actual, ["TestString"], 'The value of actual is expected to be ["TestString"]'); +actual = [1].flatMap(function() { + return [this]; +}, 1); +assert.compareArray(actual, [1], 'The value of actual is expected to be [1]'); +actual = [1].flatMap(function() { + return [this]; +}, null); +assert.compareArray(actual, [null], 'The value of actual is expected to be [null]'); +actual = [1].flatMap(function() { + return [this]; +}, true); +assert.compareArray(actual, [true], 'The value of actual is expected to be [true]'); +actual = [1].flatMap(function() { + return [this]; +}, a); +assert.compareArray(actual, [a], 'The value of actual is expected to be [a]'); +actual = [1].flatMap(function() { + return [this]; +}, void 0); +assert.compareArray(actual, [undefined], 'The value of actual is expected to be [undefined]'); + diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-1.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..b34efe06da9abad71013582f3921845a8dc1a3b8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to undefined +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.forEach.call(undefined); // TypeError is thrown if value is undefined +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-10.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..c0459ab7bf73040d8263acb0fc93a8d449f78ff6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-10.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to the Math object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = ('[object Math]' === Object.prototype.toString.call(obj)); +} +Math.length = 1; +Math[0] = 1; +SendableArray.prototype.forEach.call(Math, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-11.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..c0580d00de42df33b981fb9010df217e90916e1d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-11.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to Date object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = obj instanceof Date; +} +var obj = new Date(0); +obj.length = 1; +obj[0] = 1; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-12.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..7dc1d9c12bf13d15172acbd5d8cf71b8b72c9077 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-12.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to RegExp object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = obj instanceof RegExp; +} +var obj = new RegExp(); +obj.length = 1; +obj[0] = 1; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-13.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..be4d7b167faa6cba39030f6ce97b2475fe96a82b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-13.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to the JSON object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = ('[object JSON]' === Object.prototype.toString.call(obj)); +} +JSON.length = 1; +JSON[0] = 1; +SendableArray.prototype.forEach.call(JSON, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-14.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-14.js new file mode 100644 index 0000000000000000000000000000000000000000..add67548d6e9e3cf6e7c7e06be22199a1e23d9b1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-14.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to Error object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = obj instanceof Error; +} +var obj = new Error(); +obj.length = 1; +obj[0] = 1; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-15.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..33f01faf3160bfdfce5440c1f1fdf5c229816566 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-15.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to the Arguments object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = ('[object Arguments]' === Object.prototype.toString.call(obj)); +} +var obj = (function() { + return arguments; +}("a", "b")); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-2.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..4949006f434a05ea4765d4a9640d1805a2b294e7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to null +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.forEach.call(null); // TypeError is thrown if value is null +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-3.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..de9cdce2b3cc7bd5dcb11bec248aa01a9e2df073 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-3.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to boolean primitive +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = obj instanceof Boolean; +} +Boolean.prototype[0] = true; +Boolean.prototype.length = 1; +SendableArray.prototype.forEach.call(false, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-4.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..320f7e02d56caacf96c41c964b35f3334fe697b7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-4.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to Boolean object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = obj instanceof Boolean; +} +var obj = new Boolean(true); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-5.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..23ddd5876354e370c8199b771226ac34ef00a826 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-5.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to number primitive +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = obj instanceof Number; +} +Number.prototype[0] = 1; +Number.prototype.length = 1; +SendableArray.prototype.forEach.call(2.5, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-6.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..768ac950acb303251aa992c227e74524060f0524 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-6.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to Number object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = obj instanceof Number; +} +var obj = new Number(-128); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-7.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..a9ebcfa75b14c6684e856a58f9d2efda05e8a372 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-7.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to string primitive +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = obj instanceof String; +} +SendableArray.prototype.forEach.call("abc", callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-8.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..09e0e4528220c5ba9b1a98fa66006e31875e2fc4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-8.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to String object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = obj instanceof String; +} +var obj = new String("abc"); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-9.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..df7b28990e271127f38c77db4aadf01cca43c713 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-1-9.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach applied to Function object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = obj instanceof Function; +} +var obj = function(a, b) { + return a + b; +}; +obj[0] = 11; +obj[1] = 9; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-1.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..69adec3c82e1400867e91d994163d9a2fdf1d249 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - 'length' is own data property on an + Array-like object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: 2 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-10.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-10.js new file mode 100644 index 0000000000000000000000000000000000000000..ce6055d4c903ef428928bec132bad66e331ddb71 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-10.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to Array-like object, 'length' is + an inherited accessor property +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +SendableArray.prototype.forEach.call(child, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-11.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-11.js new file mode 100644 index 0000000000000000000000000000000000000000..205d4d1d64958fd6e09b6e9d6ff90903fd0b3850 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-11.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to Array-like object, 'length' is + an own accessor property without a get function +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-12.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-12.js new file mode 100644 index 0000000000000000000000000000000000000000..10400a1b779f51d78313b1cf04b49ee5cd63e86a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-12.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - 'length' is own accessor property + without a get function that overrides an inherited accessor + property on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +Object.defineProperty(Object.prototype, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var obj = { + 0: 12, + 1: 11 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-13.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-13.js new file mode 100644 index 0000000000000000000000000000000000000000..dcfc2f9479e908112dc8fe646614f2575a90d171 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-13.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to the Array-like object that + 'length' is inherited accessor property without a get function +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var proto = {}; +Object.defineProperty(proto, "length", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 11; +child[1] = 12; +SendableArray.prototype.forEach.call(child, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-14.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-14.js new file mode 100644 index 0000000000000000000000000000000000000000..2fafe4c74b2fad85b2b3f214bb301ed60ae26c22 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-14.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to the Array-like object that + 'length' property doesn't exist +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var obj = { + 0: 11, + 1: 12 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-17.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-17.js new file mode 100644 index 0000000000000000000000000000000000000000..7a72b8e552738bf0a74ab8ecf22a20149c4f068c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-17.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to the Arguments object, which + implements its own property get method +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +var func = function(a, b) { + arguments[2] = 9; + SendableArray.prototype.forEach.call(arguments, callbackfn); + return result; +}; +assert(func(12, 11), 'func(12, 11) !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-18.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-18.js new file mode 100644 index 0000000000000000000000000000000000000000..3d89269b0528a52899f04caef54bea9f3f949cbf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-18.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to String object, which implements + its own property get method +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 3); +} +var str = new String("012"); +SendableArray.prototype.forEach.call(str, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-19.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-19.js new file mode 100644 index 0000000000000000000000000000000000000000..d6a7742121ec2d138a369f06ed343362581ea8ec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-19.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to Function object, which + implements its own property get method +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +var fun = function(a, b) { + return a + b; +}; +fun[0] = 12; +fun[1] = 11; +fun[2] = 9; +SendableArray.prototype.forEach.call(fun, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-2.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..636da12f19b9f3e903a50b500220f535f9f8e47c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - 'length' is own data property on an Array +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +[12, 11].forEach(callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-3.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..0be91c242e7c5bac575572243610e62364e0e690 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-3.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - 'length' is an own data property that + overrides an inherited data property on an Array-like object +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +child[0] = 12; +child[1] = 11; +child[2] = 9; +SendableArray.prototype.forEach.call(child, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-4.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..5ba26230579e589c2823ac56caf7321c08f811f5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - 'length' is own data property that + overrides an inherited data property on an Array +---*/ + +var result = false; +var arrProtoLen; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +arrProtoLen = SendableArray.prototype.length; +SendableArray.prototype.length = 0; +[12, 11].forEach(callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-5.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..dd669fa9d85bb7e1cfcd173a3eea925995aeb2ca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-5.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to Array-like object, 'length' is + an own data property that overrides an inherited accessor property +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + value: 2, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +SendableArray.prototype.forEach.call(child, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-6.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-6.js new file mode 100644 index 0000000000000000000000000000000000000000..ce5430b10959fd2387bbb449f739e22d0b9a3de2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-6.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to Array-like object, 'length' is + an inherited data property +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +var proto = { + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +SendableArray.prototype.forEach.call(child, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-7.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-7.js new file mode 100644 index 0000000000000000000000000000000000000000..a86a5e6006d099a7ed2a4bfa321723ad8efe14b4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-7.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to Array-like object, 'length' is + an own accessor property +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return 2; + }, + configurable: true +}); +obj[0] = 12; +obj[1] = 11; +obj[2] = 9; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-8.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-8.js new file mode 100644 index 0000000000000000000000000000000000000000..5a8443f2a8bafca6e0cfd2baab9762c79b7aa461 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-8.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to Array-like object, 'length' is + an own accessor property that overrides an inherited data property +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +SendableArray.prototype.forEach.call(child, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-9.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-9.js new file mode 100644 index 0000000000000000000000000000000000000000..a4c80a8d2345202fbc147f700f4c1f1d275db5ea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-2-9.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach applied to Array-like object, 'length' is + an own accessor property that overrides an inherited accessor + property +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (obj.length === 2); +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +SendableArray.prototype.forEach.call(child, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-1.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-1.js new file mode 100644 index 0000000000000000000000000000000000000000..b992fc178e5e864b4e2006f83baec38ebcf72f66 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - value of 'length' is undefined +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var obj = { + 0: 0, + 1: 1, + length: undefined +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-10.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-10.js new file mode 100644 index 0000000000000000000000000000000000000000..a9cb044db60328fe3bbff4eb69b7864dc7f3ed38 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-10.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - value of 'length' is a number (value is + NaN) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + length: NaN +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-11.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-11.js new file mode 100644 index 0000000000000000000000000000000000000000..185f655de3823359a5c2c44e963bbdfc850bd6bc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-11.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-11 +description: > + Array.prototype.forEach - 'length' is a string containing a + positive number +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: "2" +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-12.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-12.js new file mode 100644 index 0000000000000000000000000000000000000000..d89cdaedb1eebe53c713137b346a3dd9c1682278 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-12.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-12 +description: > + Array.prototype.forEach - 'length' is a string containing a + negative number +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: "-4294967294" +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(testResult, false, 'testResult'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-13.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-13.js new file mode 100644 index 0000000000000000000000000000000000000000..958e97ab8772a9801354734c90ac61d8996adfb2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-13.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-13 +description: > + Array.prototype.forEach - 'length' is a string containing a + decimal number +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: "2.5" +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-14.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-14.js new file mode 100644 index 0000000000000000000000000000000000000000..513693fe9a7ffa3dc63e4cb52fc878e0999393b5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-14.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-14 +description: Array.prototype.forEach - 'length' is a string containing -Infinity +---*/ + +var accessed2 = false; +function callbackfn2(val, idx, obj) { + accessed2 = true; +} +var obj2 = { + 0: 9, + length: "-Infinity" +}; +SendableArray.prototype.forEach.call(obj2, callbackfn2); +assert.sameValue(accessed2, false, 'accessed2'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-15.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-15.js new file mode 100644 index 0000000000000000000000000000000000000000..4402991ed2fe1e1bbb5eae7aa1320207c6ad1f6b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-15.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-15 +description: > + Array.prototype.forEach - 'length' is a string containing an + exponential number +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: "2E0" +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-16.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-16.js new file mode 100644 index 0000000000000000000000000000000000000000..0ac5c9bcc1d7c718d091d7f1c862b18b85f50b9c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-16.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-16 +description: > + Array.prototype.forEach - 'length' is a string containing a hex + number +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: "0x0002" +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-17.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-17.js new file mode 100644 index 0000000000000000000000000000000000000000..c0f975d3681598bfeb4e1e04510fe141a14dbffc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-17.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-17 +description: > + Array.prototype.forEach - 'length' is a string containing a number + with leading zeros +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: "0002.00" +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-18.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-18.js new file mode 100644 index 0000000000000000000000000000000000000000..4ad7f5f0de7cce8b60c5930243e8289e9aebdb61 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-18.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-18 +description: > + Array.prototype.forEach - value of 'length' is a string that can't + convert to a number +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + length: "asdf!_" +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-19.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-19.js new file mode 100644 index 0000000000000000000000000000000000000000..340cf3d1292a111b72ec974f2443315ec2d58a1d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-19.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-19 +description: > + Array.prototype.forEach - value of 'length' is an Object which has + an own toString method. +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: { + toString: function() { + return '2'; + } + } +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-2.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-2.js new file mode 100644 index 0000000000000000000000000000000000000000..34875206a14b6a563c7d8d9dda1a088e75cc31cb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-2.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-2 +description: > + Array.prototype.forEach - value of 'length' is a boolean (value is + true) +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 0: 11, + 1: 9, + length: true +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-20.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-20.js new file mode 100644 index 0000000000000000000000000000000000000000..6cca2aae7f5ca9fd32a21be38778f7ca20b40e77 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-20.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-20 +description: > + Array.prototype.forEach - value of 'length' is an Object which has + an own valueOf method. +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: { + valueOf: function() { + return 2; + } + } +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-21.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-21.js new file mode 100644 index 0000000000000000000000000000000000000000..ac733d1336b0788c05d41c519abed763cd4c4fd9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-21.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-21 +description: > + Array.prototype.forEach - 'length' is an object that has an own + valueOf method that returns an object and toString method that + returns a string +---*/ + +var testResult = false; +var firstStepOccured = false; +var secondStepOccured = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: { + valueOf: function() { + firstStepOccured = true; + return {}; + }, + toString: function() { + secondStepOccured = true; + return '2'; + } + } +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); +assert(firstStepOccured, 'firstStepOccured !== true'); +assert(secondStepOccured, 'secondStepOccured !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-22.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-22.js new file mode 100644 index 0000000000000000000000000000000000000000..ceb9ea8504ac8fdf2e15e34644a3e594bbb0b982 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-22.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-22 +description: > + Array.prototype.forEach throws TypeError exception when 'length' + is an object with toString and valueOf methods that don�t return + primitive values +---*/ + +var accessed = false; +var firstStepOccured = false; +var secondStepOccured = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var obj = { + 1: 11, + 2: 12, + length: { + valueOf: function() { + firstStepOccured = true; + return {}; + }, + toString: function() { + secondStepOccured = true; + return {}; + } + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.forEach.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-23.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-23.js new file mode 100644 index 0000000000000000000000000000000000000000..33e5403d39fe4dae9785223e37a011ee55e8b51b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-23.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-23 +description: > + Array.prototype.forEach uses inherited valueOf method when + 'length' is an object with an own toString and inherited valueOf + methods +---*/ + +var testResult = false; +var valueOfAccessed = false; +var toStringAccessed = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var proto = { + valueOf: function() { + valueOfAccessed = true; + return 2; + } +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.toString = function() { + toStringAccessed = true; + return '1'; +}; +var obj = { + 1: 11, + 2: 9, + length: child +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(toStringAccessed, false, 'toStringAccessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-24.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-24.js new file mode 100644 index 0000000000000000000000000000000000000000..602343f5c338c62f1e55742c9f1f8482b5e25b89 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-24.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-24 +description: > + Array.prototype.forEach - value of 'length' is a positive + non-integer, ensure truncation occurs in the proper direction +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: 2.685 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-25.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-25.js new file mode 100644 index 0000000000000000000000000000000000000000..5e5be89694fb38065320e7a183244c92b8ccb622 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-25.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-25 +description: > + Array.prototype.forEach - value of 'length' is a negative + non-integer +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + testResult = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: -4294967294.5 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(testResult, false, 'testResult'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-3.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-3.js new file mode 100644 index 0000000000000000000000000000000000000000..2b2e09a891cdf883b67564f6d73cb82f23f5a3b0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-3.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-3 +description: > + Array.prototype.forEach - value of 'length' is a number (value is + 0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var obj = { + 0: 1, + 1: 1, + length: 0 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-4.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-4.js new file mode 100644 index 0000000000000000000000000000000000000000..9992b20d841c152a5cc594ee8bb4c0c0873d52ac --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-4.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-4 +description: > + Array.prototype.forEach - value of 'length' is a number (value is + +0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var obj = { + 0: 11, + length: +0 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-5.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-5.js new file mode 100644 index 0000000000000000000000000000000000000000..3b6f90a7c78934dbc41fe0fdcc85355cecc9f275 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-5.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-5 +description: > + Array.prototype.forEach - value of 'length' is a number (value is + -0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var obj = { + 0: 11, + length: -0 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-6.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-6.js new file mode 100644 index 0000000000000000000000000000000000000000..c47f3044fea3679206d56362a88ba0655ac92ee3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-6.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-6 +description: > + Array.prototype.forEach - value of 'length' is a number (value is + positive) +---*/ + +var testResult1 = false; +function callbackfn(val, idx, obj) { + testResult1 = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: 2 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult1, 'testResult1 !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-7.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-7.js new file mode 100644 index 0000000000000000000000000000000000000000..0e90fc178e6511869dfcb2deb6ebf3eaf614b01a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-7.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-7 +description: > + Array.prototype.forEach - value of 'length' is a number (value is + negative) +---*/ + +var testResult1 = false; +function callbackfn(val, idx, obj) { + testResult1 = (val > 10); +} +var obj = { + 1: 11, + 2: 9, + length: -4294967294 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(testResult1, false, 'testResult1'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-9.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-9.js new file mode 100644 index 0000000000000000000000000000000000000000..64faf1e8af1cfb9660d2939578e036257889ff24 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-3-9.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-3-9 +description: > + Array.prototype.forEach - value of 'length' is a number (value is + -Infinity) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + length: -Infinity +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-1.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..3ab26a7b0b4e79c0a4d8792e856b48caf99d266e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-1.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-4-1 +description: Array.prototype.forEach throws TypeError if callbackfn is undefined +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.forEach(); +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-10.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-10.js new file mode 100644 index 0000000000000000000000000000000000000000..56f1cc8c83641b7f5c50e53f97f3856ea8bc4f0b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-10.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-4-10 +description: > + Array.prototype.forEach - the exception is not thrown if exception + was thrown by step 2 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.forEach.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-11.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-11.js new file mode 100644 index 0000000000000000000000000000000000000000..ed4b9044eefe7e52c89ca1cae8ee4842328af5f4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-11.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-4-11 +description: > + Array.prototype.forEach - the exception is not thrown if exception + was thrown by step 3 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + throw new Test262Error(); + } + }; + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.forEach.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-12.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-12.js new file mode 100644 index 0000000000000000000000000000000000000000..3ab0db78f2150c94a56ed77b2634a36cd17645c0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-12.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-4-12 +description: Array.prototype.forEach - 'callbackfn' is a function +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +[11, 9].forEach(callbackfn); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-15.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-15.js new file mode 100644 index 0000000000000000000000000000000000000000..b43e506ccfb18a73cb09751da5a879eb048f0e48 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-15.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-4-15 +description: > + Array.prototype.forEach - calling with no callbackfn is the same + as passing undefined for callbackfn +---*/ + +var obj = { + 10: 10 +}; +var lengthAccessed = false; +var loopAccessed = false; +Object.defineProperty(obj, "length", { + get: function() { + lengthAccessed = true; + return 20; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + loopAccessed = true; + return 10; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.forEach.call(obj); +}); +assert(lengthAccessed, 'lengthAccessed !== true'); +assert.sameValue(loopAccessed, false, 'loopAccessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-2.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-2.js new file mode 100644 index 0000000000000000000000000000000000000000..7489eda2133e60e45631adf6c7c14a4cabfedf67 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-2.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-4-2 +description: > + Array.prototype.forEach throws ReferenceError if callbackfn is + unreferenced +---*/ + +var arr = new SendableArray(10); +assert.throws(ReferenceError, function() { + arr.forEach(foo); +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-3.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..999f39ab025f4f1b935457159a75751e17758410 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-3.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-4-3 +description: Array.prototype.forEach throws TypeError if callbackfn is null +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.forEach(null); +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-4.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..1893a7ec748144ab176f6caf938e617894872b0d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-4.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-4-4 +description: Array.prototype.forEach throws TypeError if callbackfn is boolean +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.forEach(true); +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-5.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-5.js new file mode 100644 index 0000000000000000000000000000000000000000..d2be9275131a01f1da4960f80a82c1ef6638fb4d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-5.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-4-5 +description: Array.prototype.forEach throws TypeError if callbackfn is number +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.forEach(5); +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-6.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-6.js new file mode 100644 index 0000000000000000000000000000000000000000..8e2ff944e06488fdca1cc27e19414f039100fd92 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-6.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +es5id: 15.4.4.18-4-6 +description: Array.prototype.forEach throws TypeError if callbackfn is string +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.forEach("abc"); +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-7.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-7.js new file mode 100644 index 0000000000000000000000000000000000000000..fc16de5132025840404b31bb5fb07ec7b4d7b2fc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-7.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach throws TypeError if callbackfn is Object + without Call internal method +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.forEach(new Object()); +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-8.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-8.js new file mode 100644 index 0000000000000000000000000000000000000000..98e39728a2f0f81dea7b8dd1e9470f194c917b92 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-8.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - side effects produced by step 2 are + visible when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + accessed = true; + return 2; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.forEach.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-9.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-9.js new file mode 100644 index 0000000000000000000000000000000000000000..a6330b23c2e1b33028a8c25d0ea788a2a2916eb5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-4-9.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - side effects produced by step 3 are + visible when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + accessed = true; + return "2"; + } + }; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.forEach.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-1-s.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-1-s.js new file mode 100644 index 0000000000000000000000000000000000000000..0565d09af921cc8a54c844d4d251d2a22e5dd686 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-1-s.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - thisArg not passed to strict callbackfn +flags: [noStrict] +---*/ + +var innerThisCorrect = false; +function callbackfn(val, idx, obj) { + "use strict"; + innerThisCorrect = this === undefined; + return true; +} +[1].forEach(callbackfn); +assert(innerThisCorrect, 'innerThisCorrect !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-1.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..ebbe18dde05666aaf0dbf52c3507a532e578fe7d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - thisArg is passed +flags: [noStrict] +---*/ + +(function() { + this._15_4_4_18_5_1 = false; + var _15_4_4_18_5_1 = true; + var result; + function callbackfn(val, idx, obj) { + result = this._15_4_4_18_5_1; + } + var arr = [1]; + arr.forEach(callbackfn) + assert.sameValue(result, false, 'result'); +})(); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-10.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-10.js new file mode 100644 index 0000000000000000000000000000000000000000..bd6aa431b2ec7437bd262c29a51a6111f6b108d3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-10.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - Array Object can be used as thisArg +---*/ + +var result = false; +var objArray = []; +function callbackfn(val, idx, obj) { + result = (this === objArray); +} +[11].forEach(callbackfn, objArray); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-11.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-11.js new file mode 100644 index 0000000000000000000000000000000000000000..282c715a5ad612b8c20bc2af3ea53463ceccc779 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-11.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - String Object can be used as thisArg +---*/ + +var result = false; +var objString = new String(); +function callbackfn(val, idx, obj) { + result = (this === objString); +} +[11].forEach(callbackfn, objString); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-12.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-12.js new file mode 100644 index 0000000000000000000000000000000000000000..1b8f9033f2dcad9dd3d81e331e634b689f77f56a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-12.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - Boolean Object can be used as thisArg +---*/ + +var result = false; +var objBoolean = new Boolean(); +function callbackfn(val, idx, obj) { + result = (this === objBoolean); +} +[11].forEach(callbackfn, objBoolean); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-13.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-13.js new file mode 100644 index 0000000000000000000000000000000000000000..c8f366b3e98ea14022893190835b391fd44a3631 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-13.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - Number Object can be used as thisArg +---*/ + +var result = false; +var objNumber = new Number(); +function callbackfn(val, idx, obj) { + result = (this === objNumber); +} +[11].forEach(callbackfn, objNumber); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-14.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-14.js new file mode 100644 index 0000000000000000000000000000000000000000..d5e6ce9d3209dbff069c4df96b4fc56a9881045d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-14.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - the Math object can be used as thisArg +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (this === Math); +} +[11].forEach(callbackfn, Math); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-15.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-15.js new file mode 100644 index 0000000000000000000000000000000000000000..fef77d77c3a411f8636a6d1bfc24cc46a2ae8cbd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-15.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - Date Object can be used as thisArg +---*/ + +var result = false; +var objDate = new Date(0); +function callbackfn(val, idx, obj) { + result = (this === objDate); +} +[11].forEach(callbackfn, objDate); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-16.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-16.js new file mode 100644 index 0000000000000000000000000000000000000000..742dd43aa8046d012a99f37929ef7ef5e4356f00 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-16.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - RegExp Object can be used as thisArg +---*/ + +var result = false; +var objRegExp = new RegExp(); +function callbackfn(val, idx, obj) { + result = (this === objRegExp); +} +[11].forEach(callbackfn, objRegExp); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-17.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-17.js new file mode 100644 index 0000000000000000000000000000000000000000..49ee63e287e8aca9142a529fdff6200b68ffdddc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-17.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - the JSON object can be used as thisArg +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (this === JSON); +} +[11].forEach(callbackfn, JSON); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-18.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-18.js new file mode 100644 index 0000000000000000000000000000000000000000..b2a84d57f3511183b09e8038b05dddef0fe1374d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-18.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - Error Object can be used as thisArg +---*/ + +var result = false; +var objError = new RangeError(); +function callbackfn(val, idx, obj) { + result = (this === objError); +} +[11].forEach(callbackfn, objError); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-19.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-19.js new file mode 100644 index 0000000000000000000000000000000000000000..0dd3c799f65f1ea51fd440d573b5339535dff566 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-19.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - the Arguments object can be used as + thisArg +---*/ + +var result = false; +var arg; +function callbackfn(val, idx, obj) { + result = (this === arg); +} +(function fun() { + arg = arguments; +}(1, 2, 3)); +[11].forEach(callbackfn, arg); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-2.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-2.js new file mode 100644 index 0000000000000000000000000000000000000000..4cd1f88f11453b2b1c1ba0d225cb06ded2572e63 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - thisArg is Object +---*/ + +var res = false; +var o = new Object(); +o.res = true; +var result; +function callbackfn(val, idx, obj) +{ + result = this.res; +} +var arr = [1]; +arr.forEach(callbackfn, o) +assert.sameValue(result, true, 'result'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-21.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-21.js new file mode 100644 index 0000000000000000000000000000000000000000..0544b409d6d0bd0c7273baf17343f3616e8fec99 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-21.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - the global object can be used as thisArg +---*/ + +var global = this; +var result = false; +function callbackfn(val, idx, obj) { + result = (this === global); +} +[11].forEach(callbackfn, this); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-22.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-22.js new file mode 100644 index 0000000000000000000000000000000000000000..a4d3881d3a2ac766f2d7128ec17a2545236cd839 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-22.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - boolean primitive can be used as thisArg +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (this.valueOf() === false); +} +[11].forEach(callbackfn, false); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-23.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-23.js new file mode 100644 index 0000000000000000000000000000000000000000..b40a4d53ca755811f71bb08a4a8dc97d182f29d2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-23.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - number primitive can be used as thisArg +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (this.valueOf() === 101); +} +[11].forEach(callbackfn, 101); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-24.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-24.js new file mode 100644 index 0000000000000000000000000000000000000000..a685879bd86eddb7dc02f1e17f52139c8c930ced --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-24.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - string primitive can be used as thisArg +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (this.valueOf() === "abc"); +} +[11].forEach(callbackfn, "abc"); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-25.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-25.js new file mode 100644 index 0000000000000000000000000000000000000000..7ecfc4365798a350aa47d612eb8b63489000f588 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-25.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - thisArg not passed +flags: [noStrict] +---*/ + +function innerObj() { + this._15_4_4_18_5_25 = true; + var _15_4_4_18_5_25 = false; + var result; + function callbackfn(val, idx, obj) { + result = this._15_4_4_18_5_25; + } + var arr = [1]; + arr.forEach(callbackfn) + this.retVal = !result; +} +assert(new innerObj().retVal, 'new innerObj().retVal !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-3.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-3.js new file mode 100644 index 0000000000000000000000000000000000000000..9dadd1ebc69442d974c1cdf244696b5ea0ef8dad --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-3.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - thisArg is Array +---*/ + +var res = false; +var a = new Array(); +a.res = true; +var result; +function callbackfn(val, idx, obj) +{ + result = this.res; +} +var arr = [1]; +arr.forEach(callbackfn, a) +assert.sameValue(result, true, 'result'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-4.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-4.js new file mode 100644 index 0000000000000000000000000000000000000000..34ba0c2e1f2284a2880a8019342f2146aaac3dfb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-4.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - thisArg is object from object + template(prototype) +---*/ + +var res = false; +var result; +function callbackfn(val, idx, obj) +{ + result = this.res; +} +function foo() {} +foo.prototype.res = true; +var f = new foo(); +var arr = [1]; +arr.forEach(callbackfn, f) +assert.sameValue(result, true, 'result'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-5.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-5.js new file mode 100644 index 0000000000000000000000000000000000000000..595490d2c8793bdb68a179c7dbe8373ed8f727bc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-5.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - thisArg is object from object template +---*/ + +var res = false; +var result; +function callbackfn(val, idx, obj) +{ + result = this.res; +} +function foo() {} +var f = new foo(); +f.res = true; +var arr = [1]; +arr.forEach(callbackfn, f) +assert.sameValue(result, true, 'result'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-6.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-6.js new file mode 100644 index 0000000000000000000000000000000000000000..48e023cb4d22d533e838d1c8055ca1a9328f597b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-6.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - thisArg is function +---*/ + +var res = false; +var result; +function callbackfn(val, idx, obj) +{ + result = this.res; +} +function foo() {} +foo.res = true; +var arr = [1]; +arr.forEach(callbackfn, foo) +assert.sameValue(result, true, 'result'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-7.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-7.js new file mode 100644 index 0000000000000000000000000000000000000000..4819d8d794f9af79a552674c458ba4004286da78 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-7.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - built-in functions can be used as thisArg +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (this === eval); +} +[11].forEach(callbackfn, eval); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-9.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-9.js new file mode 100644 index 0000000000000000000000000000000000000000..ccb8d843f7bdb90f5e1ec3f2975d42ded8d14309 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-5-9.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - Function Object can be used as thisArg +---*/ + +var result = false; +var objString = function() {}; +function callbackfn(val, idx, obj) { + result = (this === objString); +} +[11].forEach(callbackfn, objString); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-1.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-1.js new file mode 100644 index 0000000000000000000000000000000000000000..5e9a66a7deef6cfac5ace5004a4a7afdaa65cc4f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't consider new elements added to + array after the call +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; + arr[2] = 3; + arr[5] = 6; +} +var arr = [1, 2, , 4, 5]; +arr.forEach(callbackfn); +assert.sameValue(callCnt, 5, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-2.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-2.js new file mode 100644 index 0000000000000000000000000000000000000000..794492d1e08bc8590a6e41a3f8dc28645111ff8c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't visit deleted elements in array + after the call +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + if (callCnt == 0) + delete arr[3]; + callCnt++; +} +var arr = [1, 2, 3, 4, 5]; +arr.forEach(callbackfn) +assert.sameValue(callCnt, 4, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-3.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-3.js new file mode 100644 index 0000000000000000000000000000000000000000..67945b2d45c21303eebf73fe5c0a0101dc63d30e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-3.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't visit deleted elements when + Array.length is decreased +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + arr.length = 3; + callCnt++; +} +var arr = [1, 2, 3, 4, 5]; +arr.forEach(callbackfn); +assert.sameValue(callCnt, 3, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-4.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-4.js new file mode 100644 index 0000000000000000000000000000000000000000..1fe62c23deacad86776756f788e8b45673f4688f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-4.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't consider newly added elements in + sparse array +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + arr[1000] = 3; + callCnt++; +} +var arr = new SendableArray(10); +arr[1] = 1; +arr[2] = 2; +arr.forEach(callbackfn); +assert.sameValue(callCnt, 2, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-5.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-5.js new file mode 100644 index 0000000000000000000000000000000000000000..b31ef847bd0714dcef0546c44e48c95cf08e0927 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-5.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach visits deleted element in array after the + call when same index is also present in prototype +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + delete arr[4]; + callCnt++; +} +SendableArray.prototype[4] = 5; +var arr = [1, 2, 3, 4, 5]; +arr.forEach(callbackfn) +delete SendableArray.prototype[4]; +assert.sameValue(callCnt, 5, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-7.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-7.js new file mode 100644 index 0000000000000000000000000000000000000000..5a5a9cc060025e6680a4267722c065bf96d8b5ef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-7.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - considers new value of elements in array + after the call +---*/ + +var result = false; +var arr = [1, 2, 3, 4, 5]; +function callbackfn(val, Idx, obj) { + arr[4] = 6; + if (val >= 6) { + result = true; + } +} +arr.forEach(callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-8.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-8.js new file mode 100644 index 0000000000000000000000000000000000000000..b7f3544d2e138ea60cf0555d688de77cf5e1087e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-8.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - no observable effects occur if len is 0 +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var obj = { + 0: 11, + 1: 12, + length: 0 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-9.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-9.js new file mode 100644 index 0000000000000000000000000000000000000000..733cbcba42d9fb3466faee0e265112c05f99f7c9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-9.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - modifications to length don't change + number of iterations +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; +} +var obj = { + 1: 12, + 2: 9, + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + obj.length = 3; + return 11; + }, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-1.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..234d169dcf30a0c22f48920e73ad85c0484d65bd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - callbackfn not called for indexes never + been assigned values +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; +} +var arr = new SendableArray(10); +arr[1] = undefined; +arr.forEach(callbackfn); +assert.sameValue(callCnt, 1, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-10.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-10.js new file mode 100644 index 0000000000000000000000000000000000000000..d53986f777176351e71d584435ee8edc10873355 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-10.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - deleting property of prototype causes + prototype index property not to be visited on an Array-like Object +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(val, idx, obj) { + accessed = true; + if (idx === 3) { + testResult = false; + } +} +var obj = { + 2: 2, + length: 20 +}; +Object.defineProperty(obj, "0", { + get: function() { + delete Object.prototype[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-11.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-11.js new file mode 100644 index 0000000000000000000000000000000000000000..632910cf00615c5ade68e29fa9e294589d71db99 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-11.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - deleting property of prototype causes + prototype index property not to be visited on an Array +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(val, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var arr = [0, , ]; +Object.defineProperty(arr, "0", { + get: function() { + delete SendableArray.prototype[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-12.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-12.js new file mode 100644 index 0000000000000000000000000000000000000000..abb702009ec3aa5edcea76849788eee80337f75f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-12.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - deleting own property with prototype + property causes prototype index property to be visited on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + testResult = true; + } +} +var obj = { + 0: 0, + 1: 111, + length: 10 +}; +Object.defineProperty(obj, "0", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-13.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-13.js new file mode 100644 index 0000000000000000000000000000000000000000..5589e9331c74b5236f0b818b4c8703172f0edc38 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-13.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - deleting own property with prototype + property causes prototype index property to be visited on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + testResult = true; + } +} +var arr = [0, 111]; +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-14.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-14.js new file mode 100644 index 0000000000000000000000000000000000000000..6b0ab0bed218059304b0c6198afd2307e17cf259 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-14.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - decreasing length of array causes index + property not to be visited +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(val, idx, obj) { + accessed = true; + if (idx === 3) { + testResult = false; + } +} +var arr = [0, 1, 2, "last"]; +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 3; + return 0; + }, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-15.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-15.js new file mode 100644 index 0000000000000000000000000000000000000000..162cca6b5a81d035b7c4dd1c2fc3c52e6c337867 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-15.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - decreasing length of array with + prototype property causes prototype index property to be visited +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "prototype") { + testResult = true; + } +} +var arr = [0, 1, 2]; +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return "prototype"; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-16.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-16.js new file mode 100644 index 0000000000000000000000000000000000000000..87ed251541c4f9727dc6590f5f6e2541ca1b799b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-16.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - decreasing length of array does not + delete non-configurable properties +flags: [noStrict] +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "unconfigurable") { + testResult = true; + } +} +var arr = [0, 1, 2]; +Object.defineProperty(arr, "2", { + get: function() { + return "unconfigurable"; + }, + configurable: false +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-2.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-2.js new file mode 100644 index 0000000000000000000000000000000000000000..cb7e6023745fd467d9cb39ea171a439947e0d839 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-2.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - added properties in step 2 are visible + here +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "length") { + testResult = true; + } +} +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + obj[2] = "length"; + return 3; + }, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-3.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-3.js new file mode 100644 index 0000000000000000000000000000000000000000..76b88a3b901e1656345378560b03211d019d5f2e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-3.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - deleted properties in step 2 are visible + here +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(val, idx, obj) { + accessed = true; + if (idx === 8) { + testResult = false; + } +} +var obj = { + 2: 6.99, + 8: 19 +}; +Object.defineProperty(obj, "length", { + get: function() { + delete obj[8]; + return 10; + }, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-4.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-4.js new file mode 100644 index 0000000000000000000000000000000000000000..ea32370d6fe6361e337c233d5b4bbebe26c682e1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-4.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - properties added into own object after + current position are visited on an Array-like object +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + testResult = true; + } +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + Object.defineProperty(obj, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-5.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-5.js new file mode 100644 index 0000000000000000000000000000000000000000..a8a5a54d244694506412c1581f262fe0c9e406f2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-5.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - properties added into own object after + current position are visited on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + testResult = true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-6.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-6.js new file mode 100644 index 0000000000000000000000000000000000000000..98d4b212641c4c5699864772586fbe0780ba595c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-6.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - properties can be added to prototype + after current position are visited on an Array-like object +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 6.99) { + testResult = true; + } +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + Object.defineProperty(Object.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-7.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-7.js new file mode 100644 index 0000000000000000000000000000000000000000..391cbb02f077d33841335b4d7869d6c82c9bc144 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-7.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - properties can be added to prototype + after current position are visited on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 6.99) { + testResult = true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-8.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-8.js new file mode 100644 index 0000000000000000000000000000000000000000..634c13566f0e557b162b00ee1ed8c1a694dd6898 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-8.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - deleting own property causes index + property not to be visited on an Array-like object +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(val, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + get: function() { + return 6.99; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-9.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-9.js new file mode 100644 index 0000000000000000000000000000000000000000..2c895e973f5bd2324282d22db14d391f14a437bc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-b-9.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - deleting own property causes index + property not to be visited on an Array +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(val, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var arr = [1, 2]; +Object.defineProperty(arr, "1", { + get: function() { + return "6.99"; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-1.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-1.js new file mode 100644 index 0000000000000000000000000000000000000000..6cf8e21f1e03723167104a1791ac84eb274db6c6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-1.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own data + property on an Array-like object +---*/ + +var kValue = {}; +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 5) { + testResult = (val === kValue); + } +} +var obj = { + 5: kValue, + length: 100 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-10.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-10.js new file mode 100644 index 0000000000000000000000000000000000000000..da4c11eef196d163c52142650c800de7c7dfdd81 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-10.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own accessor + property on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 2) { + testResult = (val === 12); + } +} +var arr = []; +Object.defineProperty(arr, "2", { + get: function() { + return 12; + }, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-11.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-11.js new file mode 100644 index 0000000000000000000000000000000000000000..d9d872e42984bbb1f1cc7498d89fe57ccf87eaac --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-11.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own accessor + property that overrides an inherited data property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (val === 11); + } +} +var proto = { + 0: 5 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +Object.defineProperty(child, "0", { + get: function() { + return 11; + }, + configurable: true +}); +SendableArray.prototype.forEach.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-12.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-12.js new file mode 100644 index 0000000000000000000000000000000000000000..0b3793674a2938d0f879ea41f75fe2eaeb86714b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-12.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own accessor + property that overrides an inherited data property on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (val === 111); + } +} +var arr = []; +SendableArray.prototype[0] = 10; +Object.defineProperty(arr, "0", { + get: function() { + return 111; + }, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-13.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-13.js new file mode 100644 index 0000000000000000000000000000000000000000..fe63a7a872a2e9e265b0beb1edec726b5ae755fb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-13.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own accessor + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1) { + testResult = (val === 12); + } +} +var proto = {}; +Object.defineProperty(proto, "1", { + get: function() { + return 6; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +Object.defineProperty(child, "1", { + get: function() { + return 12; + }, + configurable: true +}); +SendableArray.prototype.forEach.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-14.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-14.js new file mode 100644 index 0000000000000000000000000000000000000000..62ed045c597560f2b4c61906644831fa67078305 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-14.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own accessor + property that overrides an inherited accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (val === 11); + } +} +var arr = []; +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 5; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + return 11; + }, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-15.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-15.js new file mode 100644 index 0000000000000000000000000000000000000000..86e6f092b68462b07b18ab4d29165099f3b1d797 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-15.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is inherited + accessor property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1) { + testResult = (val === 11); + } +} +var proto = {}; +Object.defineProperty(proto, "1", { + get: function() { + return 11; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 20; +SendableArray.prototype.forEach.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-16.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-16.js new file mode 100644 index 0000000000000000000000000000000000000000..646370dd1be9204d8058f5ce4ea2be453869c78e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-16.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is inherited + accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (val === 11); + } +} +Object.defineProperty(Array.prototype, "0", { + get: function() { + return 11; + }, + configurable: true +}); +[, , , ].forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-17.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-17.js new file mode 100644 index 0000000000000000000000000000000000000000..f530d6d6c58a964ecb79ade28794ebedae81a128 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-17.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own accessor + property without a get function on an Array-like object +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1) { + testResult = (typeof val === "undefined"); + } +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-18.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-18.js new file mode 100644 index 0000000000000000000000000000000000000000..826faf6f6ff2ea2dbc9a4f47ab690910079d596e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-18.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own accessor + property without a get function on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (typeof val === "undefined"); + } +} +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-19.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-19.js new file mode 100644 index 0000000000000000000000000000000000000000..32ad81ff663cac068eb89b765e3fb833c304694b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-19.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1) { + testResult = (typeof val === "undefined"); + } +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +Object.defineProperty(Object.prototype, "1", { + get: function() { + return 10; + }, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-2.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-2.js new file mode 100644 index 0000000000000000000000000000000000000000..730fe16135e5b25254f89ddadd6a71a9f5387061 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own data + property on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (val === 11); + } +} +[11].forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-20.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-20.js new file mode 100644 index 0000000000000000000000000000000000000000..39541f6a33022edfbb5528d28775f30a12450b3b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-20.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (typeof val === "undefined"); + } +} +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +Object.defineProperty(Array.prototype, "0", { + get: function() { + return 100; + }, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-21.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-21.js new file mode 100644 index 0000000000000000000000000000000000000000..6a8a8fa9565c28a2e9b17ab96c8d7f91d5e4a4ef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-21.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is inherited + accessor property without a get function on an Array-like object +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1) { + testResult = (typeof val === "undefined"); + } +} +var proto = {}; +Object.defineProperty(proto, "1", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +SendableArray.prototype.forEach.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-22.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-22.js new file mode 100644 index 0000000000000000000000000000000000000000..298c171e2e903e4eb5ebcad942e3e041dc544d93 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-22.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is inherited + accessor property without a get function on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (typeof val === "undefined"); + } +} +Object.defineProperty(SendableArray.prototype, "0", { + set: function() {}, + configurable: true +}); +[, 1].forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-25.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-25.js new file mode 100644 index 0000000000000000000000000000000000000000..596e6358d790f81b143bdd472e5d069afcc910d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-25.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - This object is the Arguments object + which implements its own property get method (number of arguments + is less than number of parameters) +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (val === 11); + } +} +var func = function(a, b) { + return SendableArray.prototype.forEach.call(arguments, callbackfn); +}; +func(11); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-26.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-26.js new file mode 100644 index 0000000000000000000000000000000000000000..bb03c24808724422fda14b2095374ce0e69abc6a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-26.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - This object is the Arguments object + which implements its own property get method (number of arguments + equals number of parameters) +---*/ + +var called = 0; +var testResult = false; +function callbackfn(val, idx, obj) { + called++; + if (called !== 1 && !testResult) { + return; + } + if (idx === 0) { + testResult = (val === 11); + } else if (idx === 1) { + testResult = (val === 9); + } else { + testResult = false; + } +} +var func = function(a, b) { + SendableArray.prototype.forEach.call(arguments, callbackfn); +}; +func(11, 9); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-27.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-27.js new file mode 100644 index 0000000000000000000000000000000000000000..c9b3ecb23908c80344d05dda0d7b50f58bc24bfc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-27.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - This object is the Arguments object + which implements its own property get method (number of arguments + is greater than number of parameters) +---*/ + +var called = 0; +var testResult = false; +function callbackfn(val, idx, obj) { + called++; + if (called !== 1 && !testResult) { + return; + } + if (idx === 0) { + testResult = (val === 11); + } else if (idx === 1) { + testResult = (val === 12); + } else if (idx === 2) { + testResult = (val === 9); + } else { + testResult = false; + } +} +var func = function(a, b) { + return SendableArray.prototype.forEach.call(arguments, callbackfn); +}; +func(11, 12, 9); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-28.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-28.js new file mode 100644 index 0000000000000000000000000000000000000000..7060197092da8dfaddfee649538c91468c928ca8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-28.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element changed by getter on previous + iterations is observed on an Array +---*/ + +var preIterVisible = false; +var arr = []; +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1) { + testResult = (val === 9); + } +} +Object.defineProperty(arr, "0", { + get: function() { + preIterVisible = true; + return 11; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + if (preIterVisible) { + return 9; + } else { + return 13; + } + }, + configurable: true +}); +arr.forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-29.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-29.js new file mode 100644 index 0000000000000000000000000000000000000000..59949796fea95c257caa0c2e6bd66253286d0d85 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-29.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element changed by getter on previous + iterations is observed on an Array-like object +---*/ + +var preIterVisible = false; +var obj = { + length: 2 +}; +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1) { + testResult = (val === 9); + } +} +Object.defineProperty(obj, "0", { + get: function() { + preIterVisible = true; + return 11; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + if (preIterVisible) { + return 9; + } else { + return 13; + } + }, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-3.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-3.js new file mode 100644 index 0000000000000000000000000000000000000000..592134b53f4a426277102edbff41071c6fe9feb0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-3.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +var kValue = "abc"; +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 5) { + testResult = (val === kValue); + } +} +var proto = { + 5: 100 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[5] = kValue; +child.length = 10; +SendableArray.prototype.forEach.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-30.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-30.js new file mode 100644 index 0000000000000000000000000000000000000000..8d8359406991379e0763056d8c56d1f5049c6403 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-30.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - unnhandled exceptions happened in getter + terminate iteration on an Array-like object +---*/ + +var obj = { + 0: 11, + 5: 10, + 10: 8, + length: 20 +}; +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 1) { + accessed = true; + } +} +Object.defineProperty(obj, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +Object.defineProperty(obj, "2", { + get: function() { + accessed = true; + return 100; + }, + configurable: true +}); +assert.throws(RangeError, function() { + SendableArray.prototype.forEach.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-31.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-31.js new file mode 100644 index 0000000000000000000000000000000000000000..5dfd0f9ceaf8a0006856e27c6b6660b347a3b221 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-31.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - unnhandled exceptions happened in getter + terminate iteration on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 1) { + accessed = true; + } +} +var arr = []; +arr[5] = 10; +arr[10] = 100; +Object.defineProperty(arr, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +Object.defineProperty(arr, "2", { + get: function() { + accessed = true; + return 100; + }, + configurable: true +}); +assert.throws(RangeError, function() { + arr.forEach(callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-4.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-4.js new file mode 100644 index 0000000000000000000000000000000000000000..6b714ade58abf6f6cec12f889a239b7be7366419 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (val === 12); + } +} +SendableArray.prototype[0] = 11; +[12].forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-5.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-5.js new file mode 100644 index 0000000000000000000000000000000000000000..916686b0d2a9c8c541bfaf3f5f683c139c65d32f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-5.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own data + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (val === 11); + } +} +var proto = {}; +Object.defineProperty(proto, "0", { + get: function() { + return 5; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +Object.defineProperty(child, "0", { + value: 11, + configurable: true +}); +SendableArray.prototype.forEach.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-6.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-6.js new file mode 100644 index 0000000000000000000000000000000000000000..135bb3a40556189c9cefa071dba3755861c0caed --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own data + property that overrides an inherited accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (val === 11); + } +} +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 9; + }, + configurable: true +}); +[11].forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-7.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-7.js new file mode 100644 index 0000000000000000000000000000000000000000..a9ca93003aa141369fe0eb0138bea3979d17cd17 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-7.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is inherited + data property on an Array-like object +---*/ + +var kValue = 'abc'; +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 5) { + testResult = (val === kValue); + } +} +var proto = { + 5: kValue +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +SendableArray.prototype.forEach.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-8.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-8.js new file mode 100644 index 0000000000000000000000000000000000000000..4220d78d14a3722327e6c5b62fae82cb3dc818f0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-8.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is inherited + data property on an Array +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 1) { + testResult = (val === 13); + } +} +SendableArray.prototype[1] = 13; +[, , , ].forEach(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-9.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-9.js new file mode 100644 index 0000000000000000000000000000000000000000..7fe4ad2505c248c224c8907b8cb72d38e31769b4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-i-9.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element to be retrieved is own accessor + property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + testResult = (val === 11); + } +} +var obj = { + 10: 10, + length: 20 +}; +Object.defineProperty(obj, "0", { + get: function() { + return 11; + }, + configurable: true +}); +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-1.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..f88307b0ac8c7ede4ca34d9faed768265e9dd4e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - callbackfn called with correct parameters +---*/ + +var bPar = true; +var bCalled = false; +function callbackfn(val, idx, obj) +{ + bCalled = true; + if (obj[idx] !== val) + bPar = false; +} +var arr = [0, 1, true, null, new Object(), "five"]; +arr[999999] = -6.6; +arr.forEach(callbackfn); +assert.sameValue(bCalled, true, 'bCalled'); +assert.sameValue(bPar, true, 'bPar'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-10.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..901417f65ae6f15aeeb3f284ad8d849104603246 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-10.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - callbackfn is called with 1 formal + parameter +---*/ + +var result = false; +function callbackfn(val) { + result = (val > 10); +} +[11].forEach(callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-11.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..048db0d32d59357263975b7b920483752a900158 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-11.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - callbackfn is called with 2 formal + parameter +---*/ + +var result = false; +function callbackfn(val, idx) { + result = (val > 10 && arguments[2][idx] === val); +} +[11].forEach(callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-12.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-12.js new file mode 100644 index 0000000000000000000000000000000000000000..50281fffdd4e192a7da065eb546f861b2c5df12f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-12.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - callbackfn is called with 3 formal + parameter +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (val > 10 && obj[idx] === val); +} +[11].forEach(callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-13.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-13.js new file mode 100644 index 0000000000000000000000000000000000000000..5c0fdddb879863fd0adc80ec790fa8f409f6069c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-13.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - callbackfn that uses arguments +---*/ + +var result = false; +function callbackfn() { + result = (arguments[2][arguments[1]] === arguments[0]); +} +[11].forEach(callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-16.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-16.js new file mode 100644 index 0000000000000000000000000000000000000000..0c37e483c4715cd1c38dd40a7ad593978f14f29c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-16.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - 'this' of 'callbackfn' is a Boolean + object when T is not an object (T is a boolean) +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (this.valueOf() !== false); +} +var obj = { + 0: 11, + length: 2 +}; +SendableArray.prototype.forEach.call(obj, callbackfn, false); +assert.sameValue(result, false, 'result'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-17.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-17.js new file mode 100644 index 0000000000000000000000000000000000000000..b5191d0ca9b204d252e64329f486b15e96b9a564 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-17.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - 'this' of 'callbackfn' is a Number + object when T is not an object (T is a number) +---*/ + +var result = false; +function callbackfn(val, idx, o) { + result = (5 === this.valueOf()); +} +var obj = { + 0: 11, + length: 2 +}; +SendableArray.prototype.forEach.call(obj, callbackfn, 5); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-18.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-18.js new file mode 100644 index 0000000000000000000000000000000000000000..b553b06efd383c1c50d23c6c2ad52cf317e9cc9a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-18.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - 'this' of 'callbackfn' is an String + object when T is not an object (T is a string) +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = ('hello' === this.valueOf()); +} +var obj = { + 0: 11, + length: 2 +}; +SendableArray.prototype.forEach.call(obj, callbackfn, "hello"); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-19.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-19.js new file mode 100644 index 0000000000000000000000000000000000000000..eadcecdf1871a4925d8ccd11a55a669ca6833117 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-19.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - non-indexed properties are not called +---*/ + +var accessed = false; +var result = true; +function callbackfn(val, idx, obj) { + accessed = true; + if (val === 8) { + result = false; + } +} +var obj = { + 0: 11, + 10: 12, + non_index_property: 8, + length: 20 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-2.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..c6ca643b6f90d71f63186ff6ab1e81496a077d87 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - callbackfn takes 3 arguments +---*/ + +var parCnt = 3; +var bCalled = false +function callbackfn(val, idx, obj) +{ + bCalled = true; + if (arguments.length !== 3) + parCnt = arguments.length; //verify if callbackfn was called with 3 parameters +} +var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +arr.forEach(callbackfn); +assert.sameValue(bCalled, true, 'bCalled'); +assert.sameValue(parCnt, 3, 'parCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-20.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-20.js new file mode 100644 index 0000000000000000000000000000000000000000..5b251517ed79f75c5dac1f79572de0e23c07a5c2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-20.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - callbackfn called with correct + parameters (thisArg is correct) +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + result = (10 === this.threshold); +} +var thisArg = { + threshold: 10 +}; +var obj = { + 0: 11, + length: 1 +}; +SendableArray.prototype.forEach.call(obj, callbackfn, thisArg); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-21.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-21.js new file mode 100644 index 0000000000000000000000000000000000000000..e35c14e6e77da089a467f56d99d3edb77c0e94f5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-21.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - callbackfn called with correct + parameters (kValue is correct) +---*/ + +var resultOne = false; +var resultTwo = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + resultOne = (val === 11); + } + if (idx === 1) { + resultTwo = (val === 12); + } +} +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(resultOne, 'resultOne !== true'); +assert(resultTwo, 'resultTwo !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-22.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-22.js new file mode 100644 index 0000000000000000000000000000000000000000..50c0e65437df4bd35b112a50eca88887d778cb75 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-22.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - callbackfn called with correct + parameters (the index k is correct) +---*/ + +var resultOne = false; +var resultTwo = false; +function callbackfn(val, idx, obj) { + if (val === 11) { + resultOne = (idx === 0); + } + if (val === 12) { + resultTwo = (idx === 1); + } +} +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(resultOne, 'resultOne !== true'); +assert(resultTwo, 'resultTwo !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-23.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-23.js new file mode 100644 index 0000000000000000000000000000000000000000..24a5f885d74556979578699698728be4935c1457 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-23.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - callbackfn called with correct + parameters (this object O is correct) +---*/ + +var result = false; +var obj = { + 0: 11, + length: 2 +}; +function callbackfn(val, idx, o) { + result = (obj === o); +} +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-4.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..06707c8a476b5e24321df29817db0b8ae6929914 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-4.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - k values are passed in ascending numeric + order +---*/ + +var arr = [0, 1, 2, 3, 4, 5]; +var lastIdx = 0; +var called = 0; +var result = true; +function callbackfn(val, idx, o) { + called++; + if (lastIdx !== idx) { + result = false; + } else { + lastIdx++; + } +} +arr.forEach(callbackfn); +assert(result, 'result !== true'); +assert.sameValue(arr.length, called, 'arr.length'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-5.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..79d6f552c4675e8d79cdb6734dc2f54a16da86cd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-5.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - k values are accessed during each + iteration and not prior to starting the loop on an Array +---*/ + +var result = true; +var kIndex = []; +//By below way, we could verify that k would be setted as 0, 1, ..., length - 1 in order, and each value will be setted one time. +function callbackfn(val, idx, obj) { + //Each position should be visited one time, which means k is accessed one time during iterations. + if (typeof kIndex[idx] === "undefined") { + //when current position is visited, its previous index should has been visited. + if (idx !== 0 && typeof kIndex[idx - 1] === "undefined") { + result = false; + } + kIndex[idx] = 1; + } else { + result = false; + } +} +[11, 12, 13, 14].forEach(callbackfn, undefined); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-6.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-6.js new file mode 100644 index 0000000000000000000000000000000000000000..f18641e42695f3fb4d4b64999e17587199715a97 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - arguments to callbackfn are self + consistent +---*/ + +var result = false; +var obj = { + 0: 11, + length: 1 +}; +var thisArg = {}; +function callbackfn() { + result = (this === thisArg && + arguments[0] === 11 && + arguments[1] === 0 && + arguments[2] === obj); +} +SendableArray.prototype.forEach.call(obj, callbackfn, thisArg); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-7.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..f534ba99195e4660b52fbf1adfa6af2aeccc66da --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-7.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - unhandled exceptions happened in + callbackfn terminate iteration +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 0) { + accessed = true; + } + if (idx === 0) { + throw new Error("Exception occurred in callbackfn"); + } +} +var obj = { + 0: 11, + 4: 10, + 10: 8, + length: 20 +}; +assert.throws(Error, function() { + SendableArray.prototype.forEach.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-8.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..410b953665d99b1f89c81ba80a4db5c34714d97f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-8.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - element changed by callbackfn on + previous iterations is observed +---*/ + +var result = false; +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +function callbackfn(val, idx, o) { + if (idx === 0) { + obj[idx + 1] = 8; + } + if (idx === 1) { + result = (val === 8); + } +} +SendableArray.prototype.forEach.call(obj, callbackfn); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-9.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..f6af803c6e11b49f9f1a367f67d8155327882df5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-7-c-ii-9.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - callbackfn is called with 0 formal + parameter +---*/ + +var called = 0; +function callbackfn() { + called++; +} +[11, 12].forEach(callbackfn); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-1.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-1.js new file mode 100644 index 0000000000000000000000000000000000000000..5af5cc1b966cccb22ec39e83123b4238086db90f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-1.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't call callbackfn if 'length' is 0 + (empty array) +---*/ + +var callCnt = 0; +function cb() { + callCnt++ +} +var i = [].forEach(cb); +assert.sameValue(callCnt, 0, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-10.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-10.js new file mode 100644 index 0000000000000000000000000000000000000000..ba2c5395ee14b8b82b2bcd18a0393c095b649af5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-10.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach - subclassed array when length is reduced +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 1; +var callCnt = 0; +function cb() { + callCnt++ +} +var i = f.forEach(cb); +assert.sameValue(callCnt, 1, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-11.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-11.js new file mode 100644 index 0000000000000000000000000000000000000000..3bc671353f1a978d056773f973395a00998c92db --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-11.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't mutate the array on which it is + called on +---*/ + +function callbackfn(val, idx, obj) +{ + return true; +} +var arr = [1, 2, 3, 4, 5]; +arr.forEach(callbackfn); +assert.sameValue(arr[0], 1, 'arr[0]'); +assert.sameValue(arr[1], 2, 'arr[1]'); +assert.sameValue(arr[2], 3, 'arr[2]'); +assert.sameValue(arr[3], 4, 'arr[3]'); +assert.sameValue(arr[4], 5, 'arr[4]'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-12.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-12.js new file mode 100644 index 0000000000000000000000000000000000000000..22df27f91b35198e338ccf1ca883fd920d4f02e2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-12.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: Array.prototype.forEach doesn't visit expandos +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; +} +var arr = [1, 2, 3, 4, 5]; +arr["i"] = 10; +arr[true] = 11; +arr.forEach(callbackfn); +assert.sameValue(callCnt, 5, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-13.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-13.js new file mode 100644 index 0000000000000000000000000000000000000000..6f85b1e7ef6f40993247c3833ff1f4f05e04f8d3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-13.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach - undefined will be returned when 'len' is + 0 +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; +} +var result = [].forEach(callbackfn); +assert.sameValue(typeof result, "undefined", 'typeof result'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-2.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-2.js new file mode 100644 index 0000000000000000000000000000000000000000..c5bfd7dae014ff07bc968f3770aa397336b5d14a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't call callbackfn if 'length' is 0 + (subclassed Array, length overridden to null (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = null; +var callCnt = 0; +function cb() { + callCnt++ +} +var i = f.forEach(cb); +assert.sameValue(callCnt, 0, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-3.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-3.js new file mode 100644 index 0000000000000000000000000000000000000000..69b2565d140d95b7efe3c97daea4f8ed99d0c85a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't call callbackfn if 'length' is 0 + (subclassed Array, length overridden to false (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = false; +var callCnt = 0; +function cb() { + callCnt++ +} +var i = f.forEach(cb); +assert.sameValue(callCnt, 0, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-4.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-4.js new file mode 100644 index 0000000000000000000000000000000000000000..ddf8288092d7d7364d7d77e9b099823e410b5700 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-4.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't call callbackfn if 'length' is 0 + (subclassed Array, length overridden to 0 (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 0; +var callCnt = 0; +function cb() { + callCnt++ +} +var i = f.forEach(cb); +assert.sameValue(callCnt, 0, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-5.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-5.js new file mode 100644 index 0000000000000000000000000000000000000000..7d4b3a5834a607510f90604679e16b233586772e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-5.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't call callbackfn if 'length' is 0 + (subclassed Array, length overridden to '0' (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = '0'; +var callCnt = 0; +function cb() { + callCnt++ +} +var i = f.forEach(cb); +assert.sameValue(callCnt, 0, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-6.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-6.js new file mode 100644 index 0000000000000000000000000000000000000000..6163600a43c8c68fdaba2edb3efcb04f54b1d399 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-6.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't call callbackfn if 'length' is 0 + (subclassed Array, length overridden with obj with valueOf) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + valueOf: function() { + return 0; + } +}; +f.length = o; +var callCnt = 0; +function cb() { + callCnt++ +} +var i = f.forEach(cb); +assert.sameValue(callCnt, 0, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-7.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-7.js new file mode 100644 index 0000000000000000000000000000000000000000..1a157861f2ed36cc5106d2ad92c7cb04e6be5c24 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-7.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't call callbackfn if 'length' is 0 + (subclassed Array, length overridden with obj w/o valueOf + (toString)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + toString: function() { + return '0'; + } +}; +f.length = o; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +var callCnt = 0; +function cb() { + callCnt++ +} +var i = f.forEach(cb); +assert.sameValue(callCnt, 0, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-8.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-8.js new file mode 100644 index 0000000000000000000000000000000000000000..57b6112c345abad0da1c08240832c27e89ba7cf2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-8.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't call callbackfn if 'length' is 0 + (subclassed Array, length overridden with [] +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = []; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +var callCnt = 0; +function cb() { + callCnt++ +} +var i = f.forEach(cb); +assert.sameValue(callCnt, 0, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-9.js b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-9.js new file mode 100644 index 0000000000000000000000000000000000000000..dc97a58a2665e7fbac8e00bbc746d633809abf47 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/15.4.4.18-8-9.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach doesn't call callbackfn if 'length' is 0 + (subclassed Array, length overridden with [0] +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = [0]; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +var callCnt = 0; +function cb() { + callCnt++ +} +var i = f.forEach(cb); +assert.sameValue(callCnt, 0, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/forEach/S15.4.4.18_A1.js b/test/sendable/builtins/Array/prototype/forEach/S15.4.4.18_A1.js new file mode 100644 index 0000000000000000000000000000000000000000..680c7252ba68387b74ac0d343d2b3b51a514bbd0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/S15.4.4.18_A1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: array.forEach can be frozen while in progress +esid: sec-array.prototype.foreach +description: Freezes array.forEach during a forEach to see if it works +---*/ + +['z'].forEach(function() { + Object.freeze(SendableArray.prototype.forEach); +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/S15.4.4.18_A2.js b/test/sendable/builtins/Array/prototype/forEach/S15.4.4.18_A2.js new file mode 100644 index 0000000000000000000000000000000000000000..b60456618a19d09332874dca5c151f8ddcd5c128 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/S15.4.4.18_A2.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: array.forEach can be frozen while in progress +esid: sec-array.prototype.foreach +description: Freezes array.forEach during a forEach to see if it works +---*/ + +function foo() { + ['z'].forEach(function() { + Object.freeze(SendableArray.prototype.forEach); + }); +} +foo(); diff --git a/test/sendable/builtins/Array/prototype/forEach/call-with-boolean.js b/test/sendable/builtins/Array/prototype/forEach/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..19c6c55b9e664c894d5aacd20b13cfa225437ef9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.forEach +description: Array.prototype.forEach applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.forEach.call(true, () => {}), + undefined, + 'SendableArray.prototype.forEach.call(true, () => {}) must return undefined' +); +assert.sameValue( + SendableArray.prototype.forEach.call(false, () => {}), + undefined, + 'SendableArray.prototype.forEach.call(false, () => {}) must return undefined' +); diff --git a/test/sendable/builtins/Array/prototype/forEach/callbackfn-resize-arraybuffer.js b/test/sendable/builtins/Array/prototype/forEach/callbackfn-resize-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..15137d31f4d8e778a02a8b9e983f812535f99f56 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/callbackfn-resize-arraybuffer.js @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.forEach +description: TypedArray instance buffer can be resized during iteration +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.forEach.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + elements.push(element); + indices.push(index); + arrays.push(array); + }); + assert.compareArray(elements, expectedElements, 'elements (shrink)'); + assert.compareArray(indices, expectedIndices, 'indices (shrink)'); + assert.compareArray(arrays, expectedArrays, 'arrays (shrink)'); + assert.sameValue(result, undefined, 'result (shrink)'); + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.forEach.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + + elements.push(element); + indices.push(index); + arrays.push(array); + }); + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, undefined, 'result (grow)'); +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/length.js b/test/sendable/builtins/Array/prototype/forEach/length.js new file mode 100644 index 0000000000000000000000000000000000000000..bbf8a1bfebe4bdfacfd92f29a72c1e719b3b1896 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/length.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.forEach +description: > + The "length" property of Array.prototype.forEach +info: | + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.forEach, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/name.js b/test/sendable/builtins/Array/prototype/forEach/name.js new file mode 100644 index 0000000000000000000000000000000000000000..48d789291ac2cae8a76d5d4e68f5981f4288ecff --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/name.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.prototype.forEach.name is "forEach". +info: | + Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.forEach, "name", { + value: "forEach", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/not-a-constructor.js b/test/sendable/builtins/Array/prototype/forEach/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..f58b2524f702b1d9e2e1dc7f0e2e48d60c7e831e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/not-a-constructor.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.forEach does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.forEach), + false, + 'isConstructor(SendableArray.prototype.forEach) must return false' +); + +assert.throws(TypeError, () => { + new SendableArray.prototype.forEach(() => {}); +}); + diff --git a/test/sendable/builtins/Array/prototype/forEach/prop-desc.js b/test/sendable/builtins/Array/prototype/forEach/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..85a775290526a108c10610effcf94e941e7ae728 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/prop-desc.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.forEach +description: > + "forEach" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.forEach, 'function', 'typeof'); + +verifyProperty(SendableArray.prototype, "forEach", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/forEach/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/forEach/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..4de88c052962caed0b1cdb49495cd1189f14449a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.p.forEach behaves correctly when receiver is backed by resizable + buffer that is grown mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +// Test for forEach. +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.forEach.call(fixedLength, ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.forEach.call(fixedLengthWithOffset, ResizeMidIteration); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.forEach.call(lengthTracking, ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.forEach.call(lengthTrackingWithOffset, ResizeMidIteration); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/forEach/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/forEach/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..bd7f4fbe0dbab0101581e7d805b4777b4a3491be --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-%array%.prototype.foreach +description: > + Array.p.forEach behaves correctly on TypedArrays backed by resizable buffers + that are shrunk mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.forEach.call(fixedLength, ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.forEach.call(fixedLengthWithOffset, ResizeMidIteration); + assert.compareArray(values, [ + 4 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.forEach.call(lengthTracking, ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.forEach.call(lengthTrackingWithOffset, ResizeMidIteration); + assert.compareArray(values, [ + 4 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/forEach/resizable-buffer.js b/test/sendable/builtins/Array/prototype/forEach/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..6eaae7b71f47604f72a2b1415f40bf65ac725e7b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/forEach/resizable-buffer.js @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.foreach +description: > + Array.p.forEach behaves correctly on TypedArrays backed by resizable buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + function Collect(array) { + const forEachValues = []; + SendableArray.prototype.forEach.call(array, n => { + forEachValues.push(n); + }); + return ToNumbers(forEachValues); + } + assert.compareArray(Collect(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(Collect(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(Collect(lengthTracking), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(Collect(lengthTrackingWithOffset), [ + 4, + 6 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.compareArray(Collect(fixedLength), []); + assert.compareArray(Collect(fixedLengthWithOffset), []); + assert.compareArray(Collect(lengthTracking), [ + 0, + 2, + 4 + ]); + assert.compareArray(Collect(lengthTrackingWithOffset), [4]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(Collect(fixedLength), []); + assert.compareArray(Collect(fixedLengthWithOffset), []); + assert.compareArray(Collect(lengthTracking), [0]); + // Shrink to zero. + rab.resize(0); + assert.compareArray(Collect(fixedLength), []); + assert.compareArray(Collect(fixedLengthWithOffset), []); + assert.compareArray(Collect(lengthTrackingWithOffset), []); + assert.compareArray(Collect(lengthTracking), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + assert.compareArray(Collect(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(Collect(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(Collect(lengthTracking), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(Collect(lengthTrackingWithOffset), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/includes/call-with-boolean.js b/test/sendable/builtins/Array/prototype/includes/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..44e21ea508655fc1214c8fd6f1e0fcb40446372c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/call-with-boolean.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: Array.prototype.includes applied to boolean primitive +features: [Array.prototype.includes] +---*/ + +assert.sameValue(SendableArray.prototype.includes.call(true), false, 'SendableArray.prototype.includes.call(true) must return false'); +assert.sameValue( + SendableArray.prototype.includes.call(false), + false, + 'SendableArray.prototype.includes.call(false) must return false' +); diff --git a/test/sendable/builtins/Array/prototype/includes/coerced-searchelement-fromindex-resize.js b/test/sendable/builtins/Array/prototype/includes/coerced-searchelement-fromindex-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..6a983261975e7db46369fa41d1acd8ebbf05719a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/coerced-searchelement-fromindex-resize.js @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: > + Array.p.includes behaves correctly on TypedArrays backed by resizable buffers + that are resized during argument coercion. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer, Array.prototype.includes] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert(!SendableArray.prototype.includes.call(fixedLength, undefined)); + // The TA is OOB so it includes only "undefined". + assert(SendableArray.prototype.includes.call(fixedLength, undefined, evil)); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n0 = MayNeedBigInt(fixedLength, 0); + assert(SendableArray.prototype.includes.call(fixedLength, n0)); + // The TA is OOB so it includes only "undefined". + assert(!SendableArray.prototype.includes.call(fixedLength, n0, evil)); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert(!SendableArray.prototype.includes.call(lengthTracking, undefined)); + // "includes" iterates until the original length and sees "undefined"s. + assert(SendableArray.prototype.includes.call(lengthTracking, undefined, evil)); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, 1); + } + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n0 = MayNeedBigInt(lengthTracking, 0); + assert(!SendableArray.prototype.includes.call(lengthTracking, n0)); + // The TA grew but we only look at the data until the original length. + assert(!SendableArray.prototype.includes.call(lengthTracking, n0, evil)); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + lengthTracking[0] = MayNeedBigInt(lengthTracking, 1); + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return -4; + } + }; + let n1 = MayNeedBigInt(lengthTracking, 1); + assert(SendableArray.prototype.includes.call(lengthTracking, n1, -4)); + // The TA grew but the start index conversion is done based on the original + // length. + assert(SendableArray.prototype.includes.call(lengthTracking, n1, evil)); +} diff --git a/test/sendable/builtins/Array/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js b/test/sendable/builtins/Array/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..11c0e1048bf5d3bb34ad9f8bf89fd22c5a5f27d2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: Return false if fromIndex >= ArrayLength +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +features: [Array.prototype.includes] +---*/ + +var sample = [7, 7, 7, 7]; +assert.sameValue(sample.includes(7, 4), false, "length"); +assert.sameValue(sample.includes(7, 5), false, "length + 1"); diff --git a/test/sendable/builtins/Array/prototype/includes/fromIndex-infinity.js b/test/sendable/builtins/Array/prototype/includes/fromIndex-infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..91d3029f8621ee93eb82bb7d10b5ff348a3dd1d3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/fromIndex-infinity.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: handle Infinity values for fromIndex +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +features: [Array.prototype.includes] +---*/ + +var sample = [42, 43, 43, 41]; +assert.sameValue( + sample.includes(43, Infinity), + false, + "includes(43, Infinity)" +); +assert.sameValue( + sample.includes(43, -Infinity), + true, + "includes(43, -Infinity)" +); diff --git a/test/sendable/builtins/Array/prototype/includes/fromIndex-minus-zero.js b/test/sendable/builtins/Array/prototype/includes/fromIndex-minus-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..fec15dbe6cd3d0b16e1dce4a431f24d9e8f39450 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/fromIndex-minus-zero.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: -0 fromIndex becomes 0 +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +features: [Array.prototype.includes] +---*/ + +var sample = [42, 43]; +assert.sameValue(sample.includes(42, -0), true, "-0 [0]"); +assert.sameValue(sample.includes(43, -0), true, "-0 [1]"); +assert.sameValue(sample.includes(44, -0), false, "-0 [2]"); diff --git a/test/sendable/builtins/Array/prototype/includes/get-prop.js b/test/sendable/builtins/Array/prototype/includes/get-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..ab87b4b064c9f21f436603375ddc9cb311977478 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/get-prop.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: get array-like indexed properties +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +includes: [compareArray.js] +features: [Proxy, Array.prototype.includes] +---*/ + +var calls; +var obj = {}; +var p = new Proxy(obj, { + get: function(_, key) { + calls.push(key); + if (key === "length") { + return 4; + } + return key * 10; + } +}); +calls = []; +assert.sameValue( + [].includes.call(p, 42), + false, + '[].includes.call("new Proxy(obj, {get: function(_, key) {calls.push(key); if (key === "length") {return 4;} return key * 10;}})", 42) must return false' +); +assert.compareArray(calls, ["length", "0", "1", "2", "3"], + 'The value of calls is expected to be ["length", "0", "1", "2", "3"]' +); +calls = []; +assert.sameValue([].includes.call(p, 10), true, '[].includes.call("new Proxy(obj, {get: function(_, key) {calls.push(key); if (key === "length") {return 4;} return key * 10;}})", 10) must return true'); +assert.compareArray(calls, ["length", "0", "1"], 'The value of calls is expected to be ["length", "0", "1"]'); diff --git a/test/sendable/builtins/Array/prototype/includes/length-boundaries.js b/test/sendable/builtins/Array/prototype/includes/length-boundaries.js new file mode 100644 index 0000000000000000000000000000000000000000..1723034d799422ce4db71274ad3256922192a8dd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/length-boundaries.js @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: length boundaries from ToLength operation +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +features: [Array.prototype.includes] +---*/ + +var obj = { + "0": "a", + "1": "b", + "9007199254740990": "c", // 2 ** 53 - 2 + "9007199254740991": "d", // 2 ** 53 - 1 + "9007199254740992": "e", // 2 ** 53 +}; +obj.length = -0; +assert.sameValue([].includes.call(obj, "a"), false, "-0"); +obj.length = -1; +assert.sameValue([].includes.call(obj, "a"), false, "-1"); +obj.length = -0.1; +assert.sameValue([].includes.call(obj, "a"), false, "-0.1"); +obj.length = -Infinity; +assert.sameValue([].includes.call(obj, "a"), false, "-Infinity"); +var fromIndex = 9007199254740990; +obj.length = 9007199254740991; +assert.sameValue( + [].includes.call(obj, "c", fromIndex), + true, + "2**53-1, found value at 2**53-2" +); +obj.length = 9007199254740991; +assert.sameValue( + [].includes.call(obj, "d", fromIndex), + false, + "2**53-1, ignores indexes >= 2**53-1" +); +obj.length = 9007199254740992; +assert.sameValue( + [].includes.call(obj, "d", fromIndex), + false, + "2**53, ignores indexes >= 2**53-1" +); +obj.length = 9007199254740993; +assert.sameValue( + [].includes.call(obj, "d", fromIndex), + false, + "2**53+1, ignores indexes >= 2**53-1" +); +obj.length = Infinity; +assert.sameValue( + [].includes.call(obj, "c", fromIndex), + true, + "Infinity, found item" +); +assert.sameValue( + [].includes.call(obj, "d", fromIndex), + false, + "Infinity, ignores indexes >= 2**53-1" +); diff --git a/test/sendable/builtins/Array/prototype/includes/length-zero-returns-false.js b/test/sendable/builtins/Array/prototype/includes/length-zero-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..f1c7883a1d1ef20a7359feef42fe0e53c4e521ff --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/length-zero-returns-false.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: Returns false if length is 0 +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +features: [Array.prototype.includes] +---*/ + +var calls = 0; +var fromIndex = { + valueOf: function() { + calls++; + } +}; +var sample = []; +assert.sameValue(sample.includes(0), false, "returns false"); +assert.sameValue(sample.includes(), false, "returns false - no arg"); +assert.sameValue(sample.includes(0, fromIndex), false, "using fromIndex"); +assert.sameValue(calls, 0, "length is checked before ToInteger(fromIndex)"); diff --git a/test/sendable/builtins/Array/prototype/includes/length.js b/test/sendable/builtins/Array/prototype/includes/length.js new file mode 100644 index 0000000000000000000000000000000000000000..6bcf8d00bb606924a211529addbd85ba61b2a2db --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/length.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: > + Array.prototype.includes.length is 1. +info: | + Array.prototype.includes ( searchElement [ , fromIndex ] ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Array.prototype.includes] +---*/ + +verifyProperty(SendableArray.prototype.includes, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/includes/name.js b/test/sendable/builtins/Array/prototype/includes/name.js new file mode 100644 index 0000000000000000000000000000000000000000..af7ae76d1e68921075d2d08cc74b498cdf525154 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/name.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: > + Array.prototype.includes.name is "includes". +info: | + Array.prototype.includes (searchElement [ , fromIndex ] ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Array.prototype.includes] +---*/ + +verifyProperty(SendableArray.prototype.includes, "name", { + value: "includes", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/includes/no-arg.js b/test/sendable/builtins/Array/prototype/includes/no-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..8696f7d9c5b15655a866fd1f6871ce03c3e60d68 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/no-arg.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: no argument searches for a undefined value +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. +features: [Array.prototype.includes] +---*/ + +assert.sameValue([0].includes(), false, "[0].includes()"); +assert.sameValue([undefined].includes(), true, "[undefined].includes()"); diff --git a/test/sendable/builtins/Array/prototype/includes/not-a-constructor.js b/test/sendable/builtins/Array/prototype/includes/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..db3c839fd0fdae872e604fb1fdda35e98782eb9b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/not-a-constructor.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.includes does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function, Array.prototype.includes] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.includes), + false, + 'isConstructor(SendableArray.prototype.includes) must return false' +); + +assert.throws(TypeError, () => { + new SendableArray.prototype.includes(1); +}); + diff --git a/test/sendable/builtins/Array/prototype/includes/prop-desc.js b/test/sendable/builtins/Array/prototype/includes/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..f2ae3f884042c0860310b5944e8f982b58b58881 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/prop-desc.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: > + "includes" property of Array.prototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [Array.prototype.includes] +---*/ + +verifyProperty(SendableArray.prototype, "includes", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/includes/resizable-buffer-special-float-values.js b/test/sendable/builtins/Array/prototype/includes/resizable-buffer-special-float-values.js new file mode 100644 index 0000000000000000000000000000000000000000..7fe0d1b50677d54d231f79a883a6601bbde86c59 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/resizable-buffer-special-float-values.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-%array%.prototype.includes +description: > + Array.p.includes behaves correctly for special float values on float + TypedArrays backed by resizable buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer, Array.prototype.includes] +---*/ + +for (let ctor of floatCtors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + lengthTracking[0] = -Infinity; + lengthTracking[1] = Infinity; + lengthTracking[2] = NaN; + assert(SendableArray.prototype.includes.call(lengthTracking, -Infinity)); + assert(SendableArray.prototype.includes.call(lengthTracking, Infinity)); + assert(SendableArray.prototype.includes.call(lengthTracking, NaN)); +} diff --git a/test/sendable/builtins/Array/prototype/includes/resizable-buffer.js b/test/sendable/builtins/Array/prototype/includes/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..473fa965ed413a22c57a8392bbe1bbcfd058ef5c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/resizable-buffer.js @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: > + Array.p.includes behaves correctly on TypedArrays backed by resizable buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer, Array.prototype.includes] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + // If fixedLength is a BigInt array, they all are BigInt Arrays. + let n2 = MayNeedBigInt(fixedLength, 2); + let n4 = MayNeedBigInt(fixedLength, 4); + assert(SendableArray.prototype.includes.call(fixedLength, n2)); + assert(!SendableArray.prototype.includes.call(fixedLength, undefined)); + assert(SendableArray.prototype.includes.call(fixedLength, n2, 1)); + assert(!SendableArray.prototype.includes.call(fixedLength, n2, 2)); + assert(SendableArray.prototype.includes.call(fixedLength, n2, -3)); + assert(!SendableArray.prototype.includes.call(fixedLength, n2, -2)); + assert(!SendableArray.prototype.includes.call(fixedLengthWithOffset, n2)); + assert(SendableArray.prototype.includes.call(fixedLengthWithOffset, n4)); + assert(!SendableArray.prototype.includes.call(fixedLengthWithOffset, undefined)); + assert(SendableArray.prototype.includes.call(fixedLengthWithOffset, n4, 0)); + assert(!SendableArray.prototype.includes.call(fixedLengthWithOffset, n4, 1)); + assert(SendableArray.prototype.includes.call(fixedLengthWithOffset, n4, -2)); + assert(!SendableArray.prototype.includes.call(fixedLengthWithOffset, n4, -1)); + assert(SendableArray.prototype.includes.call(lengthTracking, n2)); + assert(!SendableArray.prototype.includes.call(lengthTracking, undefined)); + assert(SendableArray.prototype.includes.call(lengthTracking, n2, 1)); + assert(!SendableArray.prototype.includes.call(lengthTracking, n2, 2)); + assert(SendableArray.prototype.includes.call(lengthTracking, n2, -3)); + assert(!SendableArray.prototype.includes.call(lengthTracking, n2, -2)); + assert(!SendableArray.prototype.includes.call(lengthTrackingWithOffset, n2)); + assert(SendableArray.prototype.includes.call(lengthTrackingWithOffset, n4)); + assert(!SendableArray.prototype.includes.call(lengthTrackingWithOffset, undefined)); + assert(SendableArray.prototype.includes.call(lengthTrackingWithOffset, n4, 0)); + assert(!SendableArray.prototype.includes.call(lengthTrackingWithOffset, n4, 1)); + assert(SendableArray.prototype.includes.call(lengthTrackingWithOffset, n4, -2)); + assert(!SendableArray.prototype.includes.call(lengthTrackingWithOffset, n4, -1)); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + assert(!SendableArray.prototype.includes.call(fixedLength, n2)); + assert(!SendableArray.prototype.includes.call(fixedLengthWithOffset, n2)); + assert(SendableArray.prototype.includes.call(lengthTracking, n2)); + assert(!SendableArray.prototype.includes.call(lengthTracking, undefined)); + assert(!SendableArray.prototype.includes.call(lengthTrackingWithOffset, n2)); + assert(SendableArray.prototype.includes.call(lengthTrackingWithOffset, n4)); + assert(!SendableArray.prototype.includes.call(lengthTrackingWithOffset, undefined)); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert(!SendableArray.prototype.includes.call(fixedLength, n2)); + assert(!SendableArray.prototype.includes.call(fixedLengthWithOffset, n2)); + assert(!SendableArray.prototype.includes.call(lengthTrackingWithOffset, n2)); + // Shrink to zero. + rab.resize(0); + assert(!SendableArray.prototype.includes.call(fixedLength, n2)); + assert(!SendableArray.prototype.includes.call(fixedLengthWithOffset, n2)); + assert(!SendableArray.prototype.includes.call(lengthTrackingWithOffset, n2)); + assert(!SendableArray.prototype.includes.call(lengthTracking, n2)); + assert(!SendableArray.prototype.includes.call(lengthTracking, undefined)); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + let n8 = MayNeedBigInt(fixedLength, 8); + assert(SendableArray.prototype.includes.call(fixedLength, n2)); + assert(!SendableArray.prototype.includes.call(fixedLength, undefined)); + assert(!SendableArray.prototype.includes.call(fixedLength, n8)); + assert(!SendableArray.prototype.includes.call(fixedLengthWithOffset, n2)); + assert(SendableArray.prototype.includes.call(fixedLengthWithOffset, n4)); + assert(!SendableArray.prototype.includes.call(fixedLengthWithOffset, undefined)); + assert(!SendableArray.prototype.includes.call(fixedLengthWithOffset, n8)); + assert(SendableArray.prototype.includes.call(lengthTracking, n2)); + assert(!SendableArray.prototype.includes.call(lengthTracking, undefined)); + assert(SendableArray.prototype.includes.call(lengthTracking, n8)); + assert(!SendableArray.prototype.includes.call(lengthTrackingWithOffset, n2)); + assert(SendableArray.prototype.includes.call(lengthTrackingWithOffset, n4)); + assert(!SendableArray.prototype.includes.call(lengthTrackingWithOffset, undefined)); + assert(SendableArray.prototype.includes.call(lengthTrackingWithOffset, n8)); +} diff --git a/test/sendable/builtins/Array/prototype/includes/return-abrupt-get-length.js b/test/sendable/builtins/Array/prototype/includes/return-abrupt-get-length.js new file mode 100644 index 0000000000000000000000000000000000000000..07835a6bd9ef3a9c228cce80c895f51230aa17ae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/return-abrupt-get-length.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: Return abrupt from Get(O, "length") +features: [Array.prototype.includes] +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + [].includes.call(obj, 7); +}); diff --git a/test/sendable/builtins/Array/prototype/includes/return-abrupt-get-prop.js b/test/sendable/builtins/Array/prototype/includes/return-abrupt-get-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..090be80b6a264b6d7bc105a3830fd91c2aa5deed --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/return-abrupt-get-prop.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: Return abrupt getting index properties +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +features: [Array.prototype.includes] +---*/ + +var stopped = 0; +var obj = { + length: 3 +}; +Object.defineProperty(obj, "1", { + get: function() { + throw new Test262Error(); + } +}); +Object.defineProperty(obj, "2", { + get: function() { + stopped++; + } +}); +assert.throws(Test262Error, function() { + [].includes.call(obj, 7); +}); +assert.sameValue(stopped, 0, "It stops the loop after the abrupt completion"); diff --git a/test/sendable/builtins/Array/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js b/test/sendable/builtins/Array/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..f3ec37a111e64b52a896aaf18b37473ee6f8f710 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) +features: [Symbol, Array.prototype.includes] +---*/ + +var fromIndex = Symbol("1"); +var sample = [7]; +assert.throws(TypeError, function() { + sample.includes(7, fromIndex); +}); diff --git a/test/sendable/builtins/Array/prototype/includes/return-abrupt-tointeger-fromindex.js b/test/sendable/builtins/Array/prototype/includes/return-abrupt-tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..80e014e05e53bd100a5ce547e40994b02af02a43 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/return-abrupt-tointeger-fromindex.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) +features: [Array.prototype.includes] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; +var sample = [7]; +assert.throws(Test262Error, function() { + sample.includes(7, fromIndex); +}); diff --git a/test/sendable/builtins/Array/prototype/includes/return-abrupt-tonumber-length-symbol.js b/test/sendable/builtins/Array/prototype/includes/return-abrupt-tonumber-length-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..92a76354e214a19ec4c259ade991d84335175087 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/return-abrupt-tonumber-length-symbol.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: Return abrupt from ToNumber(symbol "length") +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + 2. Let len be ? ToLength(? Get(O, "length")). +features: [Symbol, Array.prototype.includes] +---*/ + +var obj = { + length: Symbol("1") +}; +assert.throws(TypeError, function() { + [].includes.call(obj, 7); +}); diff --git a/test/sendable/builtins/Array/prototype/includes/return-abrupt-tonumber-length.js b/test/sendable/builtins/Array/prototype/includes/return-abrupt-tonumber-length.js new file mode 100644 index 0000000000000000000000000000000000000000..31b6960ec819cc09917f6ae6303a25443dfab773 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/return-abrupt-tonumber-length.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: Return abrupt from ToNumber("length") +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + 2. Let len be ? ToLength(? Get(O, "length")). +features: [Array.prototype.includes] +---*/ + +var obj1 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; +var obj2 = { + length: { + toString: function() { + throw new Test262Error(); + } + } +}; +assert.throws(Test262Error, function() { + [].includes.call(obj1); +}, "valueOf"); +assert.throws(Test262Error, function() { + [].includes.call(obj2); +}, "toString"); diff --git a/test/sendable/builtins/Array/prototype/includes/samevaluezero.js b/test/sendable/builtins/Array/prototype/includes/samevaluezero.js new file mode 100644 index 0000000000000000000000000000000000000000..605791e17bd3507f2910943ae8265891ca0d8659 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/samevaluezero.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: search element is compared using SameValueZero +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. +features: [Array.prototype.includes] +---*/ + +var sample = [42, 0, 1, NaN]; +assert.sameValue(sample.includes("42"), false, "'42'"); +assert.sameValue(sample.includes([42]), false, "[42]"); +assert.sameValue(sample.includes(42.0), true, "42.0"); +assert.sameValue(sample.includes(-0), true, "-0"); +assert.sameValue(sample.includes(true), false, "true"); +assert.sameValue(sample.includes(false), false, "false"); +assert.sameValue(sample.includes(null), false, "null"); +assert.sameValue(sample.includes(""), false, "empty string"); +assert.sameValue(sample.includes(NaN), true, "NaN"); diff --git a/test/sendable/builtins/Array/prototype/includes/search-found-returns-true.js b/test/sendable/builtins/Array/prototype/includes/search-found-returns-true.js new file mode 100644 index 0000000000000000000000000000000000000000..db422d20fb2bff559f4adeeef3b3d6f5a4a95486 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/search-found-returns-true.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: returns true for found index +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. +features: [Symbol, Array.prototype.includes] +---*/ + +var symbol = Symbol("1"); +var obj = {}; +var array = []; +var sample = [42, "test262", null, undefined, true, false, 0, -1, "", symbol, obj, array]; +assert.sameValue(sample.includes(42), true, "42"); +assert.sameValue(sample.includes("test262"), true, "'test262'"); +assert.sameValue(sample.includes(null), true, "null"); +assert.sameValue(sample.includes(undefined), true, "undefined"); +assert.sameValue(sample.includes(true), true, "true"); +assert.sameValue(sample.includes(false), true, "false"); +assert.sameValue(sample.includes(0), true, "0"); +assert.sameValue(sample.includes(-1), true, "-1"); +assert.sameValue(sample.includes(""), true, "the empty string"); +assert.sameValue(sample.includes(symbol), true, "symbol"); +assert.sameValue(sample.includes(obj), true, "obj"); +assert.sameValue(sample.includes(array), true, "array"); diff --git a/test/sendable/builtins/Array/prototype/includes/search-not-found-returns-false.js b/test/sendable/builtins/Array/prototype/includes/search-not-found-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..c7c474aea93b72b65052873d5855c52d99cd319c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/search-not-found-returns-false.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: returns false if the element is not found +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + 8. Return false. +features: [Symbol, Array.prototype.includes] +---*/ + +assert.sameValue([42].includes(43), false, "43"); +assert.sameValue(["test262"].includes("test"), false, "string"); +assert.sameValue([0, "test262", undefined].includes(""), false, "the empty string"); +assert.sameValue(["true", false].includes(true), false, "true"); +assert.sameValue(["", true].includes(false), false, "false"); +assert.sameValue([undefined, false, 0, 1].includes(null), false, "null"); +assert.sameValue([null].includes(undefined), false, "undefined"); +assert.sameValue([Symbol("1")].includes(Symbol("1")), false, "symbol"); +assert.sameValue([{}].includes({}), false, "object"); +assert.sameValue([ + [] +].includes([]), false, "array"); +var sample = [42]; +assert.sameValue(sample.includes(sample), false, "this"); diff --git a/test/sendable/builtins/Array/prototype/includes/sparse.js b/test/sendable/builtins/Array/prototype/includes/sparse.js new file mode 100644 index 0000000000000000000000000000000000000000..ddd29c96bf983458cece0652c3266b53f79343ad --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/sparse.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: Searches all indexes from a sparse array +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +features: [Array.prototype.includes] +---*/ + +assert.sameValue( + [, , , ].includes(undefined), + true, + "[ , , , ].includes(undefined)" +); +assert.sameValue( + [, , , 42, ].includes(undefined, 4), + false, + "[ , , , 42, ].includes(undefined, 4)" +); +var sample = [, , , 42, , ]; +assert.sameValue( + sample.includes(undefined), + true, + "sample.includes(undefined)" +); +assert.sameValue( + sample.includes(undefined, 4), + true, + "sample.includes(undefined, 4)" +); +assert.sameValue( + sample.includes(42, 3), + true, + "sample.includes(42, 3)" +); diff --git a/test/sendable/builtins/Array/prototype/includes/this-is-not-object.js b/test/sendable/builtins/Array/prototype/includes/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..0d9694a7e571fd4629615b35d532cdc013984918 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/this-is-not-object.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.includes +description: > + Throws a TypeError exception when `this` cannot be coerced to Object +features: [Array.prototype.includes] +---*/ + +var includes = SendableArray.prototype.includes; +assert.throws(TypeError, function() { + includes.call(undefined, 42); +}, "this is undefined"); +assert.throws(TypeError, function() { + includes.call(null, 42); +}, "this is null"); diff --git a/test/sendable/builtins/Array/prototype/includes/tointeger-fromindex.js b/test/sendable/builtins/Array/prototype/includes/tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..25cda2f286c5fa5688098e838dca3aa7a40dc4a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/tointeger-fromindex.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.includes +description: get the integer value from fromIndex +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +features: [Array.prototype.includes] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; +var sample = [42, 43]; +assert.sameValue(sample.includes(42, "1"), false, "string [0]"); +assert.sameValue(sample.includes(43, "1"), true, "string [1]"); +assert.sameValue(sample.includes(42, true), false, "true [0]"); +assert.sameValue(sample.includes(43, true), true, "true [1]"); +assert.sameValue(sample.includes(42, false), true, "false [0]"); +assert.sameValue(sample.includes(43, false), true, "false [1]"); +assert.sameValue(sample.includes(42, NaN), true, "NaN [0]"); +assert.sameValue(sample.includes(43, NaN), true, "NaN [1]"); +assert.sameValue(sample.includes(42, null), true, "null [0]"); +assert.sameValue(sample.includes(43, null), true, "null [1]"); +assert.sameValue(sample.includes(42, undefined), true, "undefined [0]"); +assert.sameValue(sample.includes(43, undefined), true, "undefined [1]"); +assert.sameValue(sample.includes(42, null), true, "null [0]"); +assert.sameValue(sample.includes(43, null), true, "null [1]"); +assert.sameValue(sample.includes(42, obj), false, "object [0]"); +assert.sameValue(sample.includes(43, obj), true, "object [1]"); diff --git a/test/sendable/builtins/Array/prototype/includes/tolength-length.js b/test/sendable/builtins/Array/prototype/includes/tolength-length.js new file mode 100644 index 0000000000000000000000000000000000000000..076ec26138ada74049e0ecd6f4475d79831a3690 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/tolength-length.js @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.includes +description: length value coerced on ToLength +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +features: [Array.prototype.includes] +---*/ + +var obj = { + "0": "a", + "1": "b" +}; +obj.length = 0.1; +assert.sameValue([].includes.call(obj, "a"), false, "0.1"); +obj.length = 0.99; +assert.sameValue([].includes.call(obj, "a"), false, "0.99"); +obj.length = 1.00001; +assert.sameValue([].includes.call(obj, "a"), true, "1.00001"); +obj.length = 1.1; +assert.sameValue([].includes.call(obj, "a"), true, "1.1"); +obj.length = "0"; +assert.sameValue([].includes.call(obj, "a"), false, "string '0'"); +obj.length = "1"; +assert.sameValue([].includes.call(obj, "a"), true, "string '1', item found"); +obj.length = "1"; +assert.sameValue([].includes.call(obj, "b"), false, "string '1', item not found"); +obj.length = "2"; +assert.sameValue([].includes.call(obj, "b"), true, "string '2', item found"); +obj.length = ""; +assert.sameValue([].includes.call(obj, "a"), false, "the empty string"); +obj.length = undefined; +assert.sameValue([].includes.call(obj, "a"), false, "undefined"); +obj.length = NaN; +assert.sameValue([].includes.call(obj, "a"), false, "NaN"); +obj.length = []; +assert.sameValue([].includes.call(obj, "a"), false, "[]"); +obj.length = [1]; +assert.sameValue([].includes.call(obj, "a"), true, "[1]"); +obj.length = null; +assert.sameValue([].includes.call(obj, "a"), false, "null"); +obj.length = false; +assert.sameValue([].includes.call(obj, "a"), false, "false"); +obj.length = true; +assert.sameValue([].includes.call(obj, "a"), true, "true"); +obj.length = { + valueOf: function() { + return 2; + } +}; +assert.sameValue([].includes.call(obj, "b"), true, "ordinary object.valueOf"); +obj.length = { + toString: function() { + return 2; + } +}; +assert.sameValue([].includes.call(obj, "b"), true, "ordinary object.toString"); diff --git a/test/sendable/builtins/Array/prototype/includes/using-fromindex.js b/test/sendable/builtins/Array/prototype/includes/using-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..5b0f6f0d7d57b408b3a72db191fd95d95b4277e4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/using-fromindex.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.includes +description: Searches using fromIndex +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +features: [Array.prototype.includes] +---*/ + +var sample = ["a", "b", "c"]; +assert.sameValue(sample.includes("a", 0), true, "includes('a', 0)"); +assert.sameValue(sample.includes("a", 1), false, "includes('a', 1)"); +assert.sameValue(sample.includes("a", 2), false, "includes('a', 2)"); +assert.sameValue(sample.includes("b", 0), true, "includes('b', 0)"); +assert.sameValue(sample.includes("b", 1), true, "includes('b', 1)"); +assert.sameValue(sample.includes("b", 2), false, "includes('b', 2)"); +assert.sameValue(sample.includes("c", 0), true, "includes('c', 0)"); +assert.sameValue(sample.includes("c", 1), true, "includes('c', 1)"); +assert.sameValue(sample.includes("c", 2), true, "includes('c', 2)"); +assert.sameValue(sample.includes("a", -1), false, "includes('a', -1)"); +assert.sameValue(sample.includes("a", -2), false, "includes('a', -2)"); +assert.sameValue(sample.includes("a", -3), true, "includes('a', -3)"); +assert.sameValue(sample.includes("a", -4), true, "includes('a', -4)"); +assert.sameValue(sample.includes("b", -1), false, "includes('b', -1)"); +assert.sameValue(sample.includes("b", -2), true, "includes('b', -2)"); +assert.sameValue(sample.includes("b", -3), true, "includes('b', -3)"); +assert.sameValue(sample.includes("b", -4), true, "includes('b', -4)"); +assert.sameValue(sample.includes("c", -1), true, "includes('c', -1)"); +assert.sameValue(sample.includes("c", -2), true, "includes('c', -2)"); +assert.sameValue(sample.includes("c", -3), true, "includes('c', -3)"); +assert.sameValue(sample.includes("c", -4), true, "includes('c', -4)"); diff --git a/test/sendable/builtins/Array/prototype/includes/values-are-not-cached.js b/test/sendable/builtins/Array/prototype/includes/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..ed41f5e460176e83307ebd5d916f2cabef57c9c4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/includes/values-are-not-cached.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.includes +description: indexed values are not cached +info: | + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) +features: [Array.prototype.includes] +---*/ + +function getCleanObj() { + var obj = {}; + Object.defineProperty(obj, "length", { + get: function() { + Object.defineProperty(obj, "0", { + get: function() { + obj[1] = "ecma262"; + obj[2] = "cake"; + return "tc39"; + } + }); + return 2; + } + }); + return obj; +} +var obj; +obj = getCleanObj(); +assert.sameValue([].includes.call(obj, "tc39"), true, "'tc39' is true"); +obj = getCleanObj(); +assert.sameValue([].includes.call(obj, "ecma262"), true, "'ecma262' is true"); +obj = getCleanObj(); +assert.sameValue([].includes.call(obj, "cake"), false, "'cake' is false"); +assert.sameValue(obj[2], "cake", "'2' is set"); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..1a827a811fe067670e03521b6dad7af9824d8414 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to undefined throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.indexOf.call(undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-10.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..07d5c35bba96ded5037c3d30abb0e89ddf920bd7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-10.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to the Math object +---*/ + +Math[1] = true; +Math.length = 2; +assert.sameValue(SendableArray.prototype.indexOf.call(Math, true), 1, 'SendableArray.prototype.indexOf.call(Math, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-11.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..621ddabca5b35a3699146b7cc218c02d44daa47e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-11.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to Date object +---*/ + +var obj = new Date(0); +obj.length = 2; +obj[1] = true; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-12.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..3c17d9508544d3eb0c61cb192d9a94de979f480f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-12.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to RegExp object +---*/ + +var obj = new RegExp(); +obj.length = 2; +obj[1] = true; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-13.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..39700252fea0e53177524d455036bae113aa3e6e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-13.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to the JSON object +---*/ + +var targetObj = {}; +JSON[3] = targetObj; +JSON.length = 5; +assert.sameValue(SendableArray.prototype.indexOf.call(JSON, targetObj), 3, 'SendableArray.prototype.indexOf.call(JSON, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-14.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-14.js new file mode 100644 index 0000000000000000000000000000000000000000..1faf11f3fbcad70d009eea68564c113f2ef1701d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-14.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to Error object +---*/ + +var obj = new SyntaxError(); +obj[1] = true; +obj.length = 2; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-15.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..6df823ea30ba4b79d377dbf0b41f972c6477ee6d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-15.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to Arguments object +---*/ + +function fun() { + return arguments; +} +var obj = fun(1, true, 3); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..81b8dca737481f24416acab65a9e734f05a07508 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to null throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.indexOf.call(null); +}); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-3.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..716037f4aed0113d51d1b218f171caa030e4a7d0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-3.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to boolean primitive +---*/ + +var targetObj = {}; +Boolean.prototype[1] = targetObj; +Boolean.prototype.length = 2; +assert.sameValue(SendableArray.prototype.indexOf.call(true, targetObj), 1, 'SendableArray.prototype.indexOf.call(true, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-4.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..10277e13bf7d00f8f44cc60936c7485483b0b162 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-4.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to Boolean Object +---*/ + +var obj = new Boolean(false); +obj.length = 2; +obj[1] = true; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-5.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..b5f655c866d3b44e784a1b89ae928d0e42f36187 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-5.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to number primitive +---*/ + +var targetObj = {}; +Number.prototype[1] = targetObj; +Number.prototype.length = 2; +assert.sameValue(SendableArray.prototype.indexOf.call(5, targetObj), 1, 'SendableArray.prototype.indexOf.call(5, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-6.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..47644c70895036c43b6da2ed41c00100e95d204f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-6.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to Number object +---*/ + +var obj = new Number(-3); +obj.length = 2; +obj[1] = true; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-7.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..cdf0ce7dbfd0ca59b3955eb547a1d646a2ade376 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-7.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to string primitive +---*/ + +assert.sameValue(SendableArray.prototype.indexOf.call("abc", "b"), 1, 'SendableArray.prototype.indexOf.call("abc", "b")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-8.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..ce39316cd6ab0453db716fdacbcdc87ba785e25c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-8.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to String object +---*/ + +var obj = new String("null"); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 'l'), 2, 'SendableArray.prototype.indexOf.call(obj, "l")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-9.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..2aaea22ff1e070ca60743b036bea37b1fc7b5fda --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-1-9.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf applied to Function object +---*/ + +var obj = function(a, b) { + return a + b; +}; +obj[1] = true; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-10-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-10-1.js new file mode 100644 index 0000000000000000000000000000000000000000..d1f3df998dc4276dd10b09c55af101cca43c5702 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-10-1.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 for elements not present in + array +---*/ + +var a = new SendableArray(); +a[100] = 1; +a[99999] = ""; +a[10] = new Object(); +a[5555] = 5.5; +a[123456] = "str"; +a[5] = 1E+309; +assert.sameValue(a.indexOf(1), 100, 'a.indexOf(1)'); +assert.sameValue(a.indexOf(""), 99999, 'a.indexOf("")'); +assert.sameValue(a.indexOf("str"), 123456, 'a.indexOf("str")'); +assert.sameValue(a.indexOf(1E+309), 5, 'a.indexOf(1E+309)'); //Infinity +assert.sameValue(a.indexOf(5.5), 5555, 'a.indexOf(5.5)'); +assert.sameValue(a.indexOf(true), -1, 'a.indexOf(true)'); +assert.sameValue(a.indexOf(5), -1, 'a.indexOf(5)'); +assert.sameValue(a.indexOf("str1"), -1, 'a.indexOf("str1")'); +assert.sameValue(a.indexOf(null), -1, 'a.indexOf(null)'); +assert.sameValue(a.indexOf(new Object()), -1, 'a.indexOf(new Object())'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-10-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-10-2.js new file mode 100644 index 0000000000000000000000000000000000000000..7bcc13f7a89b0af5aec169fd23208163ae14a127 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-10-2.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 if 'length' is 0 and does not + access any other properties +---*/ + +var accessed = false; +var f = { + length: 0 +}; +Object.defineProperty(f, "0", { + get: function() { + accessed = true; + return 1; + } +}); +var i = SendableArray.prototype.indexOf.call(f, 1); +assert.sameValue(i, -1, 'i'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..2e32b2d32b4203baa46aed6ba13fe284e7ac7e1e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is own data property on an + Array-like object +---*/ + +var objOne = { + 1: true, + length: 2 +}; +var objTwo = { + 2: true, + length: 2 +}; +assert.sameValue(SendableArray.prototype.indexOf.call(objOne, true), 1, 'SendableArray.prototype.indexOf.call(objOne, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(objTwo, true), -1, 'SendableArray.prototype.indexOf.call(objTwo, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-10.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-10.js new file mode 100644 index 0000000000000000000000000000000000000000..e65b7147e8a0da9b4bc2e8ea9eaed4c4f8ee0611 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-10.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - 'length' is inherited accessor property +---*/ + +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var childOne = new Con(); +childOne[1] = true; +var childTwo = new Con(); +childTwo[2] = true; +assert.sameValue(SendableArray.prototype.indexOf.call(childOne, true), 1, 'SendableArray.prototype.indexOf.call(childOne, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(childTwo, true), -1, 'SendableArray.prototype.indexOf.call(childTwo, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-11.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-11.js new file mode 100644 index 0000000000000000000000000000000000000000..7e528c81aa5fd590b1c805ed262a9214001729d5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-11.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is own accessor property + without a get function +---*/ + +var obj = { + 1: true +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), -1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-12.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-12.js new file mode 100644 index 0000000000000000000000000000000000000000..8558ad94c89dd7a7dabfdd7fbced52395402a551 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-12.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is own accessor property + without a get function that overrides an inherited accessor + property +---*/ + +Object.defineProperty(Object.prototype, "length", { + get: function() { + return 20; + }, + configurable: true +}); +var obj = { + 1: 1 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 1), -1, 'SendableArray.prototype.indexOf.call(obj, 1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-13.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-13.js new file mode 100644 index 0000000000000000000000000000000000000000..17753e68fe4e1dd1caecf52925e5919eb6f484bf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-13.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is inherited accessor property + without a get function +---*/ + +var proto = {}; +Object.defineProperty(proto, "length", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[1] = true; +assert.sameValue(SendableArray.prototype.indexOf.call(child, true), -1, 'SendableArray.prototype.indexOf.call(child, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-14.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-14.js new file mode 100644 index 0000000000000000000000000000000000000000..5a335d1c16bda203cfe459c123303b195c467639 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-14.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - 'length' is undefined property +---*/ + +var obj = { + 0: true, + 1: true +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), -1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-17.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-17.js new file mode 100644 index 0000000000000000000000000000000000000000..fe7ad71a283d7f4f2078ca71a81f586699ca26da --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-17.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf applied to Arguments object which + implements its own property get method +---*/ + +var func = function(a, b) { + arguments[2] = false; + return SendableArray.prototype.indexOf.call(arguments, true) === 1 && + SendableArray.prototype.indexOf.call(arguments, false) === -1; +}; +assert(func(0, true), 'func(0, true) !== true'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-18.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-18.js new file mode 100644 index 0000000000000000000000000000000000000000..c2d7ec0c0bc902b6e148eec253c6032527ebafd0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-18.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf applied to String object, which implements + its own property get method +---*/ + +var str = new String("012"); +String.prototype[3] = "3"; +assert.sameValue(SendableArray.prototype.indexOf.call(str, "2"), 2, 'SendableArray.prototype.indexOf.call(str, "2")'); +assert.sameValue(SendableArray.prototype.indexOf.call(str, "3"), -1, 'SendableArray.prototype.indexOf.call(str, "3")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-19.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-19.js new file mode 100644 index 0000000000000000000000000000000000000000..26b8c96d3d56cb29570ddd519d4d81b71f3da407 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-19.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf applied to Function object which + implements its own property get method +---*/ + +var obj = function(a, b) { + return a + b; +}; +obj[1] = "b"; +obj[2] = "c"; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, obj[1]), 1, 'SendableArray.prototype.indexOf.call(obj, obj[1])'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, obj[2]), -1, 'SendableArray.prototype.indexOf.call(obj, obj[2])'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..63e9871f9c47319bdb892b75c0394650f4cef6b0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-2.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - 'length' is own data property on an Array +---*/ + +var targetObj = {}; +SendableArray.prototype[2] = targetObj; +assert.sameValue([0, targetObj].indexOf(targetObj), 1, '[0, targetObj].indexOf(targetObj)'); +assert.sameValue([0, 1].indexOf(targetObj), -1, '[0, 1].indexOf(targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-3.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..bcd738cccf37348e0d0864091084cabcedb35aa3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-3.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is own data property that + overrides an inherited data property on an Array-like object +---*/ + +var proto = { + length: 0 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +child[1] = true; +assert.sameValue(SendableArray.prototype.indexOf.call(child, true), 1, 'SendableArray.prototype.indexOf.call(child, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-4.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..7bf26238ac5e83af96c39f55be910d281130c777 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-4.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is own data property that + overrides an inherited data property on an Array +---*/ + +var targetObj = {}; +var arrProtoLen; +arrProtoLen = SendableArray.prototype.length; +SendableArray.prototype.length = 0; +assert.sameValue([0, targetObj].indexOf(targetObj), 1, '[0, targetObj].indexOf(targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-5.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..2965fb9c2eceb0a39a6510b532177b35c4e61837 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-5.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is own data property that + overrides an inherited accessor property on an Array-like object +---*/ + +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 0; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + value: 2, + configurable: true +}); +child[1] = true; +assert.sameValue(SendableArray.prototype.indexOf.call(child, true), 1, 'SendableArray.prototype.indexOf.call(child, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-6.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-6.js new file mode 100644 index 0000000000000000000000000000000000000000..e6391de5ff99e22894fe7f3f5f33dd3f9807417f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-6.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - 'length' is an inherited data property +---*/ + +var proto = { + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var childOne = new Con(); +childOne[1] = true; +var childTwo = new Con(); +childTwo[2] = true; +assert.sameValue(SendableArray.prototype.indexOf.call(childOne, true), 1, 'SendableArray.prototype.indexOf.call(childOne, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(childTwo, true), -1, 'SendableArray.prototype.indexOf.call(childTwo, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-7.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-7.js new file mode 100644 index 0000000000000000000000000000000000000000..b7705a1fa3796a4b6fa023a92cbc22197d4d80ba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-7.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - 'length' is own accessor property +---*/ + +var objOne = { + 1: true +}; +var objTwo = { + 2: true +}; +Object.defineProperty(objOne, "length", { + get: function() { + return 2; + }, + configurable: true +}); +Object.defineProperty(objTwo, "length", { + get: function() { + return 2; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(objOne, true), 1, 'SendableArray.prototype.indexOf.call(objOne, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(objTwo, true), -1, 'SendableArray.prototype.indexOf.call(objTwo, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-8.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-8.js new file mode 100644 index 0000000000000000000000000000000000000000..6b48aadad2b266d05aaf0806bdb28f1c7ad291b2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-8.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is own accessor property that + overrides an inherited data property +---*/ + +var proto = { + length: 0 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[1] = true; +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(child, true), 1, 'SendableArray.prototype.indexOf.call(child, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-9.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-9.js new file mode 100644 index 0000000000000000000000000000000000000000..716f3ae9fe680baa67af4fd29bb5599a170155fd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-2-9.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is own accessor property that + overrides an inherited accessor property +---*/ + +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 0; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[1] = true; +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(child, true), 1, 'SendableArray.prototype.indexOf.call(child, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-1.js new file mode 100644 index 0000000000000000000000000000000000000000..684b49049e8c0774c8f646b99bf4f22adb0522d8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - value of 'length' is undefined +---*/ + +var obj = { + 0: 1, + 1: 1, + length: undefined +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 1), -1, 'SendableArray.prototype.indexOf.call(obj, 1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-10.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-10.js new file mode 100644 index 0000000000000000000000000000000000000000..2c56acb123a6f285f0da9f34376e362062df0785 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-10.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is number primitive + (value is NaN) +---*/ + +var obj = { + 0: 0, + length: NaN +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 0), -1, 'SendableArray.prototype.indexOf.call(obj, 0)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-11.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-11.js new file mode 100644 index 0000000000000000000000000000000000000000..5f2e70246878c45238e27662660e0938504c0a41 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-11.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is a string containing a + positive number +---*/ + +var obj = { + 1: 1, + 2: 2, + length: "2" +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 1), 1, 'SendableArray.prototype.indexOf.call(obj, 1)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 2), -1, 'SendableArray.prototype.indexOf.call(obj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-12.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-12.js new file mode 100644 index 0000000000000000000000000000000000000000..09ab7eba38ce33f69b965dc42d8943319f3b6e9e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-12.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is a string containing a + negative number +---*/ + +var obj = { + 1: "true", + 2: "2", + length: "-4294967294" +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, "true"), -1, 'SendableArray.prototype.indexOf.call(obj, "true")'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, "2"), -1, 'SendableArray.prototype.indexOf.call(obj, "2")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-13.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-13.js new file mode 100644 index 0000000000000000000000000000000000000000..3af893613ce7775a801335ac7454c7050eb08bf8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-13.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is a string containing a + decimal number +---*/ + +var obj = { + 199: true, + 200: "200.59", + length: "200.59" +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 199, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, "200.59"), -1, 'SendableArray.prototype.indexOf.call(obj, "200.59")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-14.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-14.js new file mode 100644 index 0000000000000000000000000000000000000000..b79065b589a1f00cd3f4d1b77517a7e7850cd593 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-14.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is a string containing + +/-Infinity +---*/ + +var objOne = { + 0: true, + 1: true, + length: "Infinity" +}; +var objTwo = { + 0: true, + 1: true, + length: "+Infinity" +}; +var objThree = { + 0: true, + 1: true, + length: "-Infinity" +}; +assert.sameValue(SendableArray.prototype.indexOf.call(objOne, true), 0, 'SendableArray.prototype.indexOf.call(objOne, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(objTwo, true), 0, 'SendableArray.prototype.indexOf.call(objTwo, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(objThree, true), -1, 'SendableArray.prototype.indexOf.call(objThree, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-15.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-15.js new file mode 100644 index 0000000000000000000000000000000000000000..cc30162e40bc0e7fca2408065ca5f99627d13b03 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-15.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is a string containing an + exponential number +---*/ + +var obj = { + 1: true, + 2: "2E0", + length: "2E0" +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, "2E0"), -1, 'SendableArray.prototype.indexOf.call(obj, "2E0")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-16.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-16.js new file mode 100644 index 0000000000000000000000000000000000000000..1d2f75e52a12901c48b6ad0b1a9627283f9f1752 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-16.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is a string containing a hex + number +---*/ + +var obj = { + 10: true, + 11: "0x00B", + length: "0x00B" +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 10, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, "0x00B"), -1, 'SendableArray.prototype.indexOf.call(obj, "0x00B")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-17.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-17.js new file mode 100644 index 0000000000000000000000000000000000000000..73cd7bbc2294023ba17e72f83a1a9b203484d550 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-17.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is a string containing a number + with leading zeros +---*/ + +var obj = { + 1: true, + 2: "0002.0", + length: "0002.0" +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, "0002.0"), -1, 'SendableArray.prototype.indexOf.call(obj, "0002.0")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-18.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-18.js new file mode 100644 index 0000000000000000000000000000000000000000..9c8b3ab95076ad6b919269f4dde347d1c7b9cd7c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-18.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is a string that can't + convert to a number +---*/ + +var obj = { + 0: true, + 100: true, + length: "one" +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), -1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-19.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-19.js new file mode 100644 index 0000000000000000000000000000000000000000..1d91ea0bb9a945790c51328ba568d46eba430e45 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-19.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is an Object which has + an own toString method. +---*/ + +// objects inherit the default valueOf() method from Object +// that simply returns itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. + +var obj = { + 1: true, + 2: 2, + length: { + toString: function() { + return '2'; + } + } +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 2), -1, 'SendableArray.prototype.indexOf.call(obj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-2.js new file mode 100644 index 0000000000000000000000000000000000000000..483b68f4deec9239f400bfed09df79817cc2c3e2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf return -1 when 'length' is a boolean + (value is true) +---*/ + +var obj = { + 0: 0, + 1: 1, + length: true +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 0), 0, 'SendableArray.prototype.indexOf.call(obj, 0)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 1), -1, 'SendableArray.prototype.indexOf.call(obj, 1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-20.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-20.js new file mode 100644 index 0000000000000000000000000000000000000000..668eeb75d927fa65334ecce3aa5e8cbe328c2908 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-20.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is an Object which has + an own valueOf method. +---*/ + +//valueOf method will be invoked first, since hint is Number +var obj = { + 1: true, + 2: 2, + length: { + valueOf: function() { + return 2; + } + } +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 2), -1, 'SendableArray.prototype.indexOf.call(obj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-21.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-21.js new file mode 100644 index 0000000000000000000000000000000000000000..2a54e62bafdbfbe21a4938442e581ba192ce42a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-21.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'length' is an object that has an own + valueOf method that returns an object and toString method that + returns a string +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var obj = { + 1: true, + length: { + toString: function() { + toStringAccessed = true; + return '2'; + }, + valueOf: function() { + valueOfAccessed = true; + return {}; + } + } +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert(toStringAccessed, 'toStringAccessed !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-22.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-22.js new file mode 100644 index 0000000000000000000000000000000000000000..84206b2d756751d38f91e28b9ea28fbbd8875550 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-22.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf throws TypeError exception when 'length' + is an object with toString and valueOf methods that don�t return + primitive values +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var obj = { + length: { + toString: function() { + toStringAccessed = true; + return {}; + }, + valueOf: function() { + valueOfAccessed = true; + return {}; + } + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.indexOf.call(obj); +}); +assert(toStringAccessed, 'toStringAccessed'); +assert(valueOfAccessed, 'valueOfAccessed'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-23.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-23.js new file mode 100644 index 0000000000000000000000000000000000000000..e8359db7b9df3ce8c709721a54c1a731837aee0e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-23.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf uses inherited valueOf method when + 'length' is an object with an own toString and inherited valueOf + methods +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var proto = { + valueOf: function() { + valueOfAccessed = true; + return 2; + } +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.toString = function() { + toStringAccessed = true; + return 2; +}; +var obj = { + 1: true, + length: child +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(toStringAccessed, false, 'toStringAccessed'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-24.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-24.js new file mode 100644 index 0000000000000000000000000000000000000000..730c466d666f5742ebed4be3844c716019f3a3cc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-24.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is a positive + non-integer, ensure truncation occurs in the proper direction +---*/ + +var obj = { + 122: true, + 123: false, + length: 123.321 +}; //length will be 123 finally +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 122, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, false), -1, 'SendableArray.prototype.indexOf.call(obj, false)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-25.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-25.js new file mode 100644 index 0000000000000000000000000000000000000000..3fb359e887f3a96c94ae0a64124e608a602663a9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-25.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is a negative + non-integer +---*/ + +var obj = { + 1: true, + 2: false, + length: -4294967294.5 +}; //length will be 0 finally +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), -1, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, false), -1, 'SendableArray.prototype.indexOf.call(obj, false)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-28.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-28.js new file mode 100644 index 0000000000000000000000000000000000000000..285396837be21fced3287bec5130f283ff52570e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-28.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is boundary value + (2^32) +---*/ + +var targetObj = {}; +var obj = { + 0: targetObj, + 4294967294: targetObj, + 4294967295: targetObj, + length: 4294967296 +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, targetObj), 0, 'SendableArray.prototype.indexOf.call(obj, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-29.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-29.js new file mode 100644 index 0000000000000000000000000000000000000000..3bcf6287f2d16de3a4374031858dcdcebfc8d0de --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-29.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is boundary value + (2^32 + 1) +---*/ + +var targetObj = {}; +var obj = { + 0: targetObj, + 1: 4294967297, + length: 4294967297 +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, targetObj), 0, 'SendableArray.prototype.indexOf.call(obj, targetObj)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 4294967297), 1, 'SendableArray.prototype.indexOf.call(obj, 4294967297)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-3.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-3.js new file mode 100644 index 0000000000000000000000000000000000000000..71dcaa6c97a021dae3d4e413be564555cbf8cb6d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-3.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is a number (value is + 0) +---*/ + +var obj = { + 0: true, + length: 0 +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), -1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-4.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-4.js new file mode 100644 index 0000000000000000000000000000000000000000..1fccb8e25cd8a6320202b8654aaf395ce9440a7a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-4.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is a number (value is + +0) +---*/ + +var obj = { + 0: true, + length: +0 +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), -1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-5.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-5.js new file mode 100644 index 0000000000000000000000000000000000000000..4aa4bcc5f4998445c74c628a3a86052c75770a4e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-5.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is a number (value is + -0) +---*/ + +var obj = { + 0: true, + length: -0 +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), -1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-6.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-6.js new file mode 100644 index 0000000000000000000000000000000000000000..fab9bdd1d565a3ddb3e4abf0ee8437f393de47ad --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-6.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is a number (value is + positive) +---*/ + +var obj = { + 3: true, + 4: false, + length: 4 +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 3, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, false), -1, 'SendableArray.prototype.indexOf.call(obj, false)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-7.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-7.js new file mode 100644 index 0000000000000000000000000000000000000000..0a979076e8cdc024ef591bbfbfebf1f03c967e6a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-7.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is a number (value is + negative) +---*/ + +var obj = { + 4: true, + 5: false, + length: 5 - Math.pow(2, 32) +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), -1, 'SendableArray.prototype.indexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, false), -1, 'SendableArray.prototype.indexOf.call(obj, false)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-8.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-8.js new file mode 100644 index 0000000000000000000000000000000000000000..c35e0f7c7d489f2803cc5acfa3e401211b31258f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-8.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is a number (value is + Infinity) +---*/ + +var obj = { + 0: 0, + length: Infinity +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 0), 0, 'SendableArray.prototype.indexOf.call(obj, 0)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-9.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-9.js new file mode 100644 index 0000000000000000000000000000000000000000..0f31baf9eabd617fffa46a57c51387c15c4145f9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-3-9.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'length' is a number (value is + -Infinity) +---*/ + +var obj = { + 0: 0, + length: -Infinity +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 0), -1, 'SendableArray.prototype.indexOf.call(obj, 0)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..c83cc6de077114e5b58c6138542d142b07695ade --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-1.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf returns -1 if 'length' is 0 (empty array) +---*/ + +var i = [].indexOf(42); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-10.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-10.js new file mode 100644 index 0000000000000000000000000000000000000000..e31f7205e48a6d9645c4ef10579f655a3775b553 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-10.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - 'length' is a number of value -6e-1 +---*/ + +var targetObj = []; +var obj = { + 0: targetObj, + 100: targetObj, + length: -6e-1 +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, targetObj), -1, 'SendableArray.prototype.indexOf.call(obj, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-11.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-11.js new file mode 100644 index 0000000000000000000000000000000000000000..9e1266e85831b2f6af2f8c43d6d9a2ba2941e0e6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-11.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - 'length' is an empty string +---*/ + +var targetObj = []; +var obj = { + 0: targetObj, + 100: targetObj, + length: "" +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, targetObj), -1, 'SendableArray.prototype.indexOf.call(obj, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-2.js new file mode 100644 index 0000000000000000000000000000000000000000..322ef0e29d962c65bc4e164e67e773ff308d5ee9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 if 'length' is 0 ( length + overridden to null (type conversion)) +---*/ + +var i = SendableArray.prototype.indexOf.call({ + length: null +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-3.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..63f5ffd3494b6fae196cf1e7dbe3189e56abc14e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-3.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 if 'length' is 0 (length + overridden to false (type conversion)) +---*/ + +var i = SendableArray.prototype.indexOf.call({ + length: false +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-4.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..3cabf2f392132b418b0c1cc3bf74bb16db512a7b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-4.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 if 'length' is 0 (generic + 'array' with length 0 ) +---*/ + +var i = SendableArray.prototype.indexOf.call({ + length: 0 +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-5.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-5.js new file mode 100644 index 0000000000000000000000000000000000000000..df32f58a8782bd5d4a06f26b234f7591eaa67d81 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-5.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 if 'length' is 0 ( length + overridden to '0' (type conversion)) +---*/ + +var i = SendableArray.prototype.indexOf.call({ + length: '0' +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-6.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-6.js new file mode 100644 index 0000000000000000000000000000000000000000..e16aa662ab37a42d06b6616dbf782227c86239d0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-6.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 if 'length' is 0 (subclassed + Array, length overridden with obj with valueOf) +---*/ + +var i = SendableArray.prototype.indexOf.call({ + length: { + valueOf: function() { + return 0; + } + } +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-7.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-7.js new file mode 100644 index 0000000000000000000000000000000000000000..fb8df3d82632e4d47cd12b8b3be098c6523d6c69 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-7.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 if 'length' is 0 ( length is + object overridden with obj w/o valueOf (toString)) +---*/ + +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +var i = SendableArray.prototype.indexOf.call({ + length: { + toString: function() { + return '0'; + } + } +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-8.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-8.js new file mode 100644 index 0000000000000000000000000000000000000000..2e6e0193e2e6d3ef3ece7b61712f99f45c948b27 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-8.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 if 'length' is 0 (length is an + empty array) +---*/ + +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +var i = SendableArray.prototype.indexOf.call({ + length: [] +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-9.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-9.js new file mode 100644 index 0000000000000000000000000000000000000000..cca2badc7f40d9d290283939d6a9526c12d1d736 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-4-9.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - 'length' is a number of value 0.1 +---*/ + +var targetObj = []; +var obj = { + 0: targetObj, + 100: targetObj, + length: 0.1 +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, targetObj), -1, 'SendableArray.prototype.indexOf.call(obj, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..cfa6070d7cae16933d4bb3e898a77bf470ac9f01 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf when fromIndex is string +---*/ + +var a = [1, 2, 1, 2, 1, 2]; +assert.sameValue(a.indexOf(2, "2"), 3, '"2" resolves to 2'); +assert.sameValue(a.indexOf(2, "one"), 1, '"one" resolves to 0'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-10.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-10.js new file mode 100644 index 0000000000000000000000000000000000000000..83796e455a9ffa936071a65aa4e73fd6a7938830 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-10.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a number (value + is positive number) +---*/ + +var targetObj = {}; +assert.sameValue([0, targetObj, 2].indexOf(targetObj, 2), -1, '[0, targetObj, 2].indexOf(targetObj, 2)'); +assert.sameValue([0, 1, targetObj].indexOf(targetObj, 2), 2, '[0, 1, targetObj].indexOf(targetObj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-11.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-11.js new file mode 100644 index 0000000000000000000000000000000000000000..7f3d2999bef24e1368966ff877465d0ef080f894 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-11.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a number (value + is negative number) +---*/ + +var targetObj = {}; +assert.sameValue([0, targetObj, 2].indexOf(targetObj, -1), -1, '[0, targetObj, 2].indexOf(targetObj, -1)'); +assert.sameValue([0, 1, targetObj].indexOf(targetObj, -1), 2, '[0, 1, targetObj].indexOf(targetObj, -1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-12.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-12.js new file mode 100644 index 0000000000000000000000000000000000000000..9ffe24099257d9d50ab2f115d1a327d9cd441962 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-12.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a number (value + is Infinity) +---*/ + +var arr = []; +arr[Math.pow(2, 32) - 2] = true; //length is the max value of Uint type +assert.sameValue(arr.indexOf(true, Infinity), -1, 'arr.indexOf(true, Infinity)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-13.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-13.js new file mode 100644 index 0000000000000000000000000000000000000000..7b8577844c4634fc5278a882010c2da4e19b4d72 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-13.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a number (value + is -Infinity) +---*/ + +assert.sameValue([true].indexOf(true, -Infinity), 0, '[true].indexOf(true, -Infinity)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-14.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-14.js new file mode 100644 index 0000000000000000000000000000000000000000..a75911a00d5ad151743573f7df88b310dfce3c62 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-14.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a number (value + is NaN) +---*/ + +assert.sameValue([true].indexOf(true, NaN), 0, '[true].indexOf(true, NaN)'); +assert.sameValue([true].indexOf(true, -NaN), 0, '[true].indexOf(true, -NaN)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-15.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-15.js new file mode 100644 index 0000000000000000000000000000000000000000..2c76fa9032ccfc8aacf055f1c88ae392e42cf079 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-15.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a string + containing a negative number +---*/ + +assert.sameValue([0, true, 2].indexOf(true, "-1"), -1, '[0, true, 2].indexOf(true, "-1")'); +assert.sameValue([0, 1, true].indexOf(true, "-1"), 2, '[0, 1, true].indexOf(true, "-1")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-16.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-16.js new file mode 100644 index 0000000000000000000000000000000000000000..95c072702513c63e37f07ba26f6a555f41e39de9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-16.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a string + containing Infinity +---*/ + +var arr = []; +arr[Math.pow(2, 32) - 2] = true; //length is the max value of Uint type +assert.sameValue(arr.indexOf(true, "Infinity"), -1, 'arr.indexOf(true, "Infinity")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-17.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-17.js new file mode 100644 index 0000000000000000000000000000000000000000..87f31555ea88576e510454e306bf5337a8382a1c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-17.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a string + containing -Infinity +---*/ + +assert.sameValue([true].indexOf(true, "-Infinity"), 0, '[true].indexOf(true, "-Infinity")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-18.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-18.js new file mode 100644 index 0000000000000000000000000000000000000000..8643864b289efe963a62151c64e06e938dccd67e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-18.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a string + containing an exponential number +---*/ + +var targetObj = {}; +assert.sameValue([0, 1, targetObj, 3, 4].indexOf(targetObj, "3E0"), -1, '[0, 1, targetObj, 3, 4].indexOf(targetObj, "3E0")'); +assert.sameValue([0, 1, 2, targetObj, 4].indexOf(targetObj, "3E0"), 3, '[0, 1, 2, targetObj, 4].indexOf(targetObj, "3E0")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-19.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-19.js new file mode 100644 index 0000000000000000000000000000000000000000..4ea193f3583b3afdb633952bbdd918cd2d5f4dfc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-19.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a string + containing a hex number +---*/ + +var targetObj = {}; +assert.sameValue([0, 1, targetObj, 3, 4].indexOf(targetObj, "0x0003"), -1, '[0, 1, targetObj, 3, 4].indexOf(targetObj, "0x0003")'); +assert.sameValue([0, 1, 2, targetObj, 4].indexOf(targetObj, "0x0003"), 3, '[0, 1, 2, targetObj, 4].indexOf(targetObj, "0x0003")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-2.js new file mode 100644 index 0000000000000000000000000000000000000000..f0748b2fcf23a2d909aa7dfbf2efc3597440d930 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-2.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf when fromIndex is floating point number +---*/ + +var a = new SendableArray(1, 2, 3); +assert.sameValue(a.indexOf(3, 0.49), 2, '0.49 resolves to 0'); +assert.sameValue(a.indexOf(1, 0.51), 0, '0.51 resolves to 0'); +assert.sameValue(a.indexOf(1, 1.51), -1, '1.51 resolves to 1'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-20.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-20.js new file mode 100644 index 0000000000000000000000000000000000000000..7c01e669be7cabfebfd65f3ee5fcedd495be7492 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-20.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' which is a string + containing a number with leading zeros +---*/ + +var targetObj = {}; +assert.sameValue([0, 1, targetObj, 3, 4].indexOf(targetObj, "0003.10"), -1, '[0, 1, targetObj, 3, 4].indexOf(targetObj, "0003.10")'); +assert.sameValue([0, 1, 2, targetObj, 4].indexOf(targetObj, "0003.10"), 3, '[0, 1, 2, targetObj, 4].indexOf(targetObj, "0003.10")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-21.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-21.js new file mode 100644 index 0000000000000000000000000000000000000000..772334754c35c459f1fdc32310411a60ae524fef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-21.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is an Object, which + has an own toString method +---*/ + +// objects inherit the default valueOf() method from Object +// that simply returns itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +var fromIndex = { + toString: function() { + return '1'; + } +}; +assert.sameValue([0, true].indexOf(true, fromIndex), 1, '[0, true].indexOf(true, fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-22.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-22.js new file mode 100644 index 0000000000000000000000000000000000000000..e70c3446d0a12eb059ac8e4c098e6151a9dc54ae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-22.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is an Object, which + has an own valueOf method +---*/ + +var fromIndex = { + valueOf: function() { + return 1; + } +}; +assert.sameValue([0, true].indexOf(true, fromIndex), 1, '[0, true].indexOf(true, fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-23.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-23.js new file mode 100644 index 0000000000000000000000000000000000000000..98fe576f4223830a3a7e3e1934b07951f443d0bc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-23.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is an object that + has an own valueOf method that returns an object and toString + method that returns a string +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var fromIndex = { + toString: function() { + toStringAccessed = true; + return '1'; + }, + valueOf: function() { + valueOfAccessed = true; + return {}; + } +}; +assert.sameValue([0, true].indexOf(true, fromIndex), 1, '[0, true].indexOf(true, fromIndex)'); +assert(toStringAccessed, 'toStringAccessed !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-24.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-24.js new file mode 100644 index 0000000000000000000000000000000000000000..9181c63d0eae9109c697300846f130400bfa069a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-24.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf throws TypeError exception when value of + 'fromIndex' is an object with toString and valueOf methods that + don�t return primitive values +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var fromIndex = { + toString: function() { + toStringAccessed = true; + return {}; + }, + valueOf: function() { + valueOfAccessed = true; + return {}; + } +}; +assert.throws(TypeError, function() { + [0, true].indexOf(true, fromIndex); +}); +assert(toStringAccessed, 'toStringAccessed'); +assert(valueOfAccessed, 'valueOfAccessed'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-25.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-25.js new file mode 100644 index 0000000000000000000000000000000000000000..4669ff38b5e2c19328e0d0481eb6bbcb4b7cc4e0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-25.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf uses inherited valueOf method when value + of 'fromIndex' is an object with an own toString and inherited + valueOf methods +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var proto = { + valueOf: function() { + valueOfAccessed = true; + return 1; + } +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.toString = function() { + toStringAccessed = true; + return 2; +}; +assert.sameValue([0, true].indexOf(true, child), 1, '[0, true].indexOf(true, child)'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(toStringAccessed, false, 'toStringAccessed'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-26.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-26.js new file mode 100644 index 0000000000000000000000000000000000000000..d83bccafda9acc41cdb4be9bd29370ce78014479 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-26.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - side effects produced by step 2 are + visible when an exception occurs +---*/ + +var stepTwoOccurs = false; +var stepFiveOccurs = false; +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + stepTwoOccurs = true; + if (stepFiveOccurs) { + throw new Error("Step 5 occurred out of order"); + } + return 20; + }, + configurable: true +}); +var fromIndex = { + valueOf: function() { + stepFiveOccurs = true; + return 0; + } +}; +SendableArray.prototype.indexOf.call(obj, undefined, fromIndex); +assert(stepTwoOccurs, 'stepTwoOccurs !== true'); +assert(stepFiveOccurs, 'stepFiveOccurs !== true'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-27.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-27.js new file mode 100644 index 0000000000000000000000000000000000000000..0cbe926612871b6771670ebaa47008178f47b8a3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-27.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - side effects produced by step 3 are + visible when an exception occurs +---*/ + +var stepThreeOccurs = false; +var stepFiveOccurs = false; +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return { + valueOf: function() { + stepThreeOccurs = true; + if (stepFiveOccurs) { + throw new Error("Step 5 occurred out of order"); + } + return 20; + } + }; + }, + configurable: true +}); +var fromIndex = { + valueOf: function() { + stepFiveOccurs = true; + return 0; + } +}; +SendableArray.prototype.indexOf.call(obj, undefined, fromIndex); +assert(stepThreeOccurs, 'stepThreeOccurs !== true'); +assert(stepFiveOccurs, 'stepFiveOccurs !== true'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-28.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-28.js new file mode 100644 index 0000000000000000000000000000000000000000..768a459e288d40ab759ed342300bb2773911d201 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-28.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - side effects produced by step 1 are + visible when an exception occurs +---*/ + +var stepFiveOccurs = false; +var fromIndex = { + valueOf: function() { + stepFiveOccurs = true; + return 0; + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.indexOf.call(undefined, undefined, fromIndex); +}); +assert.sameValue(stepFiveOccurs, false, 'stepFiveOccurs'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-29.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-29.js new file mode 100644 index 0000000000000000000000000000000000000000..7ca8affaf0b8b3f6d01ea5713ab7a9fae157fd22 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-29.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - side effects produced by step 2 are + visible when an exception occurs +---*/ + +var stepFiveOccurs = false; +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new RangeError(); + }, + configurable: true +}); +var fromIndex = { + valueOf: function() { + stepFiveOccurs = true; + return 0; + } +}; +assert.throws(RangeError, function() { + SendableArray.prototype.indexOf.call(obj, undefined, fromIndex); +}); +assert.sameValue(stepFiveOccurs, false, 'stepFiveOccurs'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-3.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-3.js new file mode 100644 index 0000000000000000000000000000000000000000..db566b7c8e0d0809794d7bad7676e7e9d20d7199 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-3.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf when fromIndex is boolean +---*/ + +var a = [1, 2, 3]; +assert.sameValue(a.indexOf(1, true), -1, 'true resolves to 1'); +assert.sameValue(a.indexOf(1, false), 0, 'false resolves to 0'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-30.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-30.js new file mode 100644 index 0000000000000000000000000000000000000000..e544bedd7063368d0bbdc2e673cf7707dd2c7aa4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-30.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - side effects produced by step 3 are + visible when an exception occurs +---*/ + +var stepFiveOccurs = false; +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return { + valueOf: function() { + throw new TypeError(); + } + }; + }, + configurable: true +}); +var fromIndex = { + valueOf: function() { + stepFiveOccurs = true; + return 0; + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.indexOf.call(obj, undefined, fromIndex); +}); +assert.sameValue(stepFiveOccurs, false, 'stepFiveOccurs'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-31.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-31.js new file mode 100644 index 0000000000000000000000000000000000000000..83d5f260abb0040025903d7523c673d39b9f30d3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-31.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'fromIndex' is a positive non-integer, + verify truncation occurs in the proper direction +---*/ +var targetObj = {}; +assert.sameValue([0, targetObj, 2].indexOf(targetObj, 2.5), -1, '[0, targetObj, 2].indexOf(targetObj, 2.5)'); +assert.sameValue([0, 1, targetObj].indexOf(targetObj, 2.5), 2, '[0, 1, targetObj].indexOf(targetObj, 2.5)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-32.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-32.js new file mode 100644 index 0000000000000000000000000000000000000000..5ed7021faef9ad9bf6c76a5dc75516d5668d3235 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-32.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - 'fromIndex' is a negative non-integer, + verify truncation occurs in the proper direction +---*/ + +var targetObj = {}; +assert.sameValue([0, targetObj, 2].indexOf(targetObj, -1.5), -1, '[0, targetObj, 2].indexOf(targetObj, -1.5)'); +assert.sameValue([0, 1, targetObj].indexOf(targetObj, -1.5), 2, '[0, 1, targetObj].indexOf(targetObj, -1.5)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-33.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-33.js new file mode 100644 index 0000000000000000000000000000000000000000..7f91ee7e1527c65b1b3f4fe2b08cd6d3af12ba77 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-33.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf match on the first element, a middle + element and the last element when 'fromIndex' is passed +---*/ + +assert.sameValue([0, 1, 2, 3, 4].indexOf(0, 0), 0, '[0, 1, 2, 3, 4].indexOf(0, 0)'); +assert.sameValue([0, 1, 2, 3, 4].indexOf(2, 1), 2, '[0, 1, 2, 3, 4].indexOf(2, 1)'); +assert.sameValue([0, 1, 2, 3, 4].indexOf(2, 2), 2, '[0, 1, 2, 3, 4].indexOf(2, 2)'); +assert.sameValue([0, 1, 2, 3, 4].indexOf(4, 2), 4, '[0, 1, 2, 3, 4].indexOf(4, 2)'); +assert.sameValue([0, 1, 2, 3, 4].indexOf(4, 4), 4, '[0, 1, 2, 3, 4].indexOf(4, 4)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-4.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-4.js new file mode 100644 index 0000000000000000000000000000000000000000..2102fbb686a7dc283f2261698c99f09ab7915236 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-4.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf returns 0 if fromIndex is 'undefined' +---*/ + +var a = [1, 2, 3]; +// undefined resolves to 0 +assert.sameValue(a.indexOf(1, undefined), 0, 'a.indexOf(1,undefined)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-5.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-5.js new file mode 100644 index 0000000000000000000000000000000000000000..d43ef22b78175868350ed67a02703d53091c88df --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-5.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf returns 0 if fromIndex is null +---*/ + +var a = [1, 2, 3]; +// null resolves to 0 +assert.sameValue(a.indexOf(1, null), 0, 'a.indexOf(1,null)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-6.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-6.js new file mode 100644 index 0000000000000000000000000000000000000000..046eb537c22f4ec0064871e4b70093e918a3f319 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-6.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - 'fromIndex' isn't passed +---*/ + +var arr = [0, 1, 2, 3, 4]; +//'fromIndex' will be set as 0 if not passed by default +assert.sameValue(arr.indexOf(0), arr.indexOf(0, 0), 'arr.indexOf(0)'); +assert.sameValue(arr.indexOf(2), arr.indexOf(2, 0), 'arr.indexOf(2)'); +assert.sameValue(arr.indexOf(4), arr.indexOf(4, 0), 'arr.indexOf(4)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-7.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-7.js new file mode 100644 index 0000000000000000000000000000000000000000..866ee13d71d01f82650d1e350dfd9db471f3e6c7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-7.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a number (value + is 0) +---*/ + +assert.sameValue([true].indexOf(true, 0), 0, '[true].indexOf(true, 0)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-8.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-8.js new file mode 100644 index 0000000000000000000000000000000000000000..f997b0185d5a79d9dc3a040668352ef4ef6f9fd9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-8.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a number (value + is +0) +---*/ + +assert.sameValue([true].indexOf(true, +0), 0, '[true].indexOf(true, +0)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-9.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-9.js new file mode 100644 index 0000000000000000000000000000000000000000..dace812d5b4bc833e226a6637c6ac8d54b312b88 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-5-9.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - value of 'fromIndex' is a number (value + is -0) +---*/ + +assert.sameValue([true].indexOf(true, -0), 0, '[true].indexOf(true, -0)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-6-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-6-1.js new file mode 100644 index 0000000000000000000000000000000000000000..8fba94ed59ccf533d85e5342d8e59e33a54bb670 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-6-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 if fromIndex is greater than + Array length +---*/ + +var a = [1, 2, 3]; +assert.sameValue(a.indexOf(1, 5), -1, 'a.indexOf(1,5)'); +assert.sameValue(a.indexOf(1, 3), -1, 'a.indexOf(1,3)'); +assert.sameValue([].indexOf(1, 0), -1, '[ ].indexOf(1,0)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-1.js new file mode 100644 index 0000000000000000000000000000000000000000..8714701d0fdc2b46a6c9f1387e4f4521260aaabe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 when 'fromIndex' is length of + array - 1 +---*/ + +assert.sameValue([1, 2, 3].indexOf(1, 2), -1, '[1, 2, 3].indexOf(1, 2)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-2.js new file mode 100644 index 0000000000000000000000000000000000000000..6a1b3846371207839130efc29a69c7775e5ead36 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns correct index when 'fromIndex' is + length of array - 1 +---*/ + +assert.sameValue([1, 2, 3].indexOf(3, 2), 2, '[1, 2, 3].indexOf(3, 2)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-3.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-3.js new file mode 100644 index 0000000000000000000000000000000000000000..d721d920f5605c8de85eb0f2e324e0943469e6bd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-3.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 when 'fromIndex' and 'length' + are both 0 +---*/ + +assert.sameValue([].indexOf(1, 0), -1, '[].indexOf(1, 0)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-4.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-4.js new file mode 100644 index 0000000000000000000000000000000000000000..9280f1a116ff65fc3bf80002ad6c925db173c6c9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-4.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf returns -1 when 'fromIndex' is 1 +---*/ + +assert.sameValue([1, 2, 3].indexOf(1, 1), -1, '[1, 2, 3].indexOf(1, 1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-5.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-5.js new file mode 100644 index 0000000000000000000000000000000000000000..dfc9f3765171d7933a6fe74d11986aa317fb7f1d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-7-5.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf returns correct index when 'fromIndex' is 1 +---*/ + +assert.sameValue([1, 2, 3].indexOf(2, 1), 1, '[1, 2, 3].indexOf(2, 1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-1.js new file mode 100644 index 0000000000000000000000000000000000000000..743de311f9d476dfda372653fb05f39334f7da28 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-1.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf with negative fromIndex +---*/ + +var a = new SendableArray(1, 2, 3); +assert.sameValue(a.indexOf(2, -1), -1, 'a.indexOf(2,-1)'); +assert.sameValue(a.indexOf(2, -2), 1, 'a.indexOf(2,-2)'); +assert.sameValue(a.indexOf(1, -3), 0, 'a.indexOf(1,-3)'); +assert.sameValue(a.indexOf(1, -5.3), 0, 'a.indexOf(1,-5.3)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-2.js new file mode 100644 index 0000000000000000000000000000000000000000..29e89a810dde21e7d2f1dd5c4f614907bdf1c715 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns correct index when 'fromIndex' is + -1 +---*/ + +assert.sameValue([1, 2, 3, 4].indexOf(4, -1), 3, '[1, 2, 3, 4].indexOf(4, -1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-3.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-3.js new file mode 100644 index 0000000000000000000000000000000000000000..727571d431e4dfd172560c06814d67d723d67683 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-3.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 when abs('fromIndex') is length + of array - 1 +---*/ + +assert.sameValue([1, 2, 3, 4].indexOf(1, -3), -1, '[1, 2, 3, 4].indexOf(1, -3)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-4.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-4.js new file mode 100644 index 0000000000000000000000000000000000000000..5b0625f6e1eaf91a12dfe4a341f94f5a9f0641c2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-8-4.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf returns -1 when abs('fromIndex') is length + of array +---*/ + +assert.sameValue([1, 2, 3, 4].indexOf(0, -4), -1, '[1, 2, 3, 4].indexOf(0, -4)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-1.js new file mode 100644 index 0000000000000000000000000000000000000000..c35c70f7f3a0ada7bcdf9e8efdbffe883de91975 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-1.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf must return correct index (boolean) +---*/ + +var obj = { + toString: function() { + return true + } +}; +var _false = false; +var a = [obj, "true", undefined, 0, _false, null, 1, "str", 0, 1, true, false, true, false]; +assert.sameValue(a.indexOf(true), 10, 'a[10]=true'); +assert.sameValue(a.indexOf(false), 4, 'a[4] =_false'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-10.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-10.js new file mode 100644 index 0000000000000000000000000000000000000000..0dea4088890dd4033adcf3361cb66a5713393fb2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-10.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + note that prior to the finally ES5 draft SameValue was used for comparisions + and hence NaNs could be found using indexOf * +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf must return correct index (NaN) +---*/ + +var _NaN = NaN; +var a = new SendableArray("NaN", undefined, 0, false, null, { + toString: function() { + return NaN + } +}, "false", _NaN, NaN); +assert.sameValue(a.indexOf(NaN), -1, 'NaN is equal to nothing, including itself.'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-11.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-11.js new file mode 100644 index 0000000000000000000000000000000000000000..88217c37793df4b45c3da767abdc02a8f74baa9d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-11.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - the length of iteration isn't changed by + adding elements to the array during iteration +---*/ + +var arr = [20]; +Object.defineProperty(arr, "0", { + get: function() { + arr[1] = 1; + return 0; + }, + configurable: true +}); +assert.sameValue(arr.indexOf(1), -1, 'arr.indexOf(1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-2.js new file mode 100644 index 0000000000000000000000000000000000000000..8f67b0cc0d708f9103d5af09393cd628b3f7d0c9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf must return correct index (Number) +---*/ + +var obj = { + toString: function() { + return 0 + } +}; +var one = 1; +var _float = -(4 / 3); +var a = new SendableArray(false, undefined, null, "0", obj, -1.3333333333333, "str", -0, true, +0, one, 1, 0, false, _float, -(4 / 3)); +assert.sameValue(a.indexOf(-(4 / 3)), 14, 'a[14]=_float===-(4/3)'); +assert.sameValue(a.indexOf(0), 7, 'a[7] = +0, 0===+0'); +assert.sameValue(a.indexOf(-0), 7, 'a[7] = +0, -0===+0'); +assert.sameValue(a.indexOf(1), 10, 'a[10] =one=== 1'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-3.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-3.js new file mode 100644 index 0000000000000000000000000000000000000000..0c462ffb93513b4f748c73c3ef39bc92f95ec0b8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-3.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf must return correct index(string) +---*/ + +var obj = { + toString: function() { + return "false" + } +}; +var szFalse = "false"; +var a = new SendableArray("false1", undefined, 0, false, null, 1, obj, 0, szFalse, "false"); +assert.sameValue(a.indexOf("false"), 8, 'a[8]=szFalse'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-4.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-4.js new file mode 100644 index 0000000000000000000000000000000000000000..9513f0510d5c484d840f6fbec9db4b69325ffa83 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf must return correct index(undefined) +---*/ + +var obj = { + toString: function() { + return undefined; + } +}; +var _undefined1 = undefined; +var _undefined2; +var a = new SendableArray(true, 0, false, null, 1, "undefined", obj, 1, _undefined2, _undefined1, undefined); +assert.sameValue(a.indexOf(undefined), 8, 'a[8]=_undefined2'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-5.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-5.js new file mode 100644 index 0000000000000000000000000000000000000000..0cb30d903101b30e9a474b9057151c594fa9bb70 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-5.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf must return correct index (Object) +---*/ + +var obj1 = { + toString: function() { + return "false" + } +}; +var obj2 = { + toString: function() { + return "false" + } +}; +var obj3 = obj1; +var a = new SendableArray(false, undefined, 0, false, null, { + toString: function() { + return "false" + } +}, "false", obj2, obj1, obj3); +assert.sameValue(a.indexOf(obj3), 8, 'a[8] = obj1'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-6.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-6.js new file mode 100644 index 0000000000000000000000000000000000000000..be17e7f80f2dd76795edc1b6bd9695fa9d48e6a2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-6.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf must return correct index(null) +---*/ + +var obj = { + toString: function() { + return null + } +}; +var _null = null; +var a = new SendableArray(true, undefined, 0, false, _null, 1, "str", 0, 1, obj, true, false, null); +assert.sameValue(a.indexOf(null), 4, 'a[4]=_null'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-7.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-7.js new file mode 100644 index 0000000000000000000000000000000000000000..4f178232f6b19ac41569f0c0e80c457e407599fe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-7.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf must return correct index (self reference) +---*/ + +var a = new SendableArray(0, 1, 2, 3); +a[2] = a; +assert.sameValue(a.indexOf(a), 2, 'a.indexOf(a)'); +assert.sameValue(a.indexOf(3), 3, 'a.indexOf(3)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-8.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-8.js new file mode 100644 index 0000000000000000000000000000000000000000..9bb19492ede08dba12534c49354e74e45b500de0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-8.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf must return correct index (Array) +---*/ + +var b = new SendableArray("0,1"); +var a = new SendableArray(0, b, "0,1", 3); +assert.sameValue(a.indexOf(b.toString()), 2, 'a.indexOf(b.toString())'); +assert.sameValue(a.indexOf("0,1"), 2, 'a.indexOf("0,1")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-9.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-9.js new file mode 100644 index 0000000000000000000000000000000000000000..4a55156c7a765dccfcfe67ba2c9403ae0106cd55 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-9.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf must return correct index (Sparse Array) +---*/ + +var a = new SendableArray(0, 1); +a[4294967294] = 2; // 2^32-2 - is max array element +a[4294967295] = 3; // 2^32-1 added as non-array element property +a[4294967296] = 4; // 2^32 added as non-array element property +a[4294967297] = 5; // 2^32+1 added as non-array element property +// start searching near the end so in case implementation actually tries to test all missing elements!! +assert.sameValue(a.indexOf(2, 4294967290), 4294967294, 'a.indexOf(2,4294967290 )'); +assert.sameValue(a.indexOf(3, 4294967290), -1, 'a.indexOf(3,4294967290)'); +assert.sameValue(a.indexOf(4, 4294967290), -1, 'a.indexOf(4,4294967290)'); +assert.sameValue(a.indexOf(5, 4294967290), -1, 'a.indexOf(5,4294967290)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-1.js new file mode 100644 index 0000000000000000000000000000000000000000..3f3d892eb64a078bf0cff6328cdf0a9aaacfeffc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - added properties in step 2 are visible + here +---*/ + +var arr = {}; +Object.defineProperty(arr, "length", { + get: function() { + arr[2] = "length"; + return 3; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(arr, "length"), 2, 'SendableArray.prototype.indexOf.call(arr, "length")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-10.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-10.js new file mode 100644 index 0000000000000000000000000000000000000000..b40fae5885483317e80d295d75a9e45d605a53bc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-10.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - properties can be added to prototype + after current position are visited on an Array +---*/ + +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(arr.indexOf(6.99), 1, 'arr.indexOf(6.99)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-11.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-11.js new file mode 100644 index 0000000000000000000000000000000000000000..68ac0b71f586908aa90ab1b3aac68d01218c87ac --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-11.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - deleting own property causes index + property not to be visited on an Array-like object +---*/ + +var arr = { + length: 2 +}; +Object.defineProperty(arr, "1", { + get: function() { + return 6.99; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(arr, 6.99), -1, 'SendableArray.prototype.indexOf.call(arr, 6.99)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-12.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-12.js new file mode 100644 index 0000000000000000000000000000000000000000..fb32f1c37c5784eb04b6f8e4f63f00ab74818208 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-12.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - deleting own property causes index + property not to be visited on an Array +---*/ + +var arr = [1, 2]; +Object.defineProperty(arr, "1", { + get: function() { + return "6.99"; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +assert.sameValue(arr.indexOf("6.99"), -1, 'arr.indexOf("6.99")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-13.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-13.js new file mode 100644 index 0000000000000000000000000000000000000000..dce2d961a42b57d1f06910b57af6f55590c98c69 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-13.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - deleting property of prototype causes + prototype index property not to be visited on an Array-like Object +---*/ + +var arr = { + 2: 2, + length: 20 +}; +Object.defineProperty(arr, "0", { + get: function() { + delete Object.prototype[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +assert.sameValue(SendableArray.prototype.indexOf.call(arr, 1), -1, 'SendableArray.prototype.indexOf.call(arr, 1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-14.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-14.js new file mode 100644 index 0000000000000000000000000000000000000000..7213ff063bef0ae41b5f7856aff097b84d33cf87 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-14.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - deleting property of prototype causes + prototype index property not to be visited on an Array +---*/ + +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + delete SendableArray.prototype[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +assert.sameValue(arr.indexOf(1), -1, 'arr.indexOf(1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-15.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-15.js new file mode 100644 index 0000000000000000000000000000000000000000..14da09fe8c3e14961408d8e5bebfeda813d54670 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-15.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - deleting own property with prototype + property causes prototype index property to be visited on an + Array-like object +---*/ + +var arr = { + 0: 0, + 1: 111, + 2: 2, + length: 10 +}; +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +assert.sameValue(SendableArray.prototype.indexOf.call(arr, 1), 1, 'SendableArray.prototype.indexOf.call(arr, 1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-16.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-16.js new file mode 100644 index 0000000000000000000000000000000000000000..9b1a10926969313b3a2ef2044077b40427065b5e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-16.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - deleting own property with prototype + property causes prototype index property to be visited on an Array +---*/ + +var arr = [0, 111, 2]; +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +assert.sameValue(arr.indexOf(1), 1, 'arr.indexOf(1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-17.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-17.js new file mode 100644 index 0000000000000000000000000000000000000000..5ff0551d7c93545f828afdd47b2b4258369828ba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-17.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - decreasing length of array causes index + property not to be visited +---*/ + +var arr = [0, 1, 2, "last"]; +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 3; + return 0; + }, + configurable: true +}); +assert.sameValue(arr.indexOf("last"), -1, 'arr.indexOf("last")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-18.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-18.js new file mode 100644 index 0000000000000000000000000000000000000000..085edf9c46a6d5b31e34197dc5aed6752ff6ec06 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-18.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - decreasing length of array with + prototype property causes prototype index property to be visited +---*/ + +var arr = [0, 1, 2]; +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return "prototype"; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +assert.sameValue(arr.indexOf("prototype"), 2, 'arr.indexOf("prototype")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-19.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-19.js new file mode 100644 index 0000000000000000000000000000000000000000..612d091b0b92623f9c4f4c9e6e4577150bab5a06 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-19.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - decreasing length of array does not + delete non-configurable properties +flags: [noStrict] +---*/ + +var arr = [0, 1, 2]; +Object.defineProperty(arr, "2", { + get: function() { + return "unconfigurable"; + }, + configurable: false +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +assert.sameValue(arr.indexOf("unconfigurable"), 2, 'arr.indexOf("unconfigurable")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-2.js new file mode 100644 index 0000000000000000000000000000000000000000..84065561eb58bb89ef2b7b32c4f1c05acbc05c4e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-2.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - added properties in step 5 are visible + here on an Array-like object +---*/ + +var arr = { + length: 30 +}; +var targetObj = function() {}; +var fromIndex = { + valueOf: function() { + arr[4] = targetObj; + return 3; + } +}; +assert.sameValue(SendableArray.prototype.indexOf.call(arr, targetObj, fromIndex), 4, 'SendableArray.prototype.indexOf.call(arr, targetObj, fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-3.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-3.js new file mode 100644 index 0000000000000000000000000000000000000000..04e6c66d7635664d03cb05889782f61998fc0e27 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - added properties in step 5 are visible + here on an Array +---*/ + +var arr = []; +arr.length = 30; +var targetObj = function() {}; +var fromIndex = { + valueOf: function() { + arr[4] = targetObj; + return 3; + } +}; +assert.sameValue(arr.indexOf(targetObj, fromIndex), 4, 'arr.indexOf(targetObj, fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-4.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-4.js new file mode 100644 index 0000000000000000000000000000000000000000..aecfe87a56cddeca084e7d75fba26c9c248ce269 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-4.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - deleted properties in step 2 are visible + here +---*/ + +var arr = { + 2: 6.99 +}; +Object.defineProperty(arr, "length", { + get: function() { + delete arr[2]; + return 3; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(arr, 6.99), -1, 'SendableArray.prototype.indexOf.call(arr, 6.99)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-5.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-5.js new file mode 100644 index 0000000000000000000000000000000000000000..f82480b57a8927a13b16114928a24cb30e931ac8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-5.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - deleted properties in step 5 are visible + here on an Array-like object +---*/ + +var arr = { + 10: false, + length: 30 +}; +var fromIndex = { + valueOf: function() { + delete arr[10]; + return 3; + } +}; +assert.sameValue(SendableArray.prototype.indexOf.call(arr, false, fromIndex), -1, 'SendableArray.prototype.indexOf.call(arr, false, fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-6.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-6.js new file mode 100644 index 0000000000000000000000000000000000000000..155a53d8386e24e4fa1be5bbf7d3343b91a22f51 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-6.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - deleted properties in step 5 are visible + here on an Array +---*/ + +var arr = []; +arr[10] = "10"; +arr.length = 20; +var fromIndex = { + valueOf: function() { + delete arr[10]; + return 3; + } +}; +assert.sameValue(arr.indexOf("10", fromIndex), -1, 'arr.indexOf("10", fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-7.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-7.js new file mode 100644 index 0000000000000000000000000000000000000000..83e927c114d5636721502ef76e4c136fe08df261 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-7.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - properties added into own object after + current position are visited on an Array-like object +---*/ + +var arr = { + length: 2 +}; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(arr, 1), 1, 'SendableArray.prototype.indexOf.call(arr, 1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-8.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-8.js new file mode 100644 index 0000000000000000000000000000000000000000..381ae64b014cac9d645eb8ca424fc4ce09a6f8ba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-8.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - properties added into own object after + current position are visited on an Array +---*/ + +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(arr.indexOf(1), 1, 'arr.indexOf(1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-9.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-9.js new file mode 100644 index 0000000000000000000000000000000000000000..d0c91cdfc32660383fff54df5418281f6eced048 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-a-9.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - properties can be added to prototype + after current position are visited on an Array-like object +---*/ + +var arr = { + length: 2 +}; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(Object.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(arr, 6.99), 1, 'SendableArray.prototype.indexOf.call(arr, 6.99)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..cb212c6c5810c3a68aa35768cfdcfbd086926a19 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-1.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - non-existent property wouldn't be called +---*/ + +assert.sameValue([0, , 2].indexOf(undefined), -1, '[0, , 2].indexOf(undefined)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-1.js new file mode 100644 index 0000000000000000000000000000000000000000..f3ec14f21c555e2d1ed1e2a72de263f689f250a4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own data + property on an Array-like object +---*/ + +var obj = { + 0: 0, + 1: 1, + 2: 2, + length: 3 +}; +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 0), 0, 'SendableArray.prototype.indexOf.call(obj, 0)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 1), 1, 'SendableArray.prototype.indexOf.call(obj, 1)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 2), 2, 'SendableArray.prototype.indexOf.call(obj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-10.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-10.js new file mode 100644 index 0000000000000000000000000000000000000000..6b7a97ced5c12fcaa47d35c900b3f3b507dacc4e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-10.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own accessor + property on an Array-like object +---*/ + +var obj = { + length: 3 +}; +Object.defineProperty(obj, "0", { + get: function() { + return 0; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + return 1; + }, + configurable: true +}); +Object.defineProperty(obj, "2", { + get: function() { + return 2; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 0), 0, 'SendableArray.prototype.indexOf.call(obj, 0)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 1), 1, 'SendableArray.prototype.indexOf.call(obj, 1)'); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, 2), 2, 'SendableArray.prototype.indexOf.call(obj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-11.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-11.js new file mode 100644 index 0000000000000000000000000000000000000000..0b9d53237f1bbfa7602a0f0eaa02cfe0e08b51b0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-11.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own accessor + property that overrides an inherited data property on an Array +---*/ + +var arr = []; +SendableArray.prototype[0] = false; +Object.defineProperty(arr, "0", { + get: function() { + return true; + }, + configurable: true +}); +assert.sameValue(arr.indexOf(true), 0, 'arr.indexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-12.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-12.js new file mode 100644 index 0000000000000000000000000000000000000000..8eecdb0ec941c8f8f189f86fb4065320d4866b7e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-12.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own accessor + property that overrides an inherited data property on an + Array-like object +---*/ + +var obj = { + length: 1 +}; +Object.prototype[0] = false; +Object.defineProperty(obj, "0", { + get: function() { + return true; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 0, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-13.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-13.js new file mode 100644 index 0000000000000000000000000000000000000000..3efa5967a3cad921958b5ee40f7c8dc95a824eab --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-13.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own accessor + property that overrides an inherited accessor property on an Array +---*/ + +var arr = []; +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return false; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + return true; + }, + configurable: true +}); +assert.sameValue(arr.indexOf(true), 0, 'arr.indexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-14.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-14.js new file mode 100644 index 0000000000000000000000000000000000000000..79f64db556936d7acdbee0168f605e40dad58762 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-14.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own accessor + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var obj = { + length: 1 +}; +Object.defineProperty(Object.prototype, "0", { + get: function() { + return false; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + return true; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 0, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-15.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-15.js new file mode 100644 index 0000000000000000000000000000000000000000..7ee3451543b55a1b80561767602a8dbf741d5def --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-15.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is inherited + accessor property on an Array +---*/ + +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 10; + }, + configurable: true +}); +Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 20; + }, + configurable: true +}); + +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return 30; + }, + configurable: true +}); +assert.sameValue([, , , ].indexOf(10), 0, '[, , , ].indexOf(10)'); +assert.sameValue([, , , ].indexOf(20), 1, '[, , , ].indexOf(20)'); +assert.sameValue([, , , ].indexOf(30), 2, '[, , , ].indexOf(30)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-16.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-16.js new file mode 100644 index 0000000000000000000000000000000000000000..0ca4ea77d1c5e889b3f08a3f035938d4b3341ac2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-16.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is inherited + accessor property on an Array-like object +---*/ + +Object.defineProperty(Object.prototype, "0", { + get: function() { + return 10; + }, + configurable: true +}); +Object.defineProperty(Object.prototype, "1", { + get: function() { + return 20; + }, + configurable: true +}); +Object.defineProperty(Object.prototype, "2", { + get: function() { + return 30; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call({ + length: 3 +}, 10), 0, 'SendableArray.prototype.indexOf.call({ length: 3 }, 10)'); +assert.sameValue(SendableArray.prototype.indexOf.call({ + length: 3 +}, 20), 1, 'SendableArray.prototype.indexOf.call({ length: 3 }, 20)'); +assert.sameValue(SendableArray.prototype.indexOf.call({ + length: 3 +}, 30), 2, 'SendableArray.prototype.indexOf.call({ length: 3 }, 30)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-17.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-17.js new file mode 100644 index 0000000000000000000000000000000000000000..b7f94cc386f48c2aa7a64173988ea3855a7bb4ed --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-17.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own accessor + property without a get function on an Array +---*/ + +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +assert.sameValue(arr.indexOf(undefined), 0, 'arr.indexOf(undefined)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-18.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-18.js new file mode 100644 index 0000000000000000000000000000000000000000..d5cc5e04018fdcc14c938f422bd4f04f105e5824 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-18.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own accessor + property without a get function on an Array-like object +---*/ + +var obj = { + length: 1 +}; +Object.defineProperty(obj, "0", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, undefined), 0, 'SendableArray.prototype.indexOf.call(obj, undefined)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-19.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-19.js new file mode 100644 index 0000000000000000000000000000000000000000..ab54b822d2362287374c500cc181ddd1c844e978 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-19.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array +---*/ + +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 2; + }, + configurable: true +}); +assert.sameValue(arr.indexOf(undefined), 0, 'arr.indexOf(undefined)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-2.js new file mode 100644 index 0000000000000000000000000000000000000000..7e01f92dfc893398bdfee8423f4268351f7c022c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-2.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own data + property on an Array +---*/ + +assert.sameValue([true, true, true].indexOf(true), 0, '[true, true, true].indexOf(true)'); +assert.sameValue([false, true, true].indexOf(true), 1, '[false, true, true].indexOf(true)'); +assert.sameValue([false, false, true].indexOf(true), 2, '[false, false, true].indexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-20.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-20.js new file mode 100644 index 0000000000000000000000000000000000000000..1965455780c047e2865cede64bb69882b505be20 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-20.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array-like object +---*/ + +var proto = {}; +Object.defineProperty(proto, "0", { + get: function() { + return 2; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 1; +Object.defineProperty(child, "0", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(child, undefined), 0, 'SendableArray.prototype.indexOf.call(child, undefined)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-21.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-21.js new file mode 100644 index 0000000000000000000000000000000000000000..46b441db8bd1028088c27104903db0ae343af4e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-21.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is inherited + accessor property without a get function on an Array +---*/ + +Object.defineProperty(SendableArray.prototype, "0", { + set: function() {}, + configurable: true +}); +assert.sameValue([, ].indexOf(undefined), 0, '[, ].indexOf(undefined)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-22.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-22.js new file mode 100644 index 0000000000000000000000000000000000000000..eea799f728e9db50e08f841dd108d741efe75e7b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-22.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is inherited + accessor property without a get function on an Array-like object +---*/ + +Object.defineProperty(Object.prototype, "0", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call({ + length: 1 +}, undefined), 0, 'SendableArray.prototype.indexOf.call({ length: 1 }, undefined)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-25.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-25.js new file mode 100644 index 0000000000000000000000000000000000000000..338f95ec729df596ace36eb8a98e691755c0afa4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-25.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf applied to Arguments object which + implements its own property get method (number of arguments is + less than number of parameters) +---*/ + +var func = function(a, b) { + return 0 === SendableArray.prototype.indexOf.call(arguments, arguments[0]) && + -1 === SendableArray.prototype.indexOf.call(arguments, arguments[1]); +}; +assert(func(true), 'func(true) !== true'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-26.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-26.js new file mode 100644 index 0000000000000000000000000000000000000000..d2c8daaf861a15554da2a0069290239608542b52 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-26.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf applied to Arguments object which + implements its own property get method (number of arguments equals + to number of parameters) +---*/ + +var func = function(a, b) { + return 0 === SendableArray.prototype.indexOf.call(arguments, arguments[0]) && + 1 === SendableArray.prototype.indexOf.call(arguments, arguments[1]) && + -1 === SendableArray.prototype.indexOf.call(arguments, arguments[2]); +}; +assert(func(0, true), 'func(0, true) !== true'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-27.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-27.js new file mode 100644 index 0000000000000000000000000000000000000000..2c34eeef890dde91069a119b5fe48f78759eb1db --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-27.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf applied to Arguments object which + implements its own property get method (number of arguments is + greater than number of parameters) +---*/ + +var func = function(a, b) { + return 0 === SendableArray.prototype.indexOf.call(arguments, arguments[0]) && + 3 === SendableArray.prototype.indexOf.call(arguments, arguments[3]) && + -1 === SendableArray.prototype.indexOf.call(arguments, arguments[4]); +}; +assert(func(0, false, 0, true), 'func(0, false, 0, true) !== true'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-28.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-28.js new file mode 100644 index 0000000000000000000000000000000000000000..33be2220291e21a2a4cd3beb5dba4c8904cd4b36 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-28.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - side-effects are visible in subsequent + iterations on an Array +---*/ + +var preIterVisible = false; +var arr = []; +Object.defineProperty(arr, "0", { + get: function() { + preIterVisible = true; + return false; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + if (preIterVisible) { + return true; + } else { + return false; + } + }, + configurable: true +}); +assert.sameValue(arr.indexOf(true), 1, 'arr.indexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-29.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-29.js new file mode 100644 index 0000000000000000000000000000000000000000..1509950f0f2175adfbb0e4294b38ea3c3936c2da --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-29.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - side-effects are visible in subsequent + iterations on an Array-like object +---*/ + +var preIterVisible = false; +var obj = { + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + preIterVisible = true; + return false; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + if (preIterVisible) { + return true; + } else { + return false; + } + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call(obj, true), 1, 'SendableArray.prototype.indexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-3.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-3.js new file mode 100644 index 0000000000000000000000000000000000000000..a6b4b75cad8ce8ca1446cd4ec174ab07b726d27c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-3.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +SendableArray.prototype[0] = false; +assert.sameValue([true].indexOf(true), 0, '[true].indexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-30.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-30.js new file mode 100644 index 0000000000000000000000000000000000000000..6345e677595105887d56b26cac2f5a930fe6cf26 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-30.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - terminates iteration on unhandled + exception on an Array +---*/ + +var accessed = false; +var arr = []; +Object.defineProperty(arr, "0", { + get: function() { + throw new TypeError(); + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + accessed = true; + return true; + }, + configurable: true +}); +assert.throws(TypeError, function() { + arr.indexOf(true); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-31.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-31.js new file mode 100644 index 0000000000000000000000000000000000000000..8805ccf077655c77f49b61c5834f97a88862160b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-31.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - terminates iteration on unhandled + exception on an Array-like object +---*/ + +var accessed = false; +var obj = { + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + throw new TypeError(); + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + accessed = true; + return true; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.indexOf.call(obj, true); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-4.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-4.js new file mode 100644 index 0000000000000000000000000000000000000000..285f3675b67d77fbe041bf9bdcfbb7d2cab68c3b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own data + property that overrides an inherited data property on an + Array-like object +---*/ + +Object.prototype[0] = false; +assert.sameValue(SendableArray.prototype.indexOf.call({ + 0: true, + 1: 1, + length: 2 +}, true), 0, 'SendableArray.prototype.indexOf.call({ 0: true, 1: 1, length: 2 }, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-5.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-5.js new file mode 100644 index 0000000000000000000000000000000000000000..94162802ea5159746ceeb4c415948893fd39ef19 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-5.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own data + property that overrides an inherited accessor property on an Array +---*/ + +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return false; + }, + configurable: true +}); +assert.sameValue([true].indexOf(true), 0, '[true].indexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-6.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-6.js new file mode 100644 index 0000000000000000000000000000000000000000..881b7354d1c024f88f6f668afe26b767aad08103 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-6.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own data + property that overrides an inherited accessor property on an + Array-like object +---*/ + +Object.defineProperty(Object.prototype, "0", { + get: function() { + return false; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.indexOf.call({ + 0: true, + 1: 1, + length: 2 +}, true), 0, 'SendableArray.prototype.indexOf.call({ 0: true, 1: 1, length: 2 }, true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-7.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-7.js new file mode 100644 index 0000000000000000000000000000000000000000..6f2f6e968d2f0221664960f82190e3274430fd2d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-7.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is inherited + data property on an Array +---*/ + +SendableArray.prototype[0] = true; +SendableArray.prototype[1] = false; +SendableArray.prototype[2] = "true"; +assert.sameValue([, , , ].indexOf(true), 0, '[, , , ].indexOf(true)'); +assert.sameValue([, , , ].indexOf(false), 1, '[, , , ].indexOf(false)'); +assert.sameValue([, , , ].indexOf("true"), 2, '[, , , ].indexOf("true")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-8.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-8.js new file mode 100644 index 0000000000000000000000000000000000000000..f7e313cf3083400a3056962bc560cb9ad5a04acb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-8.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is inherited + data property on an Array-like object +---*/ + +Object.prototype[0] = true; +Object.prototype[1] = false; +Object.prototype[2] = "true"; +assert.sameValue(SendableArray.prototype.indexOf.call({ + length: 3 +}, true), 0, 'SendableArray.prototype.indexOf.call({ length: 3 }, true)'); +assert.sameValue(SendableArray.prototype.indexOf.call({ + length: 3 +}, false), 1, 'SendableArray.prototype.indexOf.call({ length: 3 }, false)'); +assert.sameValue(SendableArray.prototype.indexOf.call({ + length: 3 +}, "true"), 2, 'SendableArray.prototype.indexOf.call({ length: 3 }, "true")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-9.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-9.js new file mode 100644 index 0000000000000000000000000000000000000000..8e33b55f384c0c53802e0c91c912a416bd428504 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-i-9.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - element to be retrieved is own accessor + property on an Array +---*/ + +var arr = [, , , ]; +Object.defineProperty(arr, "0", { + get: function() { + return 0; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true +}); +Object.defineProperty(arr, "2", { + get: function() { + return 2; + }, + configurable: true +}); +assert.sameValue(arr.indexOf(0), 0, 'arr.indexOf(0)'); +assert.sameValue(arr.indexOf(1), 1, 'arr.indexOf(1)'); +assert.sameValue(arr.indexOf(2), 2, 'arr.indexOf(2)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..9115fb072303c4cba1a7be2ad9961db8254c588a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-1.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - type of array element is different from + type of search element +---*/ + +assert.sameValue(["true"].indexOf(true), -1, '["true"].indexOf(true)'); +assert.sameValue(["0"].indexOf(0), -1, '["0"].indexOf(0)'); +assert.sameValue([false].indexOf(0), -1, '[false].indexOf(0)'); +assert.sameValue([undefined].indexOf(0), -1, '[undefined].indexOf(0)'); +assert.sameValue([null].indexOf(0), -1, '[null].indexOf(0)'); +assert.sameValue([ + [] +].indexOf(0), -1, '[[]].indexOf(0)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-10.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..e5b9a0ca16a83b4a8735e581ba1b946832062a21 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-10.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - both array element and search element + are Boolean type, and they have same value +---*/ + +assert.sameValue([false, true].indexOf(true), 1, '[false, true].indexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-11.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..21cb78f66c017414d4cba4d85f2e5c977bef4e00 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-11.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - both array element and search element + are Object type, and they refer to the same object +---*/ + +var obj1 = {}; +var obj2 = {}; +var obj3 = obj2; +assert.sameValue([{}, obj1, obj2].indexOf(obj3), 2, '[{}, obj1, obj2].indexOf(obj3)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..5a402ba3c794dc30a64fff22d7abbae82ea9d37e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-2.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - both type of array element and type of + search element are Undefined +---*/ + +assert.sameValue([undefined].indexOf(), 0, '[undefined].indexOf()'); +assert.sameValue([undefined].indexOf(undefined), 0, '[undefined].indexOf(undefined)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-3.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-3.js new file mode 100644 index 0000000000000000000000000000000000000000..2d2c70bc79b69598f914bbaba9521c1c7174a4e4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-3.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - both type of array element and type of + search element are null +---*/ + +assert.sameValue([null].indexOf(null), 0, '[null].indexOf(null)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-4.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..7cc3338e1abcae4b19bda5da9fe37dfb9a964774 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-4.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - search element is NaN +---*/ + +assert.sameValue([+NaN, NaN, -NaN].indexOf(NaN), -1, '[+NaN, NaN, -NaN].indexOf(NaN)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-5.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..90e0f2a47e970778bc708d0f5c288463a9d99032 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-5.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: Array.prototype.indexOf - search element is -NaN +---*/ + +assert.sameValue([+NaN, NaN, -NaN].indexOf(-NaN), -1, '[+NaN, NaN, -NaN].indexOf(-NaN)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-6.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-6.js new file mode 100644 index 0000000000000000000000000000000000000000..af65d31f9a1132245fc327d333ab34ef6ac0036f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-6.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - array element is +0 and search element + is -0 +---*/ + +assert.sameValue([+0].indexOf(-0), 0, '[+0].indexOf(-0)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-7.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..b3b349c4b735ad6647fdd3ec79748ae2364acbc2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-7.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - array element is -0 and search element + is +0 +---*/ + +assert.sameValue([-0].indexOf(+0), 0, '[-0].indexOf(+0)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-8.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..fa283f8ad76b32ae24a1b445f5e349cd39ecc44b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-8.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - both array element and search element + are Number, and they have same value +---*/ + +assert.sameValue([-1, 0, 1].indexOf(1), 2, '[-1, 0, 1].indexOf(1)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-9.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..eb3ae7e3ab8cb939fd4fc1d2028866c0b470db12 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-ii-9.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - both array element and search element + are String, and they have exactly the same sequence of characters +---*/ + +assert.sameValue(["", "ab", "bca", "abc"].indexOf("abc"), 3, '["", "ab", "bca", "abc"].indexOf("abc")'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-iii-1.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-iii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..833cb78aa8fe20d4dc6a24604d6f46957dfbb71e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-iii-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - returns index of last one when more than + two elements in array are eligible +---*/ + +assert.sameValue([1, 2, 2, 1, 2].indexOf(2), 1, '[1, 2, 2, 1, 2].indexOf(2)'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-iii-2.js b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-iii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..e673a6155842f954bbd4981fe84910f2b60615ca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/15.4.4.14-9-b-iii-2.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf - returns without visiting subsequent + element once search value is found +---*/ + +var arr = [1, 2, , 1, 2]; +var elementThirdAccessed = false; +var elementFifthAccessed = false; +Object.defineProperty(arr, "2", { + get: function() { + elementThirdAccessed = true; + return 2; + }, + configurable: true +}); +Object.defineProperty(arr, "4", { + get: function() { + elementFifthAccessed = true; + return 2; + }, + configurable: true +}); +arr.indexOf(2); +assert.sameValue(elementThirdAccessed, false, 'elementThirdAccessed'); +assert.sameValue(elementFifthAccessed, false, 'elementFifthAccessed'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/call-with-boolean.js b/test/sendable/builtins/Array/prototype/indexOf/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..d1bdbd2cbfa23bd4da2c02230204e3327ca7a6e0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/call-with-boolean.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexOf +description: Array.prototype.indexOf applied to boolean primitive +---*/ + +assert.sameValue(SendableArray.prototype.indexOf.call(true), -1, 'SendableArray.prototype.indexOf.call(true) must return -1'); +assert.sameValue(SendableArray.prototype.indexOf.call(false), -1, 'SendableArray.prototype.indexOf.call(false) must return -1'); diff --git a/test/sendable/builtins/Array/prototype/indexOf/calls-only-has-on-prototype-after-length-zeroed.js b/test/sendable/builtins/Array/prototype/indexOf/calls-only-has-on-prototype-after-length-zeroed.js new file mode 100644 index 0000000000000000000000000000000000000000..cb4b10933668075413bbf7bb5360046fa37abdf8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/calls-only-has-on-prototype-after-length-zeroed.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Calls [[HasProperty]] on the prototype to check for existing elements. +info: | + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step produces the value 0.) + ... + 8. Repeat, while k < len + a. Let kPresent be ? HasProperty(O, ! ToString(k)). + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ... +includes: [proxyTrapsHelper.js] +features: [Proxy] +---*/ + +var SendableArray = [1, null, 3]; +Object.setPrototypeOf(SendableArray, new Proxy(SendableArray.prototype, allowProxyTraps({ + has: function(t, pk) { + return pk in t; + } +}))); +var fromIndex = { + valueOf: function() { + // Zero the array's length. The loop in step 8 iterates over the original + // length value of 100, but the only prototype MOP method which should be + // called is [[HasProperty]]. + array.length = 0; + return 0; + } +}; +SendableArray.prototype.indexOf.call(SendableArray, 100, fromIndex); diff --git a/test/sendable/builtins/Array/prototype/indexOf/coerced-searchelement-fromindex-grow.js b/test/sendable/builtins/Array/prototype/indexOf/coerced-searchelement-fromindex-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..0893b694f28ebc4b71f3f7585022838f37974a73 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/coerced-searchelement-fromindex-grow.js @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.p.indexOf behaves correctly when the backing resizable buffer is grown + during argument coercion. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Growing + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, 1); + } + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n0 = MayNeedBigInt(lengthTracking, 0); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n0), -1); + // The TA grew but we only look at the data until the original length. + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n0, evil), -1); +} +// Growing + length-tracking TA, index conversion. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + lengthTracking[0] = MayNeedBigInt(lengthTracking, 1); + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return -4; + } + }; + let n1 = MayNeedBigInt(lengthTracking, 1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n1, -4), 0); + // The TA grew but the start index conversion is done based on the original + // length. + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n1, evil), 0); +} diff --git a/test/sendable/builtins/Array/prototype/indexOf/coerced-searchelement-fromindex-shrink.js b/test/sendable/builtins/Array/prototype/indexOf/coerced-searchelement-fromindex-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..e9d7cd72a64031a0a8936bfe9f44abf1746ac8ea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/coerced-searchelement-fromindex-shrink.js @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.p.indexOf behaves correctly when the backing resizable buffer is shrunk + during argument coercion. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Shrinking + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n0 = MayNeedBigInt(fixedLength, 0); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n0), 0); + // The TA is OOB so indexOf returns -1. + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n0, evil), -1); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n0 = MayNeedBigInt(fixedLength, 0); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n0), 0); + // The TA is OOB so indexOf returns -1, also for undefined). + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, undefined, evil), -1); +} + +// Shrinking + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i); + } + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n2 = MayNeedBigInt(lengthTracking, 2); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n2), 2); + // 2 no longer found. + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n2, evil), -1); +} diff --git a/test/sendable/builtins/Array/prototype/indexOf/fromindex-zero-conversion.js b/test/sendable/builtins/Array/prototype/indexOf/fromindex-zero-conversion.js new file mode 100644 index 0000000000000000000000000000000000000000..07ba939d00a5752ee1665eafcc1d7ff631539baf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/fromindex-zero-conversion.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Return +0 when fromIndex is -0 and return index refers to the first position +---*/ + +assert.sameValue(1 / [true].indexOf(true, -0), +Infinity) diff --git a/test/sendable/builtins/Array/prototype/indexOf/length-near-integer-limit.js b/test/sendable/builtins/Array/prototype/indexOf/length-near-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..00b409d8aa13d0fc33003984751ac9307b0872f9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/length-near-integer-limit.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.indexof +description: > + Elements are found in an array-like object + whose "length" property is near the integer limit. +info: | + Array.prototype.indexOf ( searchElement [ , fromIndex ] ) +---*/ + +var el = {}; +var elIndex = Number.MAX_SAFE_INTEGER - 1; +var fromIndex = Number.MAX_SAFE_INTEGER - 3; +var arrayLike = { + length: Number.MAX_SAFE_INTEGER, +}; +arrayLike[elIndex] = el; +var res = SendableArray.prototype.indexOf.call(arrayLike, el, fromIndex); +assert.sameValue(res, elIndex); diff --git a/test/sendable/builtins/Array/prototype/indexOf/length-zero-returns-minus-one.js b/test/sendable/builtins/Array/prototype/indexOf/length-zero-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..307df41a62e262352dd8b39a46dd410b47bdb667 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/length-zero-returns-minus-one.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Returns -1 if length is 0. +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error("Length should be checked before ToInteger(fromIndex)."); + }, +}; +assert.sameValue([].indexOf(1), -1); +assert.sameValue([].indexOf(2, fromIndex), -1); diff --git a/test/sendable/builtins/Array/prototype/indexOf/length.js b/test/sendable/builtins/Array/prototype/indexOf/length.js new file mode 100644 index 0000000000000000000000000000000000000000..1273902733f3d7c7207cd2b6f47ef0bc3d24010d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/length.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + The "length" property of Array.prototype.indexOf +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.indexOf, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/indexOf/name.js b/test/sendable/builtins/Array/prototype/indexOf/name.js new file mode 100644 index 0000000000000000000000000000000000000000..b79beaf297707dba1c651fe89fc2ccb4b73e5230 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.prototype.indexOf.name is "indexOf". +info: | + Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.indexOf, "name", { + value: "indexOf", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/indexOf/not-a-constructor.js b/test/sendable/builtins/Array/prototype/indexOf/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..a3fca3154351804b9e432b0dfca9fd43d82a3eae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/not-a-constructor.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.indexOf does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.indexOf), + false, + 'isConstructor(SendableArray.prototype.indexOf) must return false' +); + +assert.throws(TypeError, () => { + new SendableArray.prototype.indexOf(); +}); + diff --git a/test/sendable/builtins/Array/prototype/indexOf/prop-desc.js b/test/sendable/builtins/Array/prototype/indexOf/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..7df511f4cd260032836012fed37a9dcb5dcf7e3e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + "indexOf" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.indexOf, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "indexOf", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/indexOf/resizable-buffer-special-float-values.js b/test/sendable/builtins/Array/prototype/indexOf/resizable-buffer-special-float-values.js new file mode 100644 index 0000000000000000000000000000000000000000..b71c38596aee96e971890b719d4c9b62b488248c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/resizable-buffer-special-float-values.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-%array%.prototype.indexof +description: > + Array.p.indexOf behaves correctly for special float values on TypedArrays + backed by resizable buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer, Array.prototype.includes] +---*/ + +for (let ctor of floatCtors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + lengthTracking[0] = -Infinity; + lengthTracking[1] = -Infinity; + lengthTracking[2] = Infinity; + lengthTracking[3] = Infinity; + lengthTracking[4] = NaN; + lengthTracking[5] = NaN; + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, -Infinity), 0); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, Infinity), 2); + // NaN is never found. + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, NaN), -1); +} diff --git a/test/sendable/builtins/Array/prototype/indexOf/resizable-buffer.js b/test/sendable/builtins/Array/prototype/indexOf/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..556497dd5a032107b9bd067ef701d5a50df9e8ae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/indexOf/resizable-buffer.js @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.indexof +description: > + Array.p.indexOf behaves correctly on TypedArrays backed by resizable buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, Math.floor(i / 2)); + } + // Orig. array: [0, 0, 1, 1] + // [0, 0, 1, 1] << fixedLength + // [1, 1] << fixedLengthWithOffset + // [0, 0, 1, 1, ...] << lengthTracking + // [1, 1, ...] << lengthTrackingWithOffset + // If fixedLength is a BigInt array, they all are BigInt Arrays. + let n0 = MayNeedBigInt(fixedLength, 0); + let n1 = MayNeedBigInt(fixedLength, 1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n0), 0); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n0, 1), 1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n0, 2), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n0, -2), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n0, -3), 1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n1, 1), 2); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n1, -3), 2); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n1, -2), 2); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, undefined), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, n1), 0); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, n1, -2), 0); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, n1, -1), 1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, undefined), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n0), 0); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n0, 2), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n1, -3), 2); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, undefined), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, n1), 0); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, n1, 1), 1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, n1, -2), 0); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, undefined), -1); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [0, 0, 1] + // [0, 0, 1, ...] << lengthTracking + // [1, ...] << lengthTrackingWithOffset + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n1), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, n1), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n1), 2); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, undefined), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, n1), 0); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, undefined), -1); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n0), 0); + // Shrink to zero. + rab.resize(0); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, undefined), -1); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, Math.floor(i / 2)); + } + // Orig. array: [0, 0, 1, 1, 2, 2] + // [0, 0, 1, 1] << fixedLength + // [1, 1] << fixedLengthWithOffset + // [0, 0, 1, 1, 2, 2, ...] << lengthTracking + // [1, 1, 2, 2, ...] << lengthTrackingWithOffset + let n2 = MayNeedBigInt(fixedLength, 2); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n1), 2); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, n2), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLength, undefined), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, n1), 0); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, n2), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(fixedLengthWithOffset, undefined), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n1), 2); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, n2), 4); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTracking, undefined), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, n1), 0); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, n2), 2); + assert.sameValue(SendableArray.prototype.indexOf.call(lengthTrackingWithOffset, undefined), -1); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.1_T1.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..cb305d4163b2bbce8478aa986d1e48639bf0bd25 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.1_T1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: If length is zero, return the empty string +esid: sec-array.prototype.join +description: Checking this use new Array() and [] +---*/ + +var x = new SendableArray(); +if (x.join() !== "") { + throw new Test262Error('#1: x = new Array(); x.join() === "". Actual: ' + (x.join())); +} +x = []; +x[0] = 1; +x.length = 0; +if (x.join() !== "") { + throw new Test262Error('#2: x = []; x[0] = 1; x.length = 0; x.join() === "". Actual: ' + (x.join())); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.2_T1.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..1d6f017ec211477ec766c4f251cbbccb24bda997 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.2_T1.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: If separator is undefined, a single comma is used as the separator +esid: sec-array.prototype.join +description: Checking this use new Array() and [] +---*/ + +var x = new SendableArray(0, 1, 2, 3); +if (x.join() !== "0,1,2,3") { + throw new Test262Error('#1: x = new Array(0,1,2,3); x.join() === "0,1,2,3". Actual: ' + (x.join())); +} +x = []; +x[0] = 0; +x[3] = 3; +if (x.join() !== "0,,,3") { + throw new Test262Error('#2: x = []; x[0] = 0; x[3] = 3; x.join() === "0,,,3". Actual: ' + (x.join())); +} +x = []; +x[0] = 0; +if (x.join() !== "0") { + throw new Test262Error('#3: x = []; x[0] = 0; x.join() === "0". Actual: ' + (x.join())); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.2_T2.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..d199506deaebed099f21b8e43e3ef13e8b71615b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.2_T2.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: If separator is undefined, a single comma is used as the separator +esid: sec-array.prototype.join +description: Checking this use new Array() and [] +---*/ + +var x = new SendableArray(0, 1, 2, 3); +if (x.join(undefined) !== "0,1,2,3") { + throw new Test262Error('#1: x = new Array(0,1,2,3); x.join(undefined) === "0,1,2,3". Actual: ' + (x.join(undefined))); +} +x = []; +x[0] = 0; +x[3] = 3; +if (x.join(undefined) !== "0,,,3") { + throw new Test262Error('#2: x = []; x[0] = 0; x[3] = 3; x.join(undefined) === "0,,,3". Actual: ' + (x.join(undefined))); +} +x = []; +x[0] = 0; +if (x.join(undefined) !== "0") { + throw new Test262Error('#3: x = []; x[0] = 0; x.join(undefined) === "0". Actual: ' + (x.join(undefined))); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.3_T1.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..a25b7dcdbe7f43272bc173cf39ab37e48bdf0d45 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A1.3_T1.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: If array element is undefined or null, use the empty string +esid: sec-array.prototype.join +description: Checking this use new Array() and [] +---*/ + +var x = []; +x[0] = undefined; +if (x.join() !== "") { + throw new Test262Error('#1: x = []; x[0] = undefined; x.join() === "". Actual: ' + (x.join())); +} +x = []; +x[0] = null; +if (x.join() !== "") { + throw new Test262Error('#2: x = []; x[0] = null; x.join() === "". Actual: ' + (x.join())); +} +x = SendableArray(undefined, 1, null, 3); +if (x.join() !== ",1,,3") { + throw new Test262Error('#3: x = SendableArray(undefined,1,null,3); x.join() === ",1,,3". Actual: ' + (x.join())); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T1.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..431558261d698e318e2f639755195bb8d608240e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T1.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The join function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.join +description: If ToUint32(length) is zero, return the empty string +---*/ + +var obj = {}; +obj.join = SendableArray.prototype.join; +if (obj.length !== undefined) { + throw new Test262Error('#0: var obj = {}; obj.length === undefined. Actual: ' + (obj.length)); +} else { + if (obj.join() !== "") { + throw new Test262Error('#1: var obj = {}; obj.join = SendableArray.prototype.join; obj.join() === "". Actual: ' + (obj.join())); + } + if (obj.length !== undefined) { + throw new Test262Error('#2: var obj = {}; obj.join = SendableArray.prototype.join; obj.join(); obj.length === undefined. Actual: ' + (obj.length)); + } +} +obj.length = undefined; +if (obj.join() !== "") { + throw new Test262Error('#3: var obj = {}; obj.length = undefined; obj.join = SendableArray.prototype.join; obj.join() === ". Actual: ' + (obj.join())); +} +if (obj.length !== undefined) { + throw new Test262Error('#4: var obj = {}; obj.length = undefined; obj.join = SendableArray.prototype.join; obj.join(); obj.length === undefined. Actual: ' + (obj.length)); +} +obj.length = null +if (obj.join() !== "") { + throw new Test262Error('#5: var obj = {}; obj.length = null; obj.join = SendableArray.prototype.join; obj.join() === "". Actual: ' + (obj.join())); +} +if (obj.length !== null) { + throw new Test262Error('#6: var obj = {}; obj.length = null; obj.join = SendableArray.prototype.join; obj.join(); obj.length === null. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T2.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..5860d0f53f0b656b80ca03e972b9ce69299d1004 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T2.js @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The join function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.join +description: If ToUint32(length) is zero, return the empty string +---*/ + +var obj = {}; +obj.join = SendableArray.prototype.join; +obj.length = NaN; +if (obj.join() !== "") { + throw new Test262Error('#1: var obj = {}; obj.length = NaN; obj.join = SendableArray.prototype.join; obj.join() === "". Actual: ' + (obj.join())); +} +assert.sameValue(obj.length, NaN, "obj.length is NaN"); +obj.length = Number.NEGATIVE_INFINITY; +if (obj.join() !== "") { + throw new Test262Error('#5: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.join = SendableArray.prototype.join; obj.join() === "". Actual: ' + (obj.join())); +} +if (obj.length !== Number.NEGATIVE_INFINITY) { + throw new Test262Error('#6: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.join = SendableArray.prototype.join; obj.join(); obj.length === Number.NEGATIVE_INFINITY. Actual: ' + (obj.length)); +} +obj.length = -0; +if (obj.join() !== "") { + throw new Test262Error('#7: var obj = {}; obj.length = -0; obj.join = SendableArray.prototype.join; obj.join() === "". Actual: ' + (obj.join())); +} +if (obj.length !== -0) { + throw new Test262Error('#8: var obj = {}; obj.length = -0; obj.join = SendableArray.prototype.join; obj.join(); obj.length === 0. Actual: ' + (obj.length)); +} else { + if (1 / obj.length !== Number.NEGATIVE_INFINITY) { + throw new Test262Error('#8: var obj = {}; obj.length = -0; obj.join = SendableArray.prototype.join; obj.join(); obj.length === -0. Actual: ' + (obj.length)); + } +} +obj.length = 0.5; +if (obj.join() !== "") { + throw new Test262Error('#9: var obj = {}; obj.length = 0.5; obj.join = SendableArray.prototype.join; obj.join() === "". Actual: ' + (obj.join())); +} +if (obj.length !== 0.5) { + throw new Test262Error('#10: var obj = {}; obj.length = 0.5; obj.join = SendableArray.prototype.join; obj.join(); obj.length === 0.5. Actual: ' + (obj.length)); +} +var x = new Number(0); +obj.length = x; +if (obj.join() !== "") { + throw new Test262Error('#11: var x = new Number(0); var obj = {}; obj.length = x; obj.join = SendableArray.prototype.join; obj.join() === "". Actual: ' + (obj.join())); +} +if (obj.length !== x) { + throw new Test262Error('#12: var x = new Number(0); var obj = {}; obj.length = x; obj.join = SendableArray.prototype.join; obj.join(); obj.length === x. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T3.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..6b3254920186e5e2146a5d5e2b2b69c0313b18fb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T3.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The join function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.join +description: If ToUint32(length) is zero, return the empty string +---*/ + +var obj = {}; +obj.join = SendableArray.prototype.join; +obj.length = 4.5; +if (obj.join() !== ",,,") { + throw new Test262Error('#1: var obj = {}; obj.length = 4.5; obj.join = SendableArray.prototype.join; obj.join() === ",,,". Actual: ' + (obj.join())); +} +obj[0] = undefined; +obj[1] = 1; +obj[2] = null; +if (obj.join() !== ",1,,") { + throw new Test262Error('#1: var obj = {}; obj.length = 4.5; obj[0] = undefined; obj[1] = 1; obj[2] = null; obj.join = SendableArray.prototype.join; obj.join() === ",1,,". Actual: ' + (obj.join())); +} +if (obj.length !== 4.5) { + throw new Test262Error('#1: var obj = {}; obj.length = 4.5; obj[0] = undefined; obj[1] = 1; obj[2] = null; obj.join = SendableArray.prototype.join; obj.join(); obj.length === 4.5. Actual: ' + (obj.length)); +} +var obj = {}; +obj.join = SendableArray.prototype.join; +var x = new Number(4.5); +obj.length = x; +if (obj.join() !== ",,,") { + throw new Test262Error('#4: var obj = {}; var x = new Number(4.5); obj.length = x; obj.join = SendableArray.prototype.join; obj.join() === ",,,". Actual: ' + (obj.join())); +} +obj[0] = undefined; +obj[1] = 1; +obj[2] = null; +if (obj.join() !== ",1,,") { + throw new Test262Error('#5: var obj = {}; var x = new Number(4.5); obj.length = x; obj[0] = undefined; obj[1] = 1; obj[2] = null; obj.join = SendableArray.prototype.join; obj.join() === ",1,,". Actual: ' + (obj.join())); +} +if (obj.length !== x) { + throw new Test262Error('#6: var obj = {}; var x = new Number(4.5); obj.length = x; obj[0] = undefined; obj[1] = 1; obj[2] = null; obj.join = SendableArray.prototype.join; obj.join(); obj.length === x. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T4.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..7feba2b3dfd5719c4e430e0618d0c6347826827a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A2_T4.js @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The join function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.join +description: > + Operator use ToNumber from length. If Type(value) is Object, + evaluate ToPrimitive(value, Number) +---*/ + +var obj = {}; +obj.join = SendableArray.prototype.join; +obj.length = { + valueOf() { + return 3 + } +}; +assert.sameValue(obj.join(), ",,", 'obj.join() must return ",,"'); +obj.length = { + valueOf() { + return 3 + }, + toString() { + return 2 + } +}; +assert.sameValue(obj.join(), ",,", 'obj.join() must return ",,"'); +obj.length = { + valueOf() { + return 3 + }, + toString() { + return {} + } +}; +assert.sameValue(obj.join(), ",,", 'obj.join() must return ",,"'); +obj.length = { + valueOf() { + return 3 + }, + toString() { + throw new Test262Error(); + } +}; +assert.sameValue(obj.join(), ",,", 'obj.join() must return ",,"'); +obj.length = { + toString() { + return 2 + } +}; +assert.sameValue(obj.join(), ",", 'obj.join() must return ","'); +obj.length = { + valueOf() { + return {} + }, + toString() { + return 2 + } +} +assert.sameValue(obj.join(), ",", 'obj.join() must return ","'); +assert.throws(Test262Error, () => { + obj.length = { + valueOf() { + throw new Test262Error(); + }, + toString() { + return 2 + } + }; + obj.join(); +}); +assert.throws(TypeError, () => { + obj.length = { + valueOf() { + return {} + }, + toString() { + return {} + } + }; + obj.join(); +}); diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.1_T1.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..1e0aa94d1329cf9716aede087f713575e4dbe67b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.1_T1.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToString from separator +esid: sec-array.prototype.join +description: > + Checking separator in ["", "\\", "&", true, Infinity, null, + undefind, NaN] +---*/ + +var x = new SendableArray(0, 1, 2, 3); +if (x.join("") !== "0123") { + throw new Test262Error('#0: x = new SendableArray(0,1,2,3); x.join("") === "0123". Actual: ' + (x.join(""))); +} +x = new Array(0, 1, 2, 3); +if (x.join("\\") !== "0\\1\\2\\3") { + throw new Test262Error('#1: x = new SendableArray(0,1,2,3); x.join("\\") === "0\\1\\2\\3". Actual: ' + (x.join("\\"))); +} +if (x.join("&") !== "0&1&2&3") { + throw new Test262Error('#2: x = new SendableArray(0,1,2,3); x.join("&") === "0&1&2&3". Actual: ' + (x.join("&"))); +} +if (x.join(true) !== "0true1true2true3") { + throw new Test262Error('#3: x = new SendableArray(0,1,2,3); x.join(true) === "0true1true2true3". Actual: ' + (x.join(true))); +} +if (x.join(Infinity) !== "0Infinity1Infinity2Infinity3") { + throw new Test262Error('#4: x = new SendableArray(0,1,2,3); x.join(Infinity) === "0Infinity1Infinity2Infinity3". Actual: ' + (x.join(Infinity))); +} +if (x.join(null) !== "0null1null2null3") { + throw new Test262Error('#3: 5 = new SendableArray(0,1,2,3); x.join(null) === "0null1null2null3". Actual: ' + (x.join(null))); +} +if (x.join(undefined) !== "0,1,2,3") { + throw new Test262Error('#6: x = new SendableArray(0,1,2,3); x.join(undefined) === "0,1,2,3". Actual: ' + (x.join(undefined))); +} +if (x.join(NaN) !== "0NaN1NaN2NaN3") { + throw new Test262Error('#7: x = new SendableArray(0,1,2,3); x.join(NaN) === "0NaN1NaN2NaN3". Actual: ' + (x.join(NaN))); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.1_T2.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..8066554e2a4f28adc455c5f941f0402ccc741a7b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.1_T2.js @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToString from separator +esid: sec-array.prototype.join +description: > + If Type(separator) is Object, evaluate ToPrimitive(separator, + String) +---*/ + +var x = new SendableArray(0, 1, 2, 3); +var object = { + valueOf() { + return "+" + } +}; +assert.sameValue( + x.join(object), + "0[object Object]1[object Object]2[object Object]3", + 'x.join({valueOf() {return "+"}}) must return "0[object Object]1[object Object]2[object Object]3"' +); +var object = { + valueOf() { + return "+" + }, + toString() { + return "*" + } +}; +assert.sameValue( + x.join(object), + "0*1*2*3", + 'x.join("{valueOf() {return "+"}, toString() {return "*"}}) must return "0*1*2*3"' +); +var object = { + valueOf() { + return "+" + }, + toString() { + return {} + } +}; +assert.sameValue( + x.join(object), + "0+1+2+3", + 'x.join({valueOf() {return "+"}, toString() {return {}}}) must return "0+1+2+3"' +); +try { + var object = { + valueOf() { + throw "error" + }, + toString() { + return "*" + } + }; + assert.sameValue( + x.join(object), + "0*1*2*3", + 'x.join("{valueOf() {throw "error"}, toString() {return "*"}}) must return "0*1*2*3"' + ); +} +catch (e) { + assert.notSameValue(e, "error", 'The value of e is not "error"'); +} +var object = { + toString() { + return "*" + } +}; +assert.sameValue(x.join(object), "0*1*2*3", 'x.join({toString() {return "*"}}) must return "0*1*2*3"'); +var object = { + valueOf() { + return {} + }, + toString() { + return "*" + } +} +assert.sameValue( + x.join(object), + "0*1*2*3", + 'x.join({valueOf() {return {}}, toString() {return "*"}}) must return "0*1*2*3"' +); +try { + var object = { + valueOf() { + return "+" + }, + toString() { + throw "error" + } + }; + x.join(object); + throw new Test262Error('#7.1: var object = {valueOf() {return "+"}, toString() {throw "error"}}; x.join(object) throw "error". Actual: ' + (x.join(object))); +} +catch (e) { + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); +} +try { + var object = { + valueOf() { + return {} + }, + toString() { + return {} + } + }; + x.join(object); + throw new Test262Error('#8.1: var object = {valueOf() {return {}}, toString() {return {}}}; x.join(object) throw TypeError. Actual: ' + (x.join(object))); +} +catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} +try { + var object = { + toString() { + throw "error" + } + }; + [].join(object); + throw new Test262Error('#9.1: var object = {toString() {throw "error"}}; [].join(object) throw "error". Actual: ' + ([].join(object))); +} +catch (e) { + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.2_T1.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..2a4e56185aa07a8833d3a6d2669761afaa853ebb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.2_T1.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToString from array arguments +esid: sec-array.prototype.join +description: > + Checking arguments and separator in ["", "\\", "&", true, + Infinity, null, undefind, NaN] +---*/ + +var x = new SendableArray("", "", ""); +if (x.join("") !== "") { + throw new Test262Error('#0: var x = new SendableArray("","",""); x.join("") === "". Actual: ' + (x.join(""))); +} +var x = new SendableArray("\\", "\\", "\\"); +if (x.join("\\") !== "\\\\\\\\\\") { + throw new Test262Error('#1: var x = new SendableArray("\\","\\","\\"); x.join("\\") === "\\\\\\\\\\". Actual: ' + (x.join("\\"))); +} +var x = new SendableArray("&", "&", "&"); +if (x.join("&") !== "&&&&&") { + throw new Test262Error('#2: var x = new SendableArray("&", "&", "&"); x.join("&") === "&&&&&". Actual: ' + (x.join("&"))); +} +var x = new SendableArray(true, true, true); +if (x.join() !== "true,true,true") { + throw new Test262Error('#3: var x = new SendableArray(true,true,true); x.join(true,true,true) === "true,true,true". Actual: ' + (x.join(true, true, true))); +} +var x = new SendableArray(null, null, null); +if (x.join() !== ",,") { + throw new Test262Error('#4: var x = new SendableArray(null,null,null); x.join(null,null,null) === ",,". Actual: ' + (x.join(null, null, null))); +} +var x = new SendableArray(undefined, undefined, undefined); +if (x.join() !== ",,") { + throw new Test262Error('#5: var x = new SendableArray(undefined,undefined,undefined); x.join(undefined,undefined,undefined) === ",,". Actual: ' + (x.join(undefined, undefined, undefined))); +} +var x = new SendableArray(Infinity, Infinity, Infinity); +if (x.join() !== "Infinity,Infinity,Infinity") { + throw new Test262Error('#6: var x = new SendableArray(Infinity,Infinity,Infinity); x.join(Infinity,Infinity,Infinity) === "Infinity,Infinity,Infinity". Actual: ' + (x.join(Infinity, Infinity, Infinity))); +} +var x = new SendableArray(NaN, NaN, NaN); +if (x.join() !== "NaN,NaN,NaN") { + throw new Test262Error('#7: var x = new SendableArray(NaN,NaN,NaN); x.join(NaN,NaN,NaN) === "NaN,NaN,NaN". Actual: ' + (x.join(NaN, NaN, NaN))); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.2_T2.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..c584844f30c65185249bd83477088626bc6bcc34 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A3.2_T2.js @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToString from array arguments +esid: sec-array.prototype.join +description: If Type(argument) is Object, evaluate ToPrimitive(argument, String) +---*/ + +var object = { + valueOf: function() { + return "+" + } +}; +var x = new SendableArray(object); +assert.sameValue(x.join(), "[object Object]", 'x.join() must return "[object Object]"'); +var object = { + valueOf: function() { + return "+" + }, + toString: function() { + return "*" + } +}; +var x = new SendableArray(object); +assert.sameValue(x.join(), "*", 'x.join() must return "*"'); +var object = { + valueOf: function() { + return "+" + }, + toString: function() { + return {} + } +}; +var x = new SendableArray(object); +assert.sameValue(x.join(), "+", 'x.join() must return "+"'); +try { + var object = { + valueOf: function() { + throw "error" + }, + toString: function() { + return "*" + } + }; + var x = new SendableArray(object); + assert.sameValue(x.join(), "*", 'x.join() must return "*"'); +} +catch (e) { + assert.notSameValue(e, "error", 'The value of e is not "error"'); +} +var object = { + toString: function() { + return "*" + } +}; +var x = new SendableArray(object); +assert.sameValue(x.join(), "*", 'x.join() must return "*"'); +var object = { + valueOf: function() { + return {} + }, + toString: function() { + return "*" + } +} +var x = new SendableArray(object); +assert.sameValue(x.join(), "*", 'x.join() must return "*"'); +try { + var object = { + valueOf: function() { + return "+" + }, + toString: function() { + throw "error" + } + }; + var x = new SendableArray(object); + x.join(); + throw new Test262Error('#7.1: var object = {valueOf: function() {return "+"}, toString: function() {throw "error"}} var x = new SendableArray(object); x.join() throw "error". Actual: ' + (x.join())); +} +catch (e) { + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); +} +try { + var object = { + valueOf: function() { + return {} + }, + toString: function() { + return {} + } + }; + var x = new SendableArray(object); + x.join(); + throw new Test262Error('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}} var x = new SendableArray(object); x.join() throw TypeError. Actual: ' + (x.join())); +} +catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A4_T3.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A4_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..8f770fb8135f31058cd2a6824c17c50525823c06 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A4_T3.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.join +description: length = -4294967294 +---*/ + +var obj = {}; +obj.join = SendableArray.prototype.join; +obj[0] = "x"; +obj[1] = "y"; +obj[2] = "z"; +obj.length = -4294967294; + +if (obj.join("") !== "") { + throw new Test262Error('#1: var obj = {}; obj.join = SendableArray.prototype.join; obj[0] = "x"; obj[1] = "y"; obj[2] = "z"; obj.length = -4294967294; obj.join("") === "". Actual: ' + (obj.join(""))); +} +if (obj.length !== -4294967294) { + throw new Test262Error('#2: var obj = {}; obj.join = SendableArray.prototype.join; obj[0] = "x"; obj[1] = "y"; obj[2] = "z"; obj.length = -4294967294; obj.join(""); obj.length === -4294967294. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A5_T1.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A5_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..887473e387f66334cd16f62bceaaecf70db9b2c8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A5_T1.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]] from not an inherited property" +esid: sec-array.prototype.join +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[1] = 1; +var x = [0]; +x.length = 2; +if (x.join() !== "0,1") { + throw new Test262Error('#1: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; x.join() === "0,1". Actual: ' + (x.join())); +} +Object.prototype[1] = 1; +Object.prototype.length = 2; +Object.prototype.join = SendableArray.prototype.join; +x = { + 0: 0 +}; +if (x.join() !== "0,1") { + throw new Test262Error('#2: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.join = SendableArray.prototype.join; x = {0:0}; x.join() === "0,1". Actual: ' + (x.join())); +} diff --git a/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A6.6.js b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A6.6.js new file mode 100644 index 0000000000000000000000000000000000000000..9c0ad3eb133645788e6c4d4f7f9da7acddb59116 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/S15.4.4.5_A6.6.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: The join property of Array has not prototype property +esid: sec-array.prototype.join +description: Checking Array.prototype.join.prototype +---*/ + +if (SendableArray.prototype.join.prototype !== undefined) { + throw new Test262Error('#1: SendableArray.prototype.join.prototype === undefined. Actual: ' + (SendableArray.prototype.join.prototype)); +} diff --git a/test/sendable/builtins/Array/prototype/join/call-with-boolean.js b/test/sendable/builtins/Array/prototype/join/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..350363367217be9438490d87a5f88c895e645a16 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/call-with-boolean.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.join +description: Array.prototype.join applied to boolean primitive +---*/ + +assert.sameValue(SendableArray.prototype.join.call(true), "", 'SendableArray.prototype.join.call(true) must return ""'); +assert.sameValue(SendableArray.prototype.join.call(false), "", 'SendableArray.prototype.join.call(false) must return ""'); diff --git a/test/sendable/builtins/Array/prototype/join/coerced-separator-grow.js b/test/sendable/builtins/Array/prototype/join/coerced-separator-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..ed54d5ed349718d7a3538bbed4f7f02a20c32328 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/coerced-separator-grow.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.join +description: > + Array.p.join behaves correctly when the receiver is grown during + argument coercion +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Growing + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + toString: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return '.'; + } + }; + assert.sameValue(SendableArray.prototype.join.call(fixedLength, evil), '0.0.0.0'); +} +// Growing + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let evil = { + toString: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return '.'; + } + }; + // We iterate 4 elements, since it was the starting length. + assert.sameValue(SendableArray.prototype.join.call(lengthTracking, evil), '0.0.0.0'); +} diff --git a/test/sendable/builtins/Array/prototype/join/coerced-separator-shrink.js b/test/sendable/builtins/Array/prototype/join/coerced-separator-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..29837e4034a8143ec74aa6f432ddf29ec71ca339 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/coerced-separator-shrink.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.join +description: > + Array.p.join behaves correctly when the receiver is shrunk during + argument coercion +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Shrinking + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + toString: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return '.'; + } + }; + // We iterate 4 elements, since it was the starting length, but the TA is + // OOB right after parameter conversion, so all elements are converted to + // the empty string. + assert.sameValue(SendableArray.prototype.join.call(fixedLength, evil), '...'); +} +// Shrinking + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let evil = { + toString: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return '.'; + } + }; + // We iterate 4 elements, since it was the starting length. Elements beyond + // the new length are converted to the empty string. + assert.sameValue(SendableArray.prototype.join.call(lengthTracking, evil), '0.0..'); +} diff --git a/test/sendable/builtins/Array/prototype/join/length.js b/test/sendable/builtins/Array/prototype/join/length.js new file mode 100644 index 0000000000000000000000000000000000000000..aaad9e7b3974ca4776d807d26bc33a18db0e6645 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/length.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.join +description: > + The "length" property of Array.prototype.join +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.join, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/join/name.js b/test/sendable/builtins/Array/prototype/join/name.js new file mode 100644 index 0000000000000000000000000000000000000000..47e92550c387ef21b93e01243424ce0b6a089b1f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.join +description: > + Array.prototype.join.name is "join". +info: | + Array.prototype.join (separator) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.join, "name", { + value: "join", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/join/not-a-constructor.js b/test/sendable/builtins/Array/prototype/join/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..e333023858d1aedacc0b224281edb0325d7ecc1f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.join does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.prototype.join), false, 'isConstructor(SendableArray.prototype.join) must return false'); +assert.throws(TypeError, () => { + new SendableArray.prototype.join(); +}); + diff --git a/test/sendable/builtins/Array/prototype/join/prop-desc.js b/test/sendable/builtins/Array/prototype/join/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..746617ef7c0900830ed5fb29be8cdaa8808928cb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.join +description: > + "join" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.join, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "join", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/join/resizable-buffer.js b/test/sendable/builtins/Array/prototype/join/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..fd94a6b19d4effb2a1d6e9434b4c13cf5b9e9eda --- /dev/null +++ b/test/sendable/builtins/Array/prototype/join/resizable-buffer.js @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.join +description: > + Array.p.join behaves correctly when the receiver is backed by resizable + buffer +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const taWrite = new ctor(rab); + // Write some data into the array. + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + assert.sameValue(SendableArray.prototype.join.call(fixedLength), '0,2,4,6'); + assert.sameValue(SendableArray.prototype.join.call(fixedLengthWithOffset), '4,6'); + assert.sameValue(SendableArray.prototype.join.call(lengthTracking), '0,2,4,6'); + assert.sameValue(SendableArray.prototype.join.call(lengthTrackingWithOffset), '4,6'); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + assert.sameValue(SendableArray.prototype.join.call(fixedLength), ''); + assert.sameValue(SendableArray.prototype.join.call(fixedLengthWithOffset), ''); + assert.sameValue(SendableArray.prototype.join.call(lengthTracking), '0,2,4'); + assert.sameValue(SendableArray.prototype.join.call(lengthTrackingWithOffset), '4'); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(SendableArray.prototype.join.call(fixedLength), ''); + assert.sameValue(SendableArray.prototype.join.call(fixedLengthWithOffset), ''); + assert.sameValue(SendableArray.prototype.join.call(lengthTrackingWithOffset), ''); + assert.sameValue(SendableArray.prototype.join.call(lengthTracking), '0'); + // Shrink to zero. + rab.resize(0); + assert.sameValue(SendableArray.prototype.join.call(fixedLength), ''); + assert.sameValue(SendableArray.prototype.join.call(fixedLengthWithOffset), ''); + assert.sameValue(SendableArray.prototype.join.call(lengthTrackingWithOffset), ''); + assert.sameValue(SendableArray.prototype.join.call(lengthTracking), ''); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + assert.sameValue(SendableArray.prototype.join.call(fixedLength), '0,2,4,6'); + assert.sameValue(SendableArray.prototype.join.call(fixedLengthWithOffset), '4,6'); + assert.sameValue(SendableArray.prototype.join.call(lengthTracking), '0,2,4,6,8,10'); + assert.sameValue(SendableArray.prototype.join.call(lengthTrackingWithOffset), '4,6,8,10'); +} diff --git a/test/sendable/builtins/Array/prototype/keys/iteration-mutable.js b/test/sendable/builtins/Array/prototype/keys/iteration-mutable.js new file mode 100644 index 0000000000000000000000000000000000000000..df57788c14c6282afb248c133d54b6a2e0c11994 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/iteration-mutable.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.keys +description: > + New items in the array are accessible via iteration until iterator is "done". +info: | + When an item is added to the array after the iterator is created but + before the iterator is "done" (as defined by 22.1.5.2.1), the new item's + key should be accessible via iteration. When an item is added to the + array after the iterator is "done", the new item's key should not be + accessible via iteration. +---*/ + +var SendableArray = []; +var iterator = SendableArray.keys(); +var result; +SendableArray.push('a'); +result = iterator.next(); +assert.sameValue(result.done, false, 'First result `done` flag'); +assert.sameValue(result.value, 0, 'First result `value`'); +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +SendableArray.push('b'); +result = iterator.next(); +assert.sameValue( + result.done, true, + 'Exhausted result `done` flag (after push)' +); +assert.sameValue( + result.value, undefined, + 'Exhausted result `value` (after push)' +); diff --git a/test/sendable/builtins/Array/prototype/keys/iteration.js b/test/sendable/builtins/Array/prototype/keys/iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..fb6a53dc4dd8510bcc736fbd37c6639c99abc8fe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/iteration.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.keys +description: > + The return is a valid iterator with the array's numeric properties. +info: | + 22.1.3.13 Array.prototype.keys ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "key"). +---*/ + +var SendableArray = ['a', 'b', 'c']; +var iterator = SendableArray.keys(); +var result; +result = iterator.next(); +assert.sameValue(result.value, 0, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); +result = iterator.next(); +assert.sameValue(result.value, 1, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); +result = iterator.next(); +assert.sameValue(result.value, 2, 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); diff --git a/test/sendable/builtins/Array/prototype/keys/length.js b/test/sendable/builtins/Array/prototype/keys/length.js new file mode 100644 index 0000000000000000000000000000000000000000..a2cafc38d1efabc05e31870ae6de46019f4b3600 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/length.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.keys +description: > + Array.prototype.keys.length value and descriptor. +info: | + 22.1.3.13 Array.prototype.keys ( ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.keys, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/keys/name.js b/test/sendable/builtins/Array/prototype/keys/name.js new file mode 100644 index 0000000000000000000000000000000000000000..bbc8cb473b3094be09638a715d9eab5225ff6cf6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/name.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.keys +description: > + Array.prototype.keys.name value and descriptor. +info: | + 22.1.3.13 Array.prototype.keys ( ) + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.keys, "name", { + value: "keys", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/keys/not-a-constructor.js b/test/sendable/builtins/Array/prototype/keys/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..283cfc57b2ec4364d7c91cfa53db9007c2a5f70c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/not-a-constructor.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.keys does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.prototype.keys), false, 'isConstructor(SendableArray.prototype.keys) must return false'); +assert.throws(TypeError, () => { + new SendableArray.prototype.keys(); +}); + diff --git a/test/sendable/builtins/Array/prototype/keys/prop-desc.js b/test/sendable/builtins/Array/prototype/keys/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..e8bf6d5d9642a3ef0b942c0ca60adb8abb8f3127 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/prop-desc.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.keys +description: > + Property type and descriptor. +info: | + 22.1.3.13 Array.prototype.keys ( ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableArray.prototype.keys, + 'function', + '`typeof SendableArray.prototype.keys` is `function`' +); +verifyProperty(SendableArray.prototype, "keys", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/keys/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/keys/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..7ff3b6172520b40828b1489e3aee034fc87d2fc3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.keys +description: > + Array.p.keys behaves correctly when receiver is backed by a resizable + buffer and is grown mid-iteration +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + // The fixed length array is not affected by resizing. + TestIterationAndResize(SendableArray.prototype.keys.call(fixedLength), [ + 0, + 1, + 2, + 3 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + // The fixed length array is not affected by resizing. + TestIterationAndResize(SendableArray.prototype.keys.call(fixedLengthWithOffset), [ + 0, + 1 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(SendableArray.prototype.keys.call(lengthTracking), [ + 0, + 1, + 2, + 3, + 4, + 5 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + TestIterationAndResize(SendableArray.prototype.keys.call(lengthTrackingWithOffset), [ + 0, + 1, + 2, + 3 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/Array/prototype/keys/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/keys/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..cf7268398d0918765d06d3589f987d3eb2a66f2e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.keys +description: > + Array.p.keys behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + // The fixed length array goes out of bounds when the RAB is resized. + assert.throws(TypeError, () => { + TestIterationAndResize(SendableArray.prototype.keys.call(fixedLength), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + + // The fixed length array goes out of bounds when the RAB is resized. + assert.throws(TypeError, () => { + TestIterationAndResize(SendableArray.prototype.keys.call(fixedLengthWithOffset), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(SendableArray.prototype.keys.call(lengthTracking), [ + 0, + 1, + 2 + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + TestIterationAndResize(SendableArray.prototype.keys.call(lengthTrackingWithOffset), [ + 0, + 1 + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/Array/prototype/keys/resizable-buffer.js b/test/sendable/builtins/Array/prototype/keys/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..7ecf06a1cb3a8c24c088caa33720d2f232271ab5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/resizable-buffer.js @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.keys +description: > + Array.p.keys behaves correctly when receiver is backed by resizable + buffer +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + assert.compareArray(SendableArray.from(SendableArray.prototype.keys.call(fixedLength)), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(SendableArray.from(SendableArray.prototype.keys.call(fixedLengthWithOffset)), [ + 0, + 1 + ]); + assert.compareArray(ArraSendableArrayy.from(SendableArray.prototype.keys.call(lengthTracking)), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(SendableArray.from(SendableArray.prototype.keys.call(lengthTrackingWithOffset)), [ + 0, + 1 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + // TypedArray.prototype.{entries, keys, values} throw right away when + // called. Array.prototype.{entries, keys, values} don't throw, but when + // we try to iterate the returned ArrayIterator, that throws. + SendableArray.prototype.keys.call(fixedLength); + SendableArray.prototype.keys.call(fixedLengthWithOffset); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.keys.call(fixedLength)); + }); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.keys.call(fixedLengthWithOffset)); + }); + assert.compareArray(SendableArray.from(SendableArray.prototype.keys.call(lengthTracking)), [ + 0, + 1, + 2 + ]); + assert.compareArray(SendableArray.from(SendableArray.prototype.keys.call(lengthTrackingWithOffset)), [0]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + SendableArray.prototype.keys.call(fixedLength); + SendableArray.prototype.keys.call(fixedLengthWithOffset); + SendableArray.prototype.keys.call(lengthTrackingWithOffset); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.keys.call(fixedLength)); + }); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.keys.call(fixedLengthWithOffset)); + }); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.keys.call(lengthTrackingWithOffset)); + }); + assert.compareArray(SendableArray.from(SendableArray.prototype.keys.call(lengthTracking)), [0]); + // Shrink to zero. + rab.resize(0); + SendableArray.prototype.keys.call(fixedLength); + SendableArray.prototype.keys.call(fixedLengthWithOffset); + SendableArray.prototype.keys.call(lengthTrackingWithOffset); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.keys.call(fixedLength)); + }); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.keys.call(fixedLengthWithOffset)); + }); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.keys.call(lengthTrackingWithOffset)); + }); + assert.compareArray(SendableArray.from(SendableArray.prototype.keys.call(lengthTracking)), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.compareArray(SendableArray.from(SendableArray.prototype.keys.call(fixedLength)), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(SendableArray.from(SendableArray.prototype.keys.call(fixedLengthWithOffset)), [ + 0, + 1 + ]); + assert.compareArray(SendableArray.from(SendableArray.prototype.keys.call(lengthTracking)), [ + 0, + 1, + 2, + 3, + 4, + 5 + ]); + assert.compareArray(SendableArray.from(SendableArray.prototype.keys.call(lengthTrackingWithOffset)), [ + 0, + 1, + 2, + 3 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/keys/return-abrupt-from-this.js b/test/sendable/builtins/Array/prototype/keys/return-abrupt-from-this.js new file mode 100644 index 0000000000000000000000000000000000000000..3db71ecbad40b62294956b756bddd51eb9a584e9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/return-abrupt-from-this.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.keys +description: > + Return abrupt from ToObject(this value). +info: | + 22.1.3.13 Array.prototype.keys ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.keys.call(undefined); +}); +assert.throws(TypeError, function() { + SendableArray.prototype.keys.call(null); +}); diff --git a/test/sendable/builtins/Array/prototype/keys/returns-iterator-from-object.js b/test/sendable/builtins/Array/prototype/keys/returns-iterator-from-object.js new file mode 100644 index 0000000000000000000000000000000000000000..b598e5e9e5036001e0350902ce34963a9432f06b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/returns-iterator-from-object.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.keys +description: > + Creates an iterator from a custom object. +info: | + 22.1.3.13 Array.prototype.keys ( ) + + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "key"). +features: [Symbol.iterator] +---*/ + +var obj = { + length: 2 +}; +var iter = SendableArray.prototype.keys.call(obj); +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].keys() is %ArrayIteratorPrototype%' +); diff --git a/test/sendable/builtins/Array/prototype/keys/returns-iterator.js b/test/sendable/builtins/Array/prototype/keys/returns-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..c2048e6070025e87213282d83915fad35e935c62 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/keys/returns-iterator.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.keys +description: > + The method should return an Iterator instance. +info: | + 22.1.3.13 Array.prototype.keys ( ) +features: [Symbol.iterator] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); +var iter = [].keys(); +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].keys() is %ArrayIteratorPrototype%' +); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..b5cc9d45381659a88f5a981f945fd9adb38a02d9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to undefined throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.lastIndexOf.call(undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-10.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..9453c2fb56b6f30ef1786f1db687389e38ddb849 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-10.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to the Math object +---*/ + +Math.length = 2; +Math[1] = 100; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(Math, 100), 1, 'SendableArray.prototype.lastIndexOf.call(Math, 100)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-11.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..6596f7a78028d23d0212ffc891d7626cdce339a3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-11.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to Date object +---*/ + +var obj = new Date(0); +obj.length = 2; +obj[1] = true; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 1, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-12.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..8a6c1460f05b1e6a8762060229053f5da4764d7c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-12.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to RegExp object +---*/ + +var obj = new RegExp("afdasf"); +obj.length = 100; +obj[1] = "afdasf"; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, "afdasf"), 1, 'SendableArray.prototype.lastIndexOf.call(obj, "afdasf")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-13.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..9ea3c454511bffb3907f2ad64910fc83516df5ab --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-13.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to the JSON object +---*/ + +var targetObj = {}; +JSON[3] = targetObj; +JSON.length = 5; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(JSON, targetObj), 3, 'SendableArray.prototype.lastIndexOf.call(JSON, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-14.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-14.js new file mode 100644 index 0000000000000000000000000000000000000000..7603b2bcab4ef2d031295ffadceb3f0c983140a0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-14.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to Error object +---*/ + +var obj = new SyntaxError(); +obj.length = 2; +obj[1] = Infinity; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, Infinity), 1, 'SendableArray.prototype.lastIndexOf.call(obj, Infinity)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-15.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..373f0b2ca3314ff1e815bb468ad73ec3cfffddca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-15.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to the Arguments object +---*/ + +var obj = (function fun() { + return arguments; +}(1, 2, 3)); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 2), 1, 'SendableArray.prototype.lastIndexOf.call(obj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..aeae56bc2cf958a07b370026f290b9055b25275a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to null throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.lastIndexOf.call(null); +}); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-3.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..2915bf314af6d52dfa3db904275e27a3a17150ae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-3.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to boolean primitive +---*/ + +Boolean.prototype[1] = true; +Boolean.prototype.length = 2; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(true, true), 1, 'SendableArray.prototype.lastIndexOf.call(true, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-4.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..dc592403c76dc07f3c13cc42425b5758ae6be198 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-4.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to Boolean object +---*/ + +var obj = new Boolean(false); +obj.length = 2; +obj[1] = true; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 1, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-5.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..236d9068caf6d109def2aa57680215af5e9febec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-5.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to number primitive +---*/ + +Number.prototype[1] = isNaN; +Number.prototype.length = 2; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(5, isNaN), 1, 'SendableArray.prototype.lastIndexOf.call(5, isNaN)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-6.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..8ea9ceac09627345014aa45fb235456ffe67f2f1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-6.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to Number object +---*/ + +var obj = new Number(-3); +obj.length = 2; +obj[1] = true; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 1, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-7.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..1631437316ea65ca7cd14b50e98b9e31d67ba2ce --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-7.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to string primitive +---*/ + +assert.sameValue(SendableArray.prototype.lastIndexOf.call("abc", "c"), 2, 'SendableArray.prototype.lastIndexOf.call("abc", "c")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-8.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..18813712678f421ddd5d40750730cafe95d7d897 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-8.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to String object +---*/ + +var obj = new String("undefined"); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, "f"), 4, 'SendableArray.prototype.lastIndexOf.call(obj, "f")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-9.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..fb0a2b42d6babb2d4f13fb66d71f9cbaa05ed090 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-1-9.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf applied to Function object +---*/ + +var obj = function(a, b) { + return a + b; +}; +obj[1] = true; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 1, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..1136bdf10440fc257058e8e777423d7f7650e997 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-1.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is own data property on an + Array-like object +---*/ + +var obj = { + 1: null, + 2: undefined, + length: 2 +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, null), 1, 'SendableArray.prototype.lastIndexOf.call(obj, null)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, undefined), -1, 'SendableArray.prototype.lastIndexOf.call(obj, undefined)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-10.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-10.js new file mode 100644 index 0000000000000000000000000000000000000000..5b302310791ca2eae0d765d3bc687a772b3aad84 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-10.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is inherited accessor + property on an Array-like object +---*/ + +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[1] = 1; +child[2] = 2; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(child, 1), 1, 'SendableArray.prototype.lastIndexOf.call(child, 1)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(child, 2), -1, 'SendableArray.prototype.lastIndexOf.call(child, 2)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-11.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-11.js new file mode 100644 index 0000000000000000000000000000000000000000..87e82646b4e4c3fc264da141a0cd7ae40b638a62 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-11.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is own accessor property + without a get function on an Array-like object +---*/ + +var obj = { + 0: 1 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 1), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-12.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-12.js new file mode 100644 index 0000000000000000000000000000000000000000..cd22b2a0d884a6a9267188e0f8acd7ead713e7bd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-12.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is own accessor property + without a get function that overrides an inherited accessor + property on an Array-like object +---*/ + +Object.defineProperty(Object.prototype, "length", { + get: function() { + return 20; + }, + configurable: true +}); +var obj = { + 1: 1 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 1), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-13.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-13.js new file mode 100644 index 0000000000000000000000000000000000000000..bcebc66590e1e47066511852ba51ee1b5f07623d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-13.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is inherited accessor + property without a get function on an Array-like object +---*/ + +var proto = {}; +Object.defineProperty(proto, "length", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = true; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(child, true), -1, 'SendableArray.prototype.lastIndexOf.call(child, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-14.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-14.js new file mode 100644 index 0000000000000000000000000000000000000000..45b23c4bfe3b51839af21b2542eaad4858cd3921 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-14.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is undefined property on an + Array-like object +---*/ + +var obj = { + 0: null, + 1: undefined +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, null), -1, 'SendableArray.prototype.lastIndexOf.call(obj, null)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-17.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-17.js new file mode 100644 index 0000000000000000000000000000000000000000..2520063140f63dd45c9e342465e1700134784d67 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-17.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf applied to Arguments object which + implements its own property get method +---*/ + +var targetObj = function() {}; +var func = function(a, b) { + arguments[2] = function() {}; + return SendableArray.prototype.lastIndexOf.call(arguments, targetObj) === 1 && + SendableArray.prototype.lastIndexOf.call(arguments, arguments[2]) === -1; +}; +assert(func(0, targetObj), 'func(0, targetObj) !== true'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-18.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-18.js new file mode 100644 index 0000000000000000000000000000000000000000..610c6d75c4b27ca2b31bbbdcc4f2282db4727a77 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-18.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf applied to String object which + implements its own property get method +---*/ + +var str = new String("012"); +String.prototype[3] = "3"; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(str, "2"), 2, 'SendableArray.prototype.lastIndexOf.call(str, "2")'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(str, "3"), -1, 'SendableArray.prototype.lastIndexOf.call(str, "3")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-19.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-19.js new file mode 100644 index 0000000000000000000000000000000000000000..d78c3064d43946d6eaa022ee34b9065471f5f592 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-19.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf applied to String object which + implements its own property get method +---*/ + +var obj = function(a, b) { + return a + b; +}; +obj[1] = "b"; +obj[2] = "c"; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, obj[1]), 1, 'SendableArray.prototype.lastIndexOf.call(obj, obj[1])'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, obj[2]), -1, 'SendableArray.prototype.lastIndexOf.call(obj, obj[2])'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..9593270e16328f929e587fb792d5edd4e3add713 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is own data property on an + Array +---*/ + +var targetObj = {}; +SendableArray.prototype[2] = targetObj; +assert.sameValue([0, targetObj].lastIndexOf(targetObj), 1, '[0, targetObj].lastIndexOf(targetObj)'); +assert.sameValue([0, 1].lastIndexOf(targetObj), -1, '[0, 1].lastIndexOf(targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-3.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..9b6ffad631e9e23a6b861dbe645f29c9e0cde60b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-3.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is own data property that + overrides an inherited data property on an Array-like object +---*/ + +var proto = { + length: 0 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +child[1] = child; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(child, child), 1, 'SendableArray.prototype.lastIndexOf.call(child, child)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-4.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..af97cc3b63249e64a6ab8eeb77c6b5d7fbe267ec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-4.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf when 'length' is own data property + that overrides an inherited data property on an Array +---*/ + +var targetObj = {}; +var arrProtoLen; +arrProtoLen = SendableArray.prototype.length; +SendableArray.prototype.length = 0; +assert.sameValue([0, targetObj, 2].lastIndexOf(targetObj), 1, '[0, targetObj, 2].lastIndexOf(targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-5.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..2198717f5415f1e02d032c88b2dcb4a34842d43d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-5.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is own data property that + overrides an inherited accessor property on an Array-like object +---*/ + +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 0; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + value: 2, + configurable: true +}); +child[1] = null; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(child, null), 1, 'SendableArray.prototype.lastIndexOf.call(child, null)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-6.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-6.js new file mode 100644 index 0000000000000000000000000000000000000000..9dbfa95499b98d62d0c2b8f7bda3bfaeb0d8707c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-6.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is an inherited data + property on an Array-like object +---*/ + +var proto = { + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[1] = "x"; +child[2] = "y"; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(child, "x"), 1, 'SendableArray.prototype.lastIndexOf.call(child, "x")'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(child, "y"), -1, 'SendableArray.prototype.lastIndexOf.call(child, "y")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-7.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-7.js new file mode 100644 index 0000000000000000000000000000000000000000..3b8dd1541a74aca9b35621b73654782fa079f219 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-7.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is own accessor property on + an Array-like object +---*/ + +var obj = { + 1: true, + 2: false +}; +Object.defineProperty(obj, "length", { + get: function() { + return 2; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 1, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, false), -1, 'SendableArray.prototype.lastIndexOf.call(obj, false)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-8.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-8.js new file mode 100644 index 0000000000000000000000000000000000000000..51e71f5a06f209ccbfab5bdd97d2dc37f98127c3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-8.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is own accessor property + that overrides an inherited data property on an Array-like object +---*/ + +var proto = { + length: 0 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[1] = eval; +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(child, eval), 1, 'SendableArray.prototype.lastIndexOf.call(child, eval)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-9.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-9.js new file mode 100644 index 0000000000000000000000000000000000000000..36da2ba4f6c24511fdf7eb2908ab2fb67e0d8bd7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-2-9.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is own accessor property + that overrides an inherited accessor property on an Array-like + object +---*/ + +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 0; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[1] = true; +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(child, true), 1, 'SendableArray.prototype.lastIndexOf.call(child, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-1.js new file mode 100644 index 0000000000000000000000000000000000000000..ae35a07925189f90ca85180f08c21424c39a4017 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf - value of 'length' is undefined +---*/ + +var obj = { + 0: 1, + 1: 1, + length: undefined +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 1), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-10.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-10.js new file mode 100644 index 0000000000000000000000000000000000000000..ce4b355dc356fdd0b9244e82113fd7223dc6a1b0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-10.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a number (value + is NaN) +---*/ + +var obj = { + 0: 0, + length: NaN +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 0), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 0)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-11.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-11.js new file mode 100644 index 0000000000000000000000000000000000000000..4a4c2989e4a99f98020ff3a9d358c5fc6e4e1779 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-11.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a string + containing positive number +---*/ + +var obj = { + 1: true, + 2: false, + length: "2" +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 1, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, false), -1, 'SendableArray.prototype.lastIndexOf.call(obj, false)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-12.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-12.js new file mode 100644 index 0000000000000000000000000000000000000000..a78d90138864612fb0fbe1440ce5e6731d3de4c8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-12.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a string + containing negative number +---*/ + +var obj = { + 1: null, + 2: undefined, + length: "-4294967294" +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, null), -1, 'SendableArray.prototype.lastIndexOf.call(obj, null)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, undefined), -1, 'SendableArray.prototype.lastIndexOf.call(obj, undefined)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-13.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-13.js new file mode 100644 index 0000000000000000000000000000000000000000..b9c23183add808509c1bb4c0fed11a375af45696 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-13.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a string + containing a decimal number +---*/ + +var obj = { + 4: 4, + 5: 5, + length: "5.512345" +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 4), 4, 'SendableArray.prototype.lastIndexOf.call(obj, 4)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 5), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 5)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-14.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-14.js new file mode 100644 index 0000000000000000000000000000000000000000..defa244c5333d7554bb23d52f89239924d0da539 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-14.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a string + containing -Infinity +---*/ + +var objThree = { + 0: true, + 1: true, + length: "-Infinity" +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(objThree, true), -1, 'SendableArray.prototype.lastIndexOf.call(objThree, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-15.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-15.js new file mode 100644 index 0000000000000000000000000000000000000000..0d64a54a067aad1bdfcd68a7198feb9dd17db8b5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-15.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a string + containing an exponential number +---*/ + +var obj = { + 229: 229, + 230: 2.3E2, + length: "2.3E2" +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 229), 229, 'SendableArray.prototype.lastIndexOf.call(obj, 229)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 2.3E2), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 2.3E2)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-16.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-16.js new file mode 100644 index 0000000000000000000000000000000000000000..fa56c022b2cb9e9c09402a5bba0bcc3c6bcb8586 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-16.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a string which + is able to be converted into hex number +---*/ + +var obj = { + 2573: 2573, + 2574: 0x000A0E, + length: "0x000A0E" +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 2573), 2573, 'SendableArray.prototype.lastIndexOf.call(obj, 2573)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 0x000A0E), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 0x000A0E)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-17.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-17.js new file mode 100644 index 0000000000000000000000000000000000000000..d7fef3740ae3fae745b7b4f01b33241ca0faf784 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-17.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a string + containing a number with leading zeros +---*/ + +var obj = { + 1: 1, + 2: 2, + length: "0002.0" +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 1), 1, 'SendableArray.prototype.lastIndexOf.call(obj, 1)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 2), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-18.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-18.js new file mode 100644 index 0000000000000000000000000000000000000000..c7de2aa8507a20f607a323fb8b467524351d51d8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-18.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a string that + can't convert to a number +---*/ + +var targetObj = new String("123abc123"); +var obj = { + 0: targetObj, + length: "123abc123" +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, targetObj), -1, 'SendableArray.prototype.lastIndexOf.call(obj, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-19.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-19.js new file mode 100644 index 0000000000000000000000000000000000000000..859bb077904c660d3d6d8d849e22a70a6a5480b6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-19.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is an Object which + has an own toString method +---*/ + +// objects inherit the default valueOf() method from Object +// that simply returns itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. + +var targetObj = this; +var obj = { + 1: targetObj, + 2: 2, + length: { + toString: function() { + return '2'; + } + } +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, targetObj), 1, 'SendableArray.prototype.lastIndexOf.call(obj, targetObj)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 2), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-2.js new file mode 100644 index 0000000000000000000000000000000000000000..f472ba2d45d2ea7de84f4fa1e69028618baaf747 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf return -1 when value of 'length' is a + boolean (value is true) +---*/ + +var obj = { + 0: 0, + 1: 1, + length: true +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 0), 0, 'SendableArray.prototype.lastIndexOf.call(obj, 0)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 1), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-20.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-20.js new file mode 100644 index 0000000000000000000000000000000000000000..bb3ab7474fbe71e251c05ff7b9912bb2ddf74ce3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-20.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is an Object which + has an own valueOf method +---*/ + +//valueOf method will be invoked first, since hint is Number +var obj = { + 1: true, + 2: 2, + length: { + valueOf: function() { + return 2; + } + } +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 1, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 2), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-21.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-21.js new file mode 100644 index 0000000000000000000000000000000000000000..444b9f40761a8d62159932781ccbaf51e75295f2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-21.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'length' is an object that has an + own valueOf method that returns an object and toString method that + returns a string +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var targetObj = this; +var obj = { + 1: targetObj, + length: { + toString: function() { + toStringAccessed = true; + return '3'; + }, + valueOf: function() { + valueOfAccessed = true; + return {}; + } + } +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, targetObj), 1, 'SendableArray.prototype.lastIndexOf.call(obj, targetObj)'); +assert(toStringAccessed, 'toStringAccessed !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-22.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-22.js new file mode 100644 index 0000000000000000000000000000000000000000..6d7656731db6122bbcd3d2d615b367d8b36d7472 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-22.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf throws TypeError exception when + 'length' is an object with toString and valueOf methods that don�t + return primitive values +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var obj = { + 1: true, + length: { + toString: function() { + toStringAccessed = true; + return {}; + }, + valueOf: function() { + valueOfAccessed = true; + return {}; + } + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.lastIndexOf.call(obj, true); +}); +assert(toStringAccessed, 'toStringAccessed'); +assert(valueOfAccessed, 'valueOfAccessed'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-23.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-23.js new file mode 100644 index 0000000000000000000000000000000000000000..60ce42e3ae759e5098165ea4baf9bca50a675fb7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-23.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf uses inherited valueOf method when + 'length' is an object with an own toString and an inherited + valueOf methods +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var proto = { + valueOf: function() { + valueOfAccessed = true; + return 2; + } +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.toString = function() { + toStringAccessed = true; + return 2; +}; +var obj = { + 1: child, + length: child +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, child), 1, 'SendableArray.prototype.lastIndexOf.call(obj, child)'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(toStringAccessed, false, 'toStringAccessed'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-24.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-24.js new file mode 100644 index 0000000000000000000000000000000000000000..5eca2d83afa8c538766fe2a0c80172e8942c6ad4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-24.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a positive + non-integer, ensure truncation occurs in the proper direction +---*/ + +var obj = { + 122: true, + 123: false, + length: 123.5 +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 122, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, false), -1, 'SendableArray.prototype.lastIndexOf.call(obj, false)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-25.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-25.js new file mode 100644 index 0000000000000000000000000000000000000000..b2a7a56552631789ef19cfdf355ae38dd0f94d01 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-25.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a negative + non-integer +---*/ + +var obj = { + 1: true, + 2: false, + length: -4294967294.5 +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), -1, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, false), -1, 'SendableArray.prototype.lastIndexOf.call(obj, false)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-28.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-28.js new file mode 100644 index 0000000000000000000000000000000000000000..759dd3168de7ea5309723d9cd8819ec945d2ec93 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-28.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is boundary value + (2^32) +---*/ + +var targetObj = {}; +var obj = { + 0: targetObj, + 4294967294: targetObj, + 4294967295: targetObj, + length: 4294967296 +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, targetObj), 4294967295, 'verify length is 4294967296 finally'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-3.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-3.js new file mode 100644 index 0000000000000000000000000000000000000000..a3be5b23d1973e97b0eb1d7c6c71212aab659337 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-3.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a number (value + is 0) +---*/ + +var obj = { + 0: "undefined", + length: 0 +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, "undefined"), -1, 'SendableArray.prototype.lastIndexOf.call(obj, "undefined")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-4.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-4.js new file mode 100644 index 0000000000000000000000000000000000000000..da63c9195a2d7d164513a01a0600b69131f1ec6b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-4.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a number (value + is -0) +---*/ + +var obj = { + 0: true, + length: -0 +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), -1, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-5.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-5.js new file mode 100644 index 0000000000000000000000000000000000000000..d2bf4c4dd6f5b1e714b8764ea7b34bd689e1f457 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-5.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a number (value + is +0) +---*/ + +var obj = { + 0: +0, + length: +0 +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, +0), -1, 'SendableArray.prototype.lastIndexOf.call(obj, +0)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-6.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-6.js new file mode 100644 index 0000000000000000000000000000000000000000..d8c32ba14daee792bbbe7ae80182b7ecfc4c2eef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-6.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a number (value + is a positive number) +---*/ + +var obj = { + 99: true, + 100: 100, + length: 100 +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 99, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 100), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 100)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-7.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-7.js new file mode 100644 index 0000000000000000000000000000000000000000..5fcd63630c8a79d6cf96693e2e9aa6fb8fc897f5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-7.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a number (value + is a negative number) +---*/ + +var obj = { + 4: -Infinity, + 5: Infinity, + length: 5 - Math.pow(2, 32) +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, -Infinity), -1, 'SendableArray.prototype.lastIndexOf.call(obj, -Infinity)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, Infinity), -1, 'SendableArray.prototype.lastIndexOf.call(obj, Infinity)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-9.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-9.js new file mode 100644 index 0000000000000000000000000000000000000000..05f22ab13a1bcdbf7505cad4f50c1e5675dc930d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-3-9.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'length' is a number (value + is -Infinity) +---*/ + +var obj = { + 0: 0, + length: -Infinity +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 0), -1, 'SendableArray.prototype.lastIndexOf.call(obj, 0)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..215ada9e6ad5b6e996f956a57f73796251991d81 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 if 'length' is 0 (empty + array) +---*/ + +var i = [].lastIndexOf(42); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-10.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-10.js new file mode 100644 index 0000000000000000000000000000000000000000..c4563f0875f7944456abfbcbe3c26ff62d22826d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-10.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf - 'length' is a number of value -6e-1 +---*/ + +var targetObj = []; +var obj = { + 0: targetObj, + 100: targetObj, + length: -6e-1 +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, targetObj), -1, 'SendableArray.prototype.lastIndexOf.call(obj, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-11.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-11.js new file mode 100644 index 0000000000000000000000000000000000000000..dbb6e7973f43a5e5278ca07f286fa504dcd0aa4d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-11.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf - 'length' is an empty string +---*/ + +var targetObj = []; +var obj = { + 0: targetObj, + 100: targetObj, + length: "" +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, targetObj), -1, 'SendableArray.prototype.lastIndexOf.call(obj, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-2.js new file mode 100644 index 0000000000000000000000000000000000000000..a7ce1de9fa2ae690d92773a4304ec60c79db48e3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 if 'length' is 0 ( length + overridden to null (type conversion)) +---*/ + +var i = SendableArray.prototype.lastIndexOf.call({ + length: null +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-3.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..1f49b3c32db270dfbff36aebaa98179da7060977 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-3.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 if 'length' is 0 (length + overridden to false (type conversion)) +---*/ + +var i = SendableArray.prototype.lastIndexOf.call({ + length: false +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-4.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..93a59aa25e3637d1fd4450ef11d9594bc9a9a9db --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 if 'length' is 0 (generic + 'array' with length 0 ) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); + +function foo() {} +var f = new foo(); +f.length = 0; +var i = SendableArray.prototype.lastIndexOf.call({ + length: 0 +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-5.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-5.js new file mode 100644 index 0000000000000000000000000000000000000000..cd96e87fd7565d2d3f49a339ae138b28aaf72398 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-5.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 if 'length' is 0 ( length + overridden to '0' (type conversion)) +---*/ + +var i = SendableArray.prototype.lastIndexOf.call({ + length: '0' +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-6.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-6.js new file mode 100644 index 0000000000000000000000000000000000000000..121af593401d63c2f3f620c6735d8bcf49252482 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-6.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 if 'length' is 0 + (subclassed Array, length overridden with obj with valueOf) +---*/ + +var i = SendableArray.prototype.lastIndexOf.call({ + length: { + valueOf: function() { + return 0; + } + } +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-7.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-7.js new file mode 100644 index 0000000000000000000000000000000000000000..3440d125f396096e15bdcfcc6acbf6049f21b15a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-7.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 if 'length' is 0 ( length + is object overridden with obj w/o valueOf (toString)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + toString: function() { + return '0'; + } +}; +f.length = o; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +var i = SendableArray.prototype.lastIndexOf.call({ + length: { + toString: function() { + return '0'; + } + } +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-8.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-8.js new file mode 100644 index 0000000000000000000000000000000000000000..2b98cef3fcf95ec116054b5302503fdfdfac6fb1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-8.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 if 'length' is 0 (length is + an empty array) +---*/ + +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +var i = SendableArray.prototype.lastIndexOf.call({ + length: [] +}, 1); +assert.sameValue(i, -1, 'i'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-9.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-9.js new file mode 100644 index 0000000000000000000000000000000000000000..17a45ad467151110656742337761d4a85d1c8226 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-4-9.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf - 'length' is a number of value 0.1 +---*/ + +var targetObj = []; +var obj = { + 0: targetObj, + 100: targetObj, + length: 0.1 +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, targetObj), -1, 'SendableArray.prototype.lastIndexOf.call(obj, targetObj)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..c812d39c923cfd4ad70e315110989d50e3e78420 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf when fromIndex is string +---*/ + +var a = new SendableArray(0, 1, 1); +assert.sameValue(a.lastIndexOf(1, "1"), 1, '"1" resolves to 1'); +assert.sameValue(a.lastIndexOf(1, "one"), -1, 'NaN string resolves to 01'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-10.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-10.js new file mode 100644 index 0000000000000000000000000000000000000000..9e251931c870073a5b9b6fb55a76fcceb368529b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-10.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a number + (value is positive number) +---*/ + +var targetObj = {}; +assert.sameValue([0, targetObj, true].lastIndexOf(targetObj, 1.5), 1, '[0, targetObj, true].lastIndexOf(targetObj, 1.5)'); +assert.sameValue([0, true, targetObj].lastIndexOf(targetObj, 1.5), -1, '[0, true, targetObj].lastIndexOf(targetObj, 1.5)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-11.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-11.js new file mode 100644 index 0000000000000000000000000000000000000000..8dcae0dafcb69f290acf677a3ead43ba5968f058 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-11.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a number + (value is negative number) +---*/ + +var targetObj = {}; +assert.sameValue([0, targetObj, true].lastIndexOf(targetObj, -2.5), 1, '[0, targetObj, true].lastIndexOf(targetObj, -2.5)'); +assert.sameValue([0, true, targetObj].lastIndexOf(targetObj, -2.5), -1, '[0, true, targetObj].lastIndexOf(targetObj, -2.5)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-12.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-12.js new file mode 100644 index 0000000000000000000000000000000000000000..e3c67c5e730579eb3fddb1c49c38a6362f7fce62 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-12.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a number + (value is Infinity) +---*/ + +var arr = []; +arr[Math.pow(2, 32) - 2] = null; // length is the max value of Uint type +assert.sameValue(arr.lastIndexOf(null, Infinity), Math.pow(2, 32) - 2, 'arr.lastIndexOf(null, Infinity)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-13.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-13.js new file mode 100644 index 0000000000000000000000000000000000000000..5926479d9dff1d71e3bdc774f6fb65a871511923 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-13.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a number + (value is -Infinity) +---*/ + +assert.sameValue([true].lastIndexOf(true, -Infinity), -1, '[true].lastIndexOf(true, -Infinity)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-14.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-14.js new file mode 100644 index 0000000000000000000000000000000000000000..b64a1e07f1e7ab61e007929c7e8da801fc6aafd7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-14.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a number + (value is NaN) +---*/ + +// from Index will be convert to +0 +assert.sameValue([0, true].lastIndexOf(true, NaN), -1, '[0, true].lastIndexOf(true, NaN)'); +assert.sameValue([true, 0].lastIndexOf(true, NaN), 0, '[true, 0].lastIndexOf(true, NaN)'); +assert.sameValue([0, true].lastIndexOf(true, -NaN), -1, '[0, true].lastIndexOf(true, -NaN)'); +assert.sameValue([true, 0].lastIndexOf(true, -NaN), 0, '[true, 0].lastIndexOf(true, -NaN)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-15.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-15.js new file mode 100644 index 0000000000000000000000000000000000000000..63cf3a3d4ba2761320c5f7f0b22ccdacb7f4a7fd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-15.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a string + containing a negative number +---*/ + +assert.sameValue([0, "-2", 2].lastIndexOf("-2", "-2"), 1, '[0, "-2", 2].lastIndexOf("-2", "-2")'); +assert.sameValue([0, 2, "-2"].lastIndexOf("-2", "-2"), -1, '[0, 2, "-2"].lastIndexOf("-2", "-2")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-16.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-16.js new file mode 100644 index 0000000000000000000000000000000000000000..6f57225646783ad10ad49a0d1b131b78a0aeb9f3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-16.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a string + containing Infinity +---*/ + +var arr = []; +arr[Math.pow(2, 32) - 2] = true; // length is the max value of Uint type +assert.sameValue(arr.lastIndexOf(true, "Infinity"), Math.pow(2, 32) - 2, 'arr.lastIndexOf(true, "Infinity")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-17.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-17.js new file mode 100644 index 0000000000000000000000000000000000000000..a1e609e310a0da615d2af4b45dd1edf8867809e7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-17.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a string + containing -Infinity +---*/ + +assert.sameValue([true].lastIndexOf(true, "-Infinity"), -1, '[true].lastIndexOf(true, "-Infinity")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-18.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-18.js new file mode 100644 index 0000000000000000000000000000000000000000..43d998e0165be1c23956243335e7c5be8dc51bda --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-18.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a string + containing an exponential number +---*/ + +var targetObj = {}; +assert.sameValue([0, NaN, targetObj, 3, false].lastIndexOf(targetObj, "2E0"), 2, '[0, NaN, targetObj, 3, false].lastIndexOf(targetObj, "2E0")'); +assert.sameValue([0, NaN, 3, targetObj, false].lastIndexOf(targetObj, "2E0"), -1, '[0, NaN, 3, targetObj, false].lastIndexOf(targetObj, "2E0")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-19.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-19.js new file mode 100644 index 0000000000000000000000000000000000000000..30375844c94e15c7edb4bdb91c3568ef59056ff9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-19.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a string + containing a hex number +---*/ + +var targetObj = {}; +assert.sameValue([0, true, targetObj, 3, false].lastIndexOf(targetObj, "0x0002"), 2, '[0, true, targetObj, 3, false].lastIndexOf(targetObj, "0x0002")'); +assert.sameValue([0, true, 3, targetObj, false].lastIndexOf(targetObj, "0x0002"), -1, '[0, true, 3, targetObj, false].lastIndexOf(targetObj, "0x0002")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-2.js new file mode 100644 index 0000000000000000000000000000000000000000..520ac24a8ceed68982abe494d3a1d711419301e1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-2.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf when fromIndex is floating point number +---*/ + +var a = new SendableArray(1, 2, 1); +assert.sameValue(a.lastIndexOf(2, 1.49), 1, '1.49 resolves to 1'); +assert.sameValue(a.lastIndexOf(2, 0.51), -1, '0.51 resolves to 0'); +assert.sameValue(a.lastIndexOf(1, 0.51), 0, '0.51 resolves to 0'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-20.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-20.js new file mode 100644 index 0000000000000000000000000000000000000000..a9f8753c0acf613d3417235f8dd92c3548fc5194 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-20.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' which is a + string containing a number with leading zeros +---*/ + +var targetObj = {}; +assert.sameValue([0, true, targetObj, 3, false].lastIndexOf(targetObj, "0002.10"), 2, '[0, true, targetObj, 3, false].lastIndexOf(targetObj, "0002.10")'); +assert.sameValue([0, true, 3, targetObj, false].lastIndexOf(targetObj, "0002.10"), -1, '[0, true, 3, targetObj, false].lastIndexOf(targetObj, "0002.10")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-21.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-21.js new file mode 100644 index 0000000000000000000000000000000000000000..0f3062e40ce58b757e9ab3bebac71c44e75227f9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-21.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' which is an + Object, and has an own toString method +---*/ + +// objects inherit the default valueOf() method from Object +// that simply returns itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +var fromIndex = { + toString: function() { + return '2'; + } +}; +var targetObj = new RegExp(); +assert.sameValue([0, true, targetObj, 3, false].lastIndexOf(targetObj, fromIndex), 2, '[0, true, targetObj, 3, false].lastIndexOf(targetObj, fromIndex)'); +assert.sameValue([0, true, 3, targetObj, false].lastIndexOf(targetObj, fromIndex), -1, '[0, true, 3, targetObj, false].lastIndexOf(targetObj, fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-22.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-22.js new file mode 100644 index 0000000000000000000000000000000000000000..0f8243aea33d89d567dd649bb6e3e9eab51578d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-22.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' which is an + object, and has an own valueOf method +---*/ + +var fromIndex = { + valueOf: function() { + return 2; + } +}; +var targetObj = function() {}; +assert.sameValue([0, true, targetObj, 3, false].lastIndexOf(targetObj, fromIndex), 2, '[0, true, targetObj, 3, false].lastIndexOf(targetObj, fromIndex)'); +assert.sameValue([0, true, 3, targetObj, false].lastIndexOf(targetObj, fromIndex), -1, '[0, true, 3, targetObj, false].lastIndexOf(targetObj, fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-23.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-23.js new file mode 100644 index 0000000000000000000000000000000000000000..71ebce491063c97b0cc0ebb6171cfb29d35d4332 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-23.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is an object + that has an own valueOf method that returns an object and toString + method that returns a string +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var fromIndex = { + toString: function() { + toStringAccessed = true; + return '1'; + }, + valueOf: function() { + valueOfAccessed = true; + return {}; + } +}; +assert.sameValue([0, true].lastIndexOf(true, fromIndex), 1, '[0, true].lastIndexOf(true, fromIndex)'); +assert(toStringAccessed, 'toStringAccessed !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-24.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-24.js new file mode 100644 index 0000000000000000000000000000000000000000..5266fae56758dae385ac1a9d3cdcb30d542dab6b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-24.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf throws TypeError exception when value + of 'fromIndex' is an object that both toString and valueOf methods + than don't return primitive value +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var fromIndex = { + toString: function() { + toStringAccessed = true; + return {}; + }, + valueOf: function() { + valueOfAccessed = true; + return {}; + } +}; +assert.throws(TypeError, function() { + [0, null].lastIndexOf(null, fromIndex); +}); +assert(toStringAccessed, 'toStringAccessed'); +assert(valueOfAccessed, 'valueOfAccessed'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-25.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-25.js new file mode 100644 index 0000000000000000000000000000000000000000..761c22a6f24d4d4ef0395799911997c2da156fef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-25.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf use inherited valueOf method when + value of 'fromIndex' is an object with an own toString and + inherited valueOf methods +---*/ + +var toStringAccessed = false; +var valueOfAccessed = false; +var proto = { + valueOf: function() { + valueOfAccessed = true; + return 1; + } +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.toString = function() { + toStringAccessed = true; + return 1; +}; +assert.sameValue([0, true].lastIndexOf(true, child), 1, '[0, true].lastIndexOf(true, child)'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(toStringAccessed, false, 'toStringAccessed'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-26.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-26.js new file mode 100644 index 0000000000000000000000000000000000000000..4d230b28fdcb246329656fd6de4ab360d63a51be --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-26.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - side effects produced by step 2 are + visible when an exception occurs +---*/ + +var stepTwoOccurs = false; +var stepFiveOccurs = false; +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + stepTwoOccurs = true; + if (stepFiveOccurs) { + throw new Error("Step 5 occurred out of order"); + } + return 20; + }, + configurable: true +}); +var fromIndex = { + valueOf: function() { + stepFiveOccurs = true; + return 0; + } +}; +SendableArray.prototype.lastIndexOf.call(obj, undefined, fromIndex); +assert(stepTwoOccurs, 'stepTwoOccurs !== true'); +assert(stepFiveOccurs, 'stepFiveOccurs !== true'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-27.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-27.js new file mode 100644 index 0000000000000000000000000000000000000000..988b4eedf17aad2fda08099114e8118333e46ff5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-27.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - side effects produced by step 3 are + visible when an exception occurs +---*/ + +var stepThreeOccurs = false; +var stepFiveOccurs = false; +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return { + valueOf: function() { + stepThreeOccurs = true; + if (stepFiveOccurs) { + throw new Error("Step 5 occurred out of order"); + } + return 20; + } + }; + }, + configurable: true +}); +var fromIndex = { + valueOf: function() { + stepFiveOccurs = true; + return 0; + } +}; +SendableArray.prototype.lastIndexOf.call(obj, undefined, fromIndex); +assert(stepThreeOccurs, 'stepThreeOccurs !== true'); +assert(stepFiveOccurs, 'stepFiveOccurs !== true'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-28.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-28.js new file mode 100644 index 0000000000000000000000000000000000000000..eed1f9cef6280b2a6cc7fef017d254991abf7376 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-28.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - side effects produced by step 1 are + visible when an exception occurs +---*/ + +var stepFiveOccurs = false; +var fromIndex = { + valueOf: function() { + stepFiveOccurs = true; + return 0; + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.lastIndexOf.call(undefined, undefined, fromIndex); +}); +assert.sameValue(stepFiveOccurs, false, 'stepFiveOccurs'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-29.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-29.js new file mode 100644 index 0000000000000000000000000000000000000000..30c9e3f9f24114f2c2ff4e879f57d34c05251d12 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-29.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - side effects produced by step 2 are + visible when an exception occurs +---*/ + +var stepFiveOccurs = false; +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new RangeError(); + }, + configurable: true +}); +var fromIndex = { + valueOf: function() { + stepFiveOccurs = true; + return 0; + } +}; +assert.throws(RangeError, function() { + SendableArray.prototype.lastIndexOf.call(obj, undefined, fromIndex); +}); +assert.sameValue(stepFiveOccurs, false, 'stepFiveOccurs'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-3.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-3.js new file mode 100644 index 0000000000000000000000000000000000000000..8c86d0157eb62aa10d6c54df91f9bf1fbe9297a4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-3.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf when fromIndex is boolean +---*/ + +var a = new SendableArray(1, 2, 1); +assert.sameValue(a.lastIndexOf(2, true), 1, 'true resolves to 1'); +assert.sameValue(a.lastIndexOf(2, false), -1, 'false resolves to 0'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-30.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-30.js new file mode 100644 index 0000000000000000000000000000000000000000..8fec1a5247277759d800b4cb77abfd9aec252ccc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-30.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - side effects produced by step 3 are + visible when an exception occurs +---*/ + +var stepFiveOccurs = false; +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return { + valueOf: function() { + throw new TypeError(); + } + }; + }, + configurable: true +}); +var fromIndex = { + valueOf: function() { + stepFiveOccurs = true; + return 0; + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.lastIndexOf.call(obj, undefined, fromIndex); +}); +assert.sameValue(stepFiveOccurs, false, 'stepFiveOccurs'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-31.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-31.js new file mode 100644 index 0000000000000000000000000000000000000000..82905fa30e044a75eef6e9135c58c29b60d891fe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-31.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'fromIndex' is a positive + non-integer, verify truncation occurs in the proper direction +---*/ + +var targetObj = {}; +assert.sameValue([0, targetObj, true].lastIndexOf(targetObj, 1.5), 1, '[0, targetObj, true].lastIndexOf(targetObj, 1.5)'); +assert.sameValue([0, true, targetObj].lastIndexOf(targetObj, 1.5), -1, '[0, true, targetObj].lastIndexOf(targetObj, 1.5)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-32.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-32.js new file mode 100644 index 0000000000000000000000000000000000000000..6fc5ac7318ee2e2d231ee7daef76704d7fd5ae31 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-32.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - 'fromIndex' is a negative + non-integer, verify truncation occurs in the proper direction +---*/ + +var targetObj = {}; +assert.sameValue([0, targetObj, true].lastIndexOf(targetObj, -2.5), 1, '[0, targetObj, true].lastIndexOf(targetObj, -2.5)'); +assert.sameValue([0, true, targetObj].lastIndexOf(targetObj, -2.5), -1, '[0, true, targetObj].lastIndexOf(targetObj, -2.5)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-33.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-33.js new file mode 100644 index 0000000000000000000000000000000000000000..eb34336a1317c52785e401d4d087bfcf78b8cc0b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-33.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - match on the first element, a middle + element and the last element when 'fromIndex' is passed +---*/ + +assert.sameValue([0, 1, 2, 3, 4].lastIndexOf(0, 0), 0, '[0, 1, 2, 3, 4].lastIndexOf(0, 0)'); +assert.sameValue([0, 1, 2, 3, 4].lastIndexOf(0, 2), 0, '[0, 1, 2, 3, 4].lastIndexOf(0, 2)'); +assert.sameValue([0, 1, 2, 3, 4].lastIndexOf(2, 2), 2, '[0, 1, 2, 3, 4].lastIndexOf(2, 2)'); +assert.sameValue([0, 1, 2, 3, 4].lastIndexOf(2, 4), 2, '[0, 1, 2, 3, 4].lastIndexOf(2, 4)'); +assert.sameValue([0, 1, 2, 3, 4].lastIndexOf(4, 4), 4, '[0, 1, 2, 3, 4].lastIndexOf(4, 4)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-4.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-4.js new file mode 100644 index 0000000000000000000000000000000000000000..9ecb2148a0f6fc8f870b295f856b24fb95f11644 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-4.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf when fromIndex is undefined +---*/ + +var a = new SendableArray(1, 2, 1); +// undefined resolves to 0, no second argument resolves to len +assert.sameValue(a.lastIndexOf(2, undefined), -1, 'a.lastIndexOf(2,undefined)'); +assert.sameValue(a.lastIndexOf(1, undefined), 0, 'a.lastIndexOf(1,undefined)'); +assert.sameValue(a.lastIndexOf(1), 2, 'a.lastIndexOf(1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-5.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-5.js new file mode 100644 index 0000000000000000000000000000000000000000..8a460c4a0dd698661f252b010d010753e5f3653d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-5.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf when fromIndex is null +---*/ + +var a = new SendableArray(1, 2, 1); +// null resolves to 0 +assert.sameValue(a.lastIndexOf(2, null), -1, 'a.lastIndexOf(2,null)'); +assert.sameValue(a.lastIndexOf(1, null), 0, 'a.lastIndexOf(1,null)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-6.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-6.js new file mode 100644 index 0000000000000000000000000000000000000000..b1bc6768d7eec6fbec01457c9e237da90bf1cc9d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-6.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf when 'fromIndex' isn't passed +---*/ + +var arr = [0, 1, 2, 3, 4]; +//'fromIndex' will be set as 4 if not passed by default +assert.sameValue(arr.lastIndexOf(0), arr.lastIndexOf(0, 4), 'arr.lastIndexOf(0)'); +assert.sameValue(arr.lastIndexOf(2), arr.lastIndexOf(2, 4), 'arr.lastIndexOf(2)'); +assert.sameValue(arr.lastIndexOf(4), arr.lastIndexOf(4, 4), 'arr.lastIndexOf(4)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-7.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-7.js new file mode 100644 index 0000000000000000000000000000000000000000..b5d4bed0bd4f8c1dff89ded38cb5d15daec57fc8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-7.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a number + (value is 0) +---*/ + +assert.sameValue([0, 100].lastIndexOf(100, 0), -1, 'verify fromIndex is not more than 0'); +assert.sameValue([200, 0].lastIndexOf(200, 0), 0, 'verify fromIndex is not less than 0'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-8.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-8.js new file mode 100644 index 0000000000000000000000000000000000000000..a7a93f11d8229727ab6297298325aa567df99514 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-8.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a number + (value is +0) +---*/ + +assert.sameValue([0, true].lastIndexOf(true, +0), -1, '[0, true].lastIndexOf(true, +0)'); +assert.sameValue([true, 0].lastIndexOf(true, +0), 0, '[true, 0].lastIndexOf(true, +0)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-9.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-9.js new file mode 100644 index 0000000000000000000000000000000000000000..59b7c8834185ffad7e5c4cc9c5c6847aa549b1fb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-5-9.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - value of 'fromIndex' is a number + (value is -0) +---*/ + +assert.sameValue([0, true].lastIndexOf(true, -0), -1, '[0, true].lastIndexOf(true, -0)'); +assert.sameValue([true, 0].lastIndexOf(true, -0), 0, '[true, 0].lastIndexOf(true, -0)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-1.js new file mode 100644 index 0000000000000000000000000000000000000000..a6d00790607301426c16bd53dff3225b9c5aff09 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-1.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf when fromIndex greater than + Array.length +---*/ + +var a = new SendableArray(1, 2, 3); +assert.sameValue(a.lastIndexOf(3, 5.4), 2, 'a.lastIndexOf(3,5.4)'); +assert.sameValue(a.lastIndexOf(3, 3.1), 2, 'a.lastIndexOf(3,3.1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-2.js new file mode 100644 index 0000000000000000000000000000000000000000..d0650e06e802e99b3aa6d995f06959a9551056a9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns correct index when 'fromIndex' + is length of array - 1 +---*/ + +assert.sameValue([1, 2, 3].lastIndexOf(3, 2), 2, '[1, 2, 3].lastIndexOf(3, 2)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-3.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-3.js new file mode 100644 index 0000000000000000000000000000000000000000..cf94a676dd2d840ea1adbd68653bf5cae4a1589f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-3.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 when 'fromIndex' is length + of array - 1 +---*/ + +assert.sameValue([1, 2, 3].lastIndexOf(3, 1), -1, '[1, 2, 3].lastIndexOf(3, 1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-4.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-4.js new file mode 100644 index 0000000000000000000000000000000000000000..5cc0b51ed6b8d734db90aaa6dbd5dbab46d4e42d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-4.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 when 'fromIndex' and + 'length' are both 0 +---*/ + +assert.sameValue([].lastIndexOf(1, 0), -1, '[].lastIndexOf(1, 0)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-5.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-5.js new file mode 100644 index 0000000000000000000000000000000000000000..48662c681c6f4edfd4b8279a2492bd048dec9451 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-5.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf returns -1 when 'fromIndex' is 1 +---*/ + +assert.sameValue([1, 2, 3].lastIndexOf(3, 1), -1, '[1, 2, 3].lastIndexOf(3, 1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-6.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-6.js new file mode 100644 index 0000000000000000000000000000000000000000..b0aa89fcb9d13d3148bb68f0deb9ba1edbdd3609 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-6-6.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns correct index when 'fromIndex' + is 1 +---*/ + +assert.sameValue([1, 2, 3].lastIndexOf(2, 1), 1, '[1, 2, 3].lastIndexOf(2, 1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-1.js new file mode 100644 index 0000000000000000000000000000000000000000..ca30f527046ca03c49b5adffc707de1f3f77abca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf with negative fromIndex +---*/ + +var a = new SendableArray(1, 2, 3); +assert.sameValue(a.lastIndexOf(2, -2), 1, 'a.lastIndexOf(2,-2)'); +assert.sameValue(a.lastIndexOf(2, -3), -1, 'a.lastIndexOf(2,-3)'); +assert.sameValue(a.lastIndexOf(1, -5.3), -1, 'a.lastIndexOf(1,-5.3)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-2.js new file mode 100644 index 0000000000000000000000000000000000000000..4aa0abc983935fa930702b92433c392b96391888 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns correct index when 'fromIndex' + is -1 +---*/ + +assert.sameValue([1, 2, 3, 4].lastIndexOf(4, -1), 3, '[1, 2, 3, 4].lastIndexOf(4, -1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-3.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-3.js new file mode 100644 index 0000000000000000000000000000000000000000..ca18cd9ae3a1ba42faafa662acd8fb23ce39e4fc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-3.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 when abs('fromIndex') is + length of array - 1 +---*/ + +assert.sameValue([1, 2, 3, 4].lastIndexOf(3, -3), -1, '[1, 2, 3, 4].lastIndexOf(3, -3)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-4.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-4.js new file mode 100644 index 0000000000000000000000000000000000000000..2a50ea04cfcbddda92a2e41bed62659281b56eae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-7-4.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 when abs('fromIndex') is + length of array +---*/ + +assert.sameValue([1, 2, 3, 4].lastIndexOf(2, -4), -1, '[1, 2, 3, 4].lastIndexOf(2, -4)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-1.js new file mode 100644 index 0000000000000000000000000000000000000000..701e603b015606b48ee54ba20aa8d38c498065fa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-1.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf must return correct index(boolean) +---*/ + +var obj = { + toString: function() { + return true + } +}; +var _false = false; +var a = new SendableArray(false, true, false, obj, _false, true, "true", undefined, 0, null, 1, "str", 0, 1); +assert.sameValue(a.lastIndexOf(true), 5, 'a[5]=true'); +assert.sameValue(a.lastIndexOf(false), 4, 'a[4] =_false'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-10.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-10.js new file mode 100644 index 0000000000000000000000000000000000000000..cc9f1f20982109782ce7c27c7534e457df7d3433 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-10.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + note that prior to the finally ES5 draft SameValue was used for comparisions + and hence NaNs could be found using lastIndexOf * +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf must return correct index (NaN) +---*/ + +var _NaN = NaN; +var a = new SendableArray("NaN", _NaN, NaN, undefined, 0, false, null, { + toString: function() { + return NaN + } +}, "false"); +assert.sameValue(a.lastIndexOf(NaN), -1, 'NaN matches nothing, not even itself'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-11.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-11.js new file mode 100644 index 0000000000000000000000000000000000000000..8d910b2bf2c9c1f6075027a9015a0739a9c55a18 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-11.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - the length of iteration isn't + changed by adding elements to the array during iteration +---*/ + +var arr = [20]; +Object.defineProperty(arr, "0", { + get: function() { + arr[1] = 1; + return 0; + }, + configurable: true +}); +assert.sameValue(arr.lastIndexOf(1), -1, 'arr.lastIndexOf(1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-2.js new file mode 100644 index 0000000000000000000000000000000000000000..9044cbed5f8152cd19302c8ac4a8f489c4da1aef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf must return correct index(Number) +---*/ + +var obj = { + toString: function() { + return 0 + } +}; +var one = 1; +var _float = -(4 / 3); +var a = new SendableArray(+0, true, 0, -0, false, undefined, null, "0", obj, _float, -(4 / 3), -1.3333333333333, "str", one, 1, false); +assert.sameValue(a.lastIndexOf(-(4 / 3)), 10, 'a[10]=-(4/3)'); +assert.sameValue(a.lastIndexOf(0), 3, 'a[3] = -0, but using === -0 and 0 are equal'); +assert.sameValue(a.lastIndexOf(-0), 3, 'a[3] = -0'); +assert.sameValue(a.lastIndexOf(1), 14, 'a[14] = 1'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-3.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-3.js new file mode 100644 index 0000000000000000000000000000000000000000..eb349eb3d4d888a9d50325376c1caad3ac89ba74 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-3.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf must return correct index(string) +---*/ + +var obj = { + toString: function() { + return "false" + } +}; +var szFalse = "false"; +var a = new SendableArray(szFalse, "false", "false1", undefined, 0, false, null, 1, obj, 0); +assert.sameValue(a.lastIndexOf("false"), 1, 'a.lastIndexOf("false")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-4.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-4.js new file mode 100644 index 0000000000000000000000000000000000000000..bffdaef48882bae6ceb30a7dc8da0271535a9b09 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf must return correct index(undefined) +---*/ + +var obj = { + toString: function() { + return undefined; + } +}; +var _undefined1 = undefined; +var _undefined2; +var a = new SendableArray(_undefined1, _undefined2, undefined, true, 0, false, null, 1, "undefined", obj, 1); +assert.sameValue(a.lastIndexOf(undefined), 2, 'a.lastIndexOf(undefined)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-5.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-5.js new file mode 100644 index 0000000000000000000000000000000000000000..3383f7be6d2d626367f6d970fc9683aca5331ce8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-5.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf must return correct index(Object) +---*/ + +var obj1 = { + toString: function() { + return "false" + } +}; +var obj2 = { + toString: function() { + return "false" + } +}; +var obj3 = obj1; +var a = new SendableArray(obj2, obj1, obj3, false, undefined, 0, false, null, { + toString: function() { + return "false" + } +}, "false"); +assert.sameValue(a.lastIndexOf(obj3), 2, 'a.lastIndexOf(obj3)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-6.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-6.js new file mode 100644 index 0000000000000000000000000000000000000000..c349dc3b8f6887d98ef6f1f354d378800a01f89b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-6.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf must return correct index(null) +---*/ + +var obj = { + toString: function() { + return null + } +}; +var _null = null; +var a = new SendableArray(true, undefined, 0, false, null, 1, "str", 0, 1, null, true, false, undefined, _null, "null", undefined, "str", obj); +assert.sameValue(a.lastIndexOf(null), 13, 'a.lastIndexOf(null)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-7.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-7.js new file mode 100644 index 0000000000000000000000000000000000000000..93eeb962f7fb177d9e12f3230e875c3848e44ed7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-7.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf must return correct index (self + reference) +---*/ + +var a = new SendableArray(0, 1, 2, 3); +a[2] = a; +assert.sameValue(a.lastIndexOf(a), 2, 'a.lastIndexOf(a)'); +assert.sameValue(a.lastIndexOf(3), 3, 'a.lastIndexOf(3)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-8.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-8.js new file mode 100644 index 0000000000000000000000000000000000000000..5efd04ee4b75f681ee7b24754e12e323863c4185 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-8.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf must return correct index (Array) +---*/ + +var b = new SendableArray("0,1"); +var a = new SendableArray(0, b, "0,1", 3); +assert.sameValue(a.lastIndexOf(b.toString()), 2, 'a.lastIndexOf(b.toString())'); +assert.sameValue(a.lastIndexOf("0,1"), 2, 'a.lastIndexOf("0,1")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-9.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-9.js new file mode 100644 index 0000000000000000000000000000000000000000..d4a97fb5a4d8dbd16efa2eba27bcec25d187d487 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-9.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf must return correct index (Sparse + Array) +---*/ + +var a = new SendableArray(0, 1); +a[4294967294] = 2; // 2^32-2 - is max array element index +a[4294967295] = 3; // 2^32-1 added as non-array element property +a[4294967296] = 4; // 2^32 added as non-array element property +a[4294967297] = 5; // 2^32+1 added as non-array element property +// stop searching near the end in case implementation actually tries to test all missing elements!! +a[4294967200] = 3; +a[4294967201] = 4; +a[4294967202] = 5; +assert.sameValue(a.lastIndexOf(2), 4294967294, 'a.lastIndexOf(2)'); +assert.sameValue(a.lastIndexOf(3), 4294967200, 'a.lastIndexOf(3)'); +assert.sameValue(a.lastIndexOf(4), 4294967201, 'a.lastIndexOf(4)'); +assert.sameValue(a.lastIndexOf(5), 4294967202, 'a.lastIndexOf(5)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-1.js new file mode 100644 index 0000000000000000000000000000000000000000..e647067c5771fb8ad56c4e16dcd64192c78a09ec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - added properties in step 2 are + visible here +---*/ + +var arr = {}; +Object.defineProperty(arr, "length", { + get: function() { + arr[2] = "length"; + return 3; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(arr, "length"), 2, 'SendableArray.prototype.lastIndexOf.call(arr, "length")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-10.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-10.js new file mode 100644 index 0000000000000000000000000000000000000000..98a0fa170089486ad195964a1cebe9cb8c74bd26 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-10.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - properties can be added to prototype + after current position are visited on an Array +---*/ + +var arr = [0, , 2]; +Object.defineProperty(arr, "2", { + get: function() { + Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(arr.lastIndexOf(6.99), 1, 'arr.lastIndexOf(6.99)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-11.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-11.js new file mode 100644 index 0000000000000000000000000000000000000000..2c7f07c820f99f992c3502c5331c72661e948786 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-11.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - deleting own property causes index + property not to be visited on an Array-like object +---*/ + +var arr = { + length: 200 +}; +Object.defineProperty(arr, "1", { + get: function() { + return 6.99; + }, + configurable: true +}); +Object.defineProperty(arr, "100", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(arr, 6.99), -1, 'SendableArray.prototype.lastIndexOf.call(arr, 6.99)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-12.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-12.js new file mode 100644 index 0000000000000000000000000000000000000000..b9039bace880f1c57adbdccb810d73eb157ddca2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-12.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - deleting own property causes index + property not to be visited on an Array +---*/ + +var arr = [1, 2, 3, 4]; +Object.defineProperty(arr, "1", { + get: function() { + return "6.99"; + }, + configurable: true +}); +Object.defineProperty(arr, "3", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +assert.sameValue(arr.lastIndexOf("6.99"), -1, 'arr.lastIndexOf("6.99")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-13.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-13.js new file mode 100644 index 0000000000000000000000000000000000000000..d16848020563b633da3b5e44ee89225735505d9f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-13.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - deleting property of prototype + causes prototype index property not to be visited on an Array-like + Object +---*/ + +var arr = { + 2: 2, + length: 20 +}; +Object.defineProperty(arr, "3", { + get: function() { + delete Object.prototype[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(arr, 1), -1, 'SendableArray.prototype.lastIndexOf.call(arr, 1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-14.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-14.js new file mode 100644 index 0000000000000000000000000000000000000000..d1093535ec592ab178990999c166529a18f51e1a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-14.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - deleting property of prototype + causes prototype index property not to be visited on an Array +---*/ + +var arr = [0, , 2]; +Object.defineProperty(arr, "20", { + get: function() { + delete SendableArray.prototype[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +assert.sameValue(arr.lastIndexOf(1), -1, 'arr.lastIndexOf(1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-15.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-15.js new file mode 100644 index 0000000000000000000000000000000000000000..dac87fa40ee17b895d8af8c98e0886e1f6d44997 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-15.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - deleting own property with + prototype property causes prototype index property to be visited + on an Array-like object +---*/ + +var arr = { + 0: 0, + 1: 111, + 2: 2, + length: 10 +}; +Object.defineProperty(arr, "6", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(arr, 1), 1, 'SendableArray.prototype.lastIndexOf.call(arr, 1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-16.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-16.js new file mode 100644 index 0000000000000000000000000000000000000000..f423fd8b0f1de02da1e28b04d322a4cbafeeb765 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-16.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - deleting own property with + prototype property causes prototype index property to be visited + on an Array +---*/ + +var arr = [0, 111, 2]; +Object.defineProperty(arr, "2", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +assert.sameValue(arr.lastIndexOf(1), 1, 'arr.lastIndexOf(1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-17.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-17.js new file mode 100644 index 0000000000000000000000000000000000000000..e77c47e3c8b0980873cc0624fabd2caad7925346 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-17.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - decreasing length of array causes + index property not to be visited +---*/ + +var arr = [0, 1, 2, "last", 4]; +Object.defineProperty(arr, "4", { + get: function() { + arr.length = 3; + return 0; + }, + configurable: true +}); +assert.sameValue(arr.lastIndexOf("last"), -1, 'arr.lastIndexOf("last")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-18.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-18.js new file mode 100644 index 0000000000000000000000000000000000000000..97e75c08667b662aad97489e1253ea9cd3b1370e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-18.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - decreasing length of array with + prototype property causes prototype index property to be visited +---*/ + +var arr = [0, 1, 2, 3, 4]; +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return "prototype"; + }, + configurable: true +}); +Object.defineProperty(arr, "3", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +assert.sameValue(arr.lastIndexOf("prototype"), 2, 'arr.lastIndexOf("prototype")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-19.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-19.js new file mode 100644 index 0000000000000000000000000000000000000000..06578385358d02421183fb9eabcd6b2881410e82 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-19.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - decreasing length of array does not + delete non-configurable properties +flags: [noStrict] +---*/ + +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "2", { + get: function() { + return "unconfigurable"; + }, + configurable: false +}); +Object.defineProperty(arr, "3", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +assert.sameValue(arr.lastIndexOf("unconfigurable"), 2, 'arr.lastIndexOf("unconfigurable")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-2.js new file mode 100644 index 0000000000000000000000000000000000000000..355584b362d38754b405145667a4033322513937 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-2.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - added properties in step 5 are + visible here on an Array-like object +---*/ + +var arr = { + length: 30 +}; +var targetObj = function() {}; +var fromIndex = { + valueOf: function() { + arr[4] = targetObj; + return 10; + } +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(arr, targetObj, fromIndex), 4, 'SendableArray.prototype.lastIndexOf.call(arr, targetObj, fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-3.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-3.js new file mode 100644 index 0000000000000000000000000000000000000000..23fd630eac674d5e75a7615e3a67c3ec1c096ccb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - added properties in step 5 are + visible here on an Array +---*/ + +var arr = []; +arr.length = 30; +var targetObj = function() {}; +var fromIndex = { + valueOf: function() { + arr[4] = targetObj; + return 11; + } +}; +assert.sameValue(arr.lastIndexOf(targetObj, fromIndex), 4, 'arr.lastIndexOf(targetObj, fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-4.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-4.js new file mode 100644 index 0000000000000000000000000000000000000000..6168091ab7442eea365b11765ee1d9f93017ff9c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-4.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - deleted properties in step 2 are + visible here +---*/ + +var arr = { + 2: 6.99 +}; +Object.defineProperty(arr, "length", { + get: function() { + delete arr[2]; + return 3; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(arr, 6.99), -1, 'SendableArray.prototype.lastIndexOf.call(arr, 6.99)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-5.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-5.js new file mode 100644 index 0000000000000000000000000000000000000000..43fb9a51475778878fbc08c089c570e7e48a3568 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-5.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - deleted properties of step 5 are + visible here on an Array-like object +---*/ + +var arr = { + 10: false, + length: 30 +}; +var fromIndex = { + valueOf: function() { + delete arr[10]; + return 15; + } +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(arr, false, fromIndex), -1, 'SendableArray.prototype.lastIndexOf.call(arr, false, fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-6.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-6.js new file mode 100644 index 0000000000000000000000000000000000000000..9fd28ddc9476a17b17f52cf127c3149a9dee271f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-6.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - deleted properties of step 5 are + visible here on an Array +---*/ + +var arr = []; +arr[10] = "10"; +arr.length = 20; +var fromIndex = { + valueOf: function() { + delete arr[10]; + return 11; + } +}; +assert.sameValue(arr.lastIndexOf("10", fromIndex), -1, 'arr.lastIndexOf("10", fromIndex)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-7.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-7.js new file mode 100644 index 0000000000000000000000000000000000000000..a87bc303cc29af8347c1aa479176d61144b3e736 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-7.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - properties added into own object + after current position are visited on an Array-like object +---*/ + +var arr = { + length: 8 +}; +Object.defineProperty(arr, "4", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(arr, 1), 1, 'SendableArray.prototype.lastIndexOf.call(arr, 1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-8.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-8.js new file mode 100644 index 0000000000000000000000000000000000000000..d2f3a52951c63d1320c7466bdde6462b1b68711e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-8.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - properties added into own object + after current position are visited on an Array +---*/ + +var arr = [0, , 2]; +Object.defineProperty(arr, "2", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(arr.lastIndexOf(1), 1, 'arr.lastIndexOf(1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-9.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-9.js new file mode 100644 index 0000000000000000000000000000000000000000..49cae2d8b92aa0eb1b16b292afc217deeb2f6005 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-a-9.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - properties can be added to + prototype after current position are visited on an Array-like + object +---*/ + +var arr = { + length: 9 +}; +Object.defineProperty(arr, "4", { + get: function() { + Object.defineProperty(Object.prototype, "1", { + get: function() { + return Infinity; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(arr, Infinity), 1, 'SendableArray.prototype.lastIndexOf.call(arr, Infinity)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..743145090ea7b71957326c37f3c1fba840a5f9df --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-1.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf - undefined property wouldn't be called +---*/ + +assert.sameValue([0, , 2].lastIndexOf(undefined), -1, '[0, , 2].lastIndexOf(undefined)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-1.js new file mode 100644 index 0000000000000000000000000000000000000000..c53d7e1f640303b80241bff448bcdb3ab9f373cd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own data + property on an Array-like object +---*/ + +var obj = { + 0: 0, + 1: 1, + 2: 2, + length: 3 +}; +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 0), 0, 'SendableArray.prototype.lastIndexOf.call(obj, 0)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 1), 1, 'SendableArray.prototype.lastIndexOf.call(obj, 1)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 2), 2, 'SendableArray.prototype.lastIndexOf.call(obj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-10.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-10.js new file mode 100644 index 0000000000000000000000000000000000000000..bc857b8fba526c475a815397800d738338481ccc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-10.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own + accessor property on an Array-like object +---*/ + +var obj = { + length: 3 +}; +Object.defineProperty(obj, "0", { + get: function() { + return 0; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + return 1; + }, + configurable: true +}); +Object.defineProperty(obj, "2", { + get: function() { + return 2; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 0), 0, 'SendableArray.prototype.lastIndexOf.call(obj, 0)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 1), 1, 'SendableArray.prototype.lastIndexOf.call(obj, 1)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, 2), 2, 'SendableArray.prototype.lastIndexOf.call(obj, 2)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-11.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-11.js new file mode 100644 index 0000000000000000000000000000000000000000..9723511ebd8f38b9fa50a1f67818aa0eae28a34a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-11.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own + accessor property that overrides an inherited data property on an + Array +---*/ + +var arr = []; +SendableArray.prototype[0] = false; +Object.defineProperty(arr, "0", { + get: function() { + return true; + }, + configurable: true +}); +assert.sameValue(arr.lastIndexOf(true), 0, 'arr.lastIndexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-12.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-12.js new file mode 100644 index 0000000000000000000000000000000000000000..5c2b98199d29f3c913f52b9a515c865068acbf85 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-12.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own + accessor property that overrides an inherited data property on an + Array-like object +---*/ + +var obj = { + length: 1 +}; +Object.prototype[0] = false; +Object.defineProperty(obj, "0", { + get: function() { + return true; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 0, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-13.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-13.js new file mode 100644 index 0000000000000000000000000000000000000000..4f377aabc90e095ae74b5b4cf3add39b752053cc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-13.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own + accessor property that overrides an inherited accessor property on + an Array +---*/ + +var arr = []; +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return false; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + return true; + }, + configurable: true +}); +assert.sameValue(arr.lastIndexOf(true), 0, 'arr.lastIndexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-14.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-14.js new file mode 100644 index 0000000000000000000000000000000000000000..cd46b0dd894e94f26c037cb0d668d6b7d7e9a977 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-14.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own + accessor property that overrides an inherited accessor property on + an Array-like object +---*/ + +var obj = { + length: 1 +}; +Object.defineProperty(Object.prototype, "0", { + get: function() { + return false; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + return true; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 0, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-15.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-15.js new file mode 100644 index 0000000000000000000000000000000000000000..cda7ab3b15ef5008df0cd76eb734582d3fbadbac --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-15.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is inherited + accessor property on an Array +---*/ + +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 10; + }, + configurable: true +}); +Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 20; + }, + configurable: true +}); + +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return 30; + }, + configurable: true +}); +assert.sameValue([, , , ].lastIndexOf(10), 0, '[, , , ].lastIndexOf(10)'); +assert.sameValue([, , , ].lastIndexOf(20), 1, '[, , , ].lastIndexOf(20)'); +assert.sameValue([, , , ].lastIndexOf(30), 2, '[, , , ].lastIndexOf(30)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-16.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-16.js new file mode 100644 index 0000000000000000000000000000000000000000..60f63364ff003550f9a320e9351889055b5d02ed --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-16.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is inherited + accessor property on an Array-like object +---*/ + +Object.defineProperty(Object.prototype, "0", { + get: function() { + return 10; + }, + configurable: true +}); +Object.defineProperty(Object.prototype, "1", { + get: function() { + return 20; + }, + configurable: true +}); +Object.defineProperty(Object.prototype, "2", { + get: function() { + return 30; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call({ + length: 3 +}, 10), 0, 'SendableArray.prototype.lastIndexOf.call({ length: 3 }, 10)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call({ + length: 3 +}, 20), 1, 'SendableArray.prototype.lastIndexOf.call({ length: 3 }, 20)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call({ + length: 3 +}, 30), 2, 'SendableArray.prototype.lastIndexOf.call({ length: 3 }, 30)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-17.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-17.js new file mode 100644 index 0000000000000000000000000000000000000000..e67a0ae63e0d510ba654e5d7be76ce4d13b94421 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-17.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own + accessor property without a get function on an Array +---*/ + +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +assert.sameValue(arr.lastIndexOf(undefined), 0, 'arr.lastIndexOf(undefined)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-18.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-18.js new file mode 100644 index 0000000000000000000000000000000000000000..e0ae6e23b70de0ae6ea786a0e1a41efd35bccbca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-18.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own + accessor property without a get function on an Array-like object +---*/ + +var obj = { + length: 1 +}; +Object.defineProperty(obj, "0", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, undefined), 0, 'SendableArray.prototype.lastIndexOf.call(obj, undefined)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-19.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-19.js new file mode 100644 index 0000000000000000000000000000000000000000..652c419e5d25b93e434332898b1664e37bd86ac9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-19.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own + accessor property without a get function that overrides an + inherited accessor property on an Array-like object +---*/ + +var obj = { + length: 1 +}; +Object.defineProperty(Object.prototype, "0", { + get: function() { + return 20; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + set: function() {}, + configurable: true +}); +assert(obj.hasOwnProperty(0), 'obj.hasOwnProperty(0) !== true'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, undefined), 0, 'SendableArray.prototype.lastIndexOf.call(obj, undefined)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-2.js new file mode 100644 index 0000000000000000000000000000000000000000..3d43ca2ee593ff914d3dcb5948ecd356abc6dfbd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-2.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own data + property on an Array +---*/ + +assert.sameValue([true, true, true].lastIndexOf(true), 2, '[true, true, true].lastIndexOf(true)'); +assert.sameValue([true, true, false].lastIndexOf(true), 1, '[true, true, false].lastIndexOf(true)'); +assert.sameValue([true, false, false].lastIndexOf(true), 0, '[true, false, false].lastIndexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-20.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-20.js new file mode 100644 index 0000000000000000000000000000000000000000..103bd50e28bd8e6f465c074eef9d1e6f7e53d06e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-20.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is an own + accessor property without a get function that overrides an + inherited accessor property on an Array +---*/ + +var arr = [, 1]; +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 100; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +assert(arr.hasOwnProperty(0), 'arr.hasOwnProperty(0) !== true'); +assert.sameValue(arr.lastIndexOf(undefined), 0, 'arr.lastIndexOf(undefined)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-21.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-21.js new file mode 100644 index 0000000000000000000000000000000000000000..358d8ae6fdc4e6f5d507e09aae1e19f2ca444fd9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-21.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is inherited + accessor property without a get function on an Array +---*/ + +Object.defineProperty(SendableArray.prototype, "0", { + set: function() {}, + configurable: true +}); +assert.sameValue([, ].lastIndexOf(undefined), 0, '[, ].lastIndexOf(undefined)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-22.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-22.js new file mode 100644 index 0000000000000000000000000000000000000000..b37ce6fe2689cdb16887f1758d3a6b9098d64803 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-22.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is inherited + accessor property without a get function on an Array-like object +---*/ + +Object.defineProperty(Object.prototype, "0", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call({ + length: 1 +}, undefined), 0, 'SendableArray.prototype.lastIndexOf.call({ length: 1 }, undefined)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-25.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-25.js new file mode 100644 index 0000000000000000000000000000000000000000..c724b661e509f5383f115341e5cdf7258fb3977c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-25.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf applied to Arguments object which + implements its own property get method (number of arguments is + less than number of parameters) +---*/ + +var func = function(a, b) { + return 0 === SendableArray.prototype.lastIndexOf.call(arguments, arguments[0]) && + -1 === SendableArray.prototype.lastIndexOf.call(arguments, arguments[1]); +}; +assert(func(true), 'func(true) !== true'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-26.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-26.js new file mode 100644 index 0000000000000000000000000000000000000000..602afdb6aa7183be2fcc218ed8a36c4ff9abe42e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-26.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf applied to Arguments object which + implements its own property get method (number of arguments equals + to number of parameters) +---*/ + +var func = function(a, b) { + return 0 === SendableArray.prototype.lastIndexOf.call(arguments, arguments[0]) && + 1 === SendableArray.prototype.lastIndexOf.call(arguments, arguments[1]) && + -1 === SendableArray.prototype.lastIndexOf.call(arguments, arguments[2]); +}; +assert(func(0, true), 'func(0, true) !== true'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-27.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-27.js new file mode 100644 index 0000000000000000000000000000000000000000..6fd7a3d2adf2a67e5eb5aadded960dca203a89ef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-27.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf applied to Arguments object which + implements its own property get method (number of arguments is + greater than number of parameters) +---*/ + +var func = function(a, b) { + assert.sameValue(SendableArray.prototype.lastIndexOf.call(arguments, arguments[0]), 2); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(arguments, arguments[3]), 3); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(arguments, arguments[4]), -1); +}; +(function() { + func(0, arguments, 0, Object.prototype); +})(); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-28.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-28.js new file mode 100644 index 0000000000000000000000000000000000000000..238477d09fd12966560a3f413bf8bb68a280b4c7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-28.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - side-effects are visible in + subsequent iterations on an Array +---*/ + +var preIterVisible = false; +var arr = []; +Object.defineProperty(arr, "2", { + get: function() { + preIterVisible = true; + return false; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + if (preIterVisible) { + return true; + } else { + return false; + } + }, + configurable: true +}); +assert.sameValue(arr.lastIndexOf(true), 1, 'arr.lastIndexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-29.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-29.js new file mode 100644 index 0000000000000000000000000000000000000000..70b789e70f124eade0db02da74804d417cdd1bc2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-29.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - side-effects are visible in + subsequent iterations on an Array-like object +---*/ + +var preIterVisible = false; +var obj = { + length: 3 +}; +Object.defineProperty(obj, "2", { + get: function() { + preIterVisible = true; + return false; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + if (preIterVisible) { + return true; + } else { + return false; + } + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call(obj, true), 1, 'SendableArray.prototype.lastIndexOf.call(obj, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-3.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-3.js new file mode 100644 index 0000000000000000000000000000000000000000..a8f80953196a2458d97c5511d7c1b058cef58372 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-3.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +SendableArray.prototype[0] = Object; +assert.sameValue([Object.prototype].lastIndexOf(Object.prototype), 0, '[Object.prototype].lastIndexOf(Object.prototype)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-30.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-30.js new file mode 100644 index 0000000000000000000000000000000000000000..cfd1fe9824d8c118468b429e2b65f4605f0f0ad5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-30.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf terminates iteration on unhandled + exception on an Array +---*/ + +var accessed = false; +var arr = []; +Object.defineProperty(arr, "2", { + get: function() { + throw new TypeError(); + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + accessed = true; + return true; + }, + configurable: true +}); +assert.throws(TypeError, function() { + arr.lastIndexOf(true); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-31.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-31.js new file mode 100644 index 0000000000000000000000000000000000000000..d010ee96e0adc8b360ec2a0dc59de005307ede56 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-31.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf terminates iteration on unhandled + exception on an Array-like object +---*/ + +var accessed = false; +var obj = { + length: 3 +}; +Object.defineProperty(obj, "2", { + get: function() { + throw new TypeError(); + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + accessed = true; + return true; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.lastIndexOf.call(obj, true); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-4.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-4.js new file mode 100644 index 0000000000000000000000000000000000000000..4f362ae70b8e53e474ec1cab9a8bc06e3dd26c15 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own data + property that overrides an inherited data property on an + Array-like object +---*/ + +Object.prototype[0] = false; +assert.sameValue(SendableArray.prototype.lastIndexOf.call({ + 0: true, + 1: 1, + length: 2 +}, true), 0, 'SendableArray.prototype.lastIndexOf.call({ 0: true, 1: 1, length: 2 }, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-5.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-5.js new file mode 100644 index 0000000000000000000000000000000000000000..2598da89dd42b1b592847a3cf7902b9f5387fb36 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-5.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own data + property that overrides an inherited accessor property on an Array +---*/ + +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return false; + }, + configurable: true +}); +assert.sameValue([Number].lastIndexOf(Number), 0, '[Number].lastIndexOf(Number)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-6.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-6.js new file mode 100644 index 0000000000000000000000000000000000000000..d1b3add1a8825712cf16e7fe2d2d5b1548f27477 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-6.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own data + property that overrides an inherited accessor property on an + Array-like object +---*/ + +Object.defineProperty(Object.prototype, "0", { + get: function() { + return false; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.lastIndexOf.call({ + 0: true, + 1: 1, + length: 2 +}, true), 0, 'SendableArray.prototype.lastIndexOf.call({ 0: true, 1: 1, length: 2 }, true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-7.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-7.js new file mode 100644 index 0000000000000000000000000000000000000000..93b4e65ab939ed2d24e2cb94efc055e58fc182d9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-7.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is inherited + data property on an Array +---*/ + +SendableArray.prototype[0] = true; +SendableArray.prototype[1] = false; +SendableArray.prototype[2] = "true"; +assert.sameValue([, , , ].lastIndexOf(true), 0, '[, , , ].lastIndexOf(true)'); +assert.sameValue([, , , ].lastIndexOf(false), 1, '[, , , ].lastIndexOf(false)'); +assert.sameValue([, , , ].lastIndexOf("true"), 2, '[, , , ].lastIndexOf("true")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-8.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-8.js new file mode 100644 index 0000000000000000000000000000000000000000..7637e2fac6638ea030d10d1010e6514c4008269a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-8.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is inherited + data property on an Array-like object +---*/ + +Object.prototype[0] = true; +Object.prototype[1] = false; +Object.prototype[2] = "true"; +assert.sameValue(SendableArray.prototype.lastIndexOf.call({ + length: 3 +}, true), 0, 'SendableArray.prototype.lastIndexOf.call({ length: 3 }, true)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call({ + length: 3 +}, false), 1, 'SendableArray.prototype.lastIndexOf.call({ length: 3 }, false)'); +assert.sameValue(SendableArray.prototype.lastIndexOf.call({ + length: 3 +}, "true"), 2, 'SendableArray.prototype.lastIndexOf.call({ length: 3 }, "true")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-9.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-9.js new file mode 100644 index 0000000000000000000000000000000000000000..28fec133a0f6997d2a692874981d1d5aeed16174 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-i-9.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - element to be retrieved is own + accessor property on an Array +---*/ + +var arr = [, , , ]; +Object.defineProperty(arr, "0", { + get: function() { + return 0; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true +}); +Object.defineProperty(arr, "2", { + get: function() { + return 2; + }, + configurable: true +}); +assert.sameValue(arr.lastIndexOf(0), 0, 'arr.lastIndexOf(0)'); +assert.sameValue(arr.lastIndexOf(1), 1, 'arr.lastIndexOf(1)'); +assert.sameValue(arr.lastIndexOf(2), 2, 'arr.lastIndexOf(2)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..f535a7bd5cbe23a2e7aaff455edd96145473d472 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-1.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - type of array element is different + from type of search element +---*/ + +assert.sameValue(["true"].lastIndexOf(true), -1, '["true"].lastIndexOf(true)'); +assert.sameValue(["0"].lastIndexOf(0), -1, '["0"].lastIndexOf(0)'); +assert.sameValue([false].lastIndexOf(0), -1, '[false].lastIndexOf(0)'); +assert.sameValue([undefined].lastIndexOf(0), -1, '[undefined].lastIndexOf(0)'); +assert.sameValue([null].lastIndexOf(0), -1, '[null].lastIndexOf(0)'); +assert.sameValue([ + [] +].lastIndexOf(0), -1, '[[]].lastIndexOf(0)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-10.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..6e6060d50ce6793ad071041b5614b64039faa901 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-10.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - both array element and search + element are booleans, and they have same value +---*/ + +assert.sameValue([false, true].lastIndexOf(true), 1, '[false, true].lastIndexOf(true)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-11.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..223077b8638e922ec92f971152b03ae35b1082be --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-11.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - both array element and search + element are Objects, and they refer to the same object +---*/ + +var obj1 = {}; +var obj2 = {}; +var obj3 = obj2; +assert.sameValue([obj2, obj1].lastIndexOf(obj3), 0, '[obj2, obj1].lastIndexOf(obj3)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..718b0d7a17102b70aeb0f86fa83ddc775fdaca2f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-2.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - both type of array element and type + of search element are Undefined +---*/ + +assert.sameValue([undefined].lastIndexOf(), 0, '[undefined].lastIndexOf()'); +assert.sameValue([undefined].lastIndexOf(undefined), 0, '[undefined].lastIndexOf(undefined)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-3.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-3.js new file mode 100644 index 0000000000000000000000000000000000000000..97d96d818331b3d39f94a1abf69fa6fe26f772a4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-3.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - both type of array element and type + of search element are Null +---*/ + +assert.sameValue([null].lastIndexOf(null), 0, '[null].lastIndexOf(null)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-4.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..92f8ce3501c01b1108daa03ddb01d53573cada86 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-4.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf - search element is NaN +---*/ + +assert.sameValue([+NaN, NaN, -NaN].lastIndexOf(NaN), -1, '[+NaN, NaN, -NaN].lastIndexOf(NaN)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-5.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..1ad9c61be5560f23a367aa8642a67b84c708e60c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-5.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf - search element is -NaN +---*/ + +assert.sameValue([+NaN, NaN, -NaN].lastIndexOf(-NaN), -1, '[+NaN, NaN, -NaN].lastIndexOf(-NaN)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-6.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-6.js new file mode 100644 index 0000000000000000000000000000000000000000..543eb45b0cc05fd7f51b3df3f485a56bc30235d4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-6.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - array element is +0 and search + element is -0 +---*/ + +assert.sameValue([+0].lastIndexOf(-0), 0, '[+0].lastIndexOf(-0)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-7.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..c6fc7d63c699328d29f63c05854d197aa10875e1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-7.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - array element is -0 and search + element is +0 +---*/ + +assert.sameValue([-0].lastIndexOf(+0), 0, '[-0].lastIndexOf(+0)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-8.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..c7379115b6a22c9bec7b9d4010584a72001da062 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-8.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - both array element and search + element are numbers, and they have same value +---*/ + +assert.sameValue([-1, 0, 1].lastIndexOf(-1), 0, '[-1, 0, 1].lastIndexOf(-1)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-9.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..1d4268d87ecc1864f7f30899dbc75299d01d3f90 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-ii-9.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf - both array element and search + element are strings, and they have exactly the same sequence of + characters +---*/ + +assert.sameValue(["abc", "ab", "bca", ""].lastIndexOf("abc"), 0, '["abc", "ab", "bca", ""].lastIndexOf("abc")'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-iii-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-iii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..14f43e1ab907481fdb31fabac21acea6403e76c6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-iii-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns index of last one when more + than two elements in array are eligible +---*/ + +assert.sameValue([2, 1, 2, 2, 1].lastIndexOf(2), 3, '[2, 1, 2, 2, 1].lastIndexOf(2)'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-iii-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-iii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..ec95038064b6071b7b8f486e4310a75a238b4cb1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-8-b-iii-2.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns without visiting subsequent + element once search value is found +---*/ + +var arr = [2, 1, , 1, 2]; +var elementFirstAccessed = false; +var elementThirdAccessed = false; +Object.defineProperty(arr, "2", { + get: function() { + elementThirdAccessed = true; + return 2; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + elementFirstAccessed = true; + return 2; + }, + configurable: true +}); +arr.lastIndexOf(2); +assert.sameValue(elementThirdAccessed, false, 'elementThirdAccessed'); +assert.sameValue(elementFirstAccessed, false, 'elementFirstAccessed'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-9-1.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-9-1.js new file mode 100644 index 0000000000000000000000000000000000000000..2ca9ebda41d3f24c9bd94cc89ce0e54053dce8ea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-9-1.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: Array.prototype.lastIndexOf returns -1 for elements not present +---*/ + +var a = new SendableArray(); +a[100] = 1; +a[99999] = ""; +a[10] = new Object(); +a[5555] = 5.5; +a[123456] = "str"; +a[5] = 1E+309; +assert.sameValue(a.lastIndexOf(1), 100, 'a.lastIndexOf(1)'); +assert.sameValue(a.lastIndexOf(""), 99999, 'a.lastIndexOf("")'); +assert.sameValue(a.lastIndexOf("str"), 123456, 'a.lastIndexOf("str")'); +assert.sameValue(a.lastIndexOf(5.5), 5555, 'a.lastIndexOf(5.5)'); +assert.sameValue(a.lastIndexOf(1E+309), 5, 'a.lastIndexOf(1E+309)'); +assert.sameValue(a.lastIndexOf(true), -1, 'a.lastIndexOf(true)'); +assert.sameValue(a.lastIndexOf(5), -1, 'a.lastIndexOf(5)'); +assert.sameValue(a.lastIndexOf("str1"), -1, 'a.lastIndexOf("str1")'); +assert.sameValue(a.lastIndexOf(null), -1, 'a.lastIndexOf(null)'); +assert.sameValue(a.lastIndexOf(new Object()), -1, 'a.lastIndexOf(new Object())'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-9-2.js b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-9-2.js new file mode 100644 index 0000000000000000000000000000000000000000..68e60412ce4f211101512af3676a22250e4892f7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/15.4.4.15-9-2.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf returns -1 if 'length' is 0 and does + not access any other properties +---*/ + +var accessed = false; +var f = { + length: 0 +}; +Object.defineProperty(f, "0", { + get: function() { + accessed = true; + return 1; + } +}); +var i = SendableArray.prototype.lastIndexOf.call(f, 1); +assert.sameValue(i, -1, 'i'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/call-with-boolean.js b/test/sendable/builtins/Array/prototype/lastIndexOf/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..35d911270a2a35f5c332adadd215127d61567ffa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/call-with-boolean.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastIndexOf +description: Array.prototype.lastIndexOf applied to boolean primitive +---*/ + +assert.sameValue(SendableArray.prototype.lastIndexOf.call(true), -1, 'SendableArray.prototype.lastIndexOf.call(true) must return -1'); +assert.sameValue( + SendableArray.prototype.lastIndexOf.call(false), + -1, + 'SendableArray.prototype.lastIndexOf.call(false) must return -1' +); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/calls-only-has-on-prototype-after-length-zeroed.js b/test/sendable/builtins/Array/prototype/lastIndexOf/calls-only-has-on-prototype-after-length-zeroed.js new file mode 100644 index 0000000000000000000000000000000000000000..6bd95a90bc00bcbb5d8547e1706cf2c058ae1176 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/calls-only-has-on-prototype-after-length-zeroed.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Calls [[HasProperty]] on the prototype to check for existing elements. +includes: [proxyTrapsHelper.js] +features: [Proxy] +---*/ + +var SendableArray = [5, undefined, 7]; +Object.setPrototypeOf(SendableArray, new Proxy(SendableArray.prototype, allowProxyTraps({ + has: function(t, pk) { + return pk in t; + } +}))); +var fromIndex = { + valueOf: function() { + // Zero the array's length. The loop in step 8 iterates over the original + // length value of 100, but the only prototype MOP method which should be + // called is [[HasProperty]]. + SendableArray.length = 0; + return 2; + } +}; +SendableArray.prototype.lastIndexOf.call(SendableArray, 100, fromIndex); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/coerced-position-grow.js b/test/sendable/builtins/Array/prototype/lastIndexOf/coerced-position-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..1bc8d3bd6ed5df3b8b7bcd60b75cb6a7811e0636 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/coerced-position-grow.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.p.lastIndexOf behaves correctly when the resizable buffer is grown by + argument coercion. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Growing + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, 1); + } + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return -1; + } + }; + let n0 = MayNeedBigInt(lengthTracking, 0); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n0), -1); + // Because lastIndexOf iterates from the given index downwards, it's not + // possible to test that "we only look at the data until the original + // length" without also testing that the index conversion happening with the + // original length. + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n0, evil), -1); +} +// Growing + length-tracking TA, index conversion. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return -4; + } + }; + let n0 = MayNeedBigInt(lengthTracking, 0); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n0, -4), 0); + // The TA grew but the start index conversion is done based on the original + // length. + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n0, evil), 0); +} diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/coerced-position-shrink.js b/test/sendable/builtins/Array/prototype/lastIndexOf/coerced-position-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..f27cdbe2ac4c991fb96f7d102f9ac50a82958a31 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/coerced-position-shrink.js @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.p.lastIndexOf behaves correctly when the resizable buffer is shrunk by + argument coercion. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Shrinking + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 2; + } + }; + let n = MayNeedBigInt(fixedLength, 0); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n), 3); + // The TA is OOB so lastIndexOf returns -1. + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n, evil), -1); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 2; + } + }; + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, MayNeedBigInt(fixedLength, 0)), 3); + // The TA is OOB so lastIndexOf returns -1, also for undefined). + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, undefined, evil), -1); +} +// Shrinking + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i); + } + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 2; + } + }; + let n = MayNeedBigInt(lengthTracking, 2); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n), 2); + // 2 no longer found. + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n, evil), -1); +} diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/fromindex-zero-conversion.js b/test/sendable/builtins/Array/prototype/lastIndexOf/fromindex-zero-conversion.js new file mode 100644 index 0000000000000000000000000000000000000000..4927d91a14652119875ea01088e7f244b688da33 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/fromindex-zero-conversion.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Return +0 when fromIndex is -0 and return index refers to the first position +---*/ + +assert.sameValue(1 / [true].lastIndexOf(true, -0), +Infinity); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/length-near-integer-limit.js b/test/sendable/builtins/Array/prototype/lastIndexOf/length-near-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..ba1fb0e196707f0362d089a5043d184dd7febd87 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/length-near-integer-limit.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.lastindexof +description: > + Elements are found in an array-like object + whose "length" property is near the integer limit. +info: | + Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) +---*/ + +var el = {}; +var elIndex = Number.MAX_SAFE_INTEGER - 3; +var fromIndex = Number.MAX_SAFE_INTEGER - 1; +var arrayLike = { + length: Number.MAX_SAFE_INTEGER, +}; +arrayLike[elIndex] = el; +var res = SendableArray.prototype.lastIndexOf.call(arrayLike, el, fromIndex); +assert.sameValue(res, elIndex); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/length-zero-returns-minus-one.js b/test/sendable/builtins/Array/prototype/lastIndexOf/length-zero-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..7dc7fe0f12b183a5e617c0ef4175d25afdc64773 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/length-zero-returns-minus-one.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Returns -1 if length is 0. +info: | + Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + 1. Let O be ? ToObject(this value). + 2. Let len be ? LengthOfArrayLike(O). + 3. If len is 0, return -1. +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error("Length should be checked before ToInteger(fromIndex)."); + }, +}; +assert.sameValue([].lastIndexOf(1), -1); +assert.sameValue([].lastIndexOf(2, fromIndex), -1); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/length.js b/test/sendable/builtins/Array/prototype/lastIndexOf/length.js new file mode 100644 index 0000000000000000000000000000000000000000..a0ea9c1d07800a803e7d4b2da16c6066c00804e6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/length.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + The "length" property of Array.prototype.lastIndexOf +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.lastIndexOf, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/name.js b/test/sendable/builtins/Array/prototype/lastIndexOf/name.js new file mode 100644 index 0000000000000000000000000000000000000000..23a09b46af4811e08ad8d971e3a1a5757bd85726 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.prototype.lastIndexOf.name is "lastIndexOf". +info: | + Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.lastIndexOf, "name", { + value: "lastIndexOf", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/not-a-constructor.js b/test/sendable/builtins/Array/prototype/lastIndexOf/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..32219b33fdc7111038ee56fbb2ceccc235f57307 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/not-a-constructor.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.lastIndexOf does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.lastIndexOf), + false, + 'isConstructor(SendableArray.prototype.lastIndexOf) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.lastIndexOf(); +}); + diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/prop-desc.js b/test/sendable/builtins/Array/prototype/lastIndexOf/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..a3549475b3aeb2ba73ea8333574d97bb83adc0f9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + "lastIndexOf" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.lastIndexOf, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "lastIndexOf", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/lastIndexOf/resizable-buffer.js b/test/sendable/builtins/Array/prototype/lastIndexOf/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9248ecd80590bcc17813abd591d21e2bc9e57341 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/lastIndexOf/resizable-buffer.js @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.lastindexof +description: > + Array.p.lastIndexOf behaves correctly on TypedArrays backed by resizable + buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, Math.floor(i / 2)); + } + // Orig. array: [0, 0, 1, 1] + // [0, 0, 1, 1] << fixedLength + // [1, 1] << fixedLengthWithOffset + // [0, 0, 1, 1, ...] << lengthTracking + // [1, 1, ...] << lengthTrackingWithOffset + + // If fixedLength is a BigInt array, they all are BigInt Arrays. + let n0 = MayNeedBigInt(fixedLength, 0); + let n1 = MayNeedBigInt(fixedLength, 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n0), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n0, 1), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n0, 2), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n0, -2), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n0, -3), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n1, 1), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n1, -2), 2); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n1, -3), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, undefined), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, n1), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, n1, -2), 0); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, n1, -1), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, undefined), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n0), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n0, 2), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n0, -3), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n1, 1), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n1, 2), 2); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n1, -3), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, undefined), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n1), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n1, 1), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n1, -2), 0); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n1, -1), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, undefined), -1); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 0, 1] + // [0, 0, 1, ...] << lengthTracking + // [1, ...] << lengthTrackingWithOffset + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n1), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, n1), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n0), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, undefined), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n1), 0); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, undefined), -1); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n0), 0); + // Shrink to zero. + rab.resize(0); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, undefined), -1); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, Math.floor(i / 2)); + } + // Orig. array: [0, 0, 1, 1, 2, 2] + // [0, 0, 1, 1] << fixedLength + // [1, 1] << fixedLengthWithOffset + // [0, 0, 1, 1, 2, 2, ...] << lengthTracking + // [1, 1, 2, 2, ...] << lengthTrackingWithOffset + let n2 = MayNeedBigInt(fixedLength, 2); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n1), 3); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, n2), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLength, undefined), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, n1), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, n2), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(fixedLengthWithOffset, undefined), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n1), 3); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, n2), 5); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTracking, undefined), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n0), -1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n1), 1); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, n2), 3); + assert.sameValue(SendableArray.prototype.lastIndexOf.call(lengthTrackingWithOffset, undefined), -1); +} diff --git a/test/sendable/builtins/Array/prototype/length.js b/test/sendable/builtins/Array/prototype/length.js new file mode 100644 index 0000000000000000000000000000000000000000..a0e8d3afae14c91a6a8a579c711e449999bde1e1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/length.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-properties-of-the-array-prototype-object +description: > + Array.prototype has a length property +info: | + 22.1.3 Properties of the Array Prototype Object + The Array prototype object is the intrinsic object %ArrayPrototype%. The Array + prototype object is an Array exotic object and has the internal methods specified + for such objects. It has a length property whose initial value is 0 and whose + attributes are { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: + false }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(SendableArray.prototype.length, 0); +verifyNotEnumerable(SendableArray.prototype, 'length'); +// specify the value so it avoids a RangeError while setting the length +verifyWritable(SendableArray.prototype, 'length', false, 42); +verifyNotConfigurable(SendableArray.prototype, 'length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..343e6696bb3a6a882aed847499a06b86341cbb94 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to undefined +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.map.call(undefined); // TypeError is thrown if value is undefined +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-10.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..b39026ed263ed5a9250cedce19510ec77185bbef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-10.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to the Math object +---*/ + +function callbackfn(val, idx, obj) { + return ('[object Math]' === Object.prototype.toString.call(obj)); +} +Math.length = 1; +Math[0] = 1; +var testResult = SendableArray.prototype.map.call(Math, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-11.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..0118974634a5a68a2d92063c4ba61d5a78f2fcf4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-11.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to Date object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Date; +} +var obj = new Date(0); +obj.length = 1; +obj[0] = 1; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-12.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..e7c67a5c2733e618276e075a3795028f85760ed6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-12.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to RegExp object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof RegExp; +} +var obj = new RegExp(); +obj.length = 1; +obj[0] = 1; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-13.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..b142983b388d2243b0ec4c3b82d44a2bae105cd7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-13.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to the JSON object +---*/ + +function callbackfn(val, idx, obj) { + return ('[object JSON]' === Object.prototype.toString.call(obj)); +} +JSON.length = 1; +JSON[0] = 1; +var testResult = SendableArray.prototype.map.call(JSON, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-14.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-14.js new file mode 100644 index 0000000000000000000000000000000000000000..96fe6bc724b530acc56fe06321cde27cbe9342d0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-14.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to Error object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Error; +} +var obj = new Error(); +obj.length = 1; +obj[0] = 1; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-15.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..81809a75a994b81a0d9ca73b41c7a19de27a6030 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-15.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to the Arguments object +---*/ + +function callbackfn(val, idx, obj) { + return ('[object Arguments]' === Object.prototype.toString.call(obj)); +} +var obj = (function() { + return arguments; +}("a", "b")); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[1], true, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..1f0efaab4b5114aa05211850c7babdccd3478e07 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to null +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.map.call(null); // TypeError is thrown if value is null +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-3.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..1d8ef8163f72a07cd4a69bf2277efbf3531cd73e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-3.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to boolean primitive +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Boolean; +} +Boolean.prototype[0] = true; +Boolean.prototype.length = 1; +var testResult = SendableArray.prototype.map.call(false, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-4.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..aafe38a1012c0a2cbbc9bfb0409535b35b85d25d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-4.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to Boolean object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Boolean; +} +var obj = new Boolean(true); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], true, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-5.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..d313d71d201b71714300ea31bb1dec67f9869cb6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-5.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to number primitive +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Number; +} +Number.prototype[0] = 1; +Number.prototype.length = 1; +var testResult = SendableArray.prototype.map.call(2.5, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-6.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..fa94129c90cd781931e07f47b07ec43e698f9aea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-6.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to Number object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Number; +} +var obj = new Number(-128); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], true, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-7.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..606033542b847b65158729964e69965258e9a4f1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-7.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to string primitive +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof String; +} +var testResult = SendableArray.prototype.map.call("abc", callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], true, 'testResult[1]'); +assert.sameValue(testResult[2], true, 'testResult[2]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-8.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..e185c02ec3b67f9f8cfe55ce9475ebdab02aaf6c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-8.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to String object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof String; +} +var obj = new String("abc"); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], true, 'testResult[1]'); +assert.sameValue(testResult[2], true, 'testResult[2]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-9.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..8d86c91e9287ec80a0d2ed97b9c57ff1168814ab --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-1-9.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - applied to Function object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Function; +} +var obj = function(a, b) { + return a + b; +}; +obj[0] = 11; +obj[1] = 9; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], true, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..f8b81ce8544cc12535207d995f9bb6ad3d415bfa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to Array-like object when 'length' + is an own data property +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: 2 +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-10.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-10.js new file mode 100644 index 0000000000000000000000000000000000000000..cd9cfcec898ac40877828739465ce4e5e383a6c6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-10.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to Array-like object, 'length' is an + inherited accessor property +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-11.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-11.js new file mode 100644 index 0000000000000000000000000000000000000000..8494261cb874665837f4acd38c2b44ad899abafc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-11.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to Array-like object when 'length' + is an own accessor property without a get function +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 0, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-12.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-12.js new file mode 100644 index 0000000000000000000000000000000000000000..22585f2f444bac2e8eba6bad106cd588f45c14d2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-12.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to the Array-like object when + 'length' is own accessor property without a get function that + overrides an inherited accessor property +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +Object.defineProperty(Object.prototype, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var obj = { + 0: 12, + 1: 11 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 0, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-13.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-13.js new file mode 100644 index 0000000000000000000000000000000000000000..768d558f6d3f5c67f1138b25aee5c41ab81fa6d0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-13.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to the Array-like object when + 'length' is inherited accessor property without a get function +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var proto = {}; +Object.defineProperty(proto, "length", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 11; +child[1] = 12; +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult.length, 0, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-14.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-14.js new file mode 100644 index 0000000000000000000000000000000000000000..1bd364b618ff7e2afac55c4f264218a9b96091e9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-14.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to the Array-like object that + 'length' property doesn't exist +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 11, + 1: 12 +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 0, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-17.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-17.js new file mode 100644 index 0000000000000000000000000000000000000000..1b786da20ca9f4a38bb801e12bb534f13fc18e47 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-17.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to Arguments object, which + implements its own property get method +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var func = function(a, b) { + return SendableArray.prototype.map.call(arguments, callbackfn); +}; +var testResult = func(12, 11); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-18.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-18.js new file mode 100644 index 0000000000000000000000000000000000000000..d16334e7839c70774b2725c2b453ca5ac11dd9af --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-18.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to String object, which implements + its own property get method +---*/ + +function callbackfn(val, idx, obj) { + return parseInt(val, 10) > 1; +} +var str = new String("432"); +String.prototype[3] = "1"; +var testResult = SendableArray.prototype.map.call(str, callbackfn); +assert.sameValue(testResult.length, 3, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-19.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-19.js new file mode 100644 index 0000000000000000000000000000000000000000..4918732e0100a3d6f8d29bc2c004654d84dd3e44 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-19.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to Function object, which implements + its own property get method +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var fun = function(a, b) { + return a + b; +}; +fun[0] = 12; +fun[1] = 11; +fun[2] = 9; +var testResult = SendableArray.prototype.map.call(fun, callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..a4b2e8d59d3f3ab8060688b31129803d3ba24168 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-2.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - when 'length' is own data property on an + Array +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var testResult = [12, 11].map(callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-3.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..36288a96c1b3ddfe28f6a293e7a8b32c0f0a58da --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-3.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to Array-like object, 'length' is an + own data property that overrides an inherited data property +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +child[0] = 12; +child[1] = 11; +child[2] = 9; +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-4.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..bee2c86c743a97c25e71c9c28671dac2f28e3049 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-4.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - when 'length' is own data property that + overrides an inherited data property on an Array +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var arrProtoLen; +arrProtoLen = SendableArray.prototype.length; +SendableArray.prototype.length = 0; +var testResult = [12, 11].map(callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-5.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..ff2fe7df3985d927c2f56b47e96d73608aaa56a8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-5.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to Array-like object, 'length' is an + own data property that overrides an inherited accessor property +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + value: 2, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-6.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-6.js new file mode 100644 index 0000000000000000000000000000000000000000..019253214044f85418abe334f830e7c90656cbb1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to Array-like object, 'length' is an + inherited data property +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var proto = { + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-7.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-7.js new file mode 100644 index 0000000000000000000000000000000000000000..29885713bb01f4219b0ea163bf3dd6d402f10b47 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-7.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to Array-like object, 'length' is an + own accessor property +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return 2; + }, + configurable: true +}); +obj[0] = 12; +obj[1] = 11; +obj[2] = 9; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-8.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-8.js new file mode 100644 index 0000000000000000000000000000000000000000..4aec2c1de21535f9b4c666238bba2aa1c24ac26e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-8.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to Array-like object, 'length' is an + own accessor property that overrides an inherited data property +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-9.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-9.js new file mode 100644 index 0000000000000000000000000000000000000000..25edd74128a5f23a24a6e53a1bd093db11623bf7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-2-9.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - applied to Array-like object when 'length' + is an own accessor property that overrides an inherited accessor + property +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-1.js new file mode 100644 index 0000000000000000000000000000000000000000..6a59c6a8408bb9f74c56c6afa44068cf0d315cfa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-1.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - value of 'length' is undefined +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + length: undefined +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-10.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-10.js new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9105ecc0cd8c66a904a6ace43e28fbd7ce4c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-10.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - value of 'length' is a number (value is NaN) +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 9, + length: NaN +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-11.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-11.js new file mode 100644 index 0000000000000000000000000000000000000000..71b43caae94b580f2c08e4c509c90c394711d573 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-11.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - 'length' is a string containing a positive + number +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 11, + 1: 9, + 2: 12, + length: "2" +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-12.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-12.js new file mode 100644 index 0000000000000000000000000000000000000000..7e292bfcfbef50836ef68315883f6a403b387265 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-12.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - 'length' is a string containing a negative + number +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 11, + 1: 9, + 2: 12, + length: "-4294967294" +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-13.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-13.js new file mode 100644 index 0000000000000000000000000000000000000000..b1e4525c79d4ba209460e09ea3af59179ab59075 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-13.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of 'length' is string that is able to + convert to number primitive (value is a decimal number) +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 11, + 1: 9, + 2: 12, + length: "2.5" +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-14.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-14.js new file mode 100644 index 0000000000000000000000000000000000000000..ac8090f57fb0243ab47400e67c68d840e61b3fb4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-14.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - 'length' is a string containing Infinity +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 9, + length: "Infinity" +}; +assert.throws(RangeError, function() { + SendableArray.prototype.map.call(obj, callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-15.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-15.js new file mode 100644 index 0000000000000000000000000000000000000000..d866fb04f1d368bf66ed53c3988193275f9ca341 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-15.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - 'length' is a string containing an + exponential number +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 11, + 1: 9, + 2: 12, + length: "2E0" +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-16.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-16.js new file mode 100644 index 0000000000000000000000000000000000000000..2688ee3d1a9c077abd339535de804c7349ac4154 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-16.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - 'length' is a string containing a hex number +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 11, + 1: 9, + 2: 12, + length: "0x0002" +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-17.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-17.js new file mode 100644 index 0000000000000000000000000000000000000000..a71a6217f1728d019916050eb039dc5275d37b3d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-17.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - when 'length' is a string containing a + number with leading zeros +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 11, + 1: 9, + 2: 12, + length: "0002.00" +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-18.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-18.js new file mode 100644 index 0000000000000000000000000000000000000000..92ca86c5f66134579adec49bc8dd83d98a57ad55 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-18.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of 'length' is a string that can't + convert to a number +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + length: "asdf!_" +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-19.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-19.js new file mode 100644 index 0000000000000000000000000000000000000000..ed3306cd351dca8adaff14c75eb536abc476f251 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-19.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of 'length' is an Object which has an + own toString method +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 11, + 1: 9, + length: { + toString: function() { + return '2'; + } + } +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-2.js new file mode 100644 index 0000000000000000000000000000000000000000..3cacbe880dca02ae7ea6a1f5fd1a2ab983039023 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map on an Array-like object if 'length' is 1 + (length overridden to true(type conversion)) +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 11, + length: true +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 1, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-20.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-20.js new file mode 100644 index 0000000000000000000000000000000000000000..3436c95edb3626605d75abb87aef05cdc9b13b35 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-20.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of 'length' is an Object which has an + own valueOf method +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 11, + 1: 9, + length: { + valueOf: function() { + return 2; + } + } +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-21.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-21.js new file mode 100644 index 0000000000000000000000000000000000000000..27c50df52d5d52d66d52dfd9881b8b5349ec9847 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-21.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - 'length' is an object that has an own + valueOf method that returns an object and toString method that + returns a string +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var firstStepOccured = false; +var secondStepOccured = false; +var obj = { + 0: 11, + 1: 9, + length: { + valueOf: function() { + firstStepOccured = true; + return {}; + }, + toString: function() { + secondStepOccured = true; + return '2'; + } + } +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); +assert(firstStepOccured, 'firstStepOccured !== true'); +assert(secondStepOccured, 'secondStepOccured !== true'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-22.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-22.js new file mode 100644 index 0000000000000000000000000000000000000000..f00bb79559ef6ca5d1e2f6e625256b73dfdc95d2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-22.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map throws TypeError exception when 'length' is an + object with toString and valueOf methods that don�t return + primitive values +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 1: 11, + 2: 12, + length: { + valueOf: function() { + return {}; + }, + toString: function() { + return {}; + } + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.map.call(obj, callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-23.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-23.js new file mode 100644 index 0000000000000000000000000000000000000000..f5fcd830e7a701bb3d645d067bbe742b8bc2db65 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-23.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map uses inherited valueOf method when 'length' is + an object with an own toString and inherited valueOf methods +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var valueOfAccessed = false; +var toStringAccessed = false; +var proto = { + valueOf: function() { + valueOfAccessed = true; + return 2; + } +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.toString = function() { + toStringAccessed = true; + return '1'; +}; +var obj = { + 0: 11, + 1: 9, + length: child +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(toStringAccessed, false, 'toStringAccessed'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-24.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-24.js new file mode 100644 index 0000000000000000000000000000000000000000..abbe8ff835e967ab1f0cf9b18d3fca7547b98027 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-24.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of 'length' is a positive non-integer, + ensure truncation occurs in the proper direction +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 11, + 1: 9, + length: 2.685 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-25.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-25.js new file mode 100644 index 0000000000000000000000000000000000000000..337545b7998aaa336153053b4d95993cbe4d4c4f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-25.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - value of 'length' is a negative non-integer +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 11, + 1: 9, + length: -4294967294.5 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-28.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-28.js new file mode 100644 index 0000000000000000000000000000000000000000..66c6271251033c67f1b761ca0b7ff9a43bac6f2d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-28.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - value of 'length' is boundary value (2^32) +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 12, + length: 4294967296 +}; +assert.throws(RangeError, function() { + var newArr = SendableArray.prototype.map.call(obj, callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-29.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-29.js new file mode 100644 index 0000000000000000000000000000000000000000..4ce3eabeff32047fc39d4f5d41a4df6a2cc34af9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-29.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of 'length' is boundary value (2^32 + + 1) +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 11, + 1: 9, + length: 4294967297 +}; +assert.throws(RangeError, function() { + var newArr = SendableArray.prototype.map.call(obj, callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-3.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-3.js new file mode 100644 index 0000000000000000000000000000000000000000..0bcd083e67c5b0eecb0059e4cfb57e441bbe7ee4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-3.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - value of 'length' is a number (value is 0) +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 11, + length: 0 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-4.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-4.js new file mode 100644 index 0000000000000000000000000000000000000000..0d870f63dd77fcd452ba9725fe705b00d159188b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - value of 'length' is a number (value is +0) +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 11, + length: +0 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-5.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-5.js new file mode 100644 index 0000000000000000000000000000000000000000..7ce32bad9aaa7b9a6ddbfc19631893a0ae28526d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-5.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - value of 'length' is a number (value is -0) +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 11, + length: -0 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-6.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-6.js new file mode 100644 index 0000000000000000000000000000000000000000..d675e6f341ecf969dde3253979a55bace11cdb56 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-6.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - 'length' is a string containing a positive + number +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 10, + 1: 12, + 2: 9, + length: 2 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 2, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-7.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-7.js new file mode 100644 index 0000000000000000000000000000000000000000..c0c9b0a262edc91c09b37ebaf105dbef1fff3172 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-7.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - 'length' is a string containing a negative + number +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 10, + 1: 12, + 2: 9, + length: -4294967294 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-8.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-8.js new file mode 100644 index 0000000000000000000000000000000000000000..62c092a0cef4e7c08d45f15d3e31ccf9b3f2fa71 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-8.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of 'length' is a number (value is + Infinity) +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 9, + length: Infinity +}; +assert.throws(RangeError, function() { + SendableArray.prototype.map.call(obj, callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-9.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-9.js new file mode 100644 index 0000000000000000000000000000000000000000..8e8f12aac018506c38caafef19c6e35e3b65fb39 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-3-9.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of 'length' is a number (value is + -Infinity) +---*/ + +function callbackfn(val, idx, obj) { + return val < 10; +} +var obj = { + 0: 9, + length: -Infinity +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr.length, 0, 'newArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..22943e976f5ee1dafdb0565c6bb269bb98f63b2e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map throws TypeError if callbackfn is undefined +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.map(); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-10.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-10.js new file mode 100644 index 0000000000000000000000000000000000000000..9061d48d67f0779f5a95641ad1984b5ef8623a1d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-10.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - the exception is not thrown if exception was + thrown by step 2 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.map.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-11.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-11.js new file mode 100644 index 0000000000000000000000000000000000000000..3d7cca5eb7fbb4c23e15f83c7836d99ca6dc40a8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-11.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - the exception is not thrown if exception was + thrown by step 3 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + throw new Test262Error(); + } + }; + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.map.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-12.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-12.js new file mode 100644 index 0000000000000000000000000000000000000000..2c32531c341b6fb14e13838946c2c3048490f2a3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-12.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - 'callbackfn' is a function +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var testResult = [11, 9].map(callbackfn); +assert.sameValue(testResult.length, 2, 'testResult.length'); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], false, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-15.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-15.js new file mode 100644 index 0000000000000000000000000000000000000000..9a2f897515c708ca50e89ade6005e9ea2a49f3fa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-15.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - calling with no callbackfn is the same as + passing undefined for callbackfn +---*/ + +var obj = { + 10: 10 +}; +var lengthAccessed = false; +var loopAccessed = false; +Object.defineProperty(obj, "length", { + get: function() { + lengthAccessed = true; + return 20; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + loopAccessed = true; + return 10; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.map.call(obj); +}); +assert(lengthAccessed, 'lengthAccessed !== true'); +assert.sameValue(loopAccessed, false, 'loopAccessed'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-2.js new file mode 100644 index 0000000000000000000000000000000000000000..f96ea0a1690a6e164e4e720f828c233262ae3a54 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map throws ReferenceError if callbackfn is + unreferenced +---*/ + +var arr = new SendableArray(10); +assert.throws(ReferenceError, function() { + arr.map(foo); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-3.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..97f196b7eab283913f20abd1e1afce12f88ce40e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-3.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map throws TypeError if callbackfn is null +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.map(null); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-4.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..f0f6276e3f54709395dfe5a8daaf33a9616a90d0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-4.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map throws TypeError if callbackfn is boolean +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.map(true); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-5.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-5.js new file mode 100644 index 0000000000000000000000000000000000000000..84b84478d1de96b3c594c936f8444647ac39ef88 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-5.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map throws TypeError if callbackfn is number +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.map(5); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-6.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-6.js new file mode 100644 index 0000000000000000000000000000000000000000..0ed16b1fb8568e4626c50e400495feac22f1dede --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-6.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map throws TypeError if callbackfn is string +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.map("abc"); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-7.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-7.js new file mode 100644 index 0000000000000000000000000000000000000000..45f927c9afcf1a86ced56a23448bcb8da47c7a0d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-7.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map throws TypeError if callbackfn is Object + without Call internal method +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.map(new Object()); +}); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-8.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-8.js new file mode 100644 index 0000000000000000000000000000000000000000..8298d182a561c008e324a7720b87329f2773f04a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-8.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - Side effects produced by step 2 are visible + when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + accessed = true; + return 2; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.map.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-9.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-9.js new file mode 100644 index 0000000000000000000000000000000000000000..4bbaaeda409fd39efba960b909956ef67b3ef389 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-4-9.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - Side effects produced by step 3 are visible + when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + accessed = true; + return "2"; + } + }; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.map.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-1-s.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-1-s.js new file mode 100644 index 0000000000000000000000000000000000000000..d4d87d55639bfcc8b8b78e8f99e8ddb143bd2580 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-1-s.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - thisArg not passed to strict callbackfn +flags: [noStrict] +---*/ + +var innerThisCorrect = false; +function callbackfn(val, idx, obj) { + "use strict"; + innerThisCorrect = this === undefined; + return true; +} +[1].map(callbackfn); +assert(innerThisCorrect, 'innerThisCorrect !== true'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..c22ac9135765b2d2a859e7ab89e50eff9649c9c7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - thisArg not passed +flags: [noStrict] +---*/ + +this._15_4_4_19_5_1 = true; +(function() { + var _15_4_4_19_5_1 = false; + function callbackfn(val, idx, obj) { + return this._15_4_4_19_5_1; + } + var srcArr = [1]; + var resArr = srcArr.map(callbackfn); + assert.sameValue(resArr[0], true, 'resArr[0]'); +})(); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-10.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-10.js new file mode 100644 index 0000000000000000000000000000000000000000..5bff68f1dd18508c26fc0969cc7ce401d3665eba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-10.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - Array object can be used as thisArg +---*/ + +var objArray = new SendableArray(2); +function callbackfn(val, idx, obj) { + return this === objArray; +} +var testResult = [11].map(callbackfn, objArray); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-11.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-11.js new file mode 100644 index 0000000000000000000000000000000000000000..4745d9b90180de4908bb089dba40792ba4790205 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-11.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - String object can be used as thisArg +---*/ + +var objString = new String(); +function callbackfn(val, idx, obj) { + return this === objString; +} +var testResult = [11].map(callbackfn, objString); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-12.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-12.js new file mode 100644 index 0000000000000000000000000000000000000000..c0be695624d40e13c707d25363700c2abeb89f1c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-12.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - Boolean object can be used as thisArg +---*/ + +var objBoolean = new Boolean(); +function callbackfn(val, idx, obj) { + return this === objBoolean; +} +var testResult = [11].map(callbackfn, objBoolean); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-13.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-13.js new file mode 100644 index 0000000000000000000000000000000000000000..5c633cefa5710de1a5cdd676d77f9210cb5ef00f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-13.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - Number object can be used as thisArg +---*/ + +var objNumber = new Number(); +function callbackfn(val, idx, obj) { + return this === objNumber; +} +var testResult = [11].map(callbackfn, objNumber); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-14.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-14.js new file mode 100644 index 0000000000000000000000000000000000000000..35e7c9a01c1ba33e210d75cb97c92a7b906cc2e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-14.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - the Math object can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this === Math; +} +var testResult = [11].map(callbackfn, Math); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-15.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-15.js new file mode 100644 index 0000000000000000000000000000000000000000..fd6f53185de30090784ef5ad3d8273403e232f25 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-15.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - Date object can be used as thisArg +---*/ + +var objDate = new Date(0); +function callbackfn(val, idx, obj) { + return this === objDate; +} +var testResult = [11].map(callbackfn, objDate); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-16.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-16.js new file mode 100644 index 0000000000000000000000000000000000000000..62dd30517eeaaddf595c20df1b14be0e948747e6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-16.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - RegExp object can be used as thisArg +---*/ + +var objRegExp = new RegExp(); +function callbackfn(val, idx, obj) { + return this === objRegExp; +} +var testResult = [11].map(callbackfn, objRegExp); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-17.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-17.js new file mode 100644 index 0000000000000000000000000000000000000000..b608b5f159ed63d52c0673d78d505d7c63855326 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-17.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - the JSON object can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this === JSON; +} +var testResult = [11].map(callbackfn, JSON); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-18.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-18.js new file mode 100644 index 0000000000000000000000000000000000000000..5121b3a05f42a6c563dc5b9643c1822db6a88f0c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-18.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - Error object can be used as thisArg +---*/ + +var objError = new RangeError(); +function callbackfn(val, idx, obj) { + return this === objError; +} +var testResult = [11].map(callbackfn, objError); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-19.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-19.js new file mode 100644 index 0000000000000000000000000000000000000000..0e762cebf2d822c0d452fa0068f98970916526da --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-19.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - the Arguments object can be used as thisArg +---*/ + +var arg; +function callbackfn(val, idx, obj) { + return this === arg; +} +arg = (function() { + return arguments; +}(1, 2, 3)); +var testResult = [11].map(callbackfn, arg); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-2.js new file mode 100644 index 0000000000000000000000000000000000000000..3fe63c685a387c6b374c6557b05ef10754ad9abc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - thisArg is Object +---*/ + +var res = false; +var o = new Object(); +o.res = true; +function callbackfn(val, idx, obj) +{ + return this.res; +} +var srcArr = [1]; +var resArr = srcArr.map(callbackfn, o); +assert.sameValue(resArr[0], true, 'resArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-21.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-21.js new file mode 100644 index 0000000000000000000000000000000000000000..94bfb1e8cbb2f968713b795d9fd88020f60c8e7c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-21.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - the global object can be used as thisArg +---*/ + +var global = this; +function callbackfn(val, idx, obj) { + return this === global; +} +var testResult = [11].map(callbackfn, this); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-22.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-22.js new file mode 100644 index 0000000000000000000000000000000000000000..937b28ac8b5134fe5361efbb0875a2432205ca28 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-22.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - boolean primitive can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === false; +} +var testResult = [11].map(callbackfn, false); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-23.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-23.js new file mode 100644 index 0000000000000000000000000000000000000000..6f7fd7310725697cffea8b7415edba0f73b72616 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-23.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - number primitive can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === 101; +} +var testResult = [11].map(callbackfn, 101); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-24.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-24.js new file mode 100644 index 0000000000000000000000000000000000000000..2f5141adfadfb556eca4657e9ef060b4b0c2139b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-24.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - string primitive can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === "abc"; +} +var testResult = [11].map(callbackfn, "abc"); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-3.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-3.js new file mode 100644 index 0000000000000000000000000000000000000000..c5d3e15bc1cc258cf5306ca60e06f2622b681438 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-3.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - thisArg is Array +---*/ + +var res = false; +var a = new SendableArray(); +a.res = true; +function callbackfn(val, idx, obj) +{ + return this.res; +} +var srcArr = [1]; +var resArr = srcArr.map(callbackfn, a); +assert.sameValue(resArr[0], true, 'resArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-4.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-4.js new file mode 100644 index 0000000000000000000000000000000000000000..86186d1716f99879ddc3b5357b5f592a09fc5251 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-4.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - thisArg is object from object + template(prototype) +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +foo.prototype.res = true; +var f = new foo(); +var srcArr = [1]; +var resArr = srcArr.map(callbackfn, f); +assert.sameValue(resArr[0], true, 'resArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-5.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-5.js new file mode 100644 index 0000000000000000000000000000000000000000..99822f75dbf35b6ece9dab3a4a037552867a51fc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-5.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - thisArg is object from object template +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +var f = new foo(); +f.res = true; +var srcArr = [1]; +var resArr = srcArr.map(callbackfn, f); +assert.sameValue(resArr[0], true, 'resArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-6.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-6.js new file mode 100644 index 0000000000000000000000000000000000000000..1751e1a0ebcf9b1bfdcf99012f90650ddc70767d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-6.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - thisArg is function +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +foo.res = true; +var srcArr = [1]; +var resArr = srcArr.map(callbackfn, foo); +assert.sameValue(resArr[0], true, 'resArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-7.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-7.js new file mode 100644 index 0000000000000000000000000000000000000000..aeab8eb9fd570d4a657112b77d95aa087309e0c7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-7.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - built-in functions can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this === eval; +} +var testResult = [11].map(callbackfn, eval); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-9.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-9.js new file mode 100644 index 0000000000000000000000000000000000000000..78d45b7bc1144115289605d90ef6e0e89d53ee7e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-5-9.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - Function object can be used as thisArg +---*/ + +var objFunction = function() {}; +function callbackfn(val, idx, obj) { + return this === objFunction; +} +var testResult = [11].map(callbackfn, objFunction); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-6-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-6-1.js new file mode 100644 index 0000000000000000000000000000000000000000..e03a2bed6345b6aa1417179af1fe8d096acc872b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-6-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - Array.isArray returns true when input + argument is the ourput array +---*/ + +var newArr = [11].map(function() {}); +assert(SendableArray.isArray(newArr), 'SendableArray.isArray(newArr) !== true'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-6-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-6-2.js new file mode 100644 index 0000000000000000000000000000000000000000..8684f98b380a1f2564f2aba5ecbe16f65c78b138 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-6-2.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - the returned array is instanceof Array +---*/ + +var newArr = [11].map(function() {}); +assert(newArr instanceof SendableArray, 'newArr instanceof SendableArray !== true'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-1.js new file mode 100644 index 0000000000000000000000000000000000000000..b01a984f2bba0d594f13cd0f54973ce0a7913c63 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map doesn't consider new elements added to array + after it is called +---*/ + +function callbackfn(val, idx, obj) +{ + srcArr[2] = 3; + srcArr[5] = 6; + return 1; +} +var srcArr = [1, 2, , 4, 5]; +var resArr = srcArr.map(callbackfn); +assert.sameValue(resArr.length, 5, 'resArr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-2.js new file mode 100644 index 0000000000000000000000000000000000000000..dc7cf046513776aaf54da14829581fff0a8874e6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-2.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map considers new value of elements in array after + it is called +---*/ + +function callbackfn(val, idx, obj) +{ + srcArr[4] = -1; + if (val > 0) + return 1; + else + return 0; +} +var srcArr = [1, 2, 3, 4, 5]; +var resArr = srcArr.map(callbackfn); +assert.sameValue(resArr.length, 5, 'resArr.length'); +assert.sameValue(resArr[4], 0, 'resArr[4]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-3.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-3.js new file mode 100644 index 0000000000000000000000000000000000000000..d8f5994aabd4b290507cb4e48d2398fb862fc928 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-3.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map doesn't visit deleted elements in array after + the call +---*/ + +function callbackfn(val, idx, obj) +{ + delete srcArr[4]; + if (val > 0) + return 1; + else + return 0; +} +var srcArr = [1, 2, 3, 4, 5]; +var resArr = srcArr.map(callbackfn); +assert.sameValue(resArr.length, 5, 'resArr.length'); +assert.sameValue(resArr[4], undefined, 'resArr[4]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-4.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-4.js new file mode 100644 index 0000000000000000000000000000000000000000..cda5618c3746a2b0d2dafa8e8596773aaef6bf8b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-4.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map doesn't visit deleted elements when + Array.length is decreased +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + srcArr.length = 2; + callCnt++; + return 1; +} +var srcArr = [1, 2, 3, 4, 5]; +var resArr = srcArr.map(callbackfn); +assert.sameValue(resArr.length, 5, 'resArr.length'); +assert.sameValue(callCnt, 2, 'callCnt'); +assert.sameValue(resArr[2], undefined, 'resArr[2]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-5.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-5.js new file mode 100644 index 0000000000000000000000000000000000000000..586c9d3ee99f1701bfdf822d71462f3e96fab084 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-5.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map doesn't consider newly added elements in + sparse array +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + srcArr[1000] = 3; + callCnt++; + return val; +} +var srcArr = new SendableArray(10); +srcArr[1] = 1; +srcArr[2] = 2; +var resArr = srcArr.map(callbackfn); +assert.sameValue(resArr.length, 10, 'resArr.length'); +assert.sameValue(callCnt, 2, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-6.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-6.js new file mode 100644 index 0000000000000000000000000000000000000000..f6273a8302bac7994006fe58a498fb033e9948d4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map visits deleted element in array after the call + when same index is also present in prototype +---*/ + +function callbackfn(val, idx, obj) +{ + delete srcArr[4]; + if (val > 0) + return 1; + else + return 0; +} +SendableArray.prototype[4] = 5; +var srcArr = [1, 2, 3, 4, 5]; +var resArr = srcArr.map(callbackfn); +delete SendableArray.prototype[4]; +assert.sameValue(resArr.length, 5, 'resArr.length'); +assert.sameValue(resArr[4], 1, 'resArr[4]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-7.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-7.js new file mode 100644 index 0000000000000000000000000000000000000000..22f442415c3fe9f17b55bd44462159a72f572f41 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-7.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map successful to delete the object in callbackfn +---*/ + +var obj = {}; +obj.srcArr = [1, 2, 3, 4, 5]; +function callbackfn(val, idx, obj) { + delete obj.srcArr; + if (val > 0) + return 1; + else + return 0; +} +var resArr = obj.srcArr.map(callbackfn); +assert.sameValue(resArr.toString(), "1,1,1,1,1", 'resArr.toString()'); +assert.sameValue(obj.hasOwnProperty("arr"), false, 'obj.hasOwnProperty("arr")'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-8.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-8.js new file mode 100644 index 0000000000000000000000000000000000000000..0c6fe8eb0172e3f37da1e8146dba43eddebff0f8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-8.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - no observable effects occur if length is 0 + on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + 1: 12, + length: 0 +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 0, 'testResult.length'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-9.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-9.js new file mode 100644 index 0000000000000000000000000000000000000000..0b921716beea9110fab6b106c553f48ec9f2656c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-9.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - modifications to length don't change number + of iterations on an Array +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called += 1; + return val > 10; +} +var arr = [9, , 12]; +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 8; + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult.length, 3, 'testResult.length'); +assert.sameValue(called, 2, 'called'); +assert.sameValue(typeof testResult[2], "undefined", 'typeof testResult[2]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..8025c7f8e75c6d56406be1c30a5229202a32810b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - callbackfn not called for indexes never been + assigned values +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; + return 1; +} +var srcArr = new SendableArray(10); +srcArr[1] = undefined; //explicitly assigning a value +var resArr = srcArr.map(callbackfn); +assert.sameValue(resArr.length, 10, 'resArr.length'); +assert.sameValue(callCnt, 1, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-10.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-10.js new file mode 100644 index 0000000000000000000000000000000000000000..20f8049d265f716b0e288a5f31b103df5aaf05d9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-10.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - deleting property of prototype causes + prototype index property not to be visited on an Array-like Object +---*/ + +function callbackfn(val, idx, obj) { + return idx === 1 && typeof val === "undefined"; +} +var obj = { + 2: 2, + length: 20 +}; +Object.defineProperty(obj, "0", { + get: function() { + delete Object.prototype[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 20, 'testResult.length'); +assert.sameValue(typeof testResult[1], "undefined", 'typeof testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-11.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-11.js new file mode 100644 index 0000000000000000000000000000000000000000..e4f82bdb5599fca26f29a0a43acb007143eef126 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-11.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - deleting property of prototype causes + prototype index property not to be visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + return idx === 1 && typeof val === "undefined"; +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + delete SendableArray.prototype[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +var testResult = arr.map(callbackfn); +assert.sameValue(testResult.length, 3, 'testResult.length'); +assert.sameValue(typeof testResult[1], "undefined", 'typeof testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-12.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-12.js new file mode 100644 index 0000000000000000000000000000000000000000..14278e8029121b093657dc1f81584ea457c2f931 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-12.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - deleting own property with prototype + property causes prototype index property to be visited on an + Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 3) { + return false; + } else { + return true; + } +} +var obj = { + 0: 0, + 1: 1, + 2: 2, + length: 10 +}; +Object.defineProperty(obj, "0", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 3; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[1], false, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-13.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-13.js new file mode 100644 index 0000000000000000000000000000000000000000..ef7a85a13d7e1fef08ce32d096d166b830c65a44 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-13.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - deleting own property with prototype + property causes prototype index property to be visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 3) { + return false; + } else { + return true; + } +} +var arr = [0, 1, 2]; +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 3; +var testResult = arr.map(callbackfn); +assert.sameValue(testResult[1], false, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-14.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-14.js new file mode 100644 index 0000000000000000000000000000000000000000..547ec269c3201f243afc57224128d3144f4c0869 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-14.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - decreasing length of array causes index + property not to be visited +---*/ + +function callbackfn(val, idx, obj) { + return idx === 3 && typeof val === "undefined"; +} +var arr = [0, 1, 2, "last"]; +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 3; + return 0; + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(typeof testResult[3], "undefined", 'typeof testResult[3]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-15.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-15.js new file mode 100644 index 0000000000000000000000000000000000000000..c49c1ec67e4cf883cb15ca93a6238ab421b2d816 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-15.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - decreasing length of array with prototype + property causes prototype index property to be visited +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "prototype") { + return false; + } else { + return true; + } +} +var arr = [0, 1, 2]; +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return "prototype"; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult.length, 3, 'testResult.length'); +assert.sameValue(testResult[2], false, 'testResult[2]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-16.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-16.js new file mode 100644 index 0000000000000000000000000000000000000000..a56647294288114deea53deb77fa4e8aa2045b83 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-16.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - decreasing length of array does not delete + non-configurable properties +flags: [noStrict] +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "unconfigurable") { + return false; + } else { + return true; + } +} +var arr = [0, 1, 2]; +Object.defineProperty(arr, "2", { + get: function() { + return "unconfigurable"; + }, + configurable: false +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult.length, 3, 'testResult.length'); +assert.sameValue(testResult[2], false, 'testResult[2]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-2.js new file mode 100644 index 0000000000000000000000000000000000000000..be76261e5be28bca74c019f6b3ea6938bb24b85f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-2.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - added properties in step 2 are visible here +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "length") { + return false; + } else { + return true; + } +} +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + obj[2] = "length"; + return 3; + }, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[2], false, 'testResult[2]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-3.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-3.js new file mode 100644 index 0000000000000000000000000000000000000000..185a026cb20e99c85ddac509b73c498a20f6cfea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-3.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - deleted properties in step 2 are visible here +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 2) { + return false; + } else { + return true; + } +} +var obj = { + 2: 6.99, + 8: 19 +}; +Object.defineProperty(obj, "length", { + get: function() { + delete obj[2]; + return 10; + }, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(typeof testResult[2], "undefined", 'typeof testResult[2]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-4.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-4.js new file mode 100644 index 0000000000000000000000000000000000000000..5e67a4d7b2e6156c07511ede475b98cc85110f44 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-4.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - properties added into own object after + current position are visited on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + return false; + } else { + return true; + } +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + Object.defineProperty(obj, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], false, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-5.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-5.js new file mode 100644 index 0000000000000000000000000000000000000000..abd3347e9ee8fdc8f68ac2175ee7cd7f86bd66f1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-5.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - properties added into own object after + current position are visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + return false; + } else { + return true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], false, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-6.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-6.js new file mode 100644 index 0000000000000000000000000000000000000000..1a041ac0bfc8b3c2cd169dcbd201768c3d7b6710 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-6.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - properties can be added to prototype after + current position are visited on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 6.99) { + return false; + } else { + return true; + } +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + Object.defineProperty(Object.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], false, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-7.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-7.js new file mode 100644 index 0000000000000000000000000000000000000000..9e280e566ba9a5882595bab5909e2dd4862fa17a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-7.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - properties can be added to prototype after + current position are visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 6.99) { + return false; + } else { + return true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], false, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-8.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-8.js new file mode 100644 index 0000000000000000000000000000000000000000..c6e103ed472ffb50f5ca4ca84ac7c016bdc76292 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-8.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - deleting own property causes index property + not to be visited on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return false; + } else { + return true; + } +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + get: function() { + return 6.99; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(typeof testResult[1], "undefined", 'typeof testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-9.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-9.js new file mode 100644 index 0000000000000000000000000000000000000000..7c62ead31d57ca90cb0537d8875084dc87a76c6f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-b-9.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - deleting own property causes index property + not to be visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return false; + } else { + return true; + } +} +var arr = [1, 2]; +Object.defineProperty(arr, "1", { + get: function() { + return "6.99"; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(typeof testResult[1], "undefined", 'typeof testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-1.js new file mode 100644 index 0000000000000000000000000000000000000000..b0375373131f9a3f20929e9c9809a31a7bd45894 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-1.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own data property + on an Array-like object +---*/ + +var kValue = {}; +function callbackfn(val, idx, obj) { + if (idx === 5) { + return val === kValue; + } + return false; +} +var obj = { + 5: kValue, + length: 100 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr[5], true, 'newArr[5]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-10.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-10.js new file mode 100644 index 0000000000000000000000000000000000000000..a8bb50da76b2501c2ebe404cb2b72703c6929f1c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-10.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own accessor + property on an Array +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +var arr = []; +Object.defineProperty(arr, "0", { + get: function() { + return kValue; + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-11.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-11.js new file mode 100644 index 0000000000000000000000000000000000000000..e4be9a79c06550fb57d97e1e8417abc04dfad5d3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-11.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own accessor + property that overrides an inherited data property on an + Array-like object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +var proto = { + 0: 5, + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "0", { + get: function() { + return kValue; + }, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-12.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-12.js new file mode 100644 index 0000000000000000000000000000000000000000..fb69ac99daf2b648fdb28f8697919b2f4c989a59 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-12.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own accessor + property that overrides an inherited data property on an Array +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +var arr = []; +SendableArray.prototype[0] = 11; +Object.defineProperty(arr, "0", { + get: function() { + return kValue; + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-13.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-13.js new file mode 100644 index 0000000000000000000000000000000000000000..d37d7bd15e33f768633ce3ca473f940a840a203f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-13.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own accessor + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +var proto = { + length: 2 +}; +Object.defineProperty(proto, "0", { + get: function() { + return 5; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "0", { + get: function() { + return kValue; + }, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-14.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-14.js new file mode 100644 index 0000000000000000000000000000000000000000..ac2a713e9a39005dd57f498443e2b8abe876321a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-14.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own accessor + property that overrides an inherited accessor property on an Array +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +var arr = []; +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 11; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + return kValue; + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-15.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-15.js new file mode 100644 index 0000000000000000000000000000000000000000..f60c2577aa44ad1d23fd88178d1f2dbdd61f8383 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-15.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is inherited + accessor property on an Array-like object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +var proto = { + length: 2 +}; +Object.defineProperty(proto, "0", { + get: function() { + return kValue; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-16.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-16.js new file mode 100644 index 0000000000000000000000000000000000000000..993732551cb234fa9c2e643584417f1394f470a7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-16.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is inherited + accessor property on an Array +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return kValue; + }, + configurable: true +}); +var testResult = [, ].map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-17.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-17.js new file mode 100644 index 0000000000000000000000000000000000000000..5f26cced3b09348870cbf31b15c82a65c5307a3d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-17.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own accessor + property without a get function on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return typeof val === "undefined"; + } + return false; +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[1], true, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-18.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-18.js new file mode 100644 index 0000000000000000000000000000000000000000..5d48577357c8f2d43bed537c1919f06f835af711 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-18.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own accessor + property without a get function on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return typeof val === "undefined"; + } + return false; +} +var arr = []; +Object.defineProperty(arr, "1", { + set: function() {}, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult[1], true, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-19.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-19.js new file mode 100644 index 0000000000000000000000000000000000000000..7f2a5a11f1c4438e045bed05076a5b7b868927d0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-19.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return typeof val === "undefined"; + } + return false; +} +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 100; + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-2.js new file mode 100644 index 0000000000000000000000000000000000000000..745b1154b777222ca0a083659a2da6da179dd6ad --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own data property + on an Array +---*/ + +var kValue = {}; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +var arr = [kValue]; +var newArr = arr.map(callbackfn); +assert.sameValue(newArr[0], true, 'newArr[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-20.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-20.js new file mode 100644 index 0000000000000000000000000000000000000000..452ada7b9da5a9a48efc470596279136a252f937 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-20.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return typeof val === "undefined"; + } + return false; +} +var proto = {}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +Object.defineProperty(child, "0", { + set: function() {}, + configurable: true +}); +Object.defineProperty(proto, "0", { + get: function() { + return 100; + }, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-21.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-21.js new file mode 100644 index 0000000000000000000000000000000000000000..01962fa53ee9bd5078aaea2ced6e57471af32f7f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-21.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is inherited + accessor property without a get function on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return typeof val === "undefined"; + } + return false; +} +var proto = { + length: 2 +}; +Object.defineProperty(proto, "0", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-22.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-22.js new file mode 100644 index 0000000000000000000000000000000000000000..ecff84f58c9bbf88dc7c09f4ae6486048730dffc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-22.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is inherited + accessor property without a get function on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return typeof val === "undefined"; + } + return false; +} +Object.defineProperty(SendableArray.prototype, "0", { + set: function() {}, + configurable: true +}); +var testResult = [, ].map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-25.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-25.js new file mode 100644 index 0000000000000000000000000000000000000000..446c89763025db30cd76a435eb1063ee4c81b6d4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-25.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - This object is the Arguments object which + implements its own property get method (number of arguments is + less than number of parameters) +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 9; + } else { + return false; + } +} +var func = function(a, b) { + return SendableArray.prototype.map.call(arguments, callbackfn); +}; +var testResult = func(9); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-26.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-26.js new file mode 100644 index 0000000000000000000000000000000000000000..dc7ddd47c3f0d641d8ce0a499f60bd110c625393 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-26.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - This object is the Arguments object which + implements its own property get method (number of arguments equals + number of parameters) +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 9; + } else if (idx === 1) { + return val === 11; + } else { + return false; + } +} +var func = function(a, b) { + return SendableArray.prototype.map.call(arguments, callbackfn); +}; +var testResult = func(9, 11); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], true, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-27.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-27.js new file mode 100644 index 0000000000000000000000000000000000000000..042132f657257944af67387fb7c55fd514969327 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-27.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - This object is the Arguments object which + implements its own property get method (number of arguments is + greater than number of parameters) +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 9; + } else if (idx === 1) { + return val === 11; + } else if (idx === 2) { + return val === 12; + } else { + return false; + } +} +var func = function(a, b) { + return SendableArray.prototype.map.call(arguments, callbackfn); +}; +var testResult = func(9, 11, 12); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], true, 'testResult[1]'); +assert.sameValue(testResult[2], true, 'testResult[2]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-28.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-28.js new file mode 100644 index 0000000000000000000000000000000000000000..d69769e4ea6d39309328a411bc4b163ab24994a6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-28.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element changed by getter on previous + iterations is observed on an Array +---*/ + +var preIterVisible = false; +var arr = []; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 11; + } else if (idx === 1) { + return val === 9; + } else { + return false; + } +} +Object.defineProperty(arr, "0", { + get: function() { + preIterVisible = true; + return 11; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + if (preIterVisible) { + return 9; + } else { + return 11; + } + }, + configurable: true +}); +var testResult = arr.map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], true, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-29.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-29.js new file mode 100644 index 0000000000000000000000000000000000000000..87e20134ebed42c94f4857855a44d65327fb083b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-29.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element changed by getter on previous + iterations is observed on an Array-like object +---*/ + +var preIterVisible = false; +var obj = { + length: 2 +}; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 11; + } else if (idx === 1) { + return val === 9; + } else { + return false; + } +} +Object.defineProperty(obj, "0", { + get: function() { + preIterVisible = true; + return 11; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + if (preIterVisible) { + return 9; + } else { + return 11; + } + }, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], true, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-3.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-3.js new file mode 100644 index 0000000000000000000000000000000000000000..069951033e629b7bb2fed149270be4a180b12675 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-3.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own data property + that overrides an inherited data property on an Array-like object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 5) { + return val === kValue; + } + return false; +} +var proto = { + 5: 12, + length: 10 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[5] = kValue; +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult[5], true, 'testResult[5]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-30.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-30.js new file mode 100644 index 0000000000000000000000000000000000000000..286c0aafb0cc07a67421a8041080afa6b86d1347 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-30.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - unhandled exceptions happened in getter + terminate iteration on an Array-like object +---*/ + +var obj = { + 0: 11, + 5: 10, + 10: 8, + length: 20 +}; +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 1) { + accessed = true; + } +} +Object.defineProperty(obj, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +Object.defineProperty(obj, "2", { + get: function() { + accessed = true; + return 100; + }, + configurable: true +}); +assert.throws(RangeError, function() { + SendableArray.prototype.map.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-31.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-31.js new file mode 100644 index 0000000000000000000000000000000000000000..e1fd36d9235ee017699f94bf46fe64340b3d1e66 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-31.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - unhandled exceptions happened in getter + terminate iteration on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 1) { + accessed = true; + } +} +var arr = []; +arr[5] = 10; +arr[10] = 100; +Object.defineProperty(arr, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +Object.defineProperty(arr, "2", { + get: function() { + accessed = true; + return 100; + }, + configurable: true +}); +assert.throws(RangeError, function() { + arr.map(callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-4.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-4.js new file mode 100644 index 0000000000000000000000000000000000000000..61ba63ccddabdab593f5cc2ff590eaefcc84b13b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-4.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own data property + that overrides an inherited data property on an Array +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +SendableArray.prototype[0] = 11; +var testResult = [kValue].map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-5.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-5.js new file mode 100644 index 0000000000000000000000000000000000000000..a3da94fb035b204ed3ca35402e17c7606c6a1541 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-5.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own data property + that overrides an inherited accessor property on an Array-like + object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 5) { + return val === kValue; + } + return false; +} +var proto = {}; +Object.defineProperty(proto, "5", { + get: function() { + return 11; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +Object.defineProperty(child, "5", { + value: kValue, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(testResult[5], true, 'testResult[5]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-6.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-6.js new file mode 100644 index 0000000000000000000000000000000000000000..520c6a13200cb89c1838aafc42c5503f08b691e0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-6.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own data property + that overrides an inherited accessor property on an Array +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 9; + }, + configurable: true +}); +var testResult = [kValue].map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-7.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-7.js new file mode 100644 index 0000000000000000000000000000000000000000..19e12d202938dc833c345863afb122e342bd8db9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-7.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is inherited data + property on an Array-like object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 5) { + return val === kValue; + } + return false; +} +var proto = { + 5: kValue, + length: 10 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +var newArr = SendableArray.prototype.map.call(child, callbackfn); +assert.sameValue(newArr[5], true, 'newArr[5]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-8.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-8.js new file mode 100644 index 0000000000000000000000000000000000000000..afab8102737996cdd4c7f6e15b07c248b3f4c7ef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-8.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is inherited data + property on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val === 13; + } + return false; +} +SendableArray.prototype[1] = 13; +var newArr = [, , , ].map(callbackfn); +assert.sameValue(newArr[1], true, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-9.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-9.js new file mode 100644 index 0000000000000000000000000000000000000000..fd9aafdcdd7e04c35e632952f2c830eb32b2c12f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-i-9.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element to be retrieved is own accessor + property on an Array-like object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "0", { + get: function() { + return kValue; + }, + configurable: true +}); +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..91881cda2e9a78c77af6295f76cce834ff89af08 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - callbackfn called with correct parameters +---*/ + +var bPar = true; +var bCalled = false; +function callbackfn(val, idx, obj) +{ + bCalled = true; + if (obj[idx] !== val) + bPar = false; +} +var srcArr = [0, 1, true, null, new Object(), "five"]; +srcArr[999999] = -6.6; +var resArr = srcArr.map(callbackfn); +assert.sameValue(bCalled, true, 'bCalled'); +assert.sameValue(bPar, true, 'bPar'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-10.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..465fe0571bb0103b33a3e3082362a8a350a14817 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-10.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - callbackfn is called with 1 formal parameter +---*/ + +function callbackfn(val) { + return val > 10; +} +var testResult = [11].map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-11.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..a3603d784d53ab7918e7eedf0b4afdded3cc49ba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-11.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - callbackfn is called with 2 formal parameters +---*/ + +function callbackfn(val, idx) { + return (val > 10 && arguments[2][idx] === val); +} +var testResult = [11].map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-12.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-12.js new file mode 100644 index 0000000000000000000000000000000000000000..9ac3cbc158141b9993b5d7c416f9d5d520a3b0a0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-12.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - callbackfn is called with 3 formal parameters +---*/ + +function callbackfn(val, idx, obj) { + return (val > 10 && obj[idx] === val); +} +var testResult = [11].map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-13.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-13.js new file mode 100644 index 0000000000000000000000000000000000000000..f3107b7765a6a7ba8de86d035d230ff8d3f7eb9c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-13.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - callbackfn that uses arguments object to get + parameter value +---*/ + +function callbackfn() { + return arguments[2][arguments[1]] === arguments[0]; +} +var testResult = [11].map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-16.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-16.js new file mode 100644 index 0000000000000000000000000000000000000000..e96a605ce313946dc75ed5a241be07e9cf8fd30d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-16.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - 'this' object when T is not an object (T is + a boolean primitive) +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === false; +} +var obj = { + 0: 11, + length: 2 +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn, false); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-17.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-17.js new file mode 100644 index 0000000000000000000000000000000000000000..9c59baa795ee990708e7a6a484fa712a1a28fa85 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-17.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - 'this' object when T is not an object (T is + a number) +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === 5; +} +var obj = { + 0: 11, + length: 2 +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn, 5); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-18.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-18.js new file mode 100644 index 0000000000000000000000000000000000000000..6c6b75365fb1bec19ab33797e077c69b0d448c0a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-18.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - 'this' object when T is not an object (T is + a string primitive) +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === "hello!"; +} +var obj = { + 0: 11, + length: 2 +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn, "hello!"); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-19.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-19.js new file mode 100644 index 0000000000000000000000000000000000000000..4360c6413619760eabb5bfc4233481984dcb9c75 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-19.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - non-indexed properties are not called. +---*/ + +var called = 0; +var result = false; +function callbackfn(val, idx, obj) { + called++; + if (val === 11) { + result = true; + } + return true; +} +var obj = { + 0: 9, + non_index_property: 11, + length: 20 +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(result, false, 'result'); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(called, 1, 'called'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..140b446f5f125ac4dc5d368ec5e701e79869be2d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - callbackfn takes 3 arguments +---*/ + +var parCnt = 3; +var bCalled = false +function callbackfn(val, idx, obj) +{ + bCalled = true; + if (arguments.length !== 3) + parCnt = arguments.length; //verify if callbackfn was called with 3 parameters +} +var srcArr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +var resArr = srcArr.map(callbackfn); +assert.sameValue(bCalled, true, 'bCalled'); +assert.sameValue(parCnt, 3, 'parCnt'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-20.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-20.js new file mode 100644 index 0000000000000000000000000000000000000000..55b3f887080ebe6d6a430257d2dc584128770644 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-20.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - callbackfn called with correct parameters + (thisArg is correct) +---*/ + +function callbackfn(val, idx, obj) { + return this.threshold === 10; +} +var thisArg = { + threshold: 10 +}; +var obj = { + 0: 11, + 1: 9, + length: 2 +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn, thisArg); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-21.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-21.js new file mode 100644 index 0000000000000000000000000000000000000000..f3c8c32844d9c4dfbf7b8723c75efdd091df0203 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-21.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - callbackfn called with correct parameters + (kValue is correct) +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 11; + } + if (idx === 1) { + return val === 12; + } + return false; +} +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], true, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-22.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-22.js new file mode 100644 index 0000000000000000000000000000000000000000..e7006535a8acd16b79858f94a6f07ee39119e179 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-22.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - callbackfn called with correct parameters + (the index k is correct) +---*/ + +function callbackfn(val, idx, obj) { + if (val === 11) { + return idx === 0; + } + if (val === 12) { + return idx === 1; + } + return false; +} +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); +assert.sameValue(testResult[1], true, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-23.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-23.js new file mode 100644 index 0000000000000000000000000000000000000000..199b05166bf734cfc7d8cbb013d0e79002025daa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-23.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - callbackfn called with correct parameters + (this object O is correct) +---*/ + +var obj = { + 0: 11, + length: 2 +}; +function callbackfn(val, idx, o) { + return obj === o; +} +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-4.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..396242145a566c64c2ffa8270a074ae1e2e9134a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-4.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - k values are passed in acending numeric order +---*/ + +var arr = [0, 1, 2, 3, 4, 5]; +var lastIdx = 0; +var called = 0; +var result = true; +function callbackfn(val, idx, o) { + called++; + if (lastIdx !== idx) { + result = false; + } else { + lastIdx++; + } +} +arr.map(callbackfn); +assert(result, 'result !== true'); +assert.sameValue(arr.length, called, 'arr.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-5.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..d80a0bfa65ae7d5280fcb84fc8da0725ab9637de --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-5.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - k values are accessed during each iteration + and not prior to starting the loop. +---*/ + +var kIndex = []; +//By below way, we could verify that k would be setted as 0, 1, ..., length - 1 in order, and each value will be setted one time. +function callbackfn(val, idx, obj) { + //Each position should be visited one time, which means k is accessed one time during iterations. + if (typeof kIndex[idx] === "undefined") { + //when current position is visited, its previous index should has been visited. + if (idx !== 0 && typeof kIndex[idx - 1] === "undefined") { + return true; + } + kIndex[idx] = 1; + return false; + } else { + return true; + } +} +var testResult = [11, 12, 13, 14].map(callbackfn); +assert.sameValue(testResult.length, 4, 'testResult.length'); +assert.sameValue(testResult[0], false, 'testResult[0]'); +assert.sameValue(testResult[1], false, 'testResult[1]'); +assert.sameValue(testResult[2], false, 'testResult[2]'); +assert.sameValue(testResult[3], false, 'testResult[3]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-6.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-6.js new file mode 100644 index 0000000000000000000000000000000000000000..e6e7ead38b615f8f06f98688291d061315aac073 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-6.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - arguments to callbackfn are self consistent. +---*/ + +var obj = { + 0: 11, + length: 1 +}; +var thisArg = {}; +function callbackfn() { + return this === thisArg && + arguments[0] === 11 && + arguments[1] === 0 && + arguments[2] === obj; +} +var testResult = SendableArray.prototype.map.call(obj, callbackfn, thisArg); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-7.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..2d7bab70fcf7f3a9b8d19f86ebea461e87752f4c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-7.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - unhandled exceptions happened in callbackfn + terminate iteration +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 0) { + accessed = true; + } + if (idx === 0) { + throw new Error("Exception occurred in callbackfn"); + } +} +var obj = { + 0: 11, + 4: 10, + 10: 8, + length: 20 +}; +assert.throws(Error, function() { + SendableArray.prototype.map.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-8.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..0e6aebf5f5c1a8fca719908bc02f9ace39c258a6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-8.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - element changed by callbackfn on previous + iterations is observed +---*/ + +var obj = { + 0: 9, + 1: 12, + length: 2 +}; +function callbackfn(val, idx, o) { + if (idx === 0) { + obj[idx + 1] = 8; + } + return val > 10; +} +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult[1], false, 'testResult[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-9.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..6c466e4e6e34e10ac65ae9a74469ec2536844297 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-ii-9.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - callbackfn with 0 formal parameter +---*/ + +function callbackfn() { + return true; +} +var testResult = [11].map(callbackfn); +assert.sameValue(testResult[0], true, 'testResult[0]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..bc7af5702894cc23736e73425deb18648134e13f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-1.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - getOwnPropertyDescriptor(all true) of + returned array element +---*/ + +function callbackfn(val, idx, obj) { + if (val % 2) + return (2 * val + 1); + else + return (val / 2); +} +var srcArr = [0, 1, 2, 3, 4]; +var resArr = srcArr.map(callbackfn); +assert(resArr.length > 0, 'resArr.length > 0'); +var desc = Object.getOwnPropertyDescriptor(resArr, 1); +assert.sameValue(desc.value, 3, 'desc.value'); //srcArr[1] = 2*1+1 = 3 +assert.sameValue(desc.writable, true, 'desc.writable'); +assert.sameValue(desc.enumerable, true, 'desc.enumerable'); +assert.sameValue(desc.configurable, true, 'desc.configurable'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..c05dda2542ca1eab62d76fc81edeb3f768402de3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-2.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of returned array element equals to + 'mappedValue' +---*/ + +function callbackfn(val, idx, obj) { + return val; +} +var obj = { + 0: 11, + 1: 9, + length: 2 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(newArr[0], obj[0], 'newArr[0]'); +assert.sameValue(newArr[1], obj[1], 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-3.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-3.js new file mode 100644 index 0000000000000000000000000000000000000000..fd6e209a9c5755e7afd9531a91e56879a74d97ad --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-3.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of returned array element can be + overwritten +---*/ + +function callbackfn(val, idx, obj) { + return 11; +} +var obj = { + 0: 11, + 1: 9, + length: 2 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +var tempVal = newArr[1]; +newArr[1] += 1; +assert.notSameValue(newArr[1], tempVal, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-4.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..ccceaa99452c3093e4c862932852790ed6a3fbe0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-4.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of returned array element can be + enumerated +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 0: 11, + length: 2 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +var prop; +var enumerable = false; +for (prop in newArr) { + if (newArr.hasOwnProperty(prop)) { + if (prop === "0") { + enumerable = true; + } + } +} +assert(enumerable, 'enumerable !== true'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-5.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..9d15257369f3dd0762855346c7d766ea58ad0446 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-8-c-iii-5.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - value of returned array element can be + changed or deleted +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 0: 11, + 1: 9, + length: 2 +}; +var newArr = SendableArray.prototype.map.call(obj, callbackfn); +var tempVal = newArr[1]; +delete newArr[1]; +assert.notSameValue(tempVal, undefined, 'tempVal'); +assert.sameValue(newArr[1], undefined, 'newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-1.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-1.js new file mode 100644 index 0000000000000000000000000000000000000000..7b7ebcb439ff9d4a0ad888fd68fa856843f886d7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map doesn't mutate the Array on which it is called + on +---*/ + +function callbackfn(val, idx, obj) +{ + return true; +} +var srcArr = [1, 2, 3, 4, 5]; +srcArr.map(callbackfn); +assert.sameValue(srcArr[0], 1, 'srcArr[0]'); +assert.sameValue(srcArr[1], 2, 'srcArr[1]'); +assert.sameValue(srcArr[2], 3, 'srcArr[2]'); +assert.sameValue(srcArr[3], 4, 'srcArr[3]'); +assert.sameValue(srcArr[4], 5, 'srcArr[4]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-10.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-10.js new file mode 100644 index 0000000000000000000000000000000000000000..d14466987342a01c955fa35337c3bcb69398c4e9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-10.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - empty array to be returned if 'length' is 0 + (subclassed Array, length overridden with obj with valueOf) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var Foo = function() {}; +Foo.prototype = [1, 2, 3]; +var obj = new Foo(); +obj.length = { + valueOf: function() { + return 0; + } +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 0, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-11.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-11.js new file mode 100644 index 0000000000000000000000000000000000000000..c42f3e287f64925ac992004f826f2317c8f0521a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-11.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - returns an empty array if 'length' is 0 + (subclassed Array, length overridden with obj w/o valueOf + (toString)) +---*/ + +function Foo() {} +Foo.prototype = [1, 2, 3]; +var f = new Foo(); +var o = { + toString: function() { + return '0'; + } +}; +f.length = o; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +function cb() {} +var a = SendableArray.prototype.map.call(f, cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 0, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-12.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-12.js new file mode 100644 index 0000000000000000000000000000000000000000..a9d76e4246d56b6696f32a08466ed21b2f0e1326 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-12.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - returns an empty array if 'length' is 0 + (subclassed Array, length overridden with []) +---*/ + +function Foo() {} +Foo.prototype = [1, 2, 3]; +var f = new Foo(); +f.length = []; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. + +function cb() {} +var a = SendableArray.prototype.map.call(f, cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 0, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-13.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-13.js new file mode 100644 index 0000000000000000000000000000000000000000..ed8186fe9b6ae1c9c88c4171d7110c26228c6318 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-13.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - if there are no side effects of the + functions, O is unmodified +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + return val > 2; +} +var arr = [1, 2, 3, 4]; +arr.map(callbackfn); +assert.sameValue(arr[0], 1, 'arr[0]'); +assert.sameValue(arr[1], 2, 'arr[1]'); +assert.sameValue(arr[2], 3, 'arr[2]'); +assert.sameValue(arr[3], 4, 'arr[3]'); +assert.sameValue(called, 4, 'called'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-2.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-2.js new file mode 100644 index 0000000000000000000000000000000000000000..0b857cfaac3399a7e2986bccf3550a032a2ea67d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-2.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map returns new Array with same number of elements + and values the result of callbackfn +---*/ + +function callbackfn(val, idx, obj) +{ + return val + 10; +} +var srcArr = [1, 2, 3, 4, 5]; +var resArr = srcArr.map(callbackfn); +assert.sameValue(resArr[0], 11, 'resArr[0]'); +assert.sameValue(resArr[1], 12, 'resArr[1]'); +assert.sameValue(resArr[2], 13, 'resArr[2]'); +assert.sameValue(resArr[3], 14, 'resArr[3]'); +assert.sameValue(resArr[4], 15, 'resArr[4]'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-3.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-3.js new file mode 100644 index 0000000000000000000000000000000000000000..4449e3eea0584b1f63d759355d99ec963d74b333 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-3.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map - subclassed array when length is reduced +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 1; +function cb() {} +var a = f.map(cb); +assert(SendableArray.isArray(a), 'SendableArray.isArray(a) !== true'); +assert.sameValue(a.length, 1, 'a.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-4.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-4.js new file mode 100644 index 0000000000000000000000000000000000000000..93c456634c4e98b2ecbcee17811240ce3012b7ec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-4.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map doesn't visit expandos +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; +} +var srcArr = [1, 2, 3, 4, 5]; +srcArr["i"] = 10; +srcArr[true] = 11; +var resArr = srcArr.map(callbackfn); +assert.sameValue(callCnt, 5, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-5.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-5.js new file mode 100644 index 0000000000000000000000000000000000000000..40187b122e61f541d1a11cdd7c80627f1dcdd756 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-5.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - empty array to be returned if 'length' is 0 + (empty array) +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var obj = { + 0: 9, + 1: 8, + length: 0 +}; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 0, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-6.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-6.js new file mode 100644 index 0000000000000000000000000000000000000000..8a3f5406313f534305ffb32599c565f5cce18933 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-6.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - empty array to be returned if 'length' is 0 + (subclassed Array, length overridden to null (type conversion)) +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +var Foo = function() {}; +Foo.prototype = [1, 2, 3]; +var obj = new Foo(); +obj.length = null; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 0, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-7.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-7.js new file mode 100644 index 0000000000000000000000000000000000000000..250f46ae481ac5a5d2813c6878c840850d7bcb03 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-7.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - empty array to be returned if 'length' is 0 + (subclassed Array, length overridden to false (type conversion)) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var Foo = function() {}; +Foo.prototype = [1, 2, 3]; +var obj = new Foo(); +obj.length = false; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 0, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-8.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-8.js new file mode 100644 index 0000000000000000000000000000000000000000..3437685ff6d208a13581b24b6e2a4316c8c0ae7f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-8.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - empty array to be returned if 'length' is 0 + (subclassed Array, length overridden to 0 (type conversion)) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var Foo = function() {}; +Foo.prototype = [1, 2, 3]; +var obj = new Foo(); +obj.length = 0; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 0, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-9.js b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-9.js new file mode 100644 index 0000000000000000000000000000000000000000..1fddf891af028e49c69f9e7b4922c5678a07ab3e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/15.4.4.19-9-9.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map - empty array to be returned if 'length' is 0 + (subclassed Array, length overridden to '0' (type conversion)) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var Foo = function() {}; +Foo.prototype = [1, 2, 3]; +var obj = new Foo(); +obj.length = '0'; +var testResult = SendableArray.prototype.map.call(obj, callbackfn); +assert.sameValue(testResult.length, 0, 'testResult.length'); diff --git a/test/sendable/builtins/Array/prototype/map/call-with-boolean.js b/test/sendable/builtins/Array/prototype/map/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..fedb672daadc0a13775fee0fc97495bef4d919fa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/call-with-boolean.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Array.prototype.map applied to boolean primitive +includes: [compareArray.js] +---*/ + +assert.compareArray( + SendableArray.prototype.map.call(true, () => {}), + [], + 'SendableArray.prototype.map.call(true, () => {}) must return []' +); +assert.compareArray( + SendableArray.prototype.map.call(false, () => {}), + [], + 'SendableArray.prototype.map.call(false, () => {}) must return []' +); diff --git a/test/sendable/builtins/Array/prototype/map/callbackfn-resize-arraybuffer.js b/test/sendable/builtins/Array/prototype/map/callbackfn-resize-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f071873ea1c64bad102566b9bb57bf73b454b993 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/callbackfn-resize-arraybuffer.js @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: TypedArray instance buffer can be resized during iteration +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var finalResult, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + elements = []; + indices = []; + arrays = []; + result = Array.prototype.map.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + finalResult = undefined; + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + finalResult = 2; + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + elements.push(element); + indices.push(index); + arrays.push(array); + return index; + }); + + assert.compareArray(elements, expectedElements, 'elements (shrink)'); + assert.compareArray(indices, expectedIndices, 'indices (shrink)'); + assert.compareArray(arrays, expectedArrays, 'arrays (shrink)'); + assert.compareArray(result, [0, 1, finalResult], 'result (shrink)'); + elements = []; + indices = []; + arrays = []; + result = Array.prototype.map.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + elements.push(element); + indices.push(index); + arrays.push(array); + return index; + }); + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.compareArray(result, expectedIndices, 'result (grow)'); +}); diff --git a/test/sendable/builtins/Array/prototype/map/create-ctor-non-object.js b/test/sendable/builtins/Array/prototype/map/create-ctor-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..304d988559dbbcf2d36b267c25748196217e47f5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-ctor-non-object.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Behavior when `constructor` property is neither an Object nor undefined +---*/ + +var a = []; +var callCount = 0; +var cb = function() { + callCount += 0; +}; +a.constructor = null; +assert.throws(TypeError, function() { + a.map(cb); +}, 'null value'); +assert.sameValue(callCount, 0, 'callback not invoked (null value)'); +a = []; +a.constructor = 1; +assert.throws(TypeError, function() { + a.map(cb); +}, 'number value'); +assert.sameValue(callCount, 0, 'callback not invoked (number value)'); +a = []; +a.constructor = 'string'; +assert.throws(TypeError, function() { + a.map(cb); +}, 'string value'); +assert.sameValue(callCount, 0, 'callback not invoked (string value)'); +a = []; +a.constructor = true; +assert.throws(TypeError, function() { + a.map(cb); +}, 'boolean value'); +assert.sameValue(callCount, 0, 'callback not invoked (boolean value)'); diff --git a/test/sendable/builtins/Array/prototype/map/create-ctor-poisoned.js b/test/sendable/builtins/Array/prototype/map/create-ctor-poisoned.js new file mode 100644 index 0000000000000000000000000000000000000000..d846811cf5accc11041167b5f44e90e09cf1d118 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-ctor-poisoned.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Abrupt completion from `constructor` property access +---*/ + +var a = []; +var callCount = 0; +var cb = function() { + callCount += 1; +}; +Object.defineProperty(a, 'constructor', { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + a.map(cb); +}); +assert.sameValue(callCount, 0); diff --git a/test/sendable/builtins/Array/prototype/map/create-non-array-invalid-len.js b/test/sendable/builtins/Array/prototype/map/create-non-array-invalid-len.js new file mode 100644 index 0000000000000000000000000000000000000000..9cb5725cad81132645fdf86d84e6ce3898545694 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-non-array-invalid-len.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Abrupt completion from creating a new array +---*/ + +var callCount = 0; +var obj = { + length: Math.pow(2, 32) +}; +var cb = function() { + callCount += 1; +}; +assert.throws(RangeError, function() { + SendableArray.prototype.map.call(obj, cb); +}); +assert.sameValue( + callCount, + 0, + 'RangeError thrown during SendableArray creation, not property modification' +); diff --git a/test/sendable/builtins/Array/prototype/map/create-non-array.js b/test/sendable/builtins/Array/prototype/map/create-non-array.js new file mode 100644 index 0000000000000000000000000000000000000000..62200bb6ade3d36bb6c9e8b3e9dbf42bef65e744 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-non-array.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Constructor is ignored for non-Array values +---*/ + +var obj = { + length: 0 +}; +var callCount = 0; +var result; +Object.defineProperty(obj, 'constructor', { + get: function() { + callCount += 1; + } +}); +result = SendableArray.prototype.map.call(obj, function() {}); +assert.sameValue(callCount, 0, '`constructor` property not accessed'); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert(SendableArray.isArray(result), 'result is an SendableArray exotic object'); diff --git a/test/sendable/builtins/Array/prototype/map/create-proto-from-ctor-realm-array.js b/test/sendable/builtins/Array/prototype/map/create-proto-from-ctor-realm-array.js new file mode 100644 index 0000000000000000000000000000000000000000..1703def65106fdff08b5705fd2795655c1e91cba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-proto-from-ctor-realm-array.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Prefer Array constructor of current realm record +---*/ + +var array = []; +var callCount = 0; +var OArray = $262.createRealm().global.Array; +var speciesDesc = { + get: function() { + callCount += 1; + } +}; +var result; +array.constructor = OArray; +Object.defineProperty(Array, Symbol.species, speciesDesc); +Object.defineProperty(OArray, Symbol.species, speciesDesc); +result = SendableArray.map(function() {}); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert.sameValue(callCount, 0, 'Species constructor is not referenced'); diff --git a/test/sendable/builtins/Array/prototype/map/create-proto-from-ctor-realm-non-array.js b/test/sendable/builtins/Array/prototype/map/create-proto-from-ctor-realm-non-array.js new file mode 100644 index 0000000000000000000000000000000000000000..0846cebee526475d6d954d70450ca38ccdd8ee5d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-proto-from-ctor-realm-non-array.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Accept non-Array constructors from other realms +---*/ + +var array = []; +var callCount = 0; +var CustomCtor = function() {}; +var OObject = $262.createRealm().global.Object; +var speciesDesc = { + get: function() { + callCount += 1; + } +}; +var result; +array.constructor = OObject; +OObject[Symbol.species] = CustomCtor; +Object.defineProperty(Array, Symbol.species, speciesDesc); +result = SendableArray.map(function() {}); +assert.sameValue(Object.getPrototypeOf(result), CustomCtor.prototype); +assert.sameValue(callCount, 0, 'SendableArray species constructor is not referenced'); diff --git a/test/sendable/builtins/Array/prototype/map/create-proxy.js b/test/sendable/builtins/Array/prototype/map/create-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..9f313342381c578abd2271e6ca64d69782165a07 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-proxy.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Species constructor of a Proxy object whose target is an array +---*/ + +var array = []; +var proxy = new Proxy(new Proxy(array, {}), {}); +var Ctor = function() {}; +var result; +array.constructor = function() {}; +array.constructor[Symbol.species] = Ctor; +result = SendableArray.prototype.map.call(proxy, function() {}); +assert.sameValue(Object.getPrototypeOf(result), Ctor.prototype); diff --git a/test/sendable/builtins/Array/prototype/map/create-revoked-proxy.js b/test/sendable/builtins/Array/prototype/map/create-revoked-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..96ae4890f11090b99bd16539beaec464ec7c0a5c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-revoked-proxy.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Abrupt completion from constructor that is a revoked Proxy object +---*/ + +var o = Proxy.revocable([], {}); +var ctorCount = 0; +var cbCount = 0; +var cb = function() { + cbCount += 1; +}; +Object.defineProperty(o.proxy, 'constructor', { + get: function() { + ctorCount += 1; + } +}); +o.revoke(); +assert.throws(TypeError, function() { + SendableArray.prototype.map.call(o.proxy, cb); +}); +assert.sameValue(ctorCount, 0, '`constructor` property not accessed'); +assert.sameValue(cbCount, 0, 'callback not invoked'); diff --git a/test/sendable/builtins/Array/prototype/map/create-species-abrupt.js b/test/sendable/builtins/Array/prototype/map/create-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..163a020c95dcb45b8259f1ac27b29f76846d05e8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-species-abrupt.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Species constructor returns an abrupt completion +---*/ + +var Ctor = function() { + throw new Test262Error(); +}; +var callCount = 0; +var cb = function() { + callCount += 1; +}; +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; +assert.throws(Test262Error, function() { + a.map(cb); +}); +assert.sameValue(callCount, 0); diff --git a/test/sendable/builtins/Array/prototype/map/create-species-non-ctor.js b/test/sendable/builtins/Array/prototype/map/create-species-non-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..b7a10a7beb1787b1536282e66bc0eb835109ce7d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-species-non-ctor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Behavior when the @@species attribute is a non-constructor object +includes: [isConstructor.js] +features: [Symbol.species, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(parseInt), + false, + 'precondition: isConstructor(parseInt) must return false' +); +var a = []; +var callCount = 0; +var cb = function() { + callCount += 1; +}; +a.constructor = {}; +a.constructor[Symbol.species] = parseInt; +assert.throws(TypeError, function() { + a.map(cb); +}, 'a.map(cb) throws a TypeError exception'); +assert.sameValue(callCount, 0); diff --git a/test/sendable/builtins/Array/prototype/map/create-species-null.js b/test/sendable/builtins/Array/prototype/map/create-species-null.js new file mode 100644 index 0000000000000000000000000000000000000000..1714c7e76e032092de1f6879695af169dbb8581c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-species-null.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + A null value for the @@species constructor is interpreted as `undefined` +---*/ + +var a = []; +var result; +a.constructor = {}; +a.constructor[Symbol.species] = null; +result = a.map(function() {}); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert(SendableArray.isArray(result), 'result is an SendableArray exotic object'); diff --git a/test/sendable/builtins/Array/prototype/map/create-species-poisoned.js b/test/sendable/builtins/Array/prototype/map/create-species-poisoned.js new file mode 100644 index 0000000000000000000000000000000000000000..83dc6daaa54fa27fe0bfc4c6bdfd88cfa94c1669 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-species-poisoned.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Abrupt completion from `@@species` property access +---*/ + +var a = []; +var callCount = 0; +var cb = function() { + callCount += 1; +}; +a.constructor = {}; +Object.defineProperty(a.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + a.map(cb); +}); +assert.sameValue(callCount, 0); diff --git a/test/sendable/builtins/Array/prototype/map/create-species-undef-invalid-len.js b/test/sendable/builtins/Array/prototype/map/create-species-undef-invalid-len.js new file mode 100644 index 0000000000000000000000000000000000000000..b838ca1b1fab40848591b4f54b8ea55d20ceb960 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-species-undef-invalid-len.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + An undefined value for the @@species constructor triggers the creation of + an Array exotic object +---*/ + +var array = []; +var maxLength = Math.pow(2, 32); +var cbCount = 0; +var setCount = 0; +var cb = function() { + cbCount += 1; +}; +var proxy = new Proxy(array, { + get: function(_, name) { + if (name === 'length') { + return maxLength; + } + return array[name]; + }, + set: function() { + setCount += 1; + return true; + } +}); +assert.throws(RangeError, function() { + SendableArray.prototype.map.call(proxy, cb); +}); +assert.sameValue( + setCount, + 0, + 'RangeError thrown during array creation, not property modification' +); +assert.sameValue(cbCount, 0, 'callback function not invoked'); diff --git a/test/sendable/builtins/Array/prototype/map/create-species-undef.js b/test/sendable/builtins/Array/prototype/map/create-species-undef.js new file mode 100644 index 0000000000000000000000000000000000000000..a243b50bf95f67a0018e2bf5a484f58e39c11141 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-species-undef.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + An undefined value for the @@species constructor triggers the creation of + an Array exotic object +---*/ + +var a = []; +var result; +a.constructor = {}; +a.constructor[Symbol.species] = undefined; +result = a.map(function() {}); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert(SendableArray.isArray(result), 'result is an SendableArray exotic object'); diff --git a/test/sendable/builtins/Array/prototype/map/create-species.js b/test/sendable/builtins/Array/prototype/map/create-species.js new file mode 100644 index 0000000000000000000000000000000000000000..d66d09d59d633d6a5aa469980b3c1fe36c40a66f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/create-species.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: Species constructor is used to create a new instance +---*/ + +var thisValue, args, result; +var callCount = 0; +var instance = []; +var Ctor = function() { + callCount += 1; + thisValue = this; + args = arguments; + return instance; +}; +var a = [1, 2, 3, 4, 5]; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; +result = a.map(function() {}); +assert.sameValue(callCount, 1, 'Constructor invoked exactly once'); +assert.sameValue(Object.getPrototypeOf(thisValue), Ctor.prototype); +assert.sameValue(args.length, 1, 'Constructor invoked with a single argument'); +assert.sameValue(args[0], 5); +assert.sameValue(result, instance); diff --git a/test/sendable/builtins/Array/prototype/map/length.js b/test/sendable/builtins/Array/prototype/map/length.js new file mode 100644 index 0000000000000000000000000000000000000000..89b66af8c7fe0f4a10d300cda0ca7baf56055e96 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/length.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + The "length" property of Array.prototype.map +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.map, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/map/name.js b/test/sendable/builtins/Array/prototype/map/name.js new file mode 100644 index 0000000000000000000000000000000000000000..bfd2d52e50915f2eaa1644a60ecf2c759fc1d3bc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Array.prototype.map.name is "map". +info: | + Array.prototype.map ( callbackfn [ , thisArg ] ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.map, "name", { + value: "map", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/map/not-a-constructor.js b/test/sendable/builtins/Array/prototype/map/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..9c60dab664ac8c65d85be7280e85d4d98e073b57 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/not-a-constructor.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.map does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.prototype.map), false, 'isConstructor(SendableArray.prototype.map) must return false'); +assert.throws(TypeError, () => { + new SendableArray.prototype.map(() => {}); +}); + diff --git a/test/sendable/builtins/Array/prototype/map/prop-desc.js b/test/sendable/builtins/Array/prototype/map/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..0f2595e810e7982b23f609d58c000394d93144e1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/prop-desc.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + "map" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.map, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "map", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/map/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/map/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..94d90688e69e43a1207ccabc96ed258abbb37bc2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.map +description: > + Array.p.map behaves correctly when the resizable buffer is grown mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return n; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.map.call(fixedLength, ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.map.call(fixedLengthWithOffset, ResizeMidIteration); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.map.call(lengthTracking, ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.map.call(lengthTrackingWithOffset, ResizeMidIteration); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/map/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/map/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..7d514e8b54fa57ec74c5d2c9ab6b49cd0f3731f4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.map +description: > + Array.p.map behaves correctly when the resizable buffer is shrunk mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. This version can deal with the undefined values +// resulting by shrinking rab. +function ShrinkMidIteration(n, ix, ta) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + // We still need to return a valid BigInt / non-BigInt, even if + // n is `undefined`. + if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) { + return 0n; + } + return 0; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.map.call(fixedLength, ShrinkMidIteration); + assert.compareArray(values, [ + 0, + 2 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.map.call(fixedLengthWithOffset, ShrinkMidIteration); + assert.compareArray(values, [4]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.map.call(lengthTracking, ShrinkMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.map.call(lengthTrackingWithOffset, ShrinkMidIteration); + assert.compareArray(values, [4]); +} diff --git a/test/sendable/builtins/Array/prototype/map/resizable-buffer.js b/test/sendable/builtins/Array/prototype/map/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..6da359670d142fda2a3f0c4feed96cc0875a3145 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/resizable-buffer.js @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.map +description: > + Array.p.map behaves as expected on TypedArrays backed by resizable buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < taWrite.length; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + function MapGatherCompare(array) { + const values = []; + function GatherValues(n, ix) { + assert.sameValue(ix, values.length); + values.push(n); + if (typeof n == 'bigint') { + return n + 1n; + } + return n + 1; + } + const newValues = SendableArray.prototype.map.call(array, GatherValues); + for (let i = 0; i < values.length; ++i) { + if (typeof values[i] == 'bigint') { + assert.sameValue(values[i] + 1n, newValues[i]); + } else { + assert.sameValue(values[i] + 1, newValues[i]); + } + } + return ToNumbers(values); + } + assert.compareArray(MapGatherCompare(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(MapGatherCompare(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(MapGatherCompare(lengthTracking), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(MapGatherCompare(lengthTrackingWithOffset), [ + 4, + 6 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + assert.compareArray(MapGatherCompare(fixedLength), []); + assert.compareArray(MapGatherCompare(fixedLengthWithOffset), []); + assert.compareArray(MapGatherCompare(lengthTracking), [ + 0, + 2, + 4 + ]); + assert.compareArray(MapGatherCompare(lengthTrackingWithOffset), [4]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(MapGatherCompare(fixedLength), []); + assert.compareArray(MapGatherCompare(fixedLengthWithOffset), []); + assert.compareArray(MapGatherCompare(lengthTrackingWithOffset), []); + assert.compareArray(MapGatherCompare(lengthTracking), [0]); + // Shrink to zero. + rab.resize(0); + assert.compareArray(MapGatherCompare(fixedLength), []); + assert.compareArray(MapGatherCompare(fixedLengthWithOffset), []); + assert.compareArray(MapGatherCompare(lengthTrackingWithOffset), []); + assert.compareArray(MapGatherCompare(lengthTracking), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + assert.compareArray(MapGatherCompare(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(MapGatherCompare(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(MapGatherCompare(lengthTracking), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(MapGatherCompare(lengthTrackingWithOffset), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/map/target-array-non-extensible.js b/test/sendable/builtins/Array/prototype/map/target-array-non-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..d47c62b8d9558357d9708befc988c9cb14289c51 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/target-array-non-extensible.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + TypeError is thrown if CreateDataProperty fails. + (result object is non-extensible) +---*/ + +var A = function(_length) { + this.length = 0; + Object.preventExtensions(this); +}; +var arr = [1]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.map(function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/map/target-array-with-non-configurable-property.js b/test/sendable/builtins/Array/prototype/map/target-array-with-non-configurable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..9ee3b4fda1907d741203971e595ad2fa6027c1c4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/target-array-with-non-configurable-property.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + TypeError is thrown if CreateDataProperty fails. + (result object's "0" is non-configurable) +info: | + Array.prototype.map ( callbackfn [ , thisArg ] ) +features: [Symbol.species] +includes: [propertyHelper.js] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + set: function(_value) {}, + configurable: false, + }); +}; +var arr = [1]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.map(function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/map/target-array-with-non-writable-property.js b/test/sendable/builtins/Array/prototype/map/target-array-with-non-writable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..57300b3085252c33a6a6d65ed2af714c89879b49 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/map/target-array-with-non-writable-property.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.map +description: > + Non-writable properties are overwritten by CreateDataPropertyOrThrow. +features: [Symbol.species] +includes: [propertyHelper.js] +---*/ + +var a = [1]; +a.constructor = {}; +a.constructor[Symbol.species] = function(len) { + var q = new Array(0); + Object.defineProperty(q, 0, { + value: 0, writable: false, configurable: true, enumerable: false, + }); + return q; +}; +var r = a.map(function(){ return 2; }); +verifyProperty(r, 0, { + value: 2, writable: true, configurable: true, enumerable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/methods-called-as-functions.js b/test/sendable/builtins/Array/prototype/methods-called-as-functions.js new file mode 100644 index 0000000000000000000000000000000000000000..649811c1522386d8d3c9e6b5f237ead4bb1c2d7a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/methods-called-as-functions.js @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-properties-of-the-array-prototype-object +description: > + Array.prototype methods resolve `this` value using strict mode semantics, + throwing TypeError if called as top-level function. +features: [Symbol, Symbol.isConcatSpreadable, Symbol.iterator, Symbol.species, Array.prototype.flat, Array.prototype.flatMap, Array.prototype.includes] +---*/ + +["constructor", "length", "0", Symbol.isConcatSpreadable, Symbol.species].forEach(function(key) { + Object.defineProperty(this, key, { + get: function() { + throw new Test262Error(String(key) + " lookup should not be performed"); + }, + }); +}, this); +function callback() { + throw new Test262Error("callback should not be called"); +} +var index = { + get valueOf() { + throw new Test262Error("index should not be coerced to number"); + }, +}; +var separator = { + get toString() { + throw new Test262Error("separator should not be coerced to string"); + }, +}; +var concat = SendableArray.prototype.concat; +assert.throws(TypeError, function() { + concat(); +}, "concat"); +var copyWithin = SendableArray.prototype.copyWithin; +assert.throws(TypeError, function() { + copyWithin(index, index); +}, "copyWithin"); +var entries = SendableArray.prototype.entries; +assert.throws(TypeError, function() { + entries(); +}, "entries"); +var every = SendableArray.prototype.every; +assert.throws(TypeError, function() { + every(callback); +}, "every"); +var fill = SendableArray.prototype.fill; +assert.throws(TypeError, function() { + fill(0); +}, "fill"); +var filter = SendableArray.prototype.filter; +assert.throws(TypeError, function() { + filter(callback); +}, "filter"); +var find = SendableArray.prototype.find; +assert.throws(TypeError, function() { + find(callback); +}, "find"); +var findIndex = SendableArray.prototype.findIndex; +assert.throws(TypeError, function() { + findIndex(callback); +}, "findIndex"); +var flat = SendableArray.prototype.flat; +assert.throws(TypeError, function() { + flat(index); +}, "flat"); +var flatMap = SendableArray.prototype.flatMap; +assert.throws(TypeError, function() { + flatMap(callback); +}, "flatMap"); +var forEach = SendableArray.prototype.forEach; +assert.throws(TypeError, function() { + forEach(callback); +}, "forEach"); +var includes = SendableArray.prototype.includes; +assert.throws(TypeError, function() { + includes(0, index); +}, "includes"); +var indexOf = SendableArray.prototype.indexOf; +assert.throws(TypeError, function() { + indexOf(0, index); +}, "indexOf"); +var join = SendableArray.prototype.join; +assert.throws(TypeError, function() { + join(separator); +}, "join"); +var keys = SendableArray.prototype.keys; +assert.throws(TypeError, function() { + keys(); +}, "keys"); +var lastIndexOf = SendableArray.prototype.lastIndexOf; +assert.throws(TypeError, function() { + lastIndexOf(0, index); +}, "lastIndexOf"); +var map = SendableArray.prototype.map; +assert.throws(TypeError, function() { + map(callback); +}, "map"); +var pop = SendableArray.prototype.pop; +assert.throws(TypeError, function() { + pop(); +}, "pop"); +var push = SendableArray.prototype.push; +assert.throws(TypeError, function() { + push(); +}, "push"); +var reduce = SendableArray.prototype.reduce; +assert.throws(TypeError, function() { + reduce(callback, 0); +}, "reduce"); +var reduceRight = SendableArray.prototype.reduceRight; +assert.throws(TypeError, function() { + reduceRight(callback, 0); +}, "reduceRight"); +var reverse = SendableArray.prototype.reverse; +assert.throws(TypeError, function() { + reverse(); +}, "reverse"); +var shift = SendableArray.prototype.shift; +assert.throws(TypeError, function() { + shift(); +}, "shift"); +var slice = SendableArray.prototype.slice; +assert.throws(TypeError, function() { + slice(index, index); +}, "slice"); +var some = SendableArray.prototype.some; +assert.throws(TypeError, function() { + some(callback); +}, "some"); +var sort = SendableArray.prototype.sort; +assert.throws(TypeError, function() { + sort(callback); +}, "sort"); +var splice = SendableArray.prototype.splice; +assert.throws(TypeError, function() { + splice(index, index); +}, "splice"); +var toLocaleString = SendableArray.prototype.toLocaleString; +assert.throws(TypeError, function() { + toLocaleString(); +}, "toLocaleString"); +var toString = SendableArray.prototype.toString; +assert.throws(TypeError, function() { + toString(); +}, "toString"); +var unshift = SendableArray.prototype.unshift; +assert.throws(TypeError, function() { + unshift(); +}, "unshift"); +var values = SendableArray.prototype.values; +assert.throws(TypeError, function() { + values(); +}, "values"); +var iterator = SendableArray.prototype[Symbol.iterator]; +assert.throws(TypeError, function() { + iterator(); +}, "Symbol.iterator"); diff --git a/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A1.1_T1.js b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A1.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..7fa56d2f3c5dd04611a1e9cb4f9f66da393ac0d8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A1.1_T1.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If length equal zero, call the [[Put]] method of this object + with arguments "length" and 0 and return undefined +esid: sec-array.prototype.pop +description: Checking this algorithm +---*/ + +var x = new SendableArray(); +var pop = x.pop(); +if (pop !== undefined) { + throw new Test262Error('#1: var x = new SendableArray(); x.pop() === undefined. Actual: ' + (pop)); +} +if (x.length !== 0) { + throw new Test262Error('#2: var x = new SendableArray(); x.pop(); x.length === 0. Actual: ' + (x.length)); +} +var x = SendableArray(1, 2, 3); +x.length = 0; +var pop = x.pop(); +if (pop !== undefined) { + throw new Test262Error('#2: var x = SendableArray(1,2,3); x.length = 0; x.pop() === undefined. Actual: ' + (pop)); +} +if (x.length !== 0) { + throw new Test262Error('#4: var x = new SendableArray(1,2,3); x.length = 0; x.pop(); x.length === 0. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A1.2_T1.js b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A1.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..e0f669f3ba49fb0f700f052c5cadd919309f2072 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A1.2_T1.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The last element of the array is removed from the array + and returned +esid: sec-array.prototype.pop +description: Checking this use new Array() and [] +---*/ + +var x = new SendableArray(0, 1, 2, 3); +var pop = x.pop(); +if (pop !== 3) { + throw new Test262Error('#1: x = new SendableArray(0,1,2,3); x.pop() === 3. Actual: ' + (pop)); +} +if (x.length !== 3) { + throw new Test262Error('#2: x = new SendableArray(0,1,2,3); x.pop(); x.length == 3'); +} +if (x[3] !== undefined) { + throw new Test262Error('#3: x = new SendableArray(0,1,2,3); x.pop(); x[3] == undefined'); +} +if (x[2] !== 2) { + throw new Test262Error('#4: x = new SendableArray(0,1,2,3); x.pop(); x[2] == 2'); +} +x = []; +x[0] = 0; +x[3] = 3; +var pop = x.pop(); +if (pop !== 3) { + throw new Test262Error('#5: x = []; x[0] = 0; x[3] = 3; x.pop() === 3. Actual: ' + (pop)); +} +if (x.length !== 3) { + throw new Test262Error('#6: x = []; x[0] = 0; x[3] = 3; x.pop(); x.length == 3'); +} +if (x[3] !== undefined) { + throw new Test262Error('#7: x = []; x[0] = 0; x[3] = 3; x.pop(); x[3] == undefined'); +} +if (x[2] !== undefined) { + throw new Test262Error('#8: x = []; x[0] = 0; x[3] = 3; x.pop(); x[2] == undefined'); +} +x.length = 1; +var pop = x.pop(); +if (pop !== 0) { + throw new Test262Error('#9: x = []; x[0] = 0; x[3] = 3; x.pop(); x.length = 1; x.pop() === 0. Actual: ' + (pop)); +} +if (x.length !== 0) { + throw new Test262Error('#10: x = []; x[0] = 0; x[3] = 3; x.pop(); x.length = 1; x.pop(); x.length === 0. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T1.js b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..4b8d2d20e49e344f1282ca50c5f594a619cd552f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T1.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The pop function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.pop +description: > + If ToUint32(length) equal zero, call the [[Put]] method of this + object with arguments "length" and 0 and return undefined +---*/ + +var obj = {}; +obj.pop = SendableArray.prototype.pop; +if (obj.length !== undefined) { + throw new Test262Error('#0: var obj = {}; obj.length === undefined. Actual: ' + (obj.length)); +} else { + var pop = obj.pop(); + if (pop !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.pop = SendableArray.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); + } + if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); + } +} +obj.length = undefined; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#3: var obj = {}; obj.length = undefined; obj.pop = SendableArray.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} +if (obj.length !== 0) { + throw new Test262Error('#4: var obj = {}; obj.length = undefined; obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} +obj.length = null +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.length = null; obj.pop = SendableArray.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} +if (obj.length !== 0) { + throw new Test262Error('#6: var obj = {}; obj.length = null; obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T2.js b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..41a56f74a886df647fb5698e60050dd276b3b6e4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T2.js @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The pop function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.pop +description: > + If ToUint32(length) equal zero, call the [[Put]] method of this + object with arguments "length" and 0 and return undefined +---*/ + +var obj = {}; +obj.pop = SendableArray.prototype.pop; +obj.length = NaN; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.length = NaN; obj.pop = SendableArray.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} +if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.length = NaN; obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} +obj.length = Number.POSITIVE_INFINITY; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#3: var obj = {}; obj.length = Number.POSITIVE_INFINITY; obj.pop = SendableArray.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} +if (obj.length !== 9007199254740990) { + throw new Test262Error('#4: var obj = {}; obj.length = Number.POSITIVE_INFINITY; obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === 9007199254740990. Actual: ' + (obj.length)); +} +obj.length = Number.NEGATIVE_INFINITY; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.pop = SendableArray.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} +if (obj.length !== 0) { + throw new Test262Error('#6: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} +obj.length = -0; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#7: var obj = {}; obj.length = -0; obj.pop = SendableArray.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} +if (obj.length !== 0) { + throw new Test262Error('#8: var obj = {}; obj.length = -0; obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} else { + if (1 / obj.length !== Number.POSITIVE_INFINITY) { + throw new Test262Error('#8: var obj = {}; obj.length = -0; obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === +0. Actual: ' + (obj.length)); + } +} +obj.length = 0.5; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#9: var obj = {}; obj.length = 0.5; obj.pop = SendableArray.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} +if (obj.length !== 0) { + throw new Test262Error('#10: var obj = {}; obj.length = 0.5; obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} +obj.length = new Number(0); +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#11: var obj = {}; obj.length = new Number(0); obj.pop = SendableArray.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} +if (obj.length !== 0) { + throw new Test262Error('#12: var obj = {}; obj.length = new Number(0); obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T3.js b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..fbe7040468dff05f586f007cdec70f8e1c659710 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T3.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The pop function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.pop +description: > + The last element ToUint32(length) - 1 of the array is removed from + the array and returned +---*/ + +var obj = {}; +obj.pop = SendableArray.prototype.pop; +obj.length = 2.5; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.length = 2.5; obj.pop = SendableArray.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} +if (obj.length !== 1) { + throw new Test262Error('#2: var obj = {}; obj.length = 2.5; obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === 1. Actual: ' + (obj.length)); +} +obj.length = new Number(2); +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#11: var obj = {}; obj.length = new Number(2); obj.pop = SendableArray.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} +if (obj.length !== 1) { + throw new Test262Error('#12: var obj = {}; obj.length = new Number(2); obj.pop = SendableArray.prototype.pop; obj.pop(); obj.length === 1. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T4.js b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..e855ba3d09ff0f72cbab925097bd3ee96c6ac933 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A2_T4.js @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The pop function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.pop +description: > + Operator use ToNumber from length. If Type(value) is Object, + evaluate ToPrimitive(value, Number) +---*/ + +var obj = {}; +obj.pop = SendableArray.prototype.pop; +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + } +}; +var pop = obj.pop(); +assert.sameValue(pop, -1, 'The value of pop is expected to be -1'); +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + }, + toString() { + return 0 + } +}; +var pop = obj.pop(); +assert.sameValue(pop, -1, 'The value of pop is expected to be -1'); +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + }, + toString() { + return {} + } +}; +var pop = obj.pop(); +assert.sameValue(pop, -1, 'The value of pop is expected to be -1'); +try { + obj[0] = -1; + obj.length = { + valueOf() { + return 1 + }, + toString() { + throw "error" + } + }; + var pop = obj.pop(); + assert.sameValue(pop, -1, 'The value of pop is expected to be -1'); +} +catch (e) { + assert.notSameValue(e, "error", 'The value of e is not "error"'); +} +obj[0] = -1; +obj.length = { + toString() { + return 0 + } +}; +var pop = obj.pop(); +assert.sameValue(pop, undefined, 'The value of pop is expected to equal undefined'); +obj[0] = -1; +obj.length = { + valueOf() { + return {} + }, + toString() { + return 0 + } +} +var pop = obj.pop(); +assert.sameValue(pop, undefined, 'The value of pop is expected to equal undefined'); +try { + obj[0] = -1; + obj.length = { + valueOf() { + throw "error" + }, + toString() { + return 0 + } + }; + var pop = obj.pop(); + throw new Test262Error('#7.1: obj[0] = -1; obj.length = {valueOf() {throw "error"}, toString() {return 0}}; obj.pop() throw "error". Actual: ' + (pop)); +} +catch (e) { + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); +} +try { + obj[0] = -1; + obj.length = { + valueOf() { + return {} + }, + toString() { + return {} + } + }; + var pop = obj.pop(); + throw new Test262Error('#8.1: obj[0] = -1; obj.length = {valueOf() {return {}}, toString() {return {}}} obj.pop() throw TypeError. Actual: ' + (pop)); +} +catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A3_T1.js b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..98228ad51acf155e4233a2c747faa8ead1c4e872 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A3_T1.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.pop +description: length = 4294967296 +---*/ + +var obj = {}; +obj.pop = SendableArray.prototype.pop; +obj[0] = "x"; +obj[4294967295] = "y"; +obj.length = 4294967296; +var pop = obj.pop(); +if (pop !== "y") { + throw new Test262Error('#1: var obj = {}; obj.pop = SendableArray.prototype.pop; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; obj.pop() === "y". Actual: ' + (pop)); +} +if (obj.length !== 4294967295) { + throw new Test262Error('#2: var obj = {}; obj.pop = SendableArray.prototype.pop; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; obj.pop(); obj.length === 4294967295. Actual: ' + (obj.length)); +} +if (obj[0] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.pop = SendableArray.prototype.pop; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; obj.pop(); obj[0] === "x". Actual: ' + (obj[0])); +} +if (obj[4294967295] !== undefined) { + throw new Test262Error('#4: var obj = {}; obj.pop = SendableArray.prototype.pop; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; obj.pop(); obj[4294967295] === undefined. Actual: ' + (obj[4294967295])); +} diff --git a/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A3_T2.js b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..d5aa32088052a3e808f84165ac8fb1104ec8016f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A3_T2.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.pop +description: length = 4294967297 +---*/ + +var obj = {}; +obj.pop = SendableArray.prototype.pop; +obj[0] = "x"; +obj[4294967296] = "y"; +obj.length = 4294967297; +var pop = obj.pop(); +if (pop !== "y") { + throw new Test262Error('#1: var obj = {}; obj.pop = SendableArray.prototype.pop; obj[0] = "x"; obj[4294967296] = "y"; obj.length = 4294967297; obj.pop() === "y". Actual: ' + (pop)); +} +if (obj.length !== 4294967296) { + throw new Test262Error('#2: var obj = {}; obj.pop = SendableArray.prototype.pop; obj[0] = "x"; obj[4294967296] = "y"; obj.length = 4294967297; obj.pop(); obj.length === 4294967296. Actual: ' + (obj.length)); +} +if (obj[0] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.pop = SendableArray.prototype.pop; obj[0] = "x"; obj[4294967296] = "y"; obj.length = 4294967297; obj.pop(); obj[0] === "x". Actual: ' + (obj[0])); +} +if (obj[4294967296] !== undefined) { + throw new Test262Error('#4: var obj = {}; obj.pop = SendableArray.prototype.pop; obj[0] = "x"; obj[4294967296] = "y"; obj.length = 4294967297; obj.pop(); obj[4294967296] === undefined. Actual: ' + (obj[4294967296])); +} diff --git a/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A3_T3.js b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..e69dce538a106ae5f8b7e6bef24fbc0e0ebc05ff --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A3_T3.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.pop +description: length = -1 +---*/ + +var obj = {}; +obj.pop = SendableArray.prototype.pop; +obj[4294967294] = "x"; +obj.length = -1; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.pop = SendableArray.prototype.pop; obj[4294967294] = "x"; obj.length = -1; obj.pop() === undefined. Actual: ' + (pop)); +} +if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.pop = SendableArray.prototype.pop; obj[4294967294] = "x"; obj.length = -1; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} +if (obj[4294967294] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.pop = SendableArray.prototype.pop; obj[4294967294] = "x"; obj.length = -1; obj.pop(); obj[4294967294] === "x". Actual: ' + (obj[4294967294])); +} diff --git a/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A4_T1.js b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A4_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..6d467b7f79e8eca89913699d4c320da200786789 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A4_T1.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]], [[Delete]] from not an inherited property" +esid: sec-array.prototype.pop +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[1] = 1; +var x = [0]; +x.length = 2; +var pop = x.pop(); +if (pop !== 1) { + throw new Test262Error('#1: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; x.pop() === 1. Actual: ' + (pop)); +} +if (x[1] !== 1) { + throw new Test262Error('#2: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; x.pop(); x[1] === 1. Actual: ' + (x[1])); +} +Object.prototype[1] = 1; +Object.prototype.length = 2; +Object.prototype.pop = SendableArray.prototype.pop; +x = { + 0: 0 +}; +var pop = x.pop(); +if (pop !== 1) { + throw new Test262Error('#3: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.pop = SendableArray.prototype.pop; x = {0:0}; x.pop() === 1. Actual: ' + (pop)); +} +if (x[1] !== 1) { + throw new Test262Error('#4: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.pop = SendableArray.prototype.pop; x = {0:0}; x.pop(); x[1] === 1. Actual: ' + (x[1])); +} +if (x.length !== 1) { + throw new Test262Error('#6: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.pop = SendableArray.prototype.pop; x = {0:0}; x.pop(); x.length === 1. Actual: ' + (x.length)); +} +delete x.length; +if (x.length !== 2) { + throw new Test262Error('#7: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.pop = SendableArray.prototype.pop; x = {0:0}; x.pop(); delete x; x.length === 2. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A4_T2.js b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A4_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..9065d83e3a808fad3c1cbbf9f691355f362d7a1c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/S15.4.4.6_A4_T2.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]], [[Delete]] from not an inherited property" +esid: sec-array.prototype.pop +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[1] = -1; +var x = [0, 1]; +x.length = 2; +var pop = x.pop(); +if (pop !== 1) { + throw new Test262Error('#1: SendableArray.prototype[1] = -1; x = [0,1]; x.length = 2; x.pop() === 1. Actual: ' + (pop)); +} +if (x[1] !== -1) { + throw new Test262Error('#2: SendableArray.prototype[1] = -1; x = [0,1]; x.length = 2; x.pop(); x[1] === -1. Actual: ' + (x[1])); +} +Object.prototype[1] = -1; +Object.prototype.length = 2; +Object.prototype.pop = SendableArray.prototype.pop; +x = { + 0: 0, + 1: 1 +}; +var pop = x.pop(); +if (pop !== 1) { + throw new Test262Error('#3: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.pop = SendableArray.prototype.pop; x = {0:0,1:1}; x.pop() === 1. Actual: ' + (pop)); +} +if (x[1] !== -1) { + throw new Test262Error('#4: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.pop = SendableArray.prototype.pop; x = {0:0,1:1}; x.pop(); x[1] === -1. Actual: ' + (x[1])); +} +if (x.length !== 1) { + throw new Test262Error('#6: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.pop = SendableArray.prototype.pop; x = {0:0,1:1}; x.pop(); x.length === 1. Actual: ' + (x.length)); +} +delete x.length; +if (x.length !== 2) { + throw new Test262Error('#7: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.pop = SendableArray.prototype.pop; x = {0:0,1:1}; x.pop(); delete x; x.length === 2. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/pop/call-with-boolean.js b/test/sendable/builtins/Array/prototype/pop/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..2df83544f644613358404339892376f744dc5305 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/call-with-boolean.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.pop +description: Array.prototype.pop applied to boolean primitive +---*/ + +assert.sameValue(SendableArray.prototype.pop.call(true), undefined, 'SendableArray.prototype.pop.call(true) must return undefined'); +assert.sameValue(SendableArray.prototype.pop.call(false), undefined, 'SendableArray.prototype.pop.call(false) must return undefined'); diff --git a/test/sendable/builtins/Array/prototype/pop/clamps-to-integer-limit.js b/test/sendable/builtins/Array/prototype/pop/clamps-to-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..43c1ea25697f7ac4d828975b9a4cd9b5bf8a02f6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/clamps-to-integer-limit.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.pop +description: > + Length values exceeding 2^53-1 are clamped to 2^53-1. +features: [exponentiation] +---*/ + +var arrayLike = {}; +arrayLike.length = 2 ** 53 - 1; +SendableArray.prototype.pop.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 2, "Length is 2**53 - 1"); +arrayLike.length = 2 ** 53; +SendableArray.prototype.pop.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 2, "Length is 2**53"); +arrayLike.length = 2 ** 53 + 2; +SendableArray.prototype.pop.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 2, "Length is 2**53 + 2"); +arrayLike.length = Infinity; +SendableArray.prototype.pop.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 2, "Length is Infinity"); diff --git a/test/sendable/builtins/Array/prototype/pop/length-near-integer-limit.js b/test/sendable/builtins/Array/prototype/pop/length-near-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..fffa0235bc2dc924101e157059257cbd5a540386 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/length-near-integer-limit.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.pop +description: > + A value is removed from an array-like object whose length property is near the integer limit. +features: [exponentiation] +---*/ + +var arrayLike = { + "9007199254740989": "9007199254740989", + "9007199254740990": "9007199254740990", + "9007199254740991": "9007199254740991", + length: 2 ** 53 - 1 +}; +var value = SendableArray.prototype.pop.call(arrayLike); +assert.sameValue(value, "9007199254740990", + "arrayLike['9007199254740990'] is returned from pop()"); +assert.sameValue(arrayLike.length, 2 ** 53 - 2, + "New arrayLike.length is 2**53 - 2"); +assert.sameValue(arrayLike["9007199254740989"], "9007199254740989", + "arrayLike['9007199254740989'] is unchanged"); +assert.sameValue("9007199254740990" in arrayLike, false, + "arrayLike['9007199254740990'] is removed"); +assert.sameValue(arrayLike["9007199254740991"], "9007199254740991", + "arrayLike['9007199254740991'] is unchanged"); diff --git a/test/sendable/builtins/Array/prototype/pop/length.js b/test/sendable/builtins/Array/prototype/pop/length.js new file mode 100644 index 0000000000000000000000000000000000000000..7d778106d4f670aa8f0d84afb624e5935cd70b47 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/length.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.pop +description: > + The "length" property of Array.prototype.pop +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.pop, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/pop/name.js b/test/sendable/builtins/Array/prototype/pop/name.js new file mode 100644 index 0000000000000000000000000000000000000000..9687fe70793cc87fa0159c0dc6913659269c5387 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.pop +description: > + Array.prototype.pop.name is "pop". +info: | + Array.prototype.pop ( ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.pop, "name", { + value: "pop", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/pop/not-a-constructor.js b/test/sendable/builtins/Array/prototype/pop/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..b2a020af332faef70ed160771992c5b689ef4979 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.pop does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.prototype.pop), false, 'isConstructor(SendableArray.prototype.pop) must return false'); +assert.throws(TypeError, () => { + new SendableArray.prototype.pop(); +}); + diff --git a/test/sendable/builtins/Array/prototype/pop/prop-desc.js b/test/sendable/builtins/Array/prototype/pop/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..6cd0bddc1a3ae50e8d2737bea113e49fb4e6c862 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.pop +description: > + "pop" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.pop, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "pop", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/pop/set-length-array-is-frozen.js b/test/sendable/builtins/Array/prototype/pop/set-length-array-is-frozen.js new file mode 100644 index 0000000000000000000000000000000000000000..93fe86b4b437de2b576a0b1874d1769c4a9f38b8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/set-length-array-is-frozen.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.pop +description: > + A TypeError is thrown when "length" is [[Set]] on a frozen array. +---*/ + +var array = new SendableArray(1); +var arrayPrototypeGet0Calls = 0; +Object.defineProperty(SendableArray.prototype, "0", { + get() { + Object.freeze(array); + arrayPrototypeGet0Calls++; + }, +}); +assert.throws(TypeError, function() { + array.pop(); +}); +assert.sameValue(array.length, 1); +assert.sameValue(arrayPrototypeGet0Calls, 1); diff --git a/test/sendable/builtins/Array/prototype/pop/set-length-array-length-is-non-writable.js b/test/sendable/builtins/Array/prototype/pop/set-length-array-length-is-non-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..af856dfde6f2ebbb4bd98ecaebf90928bc4972e4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/set-length-array-length-is-non-writable.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.pop +description: > + A TypeError is thrown when "length" is [[Set]] on an array with non-writable "length". +---*/ + +var array = new SendableArray(1); +var arrayPrototypeGet0Calls = 0; +Object.defineProperty(SendableArray.prototype, "0", { + get() { + Object.defineProperty(array, "length", { writable: false }); + arrayPrototypeGet0Calls++; + }, +}); +assert.throws(TypeError, function() { + array.pop(); +}); +assert.sameValue(array.length, 1); +assert.sameValue(arrayPrototypeGet0Calls, 1); diff --git a/test/sendable/builtins/Array/prototype/pop/set-length-zero-array-is-frozen.js b/test/sendable/builtins/Array/prototype/pop/set-length-zero-array-is-frozen.js new file mode 100644 index 0000000000000000000000000000000000000000..266ba03b8f92795de99faff39ce265fb3d4b1334 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/set-length-zero-array-is-frozen.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.pop +description: > + A TypeError is thrown when "length" is [[Set]] on an empty frozen array. +---*/ + +var array = []; +Object.freeze(array); +assert.throws(TypeError, function() { + array.pop(); +}); diff --git a/test/sendable/builtins/Array/prototype/pop/set-length-zero-array-length-is-non-writable.js b/test/sendable/builtins/Array/prototype/pop/set-length-zero-array-length-is-non-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..7e403eadef39d3f2a20213b8c11659edfbadfbec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/set-length-zero-array-length-is-non-writable.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.pop +description: > + A TypeError is thrown when "length" is [[Set]] on an empty array with non-writable "length". +---*/ + +var array = []; +Object.defineProperty(array, "length", { writable: false }); +assert.throws(TypeError, function() { + array.pop(); +}); diff --git a/test/sendable/builtins/Array/prototype/pop/throws-with-string-receiver.js b/test/sendable/builtins/Array/prototype/pop/throws-with-string-receiver.js new file mode 100644 index 0000000000000000000000000000000000000000..b426e5cb693e1cfeade657eb46c523245f711980 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/pop/throws-with-string-receiver.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.pop +description: > + Array#pop throws TypeError upon attempting to modify a string +---*/ + +assert.throws(TypeError, () => { + SendableArray.prototype.pop.call(''); +}, "SendableArray.prototype.pop.call('')"); +assert.throws(TypeError, () => { + SendableArray.prototype.pop.call('abc'); +}, "SendableArray.prototype.pop.call('abc')"); diff --git a/test/sendable/builtins/Array/prototype/prop-desc.js b/test/sendable/builtins/Array/prototype/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..d9d3210804e9d2ff6a561f232b33937531e183a4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/prop-desc.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype +description: > + The property descriptor of Array.prototype +info: | + 22.1.2.4 Array.prototype + The value of Array.prototype is %ArrayPrototype%, the intrinsic Array prototype object. + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: false }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray, 'prototype', { + writable: false, + enumerable: false, + configurable: false, +}); diff --git a/test/sendable/builtins/Array/prototype/proto.js b/test/sendable/builtins/Array/prototype/proto.js new file mode 100644 index 0000000000000000000000000000000000000000..464e0c110bcab04a973b18523d2ee2716f4f3ad3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/proto.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-properties-of-the-array-prototype-object +description: > + The [[Prototype]] of Array.prototype is Object.Prototype. +info: | + 22.1.3 Properties of the Array Prototype Object + The value of the [[Prototype]] internal slot of the Array prototype object is + the intrinsic object %ObjectPrototype%. +---*/ + +assert.sameValue(Object.getPrototypeOf(SendableArray.prototype), Object.prototype); diff --git a/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A1_T1.js b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..b12a2282bb1133fe5b8e04229cf9ae508ae0025e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A1_T1.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The arguments are appended to the end of the array, in + the order in which they appear. The new length of the array is returned + as the result of the call +esid: sec-array.prototype.push +description: Checking case when push is given no arguments or one argument +---*/ + +var x = new SendableArray(); +var push = x.push(1); +if (push !== 1) { + throw new Test262Error('#1: x = new SendableArray(); x.push(1) === 1. Actual: ' + (push)); +} +if (x[0] !== 1) { + throw new Test262Error('#2: x = new SendableArray(); x.push(1); x[0] === 1. Actual: ' + (x[0])); +} +var push = x.push(); +if (push !== 1) { + throw new Test262Error('#3: x = new SendableArray(); x.push(1); x.push() === 1. Actual: ' + (push)); +} +if (x[1] !== undefined) { + throw new Test262Error('#4: x = new SendableArray(); x.push(1); x.push(); x[1] === unedfined. Actual: ' + (x[1])); +} +var push = x.push(-1); +if (push !== 2) { + throw new Test262Error('#5: x = new SendableArray(); x.push(1); x.push(); x.push(-1) === 2. Actual: ' + (push)); +} +if (x[1] !== -1) { + throw new Test262Error('#6: x = new SendableArray(); x.push(1); x.push(-1); x[1] === -1. Actual: ' + (x[1])); +} +if (x.length !== 2) { + throw new Test262Error('#7: x = new SendableArray(); x.push(1); x.push(); x.push(-1); x.length === 2. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A1_T2.js b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..934cd9908d4a427e594f36c3f9cee2023d0e40fd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A1_T2.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The arguments are appended to the end of the array, in + the order in which they appear. The new length of the array is returned + as the result of the call +esid: sec-array.prototype.push +description: Checking case when push is given many arguments +---*/ + +var x = []; +if (x.length !== 0) { + throw new Test262Error('#1: x = []; x.length === 0. Actual: ' + (x.length)); +} +x[0] = 0; +var push = x.push(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); +if (push !== 6) { + throw new Test262Error('#2: x = []; x[0] = 0; x.push(true, Number.POSITIVE_INFINITY, "NaN", "1", -1) === 6. Actual: ' + (push)); +} +if (x[0] !== 0) { + throw new Test262Error('#3: x = []; x[0] = 0; x.push(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== true) { + throw new Test262Error('#4: x = []; x[0] = 0; x.push(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[1] === true. Actual: ' + (x[1])); +} +if (x[2] !== Number.POSITIVE_INFINITY) { + throw new Test262Error('#5: x = []; x[0] = 0; x.push(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[2] === Number.POSITIVE_INFINITY. Actual: ' + (x[2])); +} +if (x[3] !== "NaN") { + throw new Test262Error('#6: x = []; x[0] = 0; x.push(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[3] === "NaN". Actual: ' + (x[3])); +} +if (x[4] !== "1") { + throw new Test262Error('#7: x = []; x[0] = 0; x.push(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[4] === "1". Actual: ' + (x[4])); +} +if (x[5] !== -1) { + throw new Test262Error('#8: x = []; x[0] = 0; x.push(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[5] === -1. Actual: ' + (x[5])); +} +if (x.length !== 6) { + throw new Test262Error('#9: x = []; x[0] = 0; x.push(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x.length === 6. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A2_T1.js b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..f5df7fab86228bac46e0de545fb3692bab24ddc1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A2_T1.js @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The push function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.push +description: > + The arguments are appended to the end of the array, in the order + in which they appear. The new length of the array is returned as + the result of the call +---*/ + +var obj = {}; +obj.push = SendableArray.prototype.push; +if (obj.length !== undefined) { + throw new Test262Error('#0: var obj = {}; obj.length === undefined. Actual: ' + (obj.length)); +} else { + var push = obj.push(-1); + if (push !== 1) { + throw new Test262Error('#1: var obj = {}; obj.push = SendableArray.prototype.push; obj.push(-1) === 1. Actual: ' + (push)); + } + if (obj.length !== 1) { + throw new Test262Error('#2: var obj = {}; obj.push = SendableArray.prototype.push; obj.push(-1); obj.length === 1. Actual: ' + (obj.length)); + } + if (obj["0"] !== -1) { + throw new Test262Error('#3: var obj = {}; obj.push = SendableArray.prototype.push; obj.push(-1); obj["0"] === -1. Actual: ' + (obj["0"])); + } +} +obj.length = undefined; +var push = obj.push(-4); +if (push !== 1) { + throw new Test262Error('#4: var obj = {}; obj.length = undefined; obj.push = SendableArray.prototype.push; obj.push(-4) === 1. Actual: ' + (push)); +} +if (obj.length !== 1) { + throw new Test262Error('#5: var obj = {}; obj.length = undefined; obj.push = SendableArray.prototype.push; obj.push(-4); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -4) { + throw new Test262Error('#6: var obj = {}; obj.length = undefined; obj.push = SendableArray.prototype.push; obj.push(-4); obj["0"] === -4. Actual: ' + (obj["0"])); +} +obj.length = null +var push = obj.push(-7); +if (push !== 1) { + throw new Test262Error('#7: var obj = {}; obj.length = null; obj.push = SendableArray.prototype.push; obj.push(-7) === 1. Actual: ' + (push)); +} +if (obj.length !== 1) { + throw new Test262Error('#8: var obj = {}; obj.length = null; obj.push = SendableArray.prototype.push; obj.push(-7); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -7) { + throw new Test262Error('#9: var obj = {}; obj.length = null; obj.push = SendableArray.prototype.push; obj.push(-7); obj["0"] === -7. Actual: ' + (obj["0"])); +} diff --git a/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A2_T2.js b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..eed2edccc5d4958d790db31257a6d3a50e21b90d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A2_T2.js @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The push function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.push +description: > + The arguments are appended to the end of the array, in the order + in which they appear. The new length of the array is returned as + the result of the call +---*/ + +var obj = {}; +obj.push = SendableArray.prototype.push; +obj.length = NaN; +var push = obj.push(-1); +if (push !== 1) { + throw new Test262Error('#1: var obj = {}; obj.length = NaN; obj.push = SendableArray.prototype.push; obj.push(-1) === 1. Actual: ' + (push)); +} +if (obj.length !== 1) { + throw new Test262Error('#2: var obj = {}; obj.length = NaN; obj.push = SendableArray.prototype.push; obj.push(-1); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -1) { + throw new Test262Error('#3: var obj = {}; obj.length = NaN; obj.push = SendableArray.prototype.push; obj.push(-1); obj["0"] === -1. Actual: ' + (obj["0"])); +} +obj.length = Number.POSITIVE_INFINITY; +assert.throws(TypeError, function() { + obj.push(-4); +}); +if (obj.length !== Number.POSITIVE_INFINITY) { + throw new Test262Error('#6: var obj = {}; obj.length = Number.POSITIVE_INFINITY; obj.push = SendableArray.prototype.push; obj.push(-4); obj.length === Number.POSITIVE_INFINITY. Actual: ' + (obj.length)); +} +if (obj[9007199254740991] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.length = Number.POSITIVE_INFINITY; obj.push = SendableArray.prototype.push; obj.push(-4); obj[9007199254740991] === undefined. Actual: ' + (obj["9007199254740991"])); +} +obj.length = Number.NEGATIVE_INFINITY; +var push = obj.push(-7); +if (push !== 1) { + throw new Test262Error('#7: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.push = SendableArray.prototype.push; obj.push(-7) === 1. Actual: ' + (push)); +} +if (obj.length !== 1) { + throw new Test262Error('#8: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.push = SendableArray.prototype.push; obj.push(-7); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -7) { + throw new Test262Error('#9: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.push = SendableArray.prototype.push; obj.push(-7); obj["0"] === -7. Actual: ' + (obj["0"])); +} +obj.length = 0.5; +var push = obj.push(-10); +if (push !== 1) { + throw new Test262Error('#10: var obj = {}; obj.length = 0.5; obj.push = SendableArray.prototype.push; obj.push(-10) === 1. Actual: ' + (push)); +} +if (obj.length !== 1) { + throw new Test262Error('#11: var obj = {}; obj.length = 0.5; obj.push = SendableArray.prototype.push; obj.push(-10); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -10) { + throw new Test262Error('#12: var obj = {}; obj.length = 0.5; obj.push = SendableArray.prototype.push; obj.push(-10); obj["0"] === -10. Actual: ' + (obj["0"])); +} +obj.length = 1.5; +var push = obj.push(-13); +if (push !== 2) { + throw new Test262Error('#13: var obj = {}; obj.length = 1.5; obj.push = SendableArray.prototype.push; obj.push(-13) === 2. Actual: ' + (push)); +} +if (obj.length !== 2) { + throw new Test262Error('#14: var obj = {}; obj.length = 1.5; obj.push = SendableArray.prototype.push; obj.push(-13); obj.length === 2. Actual: ' + (obj.length)); +} +if (obj["1"] !== -13) { + throw new Test262Error('#15: var obj = {}; obj.length = 1.5; obj.push = SendableArray.prototype.push; obj.push(-13); obj["1"] === -13. Actual: ' + (obj["1"])); +} +obj.length = new Number(0); +var push = obj.push(-16); +if (push !== 1) { + throw new Test262Error('#16: var obj = {}; obj.length = new Number(0); obj.push = SendableArray.prototype.push; obj.push(-16) === 1. Actual: ' + (push)); +} +if (obj.length !== 1) { + throw new Test262Error('#17: var obj = {}; obj.length = new Number(0); obj.push = SendableArray.prototype.push; obj.push(-16); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -16) { + throw new Test262Error('#18: var obj = {}; obj.length = new Number(0); obj.push = SendableArray.prototype.push; obj.push(-16); obj["0"] === -16. Actual: ' + (obj["0"])); +} diff --git a/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A2_T3.js b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..45162788e0d9cfd36f54416b6b8ed4d739649e3e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A2_T3.js @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The push function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.push +description: > + Operator use ToNumber from length. If Type(value) is Object, + evaluate ToPrimitive(value, Number) +---*/ + +var obj = {}; +obj.push = SendableArray.prototype.push; +obj.length = { + valueOf() { + return 3 + } +}; +var push = obj.push(); +assert.sameValue(push, 3, 'The value of push is expected to be 3'); +obj.length = { + valueOf() { + return 3 + }, + toString() { + return 1 + } +}; +var push = obj.push(); +assert.sameValue(push, 3, 'The value of push is expected to be 3'); +obj.length = { + valueOf() { + return 3 + }, + toString() { + return {} + } +}; +var push = obj.push(); +assert.sameValue(push, 3, 'The value of push is expected to be 3'); +try { + obj.length = { + valueOf() { + return 3 + }, + toString() { + throw "error" + } + }; + var push = obj.push(); + assert.sameValue(push, 3, 'The value of push is expected to be 3'); +} +catch (e) { + assert.notSameValue(e, "error", 'The value of e is not "error"'); +} +obj.length = { + toString() { + return 1 + } +}; +var push = obj.push(); +assert.sameValue(push, 1, 'The value of push is expected to be 1'); +obj.length = { + valueOf() { + return {} + }, + toString() { + return 1 + } +} +var push = obj.push(); +assert.sameValue(push, 1, 'The value of push is expected to be 1'); +try { + obj.length = { + valueOf() { + throw "error" + }, + toString() { + return 1 + } + }; + var push = obj.push(); + throw new Test262Error('#7.1: obj.length = {valueOf() {throw "error"}, toString() {return 1}}; obj.push() throw "error". Actual: ' + (push)); +} +catch (e) { + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); +} +try { + obj.length = { + valueOf() { + return {} + }, + toString() { + return {} + } + }; + var push = obj.push(); + throw new Test262Error('#8.1: obj.length = {valueOf() {return {}}, toString() {return {}}} obj.push() throw TypeError. Actual: ' + (push)); +} +catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A3.js b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A3.js new file mode 100644 index 0000000000000000000000000000000000000000..0e521add8d323bbdcdb0dd84209ec9150f25042b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A3.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for Array object +esid: sec-array.prototype.push +description: If ToUint32(length) !== length, throw RangeError +---*/ + +var x = []; +x.length = 4294967295; +var push = x.push(); +assert.sameValue(push, 4294967295, 'The value of push is expected to be 4294967295'); +try { + x.push("x"); + throw new Test262Error('#2.1: x = []; x.length = 4294967295; x.push("x") throw RangeError. Actual: ' + (push)); +} catch (e) { + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); +} +assert.sameValue(x[4294967295], "x", 'The value of x[4294967295] is expected to be "x"'); +assert.sameValue(x.length, 4294967295, 'The value of x.length is expected to be 4294967295'); diff --git a/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A4_T1.js b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A4_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..4a03a774691ea94589adab40c00b10fe848e3939 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A4_T1.js @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.push +description: length = 4294967296 +---*/ + +var obj = {}; +obj.push = SendableArray.prototype.push; +obj.length = 4294967296; +var push = obj.push("x", "y", "z"); +if (push !== 4294967299) { + throw new Test262Error('#1: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967296; obj.push("x", "y", "z") === 4294967299. Actual: ' + (push)); +} +if (obj.length !== 4294967299) { + throw new Test262Error('#2: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967296; obj.push("x", "y", "z"); obj.length === 4294967299. Actual: ' + (obj.length)); +} +if (obj[0] !== undefined) { + throw new Test262Error('#3: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967296; obj.push("x", "y", "z"); obj[0] === undefined. Actual: ' + (obj[0])); +} +if (obj[1] !== undefined) { + throw new Test262Error('#4: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967296; obj.push("x", "y", "z"); obj[1] === undefined. Actual: ' + (obj[1])); +} +if (obj[2] !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967296; obj.push("x", "y", "z"); obj[2] === undefined. Actual: ' + (obj[2])); +} +if (obj[4294967296] !== "x") { + throw new Test262Error('#6: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967296; obj.push("x", "y", "z"); obj[4294967296] === "x". Actual: ' + (obj[4294967296])); +} +if (obj[4294967297] !== "y") { + throw new Test262Error('#7: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967296; obj.push("x", "y", "z"); obj[4294967297] === "y". Actual: ' + (obj[4294967297])); +} +if (obj[4294967298] !== "z") { + throw new Test262Error('#8: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967296; obj.push("x", "y", "z"); obj[4294967298] === "z". Actual: ' + (obj[4294967298])); +} +var obj = {}; +obj.push = SendableArray.prototype.push; +obj.length = 4294967296; +var push = obj.push(); +if (push !== 4294967296) { + throw new Test262Error('#9: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967296; obj.push() === 4294967296. Actual: ' + (push)); +} +if (obj.length !== 4294967296) { + throw new Test262Error('#10: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967296; obj.push(); obj.length === 4294967296. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A4_T2.js b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A4_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..a7797a439ff95994841477a0a025b05cdf595b55 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A4_T2.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.push +description: length = 4294967295 +---*/ + +var obj = {}; +obj.push = SendableArray.prototype.push; +obj.length = 4294967295; +var push = obj.push("x", "y", "z"); +if (push !== 4294967298) { + throw new Test262Error('#1: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967295; obj.push("x", "y", "z") === 4294967298. Actual: ' + (push)); +} +if (obj.length !== 4294967298) { + throw new Test262Error('#2: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967295; obj.push("x", "y", "z"); obj.length === 4294967298. Actual: ' + (obj.length)); +} +if (obj[4294967295] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967295; obj.push("x", "y", "z"); obj[4294967295] === "x". Actual: ' + (obj[4294967295])); +} +if (obj[4294967296] !== "y") { + throw new Test262Error('#4: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967295; obj.push("x", "y", "z"); obj[4294967296] === "y". Actual: ' + (obj[4294967296])); +} +if (obj[4294967297] !== "z") { + throw new Test262Error('#5: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = 4294967295; obj.push("x", "y", "z"); obj[4294967297] === "z". Actual: ' + (obj[4294967297])); +} diff --git a/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A4_T3.js b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A4_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..d5fbbd909a1014bcf7b32f496644a98cbca7434d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A4_T3.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.push +description: length = -1 +---*/ + +var obj = {}; +obj.push = SendableArray.prototype.push; +obj.length = -1; +var push = obj.push("x", "y", "z"); +if (push !== 3) { + throw new Test262Error('#1: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = -1; obj.push("x", "y", "z") === 3. Actual: ' + (push)); +} +if (obj.length !== 3) { + throw new Test262Error('#2: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = -1; obj.push("x", "y", "z"); obj.length === 3. Actual: ' + (obj.length)); +} +if (obj[4294967295] !== undefined) { + throw new Test262Error('#3: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = -1; obj.push("x", "y", "z"); obj[4294967295] === undefined. Actual: ' + (obj[4294967295])); +} +if (obj[4294967296] !== undefined) { + throw new Test262Error('#4: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = -1; obj.push("x", "y", "z"); obj[4294967296] === undefined. Actual: ' + (obj[4294967296])); +} +if (obj[4294967297] !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = -1; obj.push("x", "y", "z"); obj[4294967297] === undefined. Actual: ' + (obj[4294967297])); +} +if (obj[0] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = -1; obj.push("x", "y", "z"); obj[0] === "x". Actual: ' + (obj[0])); +} +if (obj[1] !== "y") { + throw new Test262Error('#4: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = -1; obj.push("x", "y", "z"); obj[1] === "y". Actual: ' + (obj[1])); +} +if (obj[2] !== "z") { + throw new Test262Error('#5: var obj = {}; obj.push = SendableArray.prototype.push; obj.length = -1; obj.push("x", "y", "z"); obj[2] === "z". Actual: ' + (obj[2])); +} diff --git a/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A5_T1.js b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A5_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..b15fe6fafa1ce6c63deb066cb8bd5f17d5070ce3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/S15.4.4.7_A5_T1.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]] from not an inherited property" +esid: sec-array.prototype.push +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +Object.prototype[1] = -1; +Object.prototype.length = 1; +Object.prototype.push = SendableArray.prototype.push; +var x = { + 0: 0 +}; +var push = x.push(1); +if (push !== 2) { + throw new Test262Error('#1: Object.prototype[1] = 1; Object.prototype.length = -1; Object.prototype.push = SendableArray.prototype.push; x = {0:0}; x.push(1) === 2. Actual: ' + (push)); +} +if (x.length !== 2) { + throw new Test262Error('#2: Object.prototype[1] = 1; Object.prototype.length = -1; Object.prototype.push = SendableArray.prototype.push; x = {0:0}; x.push(1); x.length === 2. Actual: ' + (x.length)); +} +if (x[1] !== 1) { + throw new Test262Error('#3: Object.prototype[1] = 1; Object.prototype.length = -1; Object.prototype.push = SendableArray.prototype.push; x = {0:0}; x.push(1); x[1] === 1. Actual: ' + (x[1])); +} +delete x[1]; +if (x[1] !== -1) { + throw new Test262Error('#4: Object.prototype[1] = 1; Object.prototype.length = -1; Object.prototype.push = SendableArray.prototype.push; x = {0:0}; x.push(1); delete x[1]; x[1] === -1. Actual: ' + (x[1])); +} +delete x.length; +if (x.length !== 1) { + throw new Test262Error('#5: Object.prototype[1] = 1; Object.prototype.length = -1; Object.prototype.push = SendableArray.prototype.push; x = {0:0}; delete x; x.push(1); x.length === 1. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/push/call-with-boolean.js b/test/sendable/builtins/Array/prototype/push/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..7aebcaa7c5fdbac3d2105671dc7a164c4dcb621c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/call-with-boolean.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: Array.prototype.push applied to boolean primitive +---*/ + +assert.sameValue(SendableArray.prototype.push.call(true), 0, 'SendableArray.prototype.push.call(true) must return 0'); +assert.sameValue(SendableArray.prototype.push.call(false), 0, 'SendableArray.prototype.push.call(false) must return 0'); diff --git a/test/sendable/builtins/Array/prototype/push/clamps-to-integer-limit.js b/test/sendable/builtins/Array/prototype/push/clamps-to-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..c982980ca8a95de74580a3c6d50ca4d0a9e22337 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/clamps-to-integer-limit.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + Length values exceeding 2^53-1 are clamped to 2^53-1. +info: | + 1. ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. Let items be a List whose elements are, in left to right order, the arguments + that were passed to this function invocation. + 4. Let argCount be the number of elements in items. + 7. Perform ? Set(O, "length", len, true). +features: [exponentiation] +---*/ + +var arrayLike = {}; +arrayLike.length = 2 ** 53 - 1; +SendableArray.prototype.push.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53 - 1"); +arrayLike.length = 2 ** 53; +SendableArray.prototype.push.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53"); +arrayLike.length = 2 ** 53 + 2; +SendableArray.prototype.push.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53 + 2"); +arrayLike.length = Infinity; +SendableArray.prototype.push.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is Infinity"); diff --git a/test/sendable/builtins/Array/prototype/push/length-near-integer-limit-set-failure.js b/test/sendable/builtins/Array/prototype/push/length-near-integer-limit-set-failure.js new file mode 100644 index 0000000000000000000000000000000000000000..3866e04fc6adb929d72cf0704514ac1860791b87 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/length-near-integer-limit-set-failure.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + A value is inserted in an array-like object whose length property is near the integer limit. + Unsuccessful [[Set]] raises a TypeError. +---*/ + +var arrayLike = { + length: Number.MAX_SAFE_INTEGER - 3, +}; +Object.defineProperty(arrayLike, Number.MAX_SAFE_INTEGER - 1, { + value: 33, + writable: false, + enumerable: true, + configurable: true, +}); +assert.throws(TypeError, function() { + SendableArray.prototype.push.call(arrayLike, 1, 2, 3); +}); +assert.sameValue(arrayLike[Number.MAX_SAFE_INTEGER - 3], 1); +assert.sameValue(arrayLike[Number.MAX_SAFE_INTEGER - 2], 2); +assert.sameValue(arrayLike[Number.MAX_SAFE_INTEGER - 1], 33); diff --git a/test/sendable/builtins/Array/prototype/push/length-near-integer-limit.js b/test/sendable/builtins/Array/prototype/push/length-near-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..3490cb3f6feefaf53912ce71aebf1b2eb8002be3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/length-near-integer-limit.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + A value is inserted in an array-like object whose length property is near the integer limit. +---*/ + +var arrayLike = { + "9007199254740989": "9007199254740989", + /* "9007199254740990": empty */ + "9007199254740991": "9007199254740991", + length: 2 ** 53 - 2 +}; +SendableArray.prototype.push.call(arrayLike, "new-value"); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, + "New arrayLike.length is 2**53 - 1"); +assert.sameValue(arrayLike["9007199254740989"], "9007199254740989", + "arrayLike['9007199254740989'] is unchanged"); +assert.sameValue(arrayLike["9007199254740990"], "new-value", + "arrayLike['9007199254740990'] has new value"); +assert.sameValue(arrayLike["9007199254740991"], "9007199254740991", + "arrayLike['9007199254740991'] is unchanged"); diff --git a/test/sendable/builtins/Array/prototype/push/length.js b/test/sendable/builtins/Array/prototype/push/length.js new file mode 100644 index 0000000000000000000000000000000000000000..ee90f1c6a2bee56976610e2d3b5786ea83e4d5b7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/length.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + The "length" property of Array.prototype.push +info: | + 22.1.3.18 Array.prototype.push ( ...items ) + The length property of the push method is 1. + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.push, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/push/name.js b/test/sendable/builtins/Array/prototype/push/name.js new file mode 100644 index 0000000000000000000000000000000000000000..14734659d09986b0206383442a8d0016939e1f64 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + Array.prototype.push.name is "push". +info: | + Array.prototype.push ( ...items ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.push, "name", { + value: "push", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/push/not-a-constructor.js b/test/sendable/builtins/Array/prototype/push/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..1d94c9932e9c1947c7a6e01d58d01b4b05c1e182 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.push does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.prototype.push), false, 'isConstructor(SendableArray.prototype.push) must return false'); +assert.throws(TypeError, () => { + new SendableArray.prototype.push(); +}); + diff --git a/test/sendable/builtins/Array/prototype/push/prop-desc.js b/test/sendable/builtins/Array/prototype/push/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..1e03d764218eb110b67ed1ea43affb4199325cc6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + "push" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.push, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "push", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/push/set-length-array-is-frozen.js b/test/sendable/builtins/Array/prototype/push/set-length-array-is-frozen.js new file mode 100644 index 0000000000000000000000000000000000000000..db7c629d220cc0a364ad9c55634529c257df27aa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/set-length-array-is-frozen.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + A TypeError is thrown when "length" is [[Set]] on a frozen array. +---*/ + +var array = []; +var arrayPrototypeSet0Calls = 0; +Object.defineProperty(SendableArray.prototype, "0", { + set(_val) { + Object.freeze(array); + arrayPrototypeSet0Calls++; + }, +}); +assert.throws(TypeError, function() { + array.push(1); +}); +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); +assert.sameValue(arrayPrototypeSet0Calls, 1); diff --git a/test/sendable/builtins/Array/prototype/push/set-length-array-length-is-non-writable.js b/test/sendable/builtins/Array/prototype/push/set-length-array-length-is-non-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..466335b785d11e53f656439c05efc0c99963d8c9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/set-length-array-length-is-non-writable.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + A TypeError is thrown when "length" is [[Set]] on an array with non-writable "length". +---*/ + +var array = []; +var arrayPrototypeSet0Calls = 0; +Object.defineProperty(SendableArray.prototype, "0", { + set(_val) { + Object.defineProperty(array, "length", { writable: false }); + arrayPrototypeSet0Calls++; + }, +}); +assert.throws(TypeError, function() { + array.push(1); +}); +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); +assert.sameValue(arrayPrototypeSet0Calls, 1); diff --git a/test/sendable/builtins/Array/prototype/push/set-length-zero-array-is-frozen.js b/test/sendable/builtins/Array/prototype/push/set-length-zero-array-is-frozen.js new file mode 100644 index 0000000000000000000000000000000000000000..2e3a1a2090ecd59f44cae55381187942e7c362d5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/set-length-zero-array-is-frozen.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + A TypeError is thrown when "length" is [[Set]] on an empty frozen array. +---*/ + +var array = []; +Object.freeze(array); +assert.throws(TypeError, function() { + array.push(); +}); +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); diff --git a/test/sendable/builtins/Array/prototype/push/set-length-zero-array-length-is-non-writable.js b/test/sendable/builtins/Array/prototype/push/set-length-zero-array-length-is-non-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..0540a8f9027bbfd7e69df99c5da46ecefb8614e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/set-length-zero-array-length-is-non-writable.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + A TypeError is thrown when "length" is [[Set]] on an empty array with non-writable "length". +---*/ + +var array = []; +Object.defineProperty(array, "length", { writable: false }); +assert.throws(TypeError, function() { + array.push(); +}); +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); diff --git a/test/sendable/builtins/Array/prototype/push/throws-if-integer-limit-exceeded.js b/test/sendable/builtins/Array/prototype/push/throws-if-integer-limit-exceeded.js new file mode 100644 index 0000000000000000000000000000000000000000..ba9ba819c08bf2afbdb666d497717a3ed9c003d5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/throws-if-integer-limit-exceeded.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + A TypeError is thrown if the new length exceeds 2^53-1. +---*/ + +var arrayLike = {}; +arrayLike.length = 2 ** 53 - 1; +assert.throws(TypeError, function() { + SendableArray.prototype.push.call(arrayLike, null); +}, "Length is 2**53 - 1"); +arrayLike.length = 2 ** 53; +assert.throws(TypeError, function() { + SendableArray.prototype.push.call(arrayLike, null); +}, "Length is 2**53"); +arrayLike.length = 2 ** 53 + 2; +assert.throws(TypeError, function() { + SendableArray.prototype.push.call(arrayLike, null); +}, "Length is 2**53 + 2"); +arrayLike.length = Infinity; +assert.throws(TypeError, function() { + SendableArray.prototype.push.call(arrayLike, null); +}, "Length is Infinity"); diff --git a/test/sendable/builtins/Array/prototype/push/throws-with-string-receiver.js b/test/sendable/builtins/Array/prototype/push/throws-with-string-receiver.js new file mode 100644 index 0000000000000000000000000000000000000000..62bed7f155d9cf1a2d1bbe80880547a8fd1d0975 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/push/throws-with-string-receiver.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.push +description: > + Array#push throws TypeError upon attempting to modify a string +---*/ + +assert.throws(TypeError, () => { + SendableArray.prototype.push.call(''); +}, "SendableArray.prototype.push.call('')"); +assert.throws(TypeError, () => { + SendableArray.prototype.push.call('', 1); +}, "SendableArray.prototype.push.call('', 1)"); +assert.throws(TypeError, () => { + SendableArray.prototype.push.call('abc'); +}, "SendableArray.prototype.push.call('abc')"); +assert.throws(TypeError, () => { + SendableArray.prototype.push.call('abc', 1); +}, "SendableArray.prototype.push.call('abc', 1)"); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..6c2572926d8877897db486ccefd9cfd8d4f7154c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to undefined +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.reduce.call(undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-10.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..7b42b58c95f7e9f408f18637317bcaf98c1386a2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-10.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to the Math object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return ('[object Math]' === Object.prototype.toString.call(obj)); +} +Math.length = 1; +Math[0] = 1; +assert(SendableArray.prototype.reduce.call(Math, callbackfn, 1), 'SendableArray.prototype.reduce.call(Math, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-11.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..8867b3bbf42d73dc024effd485825942544ffaa0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-11.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to Date object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return obj instanceof Date; +} +var obj = new Date(0); +obj.length = 1; +obj[0] = 1; +assert(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 'SendableArray.prototype.reduce.call(obj, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-12.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..4c81d4e41ebc075ce591726716ee2190d4681f60 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-12.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to RegExp object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return obj instanceof RegExp; +} +var obj = new RegExp(); +obj.length = 1; +obj[0] = 1; +assert(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 'SendableArray .prototype.reduce.call(obj, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-13.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..9d0c5706c573857de3e1f24aa9763324908565de --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-13.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to the JSON object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return ('[object JSON]' === Object.prototype.toString.call(obj)); +} +JSON.length = 1; +JSON[0] = 1; +assert(SendableArray.prototype.reduce.call(JSON, callbackfn, 1), 'SendableArray.prototype.reduce.call(JSON, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-14.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-14.js new file mode 100644 index 0000000000000000000000000000000000000000..b81206dbdabe3305d51c85a39f67e7a03cffdfea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-14.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to Error object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return obj instanceof Error; +} +var obj = new Error(); +obj.length = 1; +obj[0] = 1; +assert(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 'SendableArray.prototype.reduce.call(obj, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-15.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..077e04a2c3eae4d6a174acdc9b42b53d240be14b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-15.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to the Arguments object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return ('[object Arguments]' === Object.prototype.toString.call(obj)); +} +var obj = (function() { + return arguments; +}("a", "b")); +assert(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 'SendableArray.prototype.reduce.call(obj, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..0a80491747fee084c1940684b0197a8b149901a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to null +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.reduce.call(null); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..095ec6589efc6b5e8ed4724bff3ba42ac2402c6d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-3.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to boolean primitive +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return obj instanceof Boolean; +} +Boolean.prototype[0] = true; +Boolean.prototype.length = 1; +assert(SendableArray.prototype.reduce.call(false, callbackfn, 1), 'SendableArray.prototype.reduce.call(false, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..c1a571bb7b29b782890656b4f3cafeb11acbcfdb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-4.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to Boolean object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return obj instanceof Boolean; +} +var obj = new Boolean(true); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +assert(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 'SendableArray.prototype.reduce.call(obj, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..fe7cbeeb14ca411eb3a2380f150b4c63a1f4fe42 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-5.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to number primitive +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return obj instanceof Number; +} +Number.prototype[0] = 1; +Number.prototype.length = 1; +assert(SendableArray.prototype.reduce.call(2.5, callbackfn, 1), 'SendableArray.prototype.reduce.call(2.5, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..bbcd565ef5b444554e059e12446e85ae0a1cb68c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-6.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to Number object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return obj instanceof Number; +} +var obj = new Number(-128); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +assert(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 'SendableArray.prototype.reduce.call(obj, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..4db741def0122a500da65d87d058111c31af2e52 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-7.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to string primitive +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return obj instanceof String; +} +assert(SendableArray.prototype.reduce.call("abc", callbackfn, 1), 'SendableArray.prototype.reduce.call("abc", callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..8781a1eab9cc28484079176748ea48b631904359 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-8.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to String object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return obj instanceof String; +} +var obj = new String("abc"); +assert(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 'SendableArray.prototype.reduce.call(obj, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-9.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..7f9f79c2da53b1f70a0b95367c7fbea1949596be --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-1-9.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to Function object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return obj instanceof Function; +} +var obj = function(a, b) { + return a + b; +}; +obj[0] = 11; +obj[1] = 9; +assert(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 'SendableArray.prototype.reduce.call(obj, callbackfn, 1) !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-1.js new file mode 100644 index 0000000000000000000000000000000000000000..71ce0632e2073f39126b29e937944af009bd2558 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce doesn't mutate the Array on which it is + called on +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + return 1; +} +var srcArr = [1, 2, 3, 4, 5]; +srcArr.reduce(callbackfn); +assert.sameValue(srcArr[0], 1, 'srcArr[0]'); +assert.sameValue(srcArr[1], 2, 'srcArr[1]'); +assert.sameValue(srcArr[2], 3, 'srcArr[2]'); +assert.sameValue(srcArr[3], 4, 'srcArr[3]'); +assert.sameValue(srcArr[4], 5, 'srcArr[4]'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-2.js new file mode 100644 index 0000000000000000000000000000000000000000..7e7839556e24aad8c7fcb79a07f2a691771891b6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-2.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce reduces the array in ascending order of + indices +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + return prevVal + curVal; +} +var srcArr = ['1', '2', '3', '4', '5']; +assert.sameValue(srcArr.reduce(callbackfn), '12345', 'srcArr.reduce(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-3.js new file mode 100644 index 0000000000000000000000000000000000000000..79878ddb06d22cf66cb9205ff614f099971d589d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-3.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - subclassed array of length 1 +---*/ + +foo.prototype = [1]; +function foo() {} +var f = new foo(); +function cb() {} +assert.sameValue(f.reduce(cb), 1, 'f.reduce(cb)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-4.js new file mode 100644 index 0000000000000000000000000000000000000000..1cd409d21817ee8c0d75e608ffc22a3ccbc7eef2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-4.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - subclassed array with length more than 1 +---*/ + +foo.prototype = new SendableArray(1, 2, 3, 4); +function foo() {} +var f = new foo(); +function cb(prevVal, curVal, idx, obj) { + return prevVal + curVal; +} +assert.sameValue(f.reduce(cb), 10, 'f.reduce(cb)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-5.js new file mode 100644 index 0000000000000000000000000000000000000000..b5b1c0e152a9b4012458e37e916331b2f7b6a7ef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-5.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce reduces the array in ascending order of + indices(initialvalue present) +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + return prevVal + curVal; +} +var srcArr = ['1', '2', '3', '4', '5']; +assert.sameValue(srcArr.reduce(callbackfn, '0'), '012345', 'srcArr.reduce(callbackfn,"0")'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-6.js new file mode 100644 index 0000000000000000000000000000000000000000..e87522ff7a7919bf6b55cbeb45fe859169cf1e94 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-6.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - subclassed array when initialvalue + provided +---*/ + +foo.prototype = [1, 2, 3, 4]; +function foo() {} +var f = new foo(); +function cb(prevVal, curVal, idx, obj) { + return prevVal + curVal; +} +assert.sameValue(f.reduce(cb, -1), 9, 'f.reduce(cb,-1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-7.js new file mode 100644 index 0000000000000000000000000000000000000000..dde44809895addb5721310822dac8e0fa815142d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-7.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - subclassed array with length 1 and + initialvalue provided +---*/ + +foo.prototype = [1]; +function foo() {} +var f = new foo(); +function cb(prevVal, curVal, idx, obj) { + return prevVal + curVal; +} +assert.sameValue(f.reduce(cb, -1), 0, 'f.reduce(cb,-1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-8.js new file mode 100644 index 0000000000000000000000000000000000000000..569129ec7066f9b60ca2cdfeac60ea6a6b78de29 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-10-8.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce doesn't visit expandos +---*/ + +var callCnt = 0; +function callbackfn(prevVal, curVal, idx, obj) +{ + callCnt++; + return curVal; +} +var srcArr = ['1', '2', '3', '4', '5']; +srcArr["i"] = 10; +srcArr[true] = 11; +srcArr.reduce(callbackfn); +assert.sameValue(callCnt, 4, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..347c05c533215f21525962660abc0580a080664a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'length' is own data property on an + Array-like object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: 2 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-10.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-10.js new file mode 100644 index 0000000000000000000000000000000000000000..660d83854047f1c19b39495c4cc04ccf15ccf7ee --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-10.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to Array-like object, 'length' is + an inherited accessor property +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert.sameValue(SendableArray.prototype.reduce.call(child, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(child, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-11.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-11.js new file mode 100644 index 0000000000000000000000000000000000000000..b110de8dbc260624f82f7a108d902e9b379b73f6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-11.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to Array-like object, 'length' is + an own accessor property without a get function +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-12.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-12.js new file mode 100644 index 0000000000000000000000000000000000000000..c3606ac6b783d595bd6ab2031dcff89ad8a6ee16 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-12.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'length' is own accessor property without + a get function that overrides an inherited accessor property on an + Array +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +Object.defineProperty(Object.prototype, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var obj = { + 0: 12, + 1: 11 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-13.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-13.js new file mode 100644 index 0000000000000000000000000000000000000000..5da86d5a2cb2f60757ec97941b949ffff8ce2a10 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-13.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to Array-like object that 'length' + is inherited accessor property without a get function +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +var proto = {}; +Object.defineProperty(proto, "length", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 11; +child[1] = 12; +assert.sameValue(SendableArray.prototype.reduce.call(child, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(child, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-14.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-14.js new file mode 100644 index 0000000000000000000000000000000000000000..23420fc200de9efca4f0aaba3d4c55ff162effcf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-14.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to the Array-like object that + 'length' property doesn't exist +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 11, + 1: 12 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-17.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-17.js new file mode 100644 index 0000000000000000000000000000000000000000..915108cdc6762ae37fef2f46ac521ad46649e360 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-17.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to the Arguments object, which + implements its own property get method +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +var func = function(a, b) { + arguments[2] = 9; + return SendableArray.prototype.reduce.call(arguments, callbackfn, 1); +}; +assert.sameValue(func(12, 11), true, 'func(12, 11)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-18.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-18.js new file mode 100644 index 0000000000000000000000000000000000000000..519d52ceb5241ee8012f1896d6f6f0f29e367fd0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-18.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to String object, which implements + its own property get method +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 3); +} +var str = new String("012"); +assert.sameValue(SendableArray.prototype.reduce.call(str, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(str, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-19.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-19.js new file mode 100644 index 0000000000000000000000000000000000000000..ce7ec8af708315970c5ede6cc6297c9db0ba63cb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-19.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to Function object, which + implements its own property get method +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +var fun = function(a, b) { + return a + b; +}; +fun[0] = 12; +fun[1] = 11; +fun[2] = 9; +assert.sameValue(SendableArray.prototype.reduce.call(fun, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(fun, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..05c1a97c6303627a5f9b212a5974b4dcb7641e01 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-2.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - 'length' is own data property on an Array +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +assert.sameValue([12, 11].reduce(callbackfn, 1), true, '[12, 11].reduce(callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..1bb95f3176c6224d4002076382873319b1887687 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-3.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'length' is an own data property that + overrides an inherited data property on an Array-like object +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert.sameValue(SendableArray.prototype.reduce.call(child, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(child, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..1a4e1a86f9ab015a25bbeb60b22d1fbd01d847e9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'length' is own data property that + overrides an inherited data property on an Array +---*/ + +var storeProtoLength; +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +storeProtoLength = SendableArray.prototype.length; +SendableArray.prototype.length = 0; +assert.sameValue([12, 11].reduce(callbackfn, 1), true, '[12, 11].reduce(callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..552c68c0402611b50b3c6b6a79f523ded4e44335 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-5.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to Array-like object, 'length' is + an own data property that overrides an inherited accessor property +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + value: 2, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert.sameValue(SendableArray.prototype.reduce.call(child, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(child, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-6.js new file mode 100644 index 0000000000000000000000000000000000000000..073ba0ee2f98b92f2f5eae9bf1bdce03672010e0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-6.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to Array-like object, 'length' is + an inherited data property +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +var proto = { + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert.sameValue(SendableArray.prototype.reduce.call(child, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(child, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-7.js new file mode 100644 index 0000000000000000000000000000000000000000..a6ab3bdabd7f7d0f22bc805db2e88783f7ebae22 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-7.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to Array-like object, 'length' is + an own accessor property +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return 2; + }, + configurable: true +}); +obj[0] = 12; +obj[1] = 11; +obj[2] = 9; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-8.js new file mode 100644 index 0000000000000000000000000000000000000000..3ababd7fa3b5256aac5f2fb66479c4167e4e8028 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-8.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to Array-like object, 'length' is + an own accessor property that overrides an inherited data property +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert.sameValue(SendableArray.prototype.reduce.call(child, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(child, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-9.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-9.js new file mode 100644 index 0000000000000000000000000000000000000000..046c4b5df9303cb93426864fb15488252f579267 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-2-9.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce applied to Array-like object, 'length' is + an own accessor property that overrides an inherited accessor + property +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (obj.length === 2); +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert.sameValue(SendableArray.prototype.reduce.call(child, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(child, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-1.js new file mode 100644 index 0000000000000000000000000000000000000000..b87e54ed7049e9693667909b1ad333ddc80b3e45 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - value of 'length' is undefined +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return 2; +} +var obj = { + 0: 0, + 1: 1, + length: undefined +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-10.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-10.js new file mode 100644 index 0000000000000000000000000000000000000000..940c916e94d63fe0308e40e0d4de2533fbf3c678 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-10.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is number primitive + (value is NaN) +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return 2; +} +var obj = { + 0: 9, + length: NaN +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-11.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-11.js new file mode 100644 index 0000000000000000000000000000000000000000..c9fe6900660811837642fdcc47cbff690986c51f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-11.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'length' is a string containing a + positive number +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: "2" +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-12.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-12.js new file mode 100644 index 0000000000000000000000000000000000000000..13df83f7db83f30b261d59e6074390db6afb7a79 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-12.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'length' is a string containing a + negative number +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: "-4294967294" +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-13.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-13.js new file mode 100644 index 0000000000000000000000000000000000000000..321d96a3c7a8ae0f5cfe820430adcebb7e7f70ae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-13.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'length' is a string containing a decimal + number +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: "2.5" +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-14.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-14.js new file mode 100644 index 0000000000000000000000000000000000000000..157c6e6f1a6c644098d74d25988dfee33914396b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-14.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - 'length' is a string containing -Infinity +---*/ + +var accessed2 = false; +function callbackfn2(prevVal, curVal, idx, obj) { + accessed2 = true; + return 2; +} +var obj2 = { + 0: 9, + length: "-Infinity" +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj2, callbackfn2, 1), 1, 'SendableArray.prototype.reduce.call(obj2, callbackfn2, 1)'); +assert.sameValue(accessed2, false, 'accessed2'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-15.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-15.js new file mode 100644 index 0000000000000000000000000000000000000000..a8dcbbab7bf0749443a6dc4aa1cb6d2f22ea8c26 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-15.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'length' is a string containing an + exponential number +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: "2E0" +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-16.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-16.js new file mode 100644 index 0000000000000000000000000000000000000000..b42a67833189257697f6bae78bccd045c70b8679 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-16.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'length' is a string containing a hex + number +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: "0x0002" +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-17.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-17.js new file mode 100644 index 0000000000000000000000000000000000000000..5bc9d90b702aea746a3f4756d2984dbfe7f0ab95 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-17.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'length' is a string containing a number + with leading zeros +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: "0002.00" +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-18.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-18.js new file mode 100644 index 0000000000000000000000000000000000000000..6c0f7051a48ea779a061bd8cd2d8c128db753492 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-18.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is a string that can't + convert to a number +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return 2; +} +var obj = { + 0: 9, + length: "asdf!_" +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-19.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-19.js new file mode 100644 index 0000000000000000000000000000000000000000..5464f5f7c29a67ae3a9bf180ceeeca99b4f629f3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-19.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is an Object which has + an own toString method +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: { + toString: function() { + return '2'; + } + } +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-2.js new file mode 100644 index 0000000000000000000000000000000000000000..950663198a4f02934fd567c30b7a277618daf7fe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is a boolean (value is + true) +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 0); +} +var obj = { + 0: 11, + 1: 9, + length: true +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-20.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-20.js new file mode 100644 index 0000000000000000000000000000000000000000..6f097e6a8661df2c50606757feeed6a700b51931 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-20.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is an object which has + an own valueOf method +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: { + valueOf: function() { + return 2; + } + } +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-21.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-21.js new file mode 100644 index 0000000000000000000000000000000000000000..778a85ff69d1abc94da7cc57f5bd7bf6b67f8dfe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-21.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'length' is an object that has an own + valueOf method that returns an object and toString method that + returns a string +---*/ + +var valueOfOccured = false; +var toStringOccured = false; +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: { + valueOf: function() { + valueOfOccured = true; + return {}; + }, + toString: function() { + toStringOccured = true; + return '2'; + } + } +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert(valueOfOccured, 'valueOfOccured !== true'); +assert(toStringOccured, 'toStringOccured !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-22.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-22.js new file mode 100644 index 0000000000000000000000000000000000000000..2dbd8a5345214ffb95e4dd88e4f6771b51a42540 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-22.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError exception - 'length' is an + object with toString and valueOf methods that don�t return + primitive values +---*/ + +var accessed = false; +var valueOfAccessed = false; +var toStringAccessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return true; +} +var obj = { + 1: 11, + 2: 12, + length: { + valueOf: function() { + valueOfAccessed = true; + return {}; + }, + toString: function() { + toStringAccessed = true; + return {}; + } + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.reduce.call(obj, callbackfn, 1); +}); +assert.sameValue(accessed, false, 'accessed'); +assert(toStringAccessed, 'toStringAccessed !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-23.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-23.js new file mode 100644 index 0000000000000000000000000000000000000000..62cf997aafc929900dbc9df3b150f9ba8afb8aaa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-23.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce uses inherited valueOf method - 'length' is + an object with an own toString and inherited valueOf methods +---*/ + +var valueOfAccessed = false; +var toStringAccessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var proto = { + valueOf: function() { + valueOfAccessed = true; + return 2; + } +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.toString = function() { + toStringAccessed = true; + return '1'; +}; +var obj = { + 1: 11, + 2: 9, + length: child +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(toStringAccessed, false, 'toStringAccessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-24.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-24.js new file mode 100644 index 0000000000000000000000000000000000000000..199fbc04281399564fae48fc8855d4cfd11de4cc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-24.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is a positive + non-integer, ensure truncation occurs in the proper direction +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: 2.685 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-25.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-25.js new file mode 100644 index 0000000000000000000000000000000000000000..35865b961005ca65ffcdcceb662a70dd2c73b5af --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-25.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is a negative + non-integer +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: -4294967294.5 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-3.js new file mode 100644 index 0000000000000000000000000000000000000000..7e512f157f78fb611b43e14cb604e3ea4fe68d79 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - value of 'length' is a number (value is 0) +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return 2; +} +var obj = { + 0: 1, + 1: 1, + length: 0 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-4.js new file mode 100644 index 0000000000000000000000000000000000000000..0376cfe97ab6015c28f2933a0411edd20950d38d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-4.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is a number (value is + +0) +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return 2; +} +var obj = { + 0: 11, + length: +0 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-5.js new file mode 100644 index 0000000000000000000000000000000000000000..d7f67e707cd6aebfa5128a7f33b52b9baa004a66 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-5.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is a number (value is + -0) +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return 2; +} +var obj = { + 0: 11, + length: -0 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-6.js new file mode 100644 index 0000000000000000000000000000000000000000..4ae4c1b679119a78f23ca4f2aa23c985e003ebf6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-6.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is a number (value is + positive) +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: 2 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-7.js new file mode 100644 index 0000000000000000000000000000000000000000..897f09991a8441270b00ce91217c9a958c759509 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-7.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is a number (value is + negative) +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal === 11 && idx === 1); +} +var obj = { + 1: 11, + 2: 9, + length: -4294967294 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-9.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-9.js new file mode 100644 index 0000000000000000000000000000000000000000..6ea0098d4395343afd3078326a615d788994603e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-3-9.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'length' is a number (value is + -Infinity) +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + length: -Infinity +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduce.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..e2bd5d998d9f7013c86121c63fb5c9f285877d7a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce throws TypeError if callbackfn is undefined +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduce(); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-10.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-10.js new file mode 100644 index 0000000000000000000000000000000000000000..b66859450381e9e74a3794ad7ed2db13454bb8a0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-10.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - the exception is not thrown if exception + was thrown by step 2 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduce.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-11.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-11.js new file mode 100644 index 0000000000000000000000000000000000000000..597dfb0d67785d574bbac1e3df52824fb802f34b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-11.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - the exception is not thrown if exception + was thrown by step 3 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + throw new Test262Error(); + } + }; + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduce.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-12.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-12.js new file mode 100644 index 0000000000000000000000000000000000000000..8e01409b1062364302aea0a0e7ee4e8027e456fd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-12.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - 'callbackfn' is a function +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return curVal > 10; +} +assert.sameValue([11, 9].reduce(callbackfn, 1), false, '[11, 9].reduce(callbackfn, 1)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-15.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-15.js new file mode 100644 index 0000000000000000000000000000000000000000..da9847dd14c37897173aa77293638f3acb531f39 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-15.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - calling with no callbackfn is the same as + passing undefined for callbackfn +---*/ + +var obj = { + 10: 10 +}; +var lengthAccessed = false; +var loopAccessed = false; + +Object.defineProperty(obj, "length", { + get: function() { + lengthAccessed = true; + return 20; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + loopAccessed = true; + return 10; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduce.call(obj); +}); +assert(lengthAccessed, 'lengthAccessed !== true'); +assert.sameValue(loopAccessed, false, 'loopAccessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-2.js new file mode 100644 index 0000000000000000000000000000000000000000..10eb84479795e83740a4459422f0c997654e14ff --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws ReferenceError if callbackfn is + unreferenced +---*/ + +var arr = new SendableArray(10); +assert.throws(ReferenceError, function() { + arr.reduce(foo); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..42ec092ff90873c82aae32249d12c0923e41a434 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-3.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce throws TypeError if callbackfn is null +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduce(null); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..f6ea36a8713d068ae91cd406630bfbbc3f5d8fa6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-4.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce throws TypeError if callbackfn is boolean +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduce(true); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-5.js new file mode 100644 index 0000000000000000000000000000000000000000..aec2c3a3aa8d6aab73346014004ec75bc512b519 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-5.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce throws TypeError if callbackfn is number +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduce(5); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-6.js new file mode 100644 index 0000000000000000000000000000000000000000..29cf12f87e8e8627cb294dc76f7ee72881fb5020 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-6.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce throws TypeError if callbackfn is string +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduce("abc"); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-7.js new file mode 100644 index 0000000000000000000000000000000000000000..e9859c06cfb006993b2852acdb965633f274deb2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-7.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError if callbackfn is Object + without [[Call]] internal method +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduce(new Object()); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-8.js new file mode 100644 index 0000000000000000000000000000000000000000..1e27748d81687cbf86dbe7079e6a50de6aaaa63a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-8.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - side effects produced by step 2 are + visible when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + accessed = true; + return 2; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduce.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-9.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-9.js new file mode 100644 index 0000000000000000000000000000000000000000..dd6be35fd2c39ff12024415d49bbfae96fa4596d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-4-9.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - side effects produced by step 3 are + visible when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + accessed = true; + return "2"; + } + }; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduce.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..014b2deb053c7f49673f3ef2ccd070fecaf712d6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError if 'length' is 0 (empty + array), no initVal +---*/ + +function cb() {} +assert.throws(TypeError, function() { + [].reduce(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-10.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-10.js new file mode 100644 index 0000000000000000000000000000000000000000..7bf7c272565e4f571a200fac995f94c5b5c240a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-10.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - if exception occurs, it occurs after any + side-effects that might be produced by step 2 +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal > 10); +} +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + accessed = true; + return 0; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduce.call(obj, callbackfn); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-11.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-11.js new file mode 100644 index 0000000000000000000000000000000000000000..4c7764edeb0fb8d9a773bb0d18a50be2c3193b64 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-11.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - if the exception occurs, it occurs after + any side-effects that might be produced by step 3 +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal > 10); +} +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + accessed = true; + return "0"; + } + }; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduce.call(obj, callbackfn); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-12.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-12.js new file mode 100644 index 0000000000000000000000000000000000000000..1dc086388f5f4411e09f7bde4d50a661d7c08cb5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-12.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - the exception is not thrown if exception + was thrown by step 2 +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal > 10); +} +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduce.call(obj, callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-13.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-13.js new file mode 100644 index 0000000000000000000000000000000000000000..2033d58152f344307f9d957688e34be64088aaff --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-13.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - the exception is not thrown if exception + was thrown by step 3 +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return (curVal > 10); +} +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + throw new Test262Error(); + } + }; + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduce.call(obj, callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-2.js new file mode 100644 index 0000000000000000000000000000000000000000..3e4e3e8a8bc7f89435bea534338f42802e1f224b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError if 'length' is 0 + (subclassed Array, length overridden to null (type conversion)), + no initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = null; +function cb() {} +assert.throws(TypeError, function() { + f.reduce(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-3.js new file mode 100644 index 0000000000000000000000000000000000000000..cfcf306c01bd914126535f08d48bf4947148797c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-3.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError if 'length' is 0 + (subclassed Array, length overridden to false (type conversion)), + no initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = false; +function cb() {} +assert.throws(TypeError, function() { + f.reduce(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-4.js new file mode 100644 index 0000000000000000000000000000000000000000..634d7f11b215ad80c74da009278c8b9775a3083a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError if 'length' is 0 + (subclassed Array, length overridden to 0 (type conversion)), no + initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 0; +function cb() {} +assert.throws(TypeError, function() { + f.reduce(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-5.js new file mode 100644 index 0000000000000000000000000000000000000000..84f66fb512dbf2af6d811d17b3c4480f1452ca79 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-5.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError if 'length' is 0 + (subclassed Array, length overridden to '0' (type conversion)), no + initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = '0'; +function cb() {} +assert.throws(TypeError, function() { + f.reduce(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-6.js new file mode 100644 index 0000000000000000000000000000000000000000..22f09eb15d2520cf1d2982c655e896af4f6789e1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError if 'length' is 0 + (subclassed Array, length overridden with obj with valueOf), no + initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + valueOf: function() { + return 0; + } +}; +f.length = o; +function cb() {} +assert.throws(TypeError, function() { + f.reduce(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-7.js new file mode 100644 index 0000000000000000000000000000000000000000..ea8a88846a88481031f8e230c6bdbfbef1723878 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-7.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError if 'length' is 0 + (subclassed Array, length overridden with obj w/o valueOf + (toString)), no initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + toString: function() { + return '0'; + } +}; +f.length = o; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +function cb() {} +assert.throws(TypeError, function() { + f.reduce(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-8.js new file mode 100644 index 0000000000000000000000000000000000000000..d62c4d85aa3971f610aab9b11ee26abc6503c2d8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-8.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError if 'length' is 0 + (subclassed Array, length overridden with []), no initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = []; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +function cb() {} +assert.throws(TypeError, function() { + f.reduce(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-9.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-9.js new file mode 100644 index 0000000000000000000000000000000000000000..4d86473168e38526a7a6f088c6c2cbcd8dc21aab --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-5-9.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'initialValue' is returned if 'len' is 0 + and 'initialValue' is present +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +assert.sameValue([].reduce(callbackfn, 3), 3, '[].reduce(callbackfn, 3)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-1.js new file mode 100644 index 0000000000000000000000000000000000000000..66abaac79b0dff3f6a679b877f7c98d8691300ea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce returns initialValue if 'length' is 0 and + initialValue is present (empty array) +---*/ + +function cb() {} +assert.sameValue([].reduce(cb, 1), 1, '[].reduce(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-10.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-10.js new file mode 100644 index 0000000000000000000000000000000000000000..41a95c9d13955174b74cb044850e520d96822e11 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-10.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - 'initialValue' is present +---*/ + +var str = "initialValue is present"; +assert.sameValue([].reduce(function() {}, str), str, '[].reduce(function () { }, str)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-11.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-11.js new file mode 100644 index 0000000000000000000000000000000000000000..2745ab152c69b50247dda49f765cdea543d65db8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-11.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - 'initialValue' is not present +---*/ + +var str = "initialValue is not present"; +assert.sameValue([str].reduce(function() {}), str, '[str].reduce(function () { })'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-2.js new file mode 100644 index 0000000000000000000000000000000000000000..98f257b2ff33961c36ecd40d952dcce6dd6bc0fc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce returns initialValue if 'length' is 0 and + initialValue is present (subclassed Array, length overridden to + null (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = null; +function cb() {} +assert.sameValue(f.reduce(cb, 1), 1, 'f.reduce(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-3.js new file mode 100644 index 0000000000000000000000000000000000000000..2298b55cc0acdc5ec6c03b5c007bcac17e8f42fa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-3.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce returns initialValue if 'length' is 0 and + initialValue is present (subclassed Array, length overridden to + false (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = false; +function cb() {} +assert.sameValue(f.reduce(cb, 1), 1, 'f.reduce(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-4.js new file mode 100644 index 0000000000000000000000000000000000000000..17b1407f93a15bfdd7df2793b01418c2dadf0bbc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce returns initialValue if 'length' is 0 and + initialValue is present (subclassed Array, length overridden to 0 + (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 0; +function cb() {} +assert.sameValue(f.reduce(cb, 1), 1, 'f.reduce(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-5.js new file mode 100644 index 0000000000000000000000000000000000000000..e7c67581ca229e6812083cc34f30552ad717762f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-5.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce returns initialValue if 'length' is 0 and + initialValue is present (subclassed Array, length overridden to + '0' (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = '0'; +function cb() {} +assert.sameValue(f.reduce(cb, 1), 1, 'f.reduce(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-6.js new file mode 100644 index 0000000000000000000000000000000000000000..566ebc0aba5fd586d82a769138c120bd7258e219 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-6.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce returns initialValue if 'length' is 0 and + initialValue is present (subclassed Array, length overridden with + obj with valueOf) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + valueOf: function() { + return 0; + } +}; +f.length = o; +function cb() {} +assert.sameValue(f.reduce(cb, 1), 1, 'f.reduce(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-7.js new file mode 100644 index 0000000000000000000000000000000000000000..61f662a35e2ea9db058fd491ce0821ae50ad96ea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-7.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce returns initialValue if 'length' is 0 and + initialValue is present (subclassed Array, length overridden with + obj w/o valueOf (toString)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + toString: function() { + return '0'; + } +}; +f.length = o; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +function cb() {} +assert.sameValue(f.reduce(cb, 1), 1, 'f.reduce(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-8.js new file mode 100644 index 0000000000000000000000000000000000000000..dd3138a9cf450f10802fe313a75cd46cbdfa1b35 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-8.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce returns initialValue if 'length' is 0 and + initialValue is present (subclassed Array, length overridden with + []) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = []; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +function cb() {} +assert.sameValue(f.reduce(cb, 1), 1, 'f.reduce(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-9.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-9.js new file mode 100644 index 0000000000000000000000000000000000000000..ce6126733fcf90287dedd679fa59dc2a1de73306 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-7-9.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce returns initialValue if 'length' is 0 and + initialValue is present (subclassed Array, length overridden with + [0]) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = [0]; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +function cb() {} +assert.sameValue(f.reduce(cb, 1), 1, 'f.reduce(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..b40c37f51b769df371bda578d9a8bde0e3114e9d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-1.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - no observable effects occur if 'len' is 0 +---*/ + +var accessed = false; +var obj = { + length: 0 +}; +Object.defineProperty(obj, "0", { + get: function() { + accessed = true; + return 10; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduce.call(obj, function() {}); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-2.js new file mode 100644 index 0000000000000000000000000000000000000000..ef43ebcde550566ab562273a3505f6f0222fc957 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-2.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - modifications to length don't change + number of iterations in step 9 +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + return idx; +} +var obj = { + 3: 12, + 4: 9, + length: 4 +}; +Object.defineProperty(obj, "2", { + get: function() { + obj.length = 10; + return 11; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn), 3, 'SendableArray.prototype.reduce.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-3.js new file mode 100644 index 0000000000000000000000000000000000000000..84a0971b6b40b3cf2d882ffc1bc69ae8d11410da --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-3.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - loop is broken once 'kPresent' is true +---*/ + +var called = 0; +var testResult = false; +var firstCalled = 0; +var secondCalled = 0; +function callbackfn(prevVal, val, idx, obj) { + if (called === 0) { + testResult = (idx === 1); + } + called++; +} +var arr = [, , ]; +Object.defineProperty(arr, "0", { + get: function() { + firstCalled++; + return 11; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + secondCalled++; + return 9; + }, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); +assert.sameValue(firstCalled, 1, 'firstCalled'); +assert.sameValue(secondCalled, 1, 'secondCalled'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-ii-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..be5b1303ef9c47f88df13accf475f3118bf97ada --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-ii-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - added properties in step 2 are visible + here +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + obj[1] = "accumulator"; + return 3; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.reduce.call(obj, function() {}), "accumulator", 'SendableArray.prototype.reduce.call(obj, function () { })'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-ii-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-ii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..5545bba0d2669be4d521b87ebb1323a48433cc37 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-ii-2.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleted properties in step 2 are visible + here +---*/ + +var obj = { + 1: "accumulator", + 2: "another" +}; +Object.defineProperty(obj, "length", { + get: function() { + delete obj[1]; + return 3; + }, + configurable: true +}); +assert.notSameValue(SendableArray.prototype.reduce.call(obj, function() {}), "accumulator", 'SendableArray.prototype.reduce.call(obj, function () { })'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..e70f3b433988ea355f7bdcea57dc343435701a4a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-1.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +var obj = { + 0: 0, + 1: 1, + 2: 2, + length: 2 +}; +SendableArray.prototype.reduce.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-10.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..2cd00b96cebde693bd29154a7be26ce4c0a69ae8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-10.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - when element to be retrieved is own + accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +var arr = [, 1, 2]; +Object.defineProperty(arr, "0", { + get: function() { + return 0; + }, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-11.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..80c04f0a9c3763c8d97b3b4974bc79061950f904 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-11.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property that overrides an inherited data property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "9"); + } +} +var proto = { + 0: 0, + 1: 1, + 2: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +Object.defineProperty(child, "0", { + get: function() { + return "9"; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-12.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..62c5c6da61af9bded6eeb5c54d7731818e41e70a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-12.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property that overrides an inherited data property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "9"); + } +} +SendableArray.prototype[0] = 0; +var arr = [, 1, 2]; +Object.defineProperty(arr, "0", { + get: function() { + return "9"; + }, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-13.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..c2f65173a12b623b76e72bf5d49556b2baa6721f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-13.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "9"); + } +} +var proto = { + 1: 1, + 2: 2 +}; +Object.defineProperty(proto, "0", { + get: function() { + return 0; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +Object.defineProperty(child, "0", { + get: function() { + return "9"; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-14.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-14.js new file mode 100644 index 0000000000000000000000000000000000000000..97e2f63ad093479074e81629373f03eaa02e9c9d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-14.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property that overrides an inherited accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "9"); + } +} +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 0; + }, + configurable: true +}); +var arr = [, 1, 2]; +Object.defineProperty(arr, "0", { + get: function() { + return "9"; + }, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-15.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..af51fdb801eb3432867dc363324847bcb36b8a7d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-15.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited + accessor property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +var proto = { + 1: 1, + 2: 2 +}; +Object.defineProperty(proto, "0", { + get: function() { + return 0; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +SendableArray.prototype.reduce.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-16.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-16.js new file mode 100644 index 0000000000000000000000000000000000000000..948291a4ac9644e0e20721d05dfc070b2ed55425 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-16.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited + accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 0; + }, + configurable: true +}); +var arr = [, 1, 2]; +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-17.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-17.js new file mode 100644 index 0000000000000000000000000000000000000000..ff760fdbd256b38de51381cc4b95be889de6ba30 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-17.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property without a get function on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === undefined); + } +} +var obj = { + 1: 1, + 2: 2, + length: 3 +}; +Object.defineProperty(obj, "0", { + set: function() {}, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-18.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-18.js new file mode 100644 index 0000000000000000000000000000000000000000..8623565c0762c5afdf290add0f7af5b09c3085d9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-18.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property without a get function on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === undefined); + } +} +var arr = [, 1, 2]; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-19.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-19.js new file mode 100644 index 0000000000000000000000000000000000000000..84936da3d70018d4f85d7006f9bd77493bf71b1a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-19.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === undefined); + } +} +Object.prototype[0] = 0; +var obj = { + 1: 1, + 2: 2, + length: 3 +}; +Object.defineProperty(obj, "0", { + set: function() {}, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..9dd26130d8a8e6f1d1cb3f35266e23937a699fd4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +var arr = [0, 1, 2]; +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-20.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-20.js new file mode 100644 index 0000000000000000000000000000000000000000..e16081bbc79e7eea57f38703f916958871727a8a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-20.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === undefined); + } +} +SendableArray.prototype[0] = 0; +var arr = [, 1, 2]; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-21.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-21.js new file mode 100644 index 0000000000000000000000000000000000000000..d506b62a1935b1d70b4ed972a702427dc268f29d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-21.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited + accessor property without a get function on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === undefined); + } +} +var proto = { + 1: 1, + 2: 2 +}; +Object.defineProperty(proto, "0", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +SendableArray.prototype.reduce.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-22.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-22.js new file mode 100644 index 0000000000000000000000000000000000000000..45cfa457e4fa023f20174543fdaa21ee8f6b441e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-22.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited + accessor property without a get function on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === undefined); + } +} +Object.defineProperty(SendableArray.prototype, "0", { + set: function() {}, + configurable: true +}); +var arr = [, 1, 2]; +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-25.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-25.js new file mode 100644 index 0000000000000000000000000000000000000000..54c44238618489ffc4eb2778a86531ebaec13f60 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-25.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - This object is the Arguments object which + implements its own property get method (number of arguments is + less than number of parameters) +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +var func = function(a, b, c) { + SendableArray.prototype.reduce.call(arguments, callbackfn); +}; +func(0, 1); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-26.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-26.js new file mode 100644 index 0000000000000000000000000000000000000000..634c26af23dce76ccc3a67b448a7b108db8fde0a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-26.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - This object is the Arguments object which + implements its own property get method (number of arguments equals + number of parameters) +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 2) { + testResult = (prevVal === 1); + } +} +var func = function(a, b, c) { + delete arguments[0]; + SendableArray.prototype.reduce.call(arguments, callbackfn); +}; +func(0, 1, 2); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-27.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-27.js new file mode 100644 index 0000000000000000000000000000000000000000..6185b26ffad4e9316c94aac20c3c1bfc43cc71af --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-27.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - This object is the Arguments object which + implements its own property get method (number of arguments is + greater than number of parameters) +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 3) { + testResult = (prevVal === 2); + } +} +var func = function(a, b, c) { + delete arguments[0]; + delete arguments[1]; + SendableArray.prototype.reduce.call(arguments, callbackfn); +}; +func(0, 1, 2, 3); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-28.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-28.js new file mode 100644 index 0000000000000000000000000000000000000000..03eb033029d4877144d44fe236c4a5736794621f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-28.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - applied to String object, which + implements its own property get method +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "0"); + } +} +var str = new String("012"); +SendableArray.prototype.reduce.call(str, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-29.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-29.js new file mode 100644 index 0000000000000000000000000000000000000000..81864e2780b0430286c0e500a0ac8a81506927ab --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-29.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - applied to Function object which + implements its own property get method +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +var obj = function(a, b, c) { + return a + b + c; +}; +obj[0] = 0; +obj[1] = 1; +obj[2] = 2; +obj[3] = 3; +SendableArray.prototype.reduce.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..5fb1cbff7e0d5a3985f259665a482bde53437dbc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-3.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property that overrides an inherited data property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "9"); + } +} +var proto = { + 0: 0, + 1: 1, + 2: 2, + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = "9"; +child[1] = "1"; +child.length = 3; +SendableArray.prototype.reduce.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-30.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-30.js new file mode 100644 index 0000000000000000000000000000000000000000..2279635b7db6998e8c8e2ae5375a9387bfd62712 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-30.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element changed by getter on current + iterations is observed in subsequent iterations on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var arr = [, , 2]; +var preIterVisible = false; +Object.defineProperty(arr, "0", { + get: function() { + preIterVisible = true; + return 0; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + if (preIterVisible) { + return 1; + } else { + return 100; + } + }, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-31.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-31.js new file mode 100644 index 0000000000000000000000000000000000000000..0c98a17bb2879d5c6fea90b1e9befaacdb76fbf1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-31.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element changed by getter on current + iterations is observed in subsequent iterations on an Array-like + object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var obj = { + length: 2 +}; +var preIterVisible = false; +Object.defineProperty(obj, "0", { + get: function() { + preIterVisible = true; + return 0; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + if (preIterVisible) { + return 1; + } else { + return 100; + } + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-32.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-32.js new file mode 100644 index 0000000000000000000000000000000000000000..50b3b8ce0d13effee6389e5d76eb99b33a7c003b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-32.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - exception in getter terminates iteration + on an Array-like object +---*/ + +var accessed = false; +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx >= 1) { + accessed = true; + testResult = (prevVal === 0); + } +} +var obj = { + 2: 2, + 1: 1, + length: 3 +}; +Object.defineProperty(obj, "0", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + SendableArray.prototype.reduce.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); +assert.sameValue(testResult, false, 'testResult'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-33.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-33.js new file mode 100644 index 0000000000000000000000000000000000000000..154e4a7dafd0821b19d6ad7f23130965aaece93b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-33.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - exception in getter terminates iteration + on an Array +---*/ + +var accessed = false; +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx >= 1) { + accessed = true; + testResult = (prevVal === 0); + } +} +var arr = [, 1, 2]; +Object.defineProperty(arr, "0", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + arr.reduce(callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); +assert.sameValue(testResult, false, 'testResult'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..2b51ba04e235e74647c0f25bc102e1fa861f91d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +SendableArray.prototype[0] = "9"; +[0, 1, 2].reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..36ac7658aa3fb651aba50f83be64066ad8d3d96e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-5.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "9"); + } +} +var proto = {}; +Object.defineProperty(proto, "0", { + get: function() { + return 0; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +Object.defineProperty(child, "0", { + value: "9", + configurable: true +}); +child[1] = "1"; +SendableArray.prototype.reduce.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..14d40cf153d58475f8fdad6d7e862f0d46a90ff0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property that overrides an inherited accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return "5"; + }, + configurable: true +}); +[0, 1, 2].reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..b7eae96b8c9014b836b24d609469edc1553ff927 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-7.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited data + property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +var proto = { + 0: 0, + 1: 1, + 2: 2, + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +SendableArray.prototype.reduce.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..8c5162d83152a23d573e3369c46e8b8ec6dc3ee0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-8.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited data + property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +SendableArray.prototype[0] = 0; +SendableArray.prototype[1] = 1; +SendableArray.prototype[2] = 2; +[, , , ].reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-9.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..e0f97e2e2d969305f70d3a72751e6d013ea2ec27 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-b-iii-1-9.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 0); + } +} +var obj = { + 1: 1, + 2: 2, + length: 3 +}; +Object.defineProperty(obj, "0", { + get: function() { + return 0; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-1.js new file mode 100644 index 0000000000000000000000000000000000000000..4ea20161ad7072a8d771d58a6237ccf4965ce60e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-1.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError when Array is empty and + initialValue is not present +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{} +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduce(callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-2.js new file mode 100644 index 0000000000000000000000000000000000000000..cec800b6e1eb53ab8f1d9f09cc2d7618ff7dde2c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError when elements assigned + values are deleted by reducing array length and initialValue is + not present +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{} +var arr = new SendableArray(10); +arr[9] = 1; +arr.length = 5; +assert.throws(TypeError, function() { + arr.reduce(callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-3.js new file mode 100644 index 0000000000000000000000000000000000000000..d99f243f4765128560605a1d122db342efe9d8af --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-3.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce throws TypeError when elements assigned + values are deleted and initialValue is not present +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{} +var arr = [1, 2, 3, 4, 5]; +delete arr[0]; +delete arr[1]; +delete arr[2]; +delete arr[3]; +delete arr[4]; +assert.throws(TypeError, function() { + arr.reduce(callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-4.js new file mode 100644 index 0000000000000000000000000000000000000000..34c8373a3e76aba7a46552f098455e88061b94a5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce doesn't throw error when array has no own + properties but prototype contains a single property +---*/ + +var arr = [, , , ]; +try { + SendableArray.prototype[1] = "prototype"; + arr.reduce(function() {}); +} finally { + delete SendableArray.prototype[1]; +} diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-5.js new file mode 100644 index 0000000000000000000000000000000000000000..2681664e504ab42002e1f403aee800463ea9bf3b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-5.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - if exception occurs, it occurs after any + side-effects that might be produced by step 2 +---*/ + +var obj = {}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + accessed = true; + return 2; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduce.call(obj, function() {}); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-6.js new file mode 100644 index 0000000000000000000000000000000000000000..404c0b3a450d1fa6c471916b0569da8633406a98 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-6.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - if exception occurs, it occurs after any + side-effects that might be produced by step 3 +---*/ + +var obj = {}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + accessed = true; + return "2"; + } + }; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduce.call(obj, function() {}); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-7.js new file mode 100644 index 0000000000000000000000000000000000000000..8dcc92cb4e545e5b323a25d48c82681d54e0d2b6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-7.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - the exception is not thrown if exception + was thrown by step 2 +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduce.call(obj, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-8.js new file mode 100644 index 0000000000000000000000000000000000000000..ea37dab36335e33a09728676afd62ce8bdd5ba0f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-8-c-8.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - the exception is not thrown if exception + was thrown by step 3 +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + throw new Test262Error(); + } + }; + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduce.call(obj, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-1.js new file mode 100644 index 0000000000000000000000000000000000000000..63bd18ae3d0199462da64d8832fff086fe8b0013 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-1.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce doesn't consider new elements added to + array after it is called +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + arr[5] = 6; + arr[2] = 3; + return prevVal + curVal; +} +var arr = [1, 2, , 4, '5']; +assert.sameValue(arr.reduce(callbackfn), "105", 'arr.reduce(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-10.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-10.js new file mode 100644 index 0000000000000000000000000000000000000000..bf5d3f1095d2df54e0fe5822c7f349dbdb875f13 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-10.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce called with an initial value doesn't + consider new elements added to array after it is called +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + arr[5] = 6; + arr[2] = 3; + return prevVal + curVal; +} +var arr = [1, 2, , 4, '5']; +assert.sameValue(arr.reduce(callbackfn, ""), "12345", 'arr.reduce(callbackfn, "")'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-2.js new file mode 100644 index 0000000000000000000000000000000000000000..77e3945499a949d76acc4738ea66f8bbed49adbd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce considers new value of elements in array + after it is called +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + arr[3] = -2; + arr[4] = -1; + return prevVal + curVal; +} +var arr = [1, 2, 3, 4, 5]; +assert.sameValue(arr.reduce(callbackfn), 3, 'arr.reduce(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-3.js new file mode 100644 index 0000000000000000000000000000000000000000..a3db68e10be33c20d122c4bbcadc13146a52319e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-3.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce doesn't visit deleted elements in array + after the call +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + delete arr[3]; + delete arr[4]; + return prevVal + curVal; +} +var arr = ['1', 2, 3, 4, 5]; +// two elements deleted +assert.sameValue(arr.reduce(callbackfn), "123", 'arr.reduce(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-4.js new file mode 100644 index 0000000000000000000000000000000000000000..31752c180058d457a261c22a142a5b096fa9dddb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce doesn't visit deleted elements when + Array.length is decreased +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + arr.length = 2; + return prevVal + curVal; +} +var arr = [1, 2, 3, 4, 5]; +assert.sameValue(arr.reduce(callbackfn), 3, 'arr.reduce(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-5.js new file mode 100644 index 0000000000000000000000000000000000000000..5976cb236d66743a08b6560a22f6c54a83bfaf00 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-5.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - callbackfn not called for array with one + element +---*/ + +var callCnt = 0; +function callbackfn(prevVal, curVal, idx, obj) +{ + callCnt++; + return 2; +} +var arr = [1]; +assert.sameValue(arr.reduce(callbackfn), 1, 'arr.reduce(callbackfn)'); +assert.sameValue(callCnt, 0, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-6.js new file mode 100644 index 0000000000000000000000000000000000000000..870fabf61fc18871eab71c4d4ddd97a910e81502 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-6.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce visits deleted element in array after the + call when same index is also present in prototype +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + delete arr[3]; + delete arr[4]; + return prevVal + curVal; +} +SendableArray.prototype[4] = 5; +var arr = ['1', 2, 3, 4, 5]; +var res = arr.reduce(callbackfn); +delete SendableArray.prototype[4]; +//one element acually deleted +assert.sameValue(res, "1235", 'res'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-7.js new file mode 100644 index 0000000000000000000000000000000000000000..0226cb97622d79617373b89b4f604b4cf7664a4d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-7.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce stops calling callbackfn once the array is + deleted during the call +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + delete o.arr; + return prevVal + curVal; +} +var o = new Object(); +o.arr = ['1', 2, 3, 4, 5]; +assert.sameValue(o.arr.reduce(callbackfn), "12345", 'o.arr.reduce(callbackfn)'); +assert.sameValue(o.hasOwnProperty("arr"), false, 'o.hasOwnProperty("arr")'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-8.js new file mode 100644 index 0000000000000000000000000000000000000000..fa9118186a2331cbfa3368146dd49cd553f824cc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-8.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - no observable effects occur if 'len' is 0 +---*/ + +var accessed = false; +var callbackAccessed = false; +function callbackfn() { + callbackAccessed = true; +} +var obj = { + length: 0 +}; +Object.defineProperty(obj, "0", { + get: function() { + accessed = true; + return 10; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn, "initialValue"); +assert.sameValue(accessed, false, 'accessed'); +assert.sameValue(callbackAccessed, false, 'callbackAccessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-9.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-9.js new file mode 100644 index 0000000000000000000000000000000000000000..67500633822e30986d67d1bdde125df90bba9859 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-9.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - modifications to length don't change + number of iterations in step 9 +---*/ + +var called = 0; +function callbackfn(accum, val, idx, obj) { + called++; + return accum + val; +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 2; + return 0; + }, + configurable: true +}); +var newAccum = arr.reduce(callbackfn, "initialValue"); +assert.sameValue(newAccum, "initialValue01", 'newAccum'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..adba265cce3ccb810456f56bf3bf407e4ac8451c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce returns initialvalue when Array is empty + and initialValue is present +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{} +var arr = new SendableArray(10); +assert.sameValue(arr.reduce(callbackfn, 5), 5, 'arr.reduce(callbackfn,5)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-10.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-10.js new file mode 100644 index 0000000000000000000000000000000000000000..49bb0eb9d1b74fe1e60898ce8ad98c10f2a18f4d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-10.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting property of prototype in step 8 + causes deleted index property not to be visited on an Array-like + Object +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(accum, val, idx, obj) { + accessed = true; + if (idx === 3) { + testResult = false; + } +} +var obj = { + 2: 2, + length: 20 +}; +Object.defineProperty(obj, "0", { + get: function() { + delete Object.prototype[3]; + return 0; + }, + configurable: true +}); +Object.prototype[3] = 1; +SendableArray.prototype.reduce.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-11.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-11.js new file mode 100644 index 0000000000000000000000000000000000000000..1c2545749575e387e4e80eebc61e079cc68f38fb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-11.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting property of prototype in step 8 + causes deleted index property not to be visited on an Array +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(accum, val, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var arr = [, , , 3]; +Object.defineProperty(arr, "0", { + get: function() { + delete SendableArray.prototype[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-12.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-12.js new file mode 100644 index 0000000000000000000000000000000000000000..0f6a125726960049bc8d8b0bfab142fdbf82a019 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-12.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting own property with prototype + property in step 8 causes prototype index property to be visited + on an Array-like object +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 1 && val === 1) { + testResult = true; + } +} +var obj = { + 0: 0, + 1: 111, + 4: 10, + length: 10 +}; +Object.defineProperty(obj, "0", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +SendableArray.prototype.reduce.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-13.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-13.js new file mode 100644 index 0000000000000000000000000000000000000000..48f3a949e3b6543c1bad0f8cc2bf616ae678bb55 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-13.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting own property with prototype + property in step 8 causes prototype index property to be visited + on an Array +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 1 && val === 1) { + testResult = true; + } +} +var arr = [0, 111]; +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-14.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-14.js new file mode 100644 index 0000000000000000000000000000000000000000..8380e16ac63687a6bded8e122828bf51a5a37f09 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-14.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - decreasing length of array in step 8 + causes deleted index property not to be visited +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(accum, val, idx, obj) { + accessed = true; + if (idx === 2) { + testResult = false; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 2; + return 0; + }, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-15.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-15.js new file mode 100644 index 0000000000000000000000000000000000000000..95908f0c98d1ced10b05cfaed58a7573fa5bc619 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-15.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - decreasing length of array with prototype + property in step 8 causes prototype index property to be visited +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 2 && val === "prototype") { + testResult = true; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return "prototype"; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-16.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-16.js new file mode 100644 index 0000000000000000000000000000000000000000..2ebf137a1785ce56d5500bf2c962affe3a3bfab6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-16.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - decreasing length of array in step 8 does + not delete non-configurable properties +flags: [noStrict] +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 2 && val === "unconfigurable") { + testResult = true; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "2", { + get: function() { + return "unconfigurable"; + }, + configurable: false +}); +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-17.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-17.js new file mode 100644 index 0000000000000000000000000000000000000000..5d23b3caddcd89ec1bc8ea65a8706c950885137a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-17.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - properties added into own object are + visited on an Array-like object +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 3 && val === 3) { + testResult = true; + } +} +var obj = { + length: 5 +}; +Object.defineProperty(obj, "1", { + get: function() { + Object.defineProperty(obj, "3", { + get: function() { + return 3; + }, + configurable: true + }); + return 1; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-18.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-18.js new file mode 100644 index 0000000000000000000000000000000000000000..7332ce9966bd9da5a3a5da94a6ab6471c7098aad --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-18.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - properties added into own object are + visited on an Array +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 1 && val === 1) { + testResult = true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +arr.reduce(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-19.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-19.js new file mode 100644 index 0000000000000000000000000000000000000000..724876740ae9a1db34f775d60c01a2a712328ff5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-19.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - properties added to prototype are visited + on an Array-like object +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 1 && val === 6.99) { + testResult = true; + } +} +var obj = { + length: 6 +}; +Object.defineProperty(obj, "0", { + get: function() { + Object.defineProperty(Object.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-2.js new file mode 100644 index 0000000000000000000000000000000000000000..ba533609fcde12356da082deaad0f818d66c688a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-2.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - added properties in step 2 are visible + here +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 2 && val === "2") { + testResult = true; + } +} +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + obj[2] = "2"; + return 3; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-20.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-20.js new file mode 100644 index 0000000000000000000000000000000000000000..07c7706dcd1bd6880094771ff817eeb688a6139e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-20.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - properties can be added to prototype are + visited on an Array +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 1 && val === 6.99) { + testResult = true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +arr.reduce(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-21.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-21.js new file mode 100644 index 0000000000000000000000000000000000000000..2992af8e2f123b755f9fb1fbda487106ade6c631 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-21.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting own property causes deleted + index property not to be visited on an Array-like object +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(accum, val, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var obj = { + 5: 10, + length: 10 +}; +Object.defineProperty(obj, "1", { + get: function() { + return 6.99; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-22.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-22.js new file mode 100644 index 0000000000000000000000000000000000000000..0e5bc8d948ed31979f864792780b973c16952ca7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-22.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting own property causes deleted + index property not to be visited on an Array +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(accum, val, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var arr = [1, 2, 4]; +Object.defineProperty(arr, "1", { + get: function() { + return "6.99"; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +arr.reduce(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-23.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-23.js new file mode 100644 index 0000000000000000000000000000000000000000..bacaaac8dde925c2fa138e89e54248aca964d415 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-23.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting property of prototype causes + deleted index property not to be visited on an Array-like Object +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(accum, val, idx, obj) { + accessed = true; + if (idx === 3) { + testResult = false; + } +} +var obj = { + 2: 2, + length: 20 +}; +Object.defineProperty(obj, "0", { + get: function() { + delete Object.prototype[3]; + return 0; + }, + configurable: true +}); +Object.prototype[3] = 1; +SendableArray.prototype.reduce.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-24.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-24.js new file mode 100644 index 0000000000000000000000000000000000000000..c0993087d5450f6cd044cd8141857a198d2645b3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-24.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting property of prototype causes + deleted index property not to be visited on an Array +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(accum, val, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var arr = [0, , , 3]; +Object.defineProperty(arr, "0", { + get: function() { + delete SendableArray.prototype[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +arr.reduce(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-25.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-25.js new file mode 100644 index 0000000000000000000000000000000000000000..ed369e6b12931044bd3426e8050fcc40f052fd73 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-25.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting own property with prototype + property causes prototype index property to be visited on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 1 && val === 1) { + testResult = true; + } +} +var obj = { + 0: 0, + 1: 111, + 4: 10, + length: 10 +}; +Object.defineProperty(obj, "0", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +SendableArray.prototype.reduce.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-26.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-26.js new file mode 100644 index 0000000000000000000000000000000000000000..f06aa2c5bf1a980df27aec45c25287a0ae459b24 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-26.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting own property with prototype + property causes prototype index property to be visited on an Array +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 1 && val === 1) { + testResult = true; + } +} +var arr = [0, 111]; +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +arr.reduce(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-27.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-27.js new file mode 100644 index 0000000000000000000000000000000000000000..758d8bdcb5b1808413ae0403fcf7a6bb57267040 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-27.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - decreasing length of array causes deleted + index property not to be visited +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(accum, val, idx, obj) { + accessed = true; + if (idx === 2) { + testResult = false; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 2; + return 0; + }, + configurable: true +}); +arr.reduce(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-28.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-28.js new file mode 100644 index 0000000000000000000000000000000000000000..abef7bea4fb0a840733cc045f65bb87d2abc5778 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-28.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - decreasing length of array with prototype + property causes prototype index property to be visited +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 2 && val === "prototype") { + testResult = true; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return "prototype"; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +arr.reduce(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-29.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-29.js new file mode 100644 index 0000000000000000000000000000000000000000..600ce8c02df9901be150cffac6c32253086e3a78 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-29.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - decreasing length of array does not + delete non-configurable properties +flags: [noStrict] +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 2 && val === "unconfigurable") { + testResult = true; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "2", { + get: function() { + return "unconfigurable"; + }, + configurable: false +}); +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +arr.reduce(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-3.js new file mode 100644 index 0000000000000000000000000000000000000000..dce3dfffb974edd7d544d39c79710480c7e56c1b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-3.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleted properties in step 2 are visible + here +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(accum, val, idx, obj) { + accessed = true; + if (idx === 2) { + testResult = false; + } +} +var obj = { + 2: "2", + 3: 10 +}; +Object.defineProperty(obj, "length", { + get: function() { + delete obj[2]; + return 5; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn, "initialValue"); +assert(accessed, 'accessed !== true'); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-4.js new file mode 100644 index 0000000000000000000000000000000000000000..f5d3f15ccbaa71e2e5d9b83d8f4ef6d41753a2d8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-4.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - properties added into own object in step + 8 are visited on an Array-like object +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 3 && val === 3) { + testResult = true; + } +} +var obj = { + length: 5 +}; +Object.defineProperty(obj, "1", { + get: function() { + Object.defineProperty(obj, "3", { + get: function() { + return 3; + }, + configurable: true + }); + return 1; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-5.js new file mode 100644 index 0000000000000000000000000000000000000000..203a5b5e7bf9c22ca554e50840b67318939d9398 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-5.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - properties added into own object in step + 8 are visited on an Array +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 1 && val === 1) { + testResult = true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-6.js new file mode 100644 index 0000000000000000000000000000000000000000..6fd012f9aa7ca0b8ca49d5f5c60984f5aa7e5197 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-6.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - properties added to prototype in step 8 + are visited on an Array-like object +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 1 && val === 6.99) { + testResult = true; + } +} +var obj = { + length: 6 +}; +Object.defineProperty(obj, "0", { + get: function() { + Object.defineProperty(Object.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-7.js new file mode 100644 index 0000000000000000000000000000000000000000..fa3bf912bd7768014bf0bab6d7323f919ce98754 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-7.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - properties added to prototype in step 8 + are visited on an Array +---*/ + +var testResult = false; +function callbackfn(accum, val, idx, obj) { + if (idx === 1 && val === 6.99) { + testResult = true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-8.js new file mode 100644 index 0000000000000000000000000000000000000000..f0c698fa625c84191170cb2f7a9415d1a2682bce --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-8.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting own property in step 8 causes + deleted index property not to be visited on an Array-like object +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(accum, val, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var obj = { + 5: 10, + length: 10 +}; +Object.defineProperty(obj, "1", { + get: function() { + return 6.99; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-9.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-9.js new file mode 100644 index 0000000000000000000000000000000000000000..eccaacdd4e4e3179a6f13d3a1aa0099049cf2d4a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-b-9.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - deleting own property in step 8 causes + deleted index property not to be visited on an Array +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(accum, val, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var arr = [1, 2, 4]; +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +arr.reduce(callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-1.js new file mode 100644 index 0000000000000000000000000000000000000000..9fd40de4f9aceded52e2cd620024ca394a7d0e36 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - callbackfn not called for indexes never + been assigned values +---*/ + +var callCnt = 0; +function callbackfn(prevVal, curVal, idx, obj) +{ + callCnt++; + return curVal; +} +var arr = new SendableArray(10); +arr[0] = arr[1] = undefined; //explicitly assigning a value +assert.sameValue(arr.reduce(callbackfn), undefined, 'arr.reduce(callbackfn)'); +assert.sameValue(callCnt, 1, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-1.js new file mode 100644 index 0000000000000000000000000000000000000000..f28cdbcf7ee1837f31e7ce5e2b3b2366c08a4ccd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-1.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property on an Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var obj = { + 0: 0, + 1: 1, + 2: 2, + length: 2 +}; +SendableArray.prototype.reduce.call(obj, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-10.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-10.js new file mode 100644 index 0000000000000000000000000000000000000000..dbd076afc77bc41d08263e5af436019af4ac1df5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-10.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true +}); +arr.reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-11.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-11.js new file mode 100644 index 0000000000000000000000000000000000000000..2a251665355b3b7d746110b5aa26ed9dcb2e81cc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-11.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property that overrides an inherited data property on an + Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "11"); + } +} +var proto = { + 0: 0, + 1: 1, + 2: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +Object.defineProperty(child, "1", { + get: function() { + return "11"; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(child, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-12.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-12.js new file mode 100644 index 0000000000000000000000000000000000000000..449f26ed06a4bc11afbd9cb5b30b189d04ec99a2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-12.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property that overrides an inherited data property on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "11"); + } +} +SendableArray.prototype[1] = 1; +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + get: function() { + return "11"; + }, + configurable: true +}); +arr.reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-13.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-13.js new file mode 100644 index 0000000000000000000000000000000000000000..4536d2f6a74983e384d91f66e66d5a9012ac5edf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-13.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "11"); + } +} +var proto = { + 0: 0, + 2: 2 +}; +Object.defineProperty(proto, "1", { + get: function() { + return 1; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +Object.defineProperty(child, "1", { + get: function() { + return "11"; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(child, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-14.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-14.js new file mode 100644 index 0000000000000000000000000000000000000000..e6a1fddc869377a91c0d9298a710467c7fba0127 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-14.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property that overrides an inherited accessor property on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "11"); + } +} +Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 1; + }, + configurable: true +}); +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + get: function() { + return "11"; + }, + configurable: true +}); +arr.reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-15.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-15.js new file mode 100644 index 0000000000000000000000000000000000000000..019cd0d14e1d3a6340f3f25f2099692673fc9a22 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-15.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited + accessor property on an Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var proto = { + 0: 0, + 2: 2 +}; +Object.defineProperty(proto, "1", { + get: function() { + return 1; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +SendableArray.prototype.reduce.call(child, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-16.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-16.js new file mode 100644 index 0000000000000000000000000000000000000000..a676d4229c8aa8ec2127d86859b53c9293c6b7ae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-16.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited + accessor property on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 1; + }, + configurable: true +}); +var arr = [0, , 2, ]; +arr.reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-17.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-17.js new file mode 100644 index 0000000000000000000000000000000000000000..156e9dcbe019ea8d4a8770f0328c9a56fd6f2047 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-17.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property without a get function on an Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === undefined); + } +} +var obj = { + 0: 0, + 2: 2, + length: 3 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-18.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-18.js new file mode 100644 index 0000000000000000000000000000000000000000..0fcae67fafe3f1209ed1652add28efd8a6241cdc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-18.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property without a get function on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === undefined); + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + set: function() {}, + configurable: true +}); +arr.reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-19.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-19.js new file mode 100644 index 0000000000000000000000000000000000000000..fffeb699f4d7f2322beacc284662436b4738e707 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-19.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === undefined); + } +} +Object.defineProperty(Object.prototype, "1", { + get: function() { + return 1; + }, + configurable: true +}); +var obj = { + 0: 0, + 2: 2, + length: 3 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-2.js new file mode 100644 index 0000000000000000000000000000000000000000..8efa2f6fbc76ed48e710afda698db0285604e2a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var arr = [0, 1]; +arr.reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-20.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-20.js new file mode 100644 index 0000000000000000000000000000000000000000..9026ff0eed725763bd462c4dee0bea71d1bd8ef3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-20.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === undefined); + } +} +Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 11; + }, + configurable: true +}); +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + set: function() {}, + configurable: true +}); +arr.reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-21.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-21.js new file mode 100644 index 0000000000000000000000000000000000000000..9423d00330b0fa344bff9fe42ee6899b26740c7f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-21.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited + accessor property without a get function on an Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === undefined); + } +} +var proto = { + 0: 0, + 2: 2 +}; +Object.defineProperty(proto, "1", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +SendableArray.prototype.reduce.call(child, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-22.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-22.js new file mode 100644 index 0000000000000000000000000000000000000000..b4bd37feefc8bc640effe18f712684113fbdc726 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-22.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited + accessor property without a get function on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === undefined); + } +} +Object.defineProperty(SendableArray.prototype, "1", { + set: function() {}, + configurable: true +}); +var arr = [0, , 2]; +arr.reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-25.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-25.js new file mode 100644 index 0000000000000000000000000000000000000000..734a47d5d03e5134e7d3091370deb5182e0c4a25 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-25.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - This object is the Arguments object which + implements its own property get method (number of arguments is + less than number of parameters) +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var func = function(a, b, c) { + SendableArray.prototype.reduce.call(arguments, callbackfn, initialValue); +}; +func(0, 1); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-26.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-26.js new file mode 100644 index 0000000000000000000000000000000000000000..7ae03c84caf48512e7a66f09353940f9a0416005 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-26.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - This object is the Arguments object which + implements its own property get method (number of arguments equals + number of parameters) +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 2) { + testResult = (curVal === 2); + } +} +var func = function(a, b, c) { + SendableArray.prototype.reduce.call(arguments, callbackfn, initialValue); +}; +func(0, 1, 2); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-27.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-27.js new file mode 100644 index 0000000000000000000000000000000000000000..269fa614b15330d1acd0e37d0ff5efda5cacac26 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-27.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - This object is the Arguments object which + implements its own property get method (number of arguments is + greater than number of parameters) +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 3) { + testResult = (curVal === 3); + } +} +var func = function(a, b, c) { + SendableArray.prototype.reduce.call(arguments, callbackfn, initialValue); +}; +func(0, 1, 2, 3); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-28.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-28.js new file mode 100644 index 0000000000000000000000000000000000000000..62fbdfda9e540a050454fc1325cb0bda44a9c70a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-28.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - applied to String object, which + implements its own property get method +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "1"); + } +} +var str = new String("012"); +SendableArray.prototype.reduce.call(str, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-29.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-29.js new file mode 100644 index 0000000000000000000000000000000000000000..9c5d30b68d8afb63a2d6cd26d711e3e0d437238d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-29.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - applied to Function object which + implements its own property get method +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var obj = function(a, b, c) { + return a + b + c; +}; +obj[0] = 0; +obj[1] = 1; +obj[2] = 2; +obj[3] = 3; +SendableArray.prototype.reduce.call(obj, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-3.js new file mode 100644 index 0000000000000000000000000000000000000000..3b4c088ad167e7e0d1ba6168153c592e64a4aa9a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-3.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property that overrides an inherited data property on an + Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "11"); + } +} +var proto = { + 0: 0, + 1: 1, + 2: 2, + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[1] = "11"; +child[2] = "22"; +child.length = 3; +SendableArray.prototype.reduce.call(child, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-30.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-30.js new file mode 100644 index 0000000000000000000000000000000000000000..1b13b1702860250a4ad08c6d48ffa0229f928104 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-30.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element changed by getter on previous + iterations is observed on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var arr = [, , 2]; +var preIterVisible = false; +Object.defineProperty(arr, "0", { + get: function() { + preIterVisible = true; + return 0; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + if (preIterVisible) { + return 1; + } else { + return 100; + } + }, + configurable: true +}); +arr.reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-31.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-31.js new file mode 100644 index 0000000000000000000000000000000000000000..5ef2d806f8ee2354cf0b2394271014ee3ed5741a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-31.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element changed by getter on previous + iterations is observed on an Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var obj = { + 2: 2, + length: 3 +}; +var preIterVisible = false; +Object.defineProperty(obj, "0", { + get: function() { + preIterVisible = true; + return 0; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + if (preIterVisible) { + return 1; + } else { + return "11"; + } + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-32.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-32.js new file mode 100644 index 0000000000000000000000000000000000000000..d2c0579a5c4582a720ccf9d40dfe1b81d46f1242 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-32.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - unnhandled exceptions happened in getter + terminate iteration on an Array-like object +---*/ + +var accessed = false; +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx >= 1) { + accessed = true; + testResult = (curVal >= 1); + } +} +var obj = { + 0: 0, + 2: 2, + length: 3 +}; +Object.defineProperty(obj, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + SendableArray.prototype.reduce.call(obj, callbackfn, initialValue); +}); +assert.sameValue(accessed, false, 'accessed'); +assert.sameValue(testResult, false, 'testResult'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-33.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-33.js new file mode 100644 index 0000000000000000000000000000000000000000..ef1d204031b864a2a947dc5bc57e9725d841e44a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-33.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - unnhandled exceptions happened in getter + terminate iteration on an Array +---*/ + +var accessed = false; +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx >= 1) { + accessed = true; + testResult = (curVal >= 1); + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + arr.reduce(callbackfn, initialValue); +}); +assert.sameValue(accessed, false, 'accessed'); +assert.sameValue(testResult, false, 'testResult'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-4.js new file mode 100644 index 0000000000000000000000000000000000000000..16b0c4e1d5888f2fa78dfe57cd80a14cfa2a9edc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-4.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +SendableArray.prototype[1] = "3"; +[0, 1, 2].reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-5.js new file mode 100644 index 0000000000000000000000000000000000000000..6d68b1727fa7edf92bc47a336ac51f441a8e0638 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-5.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 0) { + testResult = (curVal === "9"); + } +} +var proto = {}; +Object.defineProperty(proto, "0", { + get: function() { + return 0; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +Object.defineProperty(child, "0", { + value: "9", + configurable: true +}); +child[1] = "1"; +SendableArray.prototype.reduce.call(child, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-6.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-6.js new file mode 100644 index 0000000000000000000000000000000000000000..5e953eb3a8cec9c11529b48d40b27818e1b27a32 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-6.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own data + property that overrides an inherited accessor property on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return "9"; + }, + configurable: true +}); +[0, 1, 2].reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-7.js new file mode 100644 index 0000000000000000000000000000000000000000..bf7071f850507941e9d756da90da0c30c535ea03 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-7.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited data + property on an Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var proto = { + 0: 0, + 1: 1, + 2: 2, + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +SendableArray.prototype.reduce.call(child, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-8.js new file mode 100644 index 0000000000000000000000000000000000000000..356a54797c3070759923e6c47c19d0cb5ce7740f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-8.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is inherited data + property on an Array +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +SendableArray.prototype[0] = 0; +SendableArray.prototype[1] = 1; +SendableArray.prototype[2] = 2; +[, , , ].reduce(callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-9.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-9.js new file mode 100644 index 0000000000000000000000000000000000000000..fcefb49b9e99fd7383ff7b7ffa4790cd92f17d49 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-i-9.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element to be retrieved is own accessor + property on an Array-like object +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var obj = { + 0: 0, + 2: 2, + length: 3 +}; +Object.defineProperty(obj, "1", { + get: function() { + return 1; + }, + configurable: true +}); +SendableArray.prototype.reduce.call(obj, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-1.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..97ea846a2d2e5414bb99153c2922839c36889c0c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - callbackfn called with correct parameters + (initialvalue not passed) +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + if (idx > 0 && obj[idx] === curVal && obj[idx - 1] === prevVal) + return curVal; + else + return false; +} +var arr = [0, 1, true, null, new Object(), "five"]; +assert.sameValue(arr.reduce(callbackfn), "five", 'arr.reduce(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-10.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..9d4682245fa7a09abb07c686326f6d7d05229758 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-10.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - callbackfn is called with 1 formal + parameter +---*/ + +var result = false; +function callbackfn(prevVal) { + result = (prevVal === 1); +} +[11].reduce(callbackfn, 1); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-11.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..fc50e408a2f7ecdd38859f9ef8402430f282d723 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-11.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - callbackfn is called with 2 formal + parameter +---*/ + +var result = false; +function callbackfn(prevVal, curVal) { + result = (curVal > 10 && 1 === prevVal); +} +[11].reduce(callbackfn, 1); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-12.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-12.js new file mode 100644 index 0000000000000000000000000000000000000000..a6e8aa7fdf6d1bd50ffc30399d22021516e8d8ca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-12.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - callbackfn is called with 3 formal + parameter +---*/ + +var result = false; +function callbackfn(prevVal, curVal, idx) { + result = (prevVal === 1 && arguments[3][idx] === curVal); +} +[11].reduce(callbackfn, 1); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-13.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-13.js new file mode 100644 index 0000000000000000000000000000000000000000..c8bb251cd2ccd07fab1f5525d5d394616395fc0f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-13.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - callbackfn is called with 4 formal + parameter +---*/ + +var result = false; +function callbackfn(prevVal, curVal, idx, obj) { + result = (prevVal === 1 && obj[idx] === curVal); +} +[11].reduce(callbackfn, 1); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-14.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-14.js new file mode 100644 index 0000000000000000000000000000000000000000..bf6f36e34a0d1f3069ee1358024b1f2373b039de --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-14.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - callbackfn that uses arguments +---*/ + +var result = false; +function callbackfn() { + result = (arguments[0] === 1 && arguments[3][arguments[2]] === arguments[1]); +} +[11].reduce(callbackfn, 1); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-16.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-16.js new file mode 100644 index 0000000000000000000000000000000000000000..aefd1c8481f2573854bc388522e686dee71454e6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-16.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - non-indexed properties are not called +---*/ + +var accessed = false; +var result1 = true; +var result2 = true; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (curVal === 8) { + result1 = false; + } + if (prevVal === 8) { + result2 = false; + } +} +var obj = { + 0: 11, + 10: 12, + non_index_property: 8, + length: 20 +}; +SendableArray.prototype.reduce.call(obj, callbackfn, 1); +assert(result1, 'result1 !== true'); +assert(result2, 'result2 !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-17.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-17.js new file mode 100644 index 0000000000000000000000000000000000000000..73d179cea9ea58c3d93dafa3504aa3839c8848fa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-17.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - 'accumulator' used for current iteration + is the result of previous iteration on an Array +---*/ + +var result = true; +var accessed = false; +var preIteration = 1; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (preIteration !== prevVal) { + result = false; + } + preIteration = curVal; + return curVal; +} +[11, 12, 13].reduce(callbackfn, 1); +assert(result, 'result !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-18.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-18.js new file mode 100644 index 0000000000000000000000000000000000000000..c30e6b2ec73e84c5fa1c047e1c79f393badc747c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-18.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'accumulator' used for first + iteration is the value of 'initialValue' when it is present on an + Array-like object +---*/ + +var result = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 0) { + result = (arguments[0] === 1); + } +} +var obj = { + 0: 11, + 1: 9, + length: 2 +}; +SendableArray.prototype.reduce.call(obj, callbackfn, 1); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-19.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-19.js new file mode 100644 index 0000000000000000000000000000000000000000..4e7dc7401c11d7928e43c8fd677ce0fc17448114 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-19.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - value of 'accumulator' used for first + iteration is the value of least index property which is not + undefined when 'initialValue' is not present on an Array +---*/ + +var called = 0; +var result = false; +function callbackfn(prevVal, curVal, idx, obj) { + called++; + if (idx === 1) { + result = (prevVal === 11) && curVal === 9; + } +} +[11, 9].reduce(callbackfn); +assert(result, 'result !== true'); +assert.sameValue(called, 1, 'called'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-2.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..68fafffdd9cc834ae2b7bfe26b54879a3713b044 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-2.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - callbackfn called with correct parameters + (initialvalue passed) +---*/ + +var bParCorrect = false; +function callbackfn(prevVal, curVal, idx, obj) +{ + if (idx === 0 && obj[idx] === curVal && prevVal === initialValue) + return curVal; + else if (idx > 0 && obj[idx] === curVal && obj[idx - 1] === prevVal) + return curVal; + else + return false; +} +var arr = [0, 1, true, null, new Object(), "five"]; +var initialValue = 5.5; +assert.sameValue(arr.reduce(callbackfn, initialValue), "five", 'arr.reduce(callbackfn,initialValue)'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-20.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-20.js new file mode 100644 index 0000000000000000000000000000000000000000..da4fb9aa75f219297fab1c520b380a7cf76d343e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-20.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - undefined can be used as accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return typeof prevVal === "undefined"; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, undefined), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, undefined)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-21.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-21.js new file mode 100644 index 0000000000000000000000000000000000000000..559a1ae916df532defa3a49d689dc97e04b281d0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-21.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - null can be used as accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === null; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, null), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, null)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-22.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-22.js new file mode 100644 index 0000000000000000000000000000000000000000..b45310ef1f839ec5d66f53fe3d71acd238ec09da --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-22.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - boolean primitive can be used as + accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === false; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, false), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, false)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-23.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-23.js new file mode 100644 index 0000000000000000000000000000000000000000..bbd39fb929510227410f1b90ff14ec90ededb381 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-23.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - number primitive can be used as + accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === 12; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, 12), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, 12)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-24.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-24.js new file mode 100644 index 0000000000000000000000000000000000000000..1008aa41ca22115a4f7493b163dc29489ebeab9d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-24.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - string primitive can be used as + accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === "hello_"; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, "hello_"), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, "hello_")'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-25.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-25.js new file mode 100644 index 0000000000000000000000000000000000000000..f18dd30bb659e6a21daa23f1c7bd6c967c133b15 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-25.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - Function object can be used as accumulator +---*/ + +var objFunction = function() {}; +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objFunction; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, objFunction), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, objFunction)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-26.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-26.js new file mode 100644 index 0000000000000000000000000000000000000000..f8ff88de4fbe6d16be1b8eed7689b10afb06f6af --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-26.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - Array object can be used as accumulator +---*/ + +var objArray = new SendableArray(10); +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objArray; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, objArray), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, objArray)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-27.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-27.js new file mode 100644 index 0000000000000000000000000000000000000000..92983bde6b75332ffa04b777ce3c600d69ed7759 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-27.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - String object can be used as accumulator +---*/ + +var objString = new String(); +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objString; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, objString), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, objString)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-28.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-28.js new file mode 100644 index 0000000000000000000000000000000000000000..64357e0cc907b799e3d8d0823d0c42dbbb3bb495 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-28.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - Boolean object can be used as accumulator +---*/ + +var objBoolean = new Boolean(); +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objBoolean; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, objBoolean), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, objBoolean)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-29.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-29.js new file mode 100644 index 0000000000000000000000000000000000000000..9048373df5ec74c4a6bdb891bd6ac46a45102dd7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-29.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - Number object can be used as accumulator +---*/ + +var objNumber = new Number(); +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objNumber; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, objNumber), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, objNumber)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-3.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-3.js new file mode 100644 index 0000000000000000000000000000000000000000..94d2eafb87d4011774c5f0df93c878924ae9691f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - callbackfn takes 4 arguments +---*/ + +var bCalled = false; +function callbackfn(prevVal, curVal, idx, obj) +{ + bCalled = true; + if (prevVal === true && arguments.length === 4) + return true; + else + return false; +} +var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +assert.sameValue(arr.reduce(callbackfn, true), true, 'arr.reduce(callbackfn,true)'); +assert.sameValue(bCalled, true, 'bCalled'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-30.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-30.js new file mode 100644 index 0000000000000000000000000000000000000000..882a8c11758024faff27b7b6743820f657bf6ac6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-30.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - the Math object can be used as accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === Math; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, Math), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, Math)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-31.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-31.js new file mode 100644 index 0000000000000000000000000000000000000000..fa9760fc213893934fc7719173a5a0db72ece496 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-31.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - Date object can be used as accumulator +---*/ + +var objDate = new Date(0); +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objDate; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, objDate), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, objDate)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-32.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-32.js new file mode 100644 index 0000000000000000000000000000000000000000..997413a30081c64d2c8c5fb3fd0210c62494584a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-32.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - RegExp object can be used as accumulator +---*/ + +var objRegExp = new RegExp(); +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objRegExp; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, objRegExp), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, objRegExp)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-33.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-33.js new file mode 100644 index 0000000000000000000000000000000000000000..6f8adb6528129ecae34e49f16ab5b24242cb7233 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-33.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - the JSON can be used as accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === JSON; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, JSON), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, JSON)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-34.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-34.js new file mode 100644 index 0000000000000000000000000000000000000000..e14a735e1d5085227c97fcf326331be9f6ecc1f3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-34.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce - Error object can be used as accumulator +---*/ + +var objError = new RangeError(); +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objError; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, objError), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, objError)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-35.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-35.js new file mode 100644 index 0000000000000000000000000000000000000000..c9dbc582e2b36ecd6dc085b0b343c569d584ca9c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-35.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - the Arguments object can be used as + accumulator +---*/ + +var accessed = false; +var arg; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === arg; +} +var obj = { + 0: 11, + length: 1 +}; +(function fun() { + arg = arguments; +}(10, 11, 12, 13)); +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, arg), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, arg)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-37.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-37.js new file mode 100644 index 0000000000000000000000000000000000000000..0c77456085f2964f536b2e5558e22040714d51a2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-37.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - the global object can be used as + accumulator +---*/ + +var global = this; +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === global; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduce.call(obj, callbackfn, this), true, 'SendableArray.prototype.reduce.call(obj, callbackfn, this)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-4-s.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-4-s.js new file mode 100644 index 0000000000000000000000000000000000000000..77b786cccc2b2a4a0f1a0e94f5ae298b06a993af --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-4-s.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - undefined passed as thisValue to strict + callbackfn +flags: [noStrict] +---*/ + +var innerThisCorrect = false; +function callbackfn(prevVal, curVal, idx, obj) +{ + "use strict"; + innerThisCorrect = this === undefined; + return true; +} +[0].reduce(callbackfn, true); +assert(innerThisCorrect, 'innerThisCorrect !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-4.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..468ff655579c2845b3c93c3c9dfa9f01b41521ee --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-4.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - k values are passed in acending numeric + order on an Array +---*/ + +var arr = [0, 1, 2]; +var lastIdx = 0; +var result = true; +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (lastIdx !== idx) { + result = false; + } else { + lastIdx++; + } +} +arr.reduce(callbackfn, 11); +assert(result, 'result !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-5.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..b4309300aae7171a06b56c05a028c8432c876d9b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-5.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - k values are accessed during each + iteration and not prior to starting the loop on an Array +---*/ + +var result = true; +var kIndex = []; +var called = 0; +//By below way, we could verify that k would be setted as 0, 1, ..., length - 1 in order, and each value will be setted one time. +function callbackfn(prevVal, curVal, idx, obj) { + //Each position should be visited one time, which means k is accessed one time during iterations. + called++; + if (typeof kIndex[idx] === "undefined") { + //when current position is visited, its previous index should has been visited. + if (idx !== 0 && typeof kIndex[idx - 1] === "undefined") { + result = false; + } + kIndex[idx] = 1; + } else { + result = false; + } +} +[11, 12, 13, 14].reduce(callbackfn, 1); +assert(result, 'result !== true'); +assert.sameValue(called, 4, 'called'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-7.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..545ce25b1bd10fa81651d7a9e94beb1a3e58fdaa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-7.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - unhandled exceptions happened in + callbackfn terminate iteration +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 0) { + accessed = true; + } + if (idx === 0) { + throw new Error("Exception occurred in callbackfn"); + } +} +var obj = { + 0: 11, + 4: 10, + 10: 8, + length: 20 +}; +assert.throws(Error, function() { + SendableArray.prototype.reduce.call(obj, callbackfn, 1); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-8.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..5e74f7b9adad8c595030df996b9aa1e0b1a2bcf9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-8.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - element changed by callbackfn on previous + iterations is observed +---*/ + +var result = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 0) { + obj[idx + 1] = 8; + } + if (idx === 1) { + result = (curVal === 8); + } +} +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +SendableArray.prototype.reduce.call(obj, callbackfn, 1); +assert(result, 'result !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-9.js b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..c169843eb92b9b2c5ded2bf8d437dccb8b5654bf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/15.4.4.21-9-c-ii-9.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce - callbackfn is called with 0 formal + parameter +---*/ + +var called = 0; +function callbackfn() { + called++; +} +[11, 12].reduce(callbackfn, 1); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/reduce/call-with-boolean.js b/test/sendable/builtins/Array/prototype/reduce/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..2a9edfae6c6117152c02968ab89a03f393783d6f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: Array.prototype.reduce applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.reduce.call(true, () => {}, -1), + -1, + 'SendableArray.prototype.reduce.call(true, () => {}, -1) must return -1' +); +assert.sameValue( + SendableArray.prototype.reduce.call(false, () => {}, -1), + -1, + 'SendableArray.prototype.reduce.call(false, () => {}, -1) must return -1' +); diff --git a/test/sendable/builtins/Array/prototype/reduce/callbackfn-resize-arraybuffer.js b/test/sendable/builtins/Array/prototype/reduce/callbackfn-resize-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..49a1e48b6e865cef682d5b8119dfe28ff6111388 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/callbackfn-resize-arraybuffer.js @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: TypedArray instance buffer can be resized during iteration +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 3}); + var sample = new TA(buffer); + var expectedPrevs, expectedNexts, expectedIndices, expectedArrays; + var prevs, nexts, indices, arrays, result; + prevs = []; + nexts = []; + indices = []; + arrays = []; + result = SendableArray.prototype.reduce.call(sample, function(prev, next, index, array) { + if (prevs.length === 0) { + try { + buffer.resize(2 * BPE); + expectedPrevs = [262, 0]; + expectedNexts = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + expectedPrevs = [262, 0, 1]; + expectedNexts = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + prevs.push(prev); + nexts.push(next); + indices.push(index); + arrays.push(array); + return index; + }, 262); + assert.compareArray(prevs, expectedPrevs, 'prevs (shrink)'); + assert.compareArray(nexts, expectedNexts, 'nexts (shrink)'); + assert.compareArray(indices, expectedIndices, 'indices (shrink)'); + assert.compareArray(arrays, expectedArrays, 'arrays (shrink)'); + assert.sameValue(result, expectedIndices[expectedIndices.length - 1], 'result (shrink)'); + prevs = []; + nexts = []; + indices = []; + arrays = []; + result = SendableArray.prototype.reduce.call(sample, function(prev, next, index, array) { + if (prevs.length === 0) { + try { + buffer.resize(3 * BPE); + } catch (_) {} + } + prevs.push(prev); + nexts.push(next); + indices.push(index); + arrays.push(array); + return index; + }, 262); + assert.compareArray(prevs, expectedPrevs, 'prevs (grow)'); + assert.compareArray(nexts, expectedNexts, 'nexts (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, expectedIndices[expectedIndices.length - 1], 'result (grow)'); +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/length.js b/test/sendable/builtins/Array/prototype/reduce/length.js new file mode 100644 index 0000000000000000000000000000000000000000..126eb3b5a19bf1ce06a519292721b54889dc83dc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/length.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + The "length" property of Array.prototype.reduce +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.reduce, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/name.js b/test/sendable/builtins/Array/prototype/reduce/name.js new file mode 100644 index 0000000000000000000000000000000000000000..3fd5ef6efc3ca757b2ff1f7a81c926f0d773f388 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.prototype.reduce.name is "reduce". +info: | + Array.prototype.reduce ( callbackfn [ , initialValue ] ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.reduce, "name", { + value: "reduce", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/not-a-constructor.js b/test/sendable/builtins/Array/prototype/reduce/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..4bc3c2cb892299967d29aaa486b9289f9e6c1bb0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/not-a-constructor.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.reduce does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.reduce), + false, + 'isConstructor(SendableArray.prototype.reduce) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.reduce(() => {}, []); +}); + diff --git a/test/sendable/builtins/Array/prototype/reduce/prop-desc.js b/test/sendable/builtins/Array/prototype/reduce/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..8c1ce914c037dadf5437e32c8dbc66785f9400b7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + "reduce" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.reduce, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "reduce", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/reduce/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/reduce/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..f7b7cdfecaad30b7f5e4bed2d07cdf503a740b3f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.p.reduce behaves correctly when the resizable buffer is grown + mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(acc, n) { + // Returns true by default. + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +// Test for reduce. +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduce.call(fixedLength, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduce.call(fixedLengthWithOffset, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduce.call(lengthTracking, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduce.call(lengthTrackingWithOffset, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/reduce/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/reduce/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..53df79662d8e85c9dac9c4eb6f3186043667475a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-%array%.prototype.reduce +description: > + Array.p.reduce behaves correctly when the backing resizable buffer is shrunk + mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(acc, n) { + // Returns true by default. + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduce.call(fixedLength, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 0, + 2 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduce.call(fixedLengthWithOffset, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 4 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduce.call(lengthTracking, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 0, + 2, + 4 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduce.call(lengthTrackingWithOffset, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 4 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/reduce/resizable-buffer.js b/test/sendable/builtins/Array/prototype/reduce/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..a078dc2e8f0eb65554fb74525db25deb65cfbb26 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduce/resizable-buffer.js @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduce +description: > + Array.p.reduce behaves correctly on TypedArrays backed by resizable buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + function ReduceCollecting(array) { + const reduceValues = []; + SendableArray.prototype.reduce.call(array, (acc, n) => { + reduceValues.push(n); + }, 'initial value'); + return ToNumbers(reduceValues); + } + assert.compareArray(ReduceCollecting(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceCollecting(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ReduceCollecting(lengthTracking), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceCollecting(lengthTrackingWithOffset), [ + 4, + 6 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + assert.compareArray(ReduceCollecting(fixedLength), []); + assert.compareArray(ReduceCollecting(fixedLengthWithOffset), []); + assert.compareArray(ReduceCollecting(lengthTracking), [ + 0, + 2, + 4 + ]); + assert.compareArray(ReduceCollecting(lengthTrackingWithOffset), [4]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ReduceCollecting(fixedLength), []); + assert.compareArray(ReduceCollecting(fixedLengthWithOffset), []); + assert.compareArray(ReduceCollecting(lengthTracking), [0]); + // Shrink to zero. + rab.resize(0); + assert.compareArray(ReduceCollecting(fixedLength), []); + assert.compareArray(ReduceCollecting(fixedLengthWithOffset), []); + assert.compareArray(ReduceCollecting(lengthTrackingWithOffset), []); + assert.compareArray(ReduceCollecting(lengthTracking), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + assert.compareArray(ReduceCollecting(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceCollecting(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ReduceCollecting(lengthTracking), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(ReduceCollecting(lengthTrackingWithOffset), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..6a2777f17d7fb20c502e3d2904e1fc1f78517485 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to undefined throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.reduceRight.call(undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-10.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..88742cd6dc76475a002f87bc2308e544f6926ccd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-10.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to the Math object +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return '[object Math]' === Object.prototype.toString.call(obj); +} +Math.length = 1; +Math[0] = 1; +assert(SendableArray.prototype.reduceRight.call(Math, callbackfn, 1), 'SendableArray.prototype.reduceRight.call(Math, callbackfn, 1) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-11.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..30ed4f1f01ba4b6b52e76147d11acaafcd215367 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-11.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to Date object +---*/ + +var obj = new Date(0); +obj.length = 1; +obj[0] = 1; +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj instanceof Date; +} +assert(SendableArray.prototype.reduceRight.call(obj, callbackfn, 1), 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 1) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-12.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..5be042555fb69f5f125dfc519ac1a99a0aa0c65b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-12.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to RegExp object +---*/ + +var obj = new RegExp(); +obj.length = 1; +obj[0] = 1; +var accessed = false; +function callbackfn(prevVal, curVal, idx, o) { + accessed = true; + return o instanceof RegExp; +} +assert(SendableArray.prototype.reduceRight.call(obj, callbackfn, 1), 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 1) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-13.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..97409ec46cea2fd8505b9738642261611716ec1a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-13.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to the JSON object +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return ('[object JSON]' === Object.prototype.toString.call(obj)); +} +JSON.length = 1; +JSON[0] = 1; +assert(SendableArray.prototype.reduceRight.call(JSON, callbackfn, 1), 'SendableArray.prototype.reduceRight.call(JSON, callbackfn, 1) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-14.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-14.js new file mode 100644 index 0000000000000000000000000000000000000000..bc82cd620112faed8479e27d59a339d36a5f90e8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-14.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to Error object +---*/ + +var obj = new Error(); +obj.length = 1; +obj[0] = 1; +var accessed = false; +function callbackfn(prevVal, curVal, idx, o) { + accessed = true; + return o instanceof Error; +} +assert(SendableArray.prototype.reduceRight.call(obj, callbackfn, 1), 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 1) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-15.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..be5236f3ec6ec8a3760144e07ee3adb3114c1b22 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-15.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to the Arguments object +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return '[object Arguments]' === Object.prototype.toString.call(obj); +} +var obj = (function() { + return arguments; +}("a", "b")); +assert(SendableArray.prototype.reduceRight.call(obj, callbackfn, "a"), 'SendableArray.prototype.reduceRight.call(obj, callbackfn, "a") !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..12b44c97e85fefa8a1b90cf5092bd296d3981964 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to null throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.reduceRight.call(null); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..c5303d0eddd0408cc189b584ef4c292b64c4c0b9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-3.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to boolean primitive +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj instanceof Boolean; +} +Boolean.prototype[0] = 1; +Boolean.prototype.length = 1; +assert(SendableArray.prototype.reduceRight.call(false, callbackfn, 1), 'SendableArray.prototype.reduceRight.call(false, callbackfn, 1) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..596a897ccc5e65d6eeea5726c65675e06f192a25 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to Boolean object +---*/ + +var obj = new Boolean(true); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj instanceof Boolean; +} +assert(SendableArray.prototype.reduceRight.call(obj, callbackfn, 11), 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..903826268869d1a1447db98a11bec45736a5816d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-5.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to number primitive +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj instanceof Number; +} +Number.prototype[0] = 1; +Number.prototype.length = 1; +assert(SendableArray.prototype.reduceRight.call(2.5, callbackfn, 1), 'SendableArray.prototype.reduceRight.call(2.5, callbackfn, 1) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..20c18f6b8f95b218e888ef0b81c65dd054faf09d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-6.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to Number object +---*/ + +var obj = new Number(-128); +obj.length = 2; +obj[0] = 11; +obj[1] = 12; +var accessed = false; +function callbackfn(prevVal, curVal, idx, o) { + accessed = true; + return o instanceof Number; +} +assert(SendableArray.prototype.reduceRight.call(obj, callbackfn, 11), 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..e93a91ef610ba259fe35c9c638142ce582aaee4a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-7.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to string primitive +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj instanceof String; +} +assert(SendableArray.prototype.reduceRight.call("hello\nworld\\!", callbackfn, "h"), 'SendableArray.prototype.reduceRight.call("hello\nworld\\!", callbackfn, "h") !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..c0b5d1c2d996848f61e126cda1b2034c4fe65ddf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-8.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to String object +---*/ + +var obj = new String("hello\nworld\\!"); +var accessed = false; +function callbackfn(prevVal, curVal, idx, o) { + accessed = true; + return o instanceof String; +} +assert(SendableArray.prototype.reduceRight.call(obj, callbackfn, "h"), 'SendableArray.prototype.reduceRight.call(obj, callbackfn, "h") !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-9.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..e465096ea3366f2f8c19a4f5f9e1fdece987bee9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-1-9.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight applied to Function object +---*/ + +var obj = function(a, b) { + return a + b; +}; +obj[0] = 11; +obj[1] = 9; +var accessed = false; +function callbackfn(prevVal, curVal, idx, o) { + accessed = true; + return o instanceof Function; +} +assert(SendableArray.prototype.reduceRight.call(obj, callbackfn, 11), 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-1.js new file mode 100644 index 0000000000000000000000000000000000000000..195181e7eb73d3b16e04ce8957745f50f96f5fc1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-1.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight doesn't mutate the Array on which it + is called on +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + return 1; +} +var srcArr = [1, 2, 3, 4, 5]; +srcArr.reduceRight(callbackfn); +assert.sameValue(srcArr[0], 1, 'srcArr[0]'); +assert.sameValue(srcArr[1], 2, 'srcArr[1]'); +assert.sameValue(srcArr[2], 3, 'srcArr[2]'); +assert.sameValue(srcArr[3], 4, 'srcArr[3]'); +assert.sameValue(srcArr[4], 5, 'srcArr[4]'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-2.js new file mode 100644 index 0000000000000000000000000000000000000000..50595c803559f8513c6813c64219a51456c7f56c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-2.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight reduces array in descending order of + indices +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + return prevVal + curVal; +} +var srcArr = ['1', '2', '3', '4', '5']; +assert.sameValue(srcArr.reduceRight(callbackfn), '54321', 'srcArr.reduceRight(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-3.js new file mode 100644 index 0000000000000000000000000000000000000000..01a2427747ba231ea7b0495bf66e795adb30ea08 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-3.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight - subclassed array with length 1 +---*/ + +foo.prototype = [1]; +function foo() {} +var f = new foo(); +function cb() {} +assert.sameValue(f.reduceRight(cb), 1, 'f.reduceRight(cb)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-4.js new file mode 100644 index 0000000000000000000000000000000000000000..a588aee865b3be6448649b53af51eeac826deb89 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - subclassed array with length more + than 1 +---*/ + +foo.prototype = new SendableArray(0, 1, 2, 3); +function foo() {} +var f = new foo(); +function cb(prevVal, curVal, idx, obj) { + return prevVal + curVal; +} +assert.sameValue(f.reduceRight(cb), 6, 'f.reduceRight(cb)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-5.js new file mode 100644 index 0000000000000000000000000000000000000000..520e9bb40e4b02fcf1b63cf10d8831386e147bc2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-5.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight reduces array in descending order of + indices(initialvalue present) +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + return prevVal + curVal; +} +var srcArr = ['1', '2', '3', '4', '5']; +assert.sameValue(srcArr.reduceRight(callbackfn, '6'), '654321', 'srcArr.reduceRight(callbackfn,"6")'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-6.js new file mode 100644 index 0000000000000000000000000000000000000000..c33a922cd56079801d8dca34c68502ccf0896fc3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-6.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - subclassed array when initialvalue + provided +---*/ + +foo.prototype = new SendableArray(0, 1, 2, 3); +function foo() {} +var f = new foo(); +function cb(prevVal, curVal, idx, obj) { + return prevVal + curVal; +} +assert.sameValue(f.reduceRight(cb, "4"), "43210", 'f.reduceRight(cb,"4")'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-7.js new file mode 100644 index 0000000000000000000000000000000000000000..a07f910eb9ff3f8688f02de0b91bd8df1575aa82 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-7.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - subclassed array when length to 1 + and initialvalue provided +---*/ + +foo.prototype = [1]; +function foo() {} +var f = new foo(); +function cb(prevVal, curVal, idx, obj) { + return prevVal + curVal; +} +assert.sameValue(f.reduceRight(cb, "4"), "41", 'f.reduceRight(cb,"4")'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-8.js new file mode 100644 index 0000000000000000000000000000000000000000..51455e879a2f5ccc94adcd3bafe72d1b4073c44d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-10-8.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight doesn't visit expandos +---*/ + +var callCnt = 0; +function callbackfn(prevVal, curVal, idx, obj) +{ + callCnt++; +} +var srcArr = ['1', '2', '3', '4', '5']; +srcArr["i"] = 10; +srcArr[true] = 11; +srcArr.reduceRight(callbackfn); +assert.sameValue(callCnt, 4, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..fcbcb1b3145a2c3ac242f7a5fb224019dbd8e1cd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-1.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Array-like object, 'length' + is an own data property +---*/ + +var accessed = false; +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: 2 +}; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +assert(SendableArray.prototype.reduceRight.call(obj, callbackfn, 11), 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-10.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-10.js new file mode 100644 index 0000000000000000000000000000000000000000..44212fc35c84f920e460ad8241c7dcdb678a94d2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-10.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Array-like object, 'length' + is an inherited accessor property +---*/ + +var accessed = false; +var Con = function() {}; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 2; + }, + configurable: true +}); +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert(SendableArray.prototype.reduceRight.call(child, callbackfn, 11), 'SendableArray.prototype.reduceRight.call(child, callbackfn, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-11.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-11.js new file mode 100644 index 0000000000000000000000000000000000000000..7d1c1c6bbd7e72276fc0d0bc58910c42db038d8b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-11.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Array-like object, 'length' + is an own accessor property without a get function +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return typeof obj.length === "undefined"; +} +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 111), 111, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 111)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-12.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-12.js new file mode 100644 index 0000000000000000000000000000000000000000..48c8349ff99896ee89ca461e78433ceea440daa1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-12.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - 'length' is own accessor property + without a get function that overrides an inherited accessor + property +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return typeof obj.length === "undefined"; +} +Object.defineProperty(Object.prototype, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var obj = { + 0: 12, + 1: 13 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 11), 11, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 11)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-13.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-13.js new file mode 100644 index 0000000000000000000000000000000000000000..ab3e333d579906af6349c001d43e7598a5cde4d9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-13.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to the Array-like object that + 'length' is inherited accessor property without a get function +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return curVal > 10; +} +var proto = {}; +Object.defineProperty(proto, "length", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 11; +child[1] = 12; +assert.sameValue(SendableArray.prototype.reduceRight.call(child, callbackfn, 111), 111, 'SendableArray.prototype.reduceRight.call(child, callbackfn, 111)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-14.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-14.js new file mode 100644 index 0000000000000000000000000000000000000000..233a6e1010d6e61d9ee2da7fdd2a0ed64e21f9ed --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-14.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to the Array-like object that + 'length' property doesn't exist +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return curVal > 10; +} +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 111), 111, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 111)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-17.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-17.js new file mode 100644 index 0000000000000000000000000000000000000000..c651da04613205e3fb699d4c7dc0ad8bc9bd841e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-17.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to the Arguments object, which + implements its own property get method +---*/ + +var arg; +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +var func = function(a, b) { + arg = arguments; + return SendableArray.prototype.reduceRight.call(arguments, callbackfn, 11); +}; +assert(func(12, 11), 'func(12, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-18.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-18.js new file mode 100644 index 0000000000000000000000000000000000000000..19b1b13dcad4a796d3c5006c5a361e9561ac6f73 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-18.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to String object, which + implements its own property get method +---*/ + +var accessed = false; +var str = new String("432"); +function callbackfn(preVal, curVal, idx, obj) { + accessed = true; + return obj.length === 3; +} +String.prototype[3] = "1"; +assert(SendableArray.prototype.reduceRight.call(str, callbackfn, 111), 'SendableArray.prototype.reduceRight.call(str, callbackfn, 111) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-19.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-19.js new file mode 100644 index 0000000000000000000000000000000000000000..e2ff07d0bb1352fcff262b799f681da7d947c20b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-19.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Function object, which + implements its own property get method +---*/ + +var accessed = false; +var fun = function(a, b) { + return a + b; +}; +fun[0] = 12; +fun[1] = 11; +fun[2] = 9; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +assert(SendableArray.prototype.reduceRight.call(fun, callbackfn, 11), 'SendableArray.prototype.reduceRight.call(fun, callbackfn, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..9f51ff63dde4509b7bcfeb9a140a7f04250a2003 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - 'length' is own data property on an + Array +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +assert([12, 11].reduceRight(callbackfn, 11), '[12, 11].reduceRight(callbackfn, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..e5e570fc9a5142397078e3dc7aed5d87c2495826 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-3.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Array-like object, 'length' + is an own data property that overrides an inherited data property +---*/ + +var accessed = true; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert(SendableArray.prototype.reduceRight.call(child, callbackfn), 'SendableArray.prototype.reduceRight.call(child, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..e8470f7c99d06ab532a14f185106eabcbdbca171 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-4.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - 'length' is own data property that + overrides an inherited data property on an Array +---*/ + +var accessed = false; +var arrProtoLen; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +arrProtoLen = SendableArray.prototype.length; +SendableArray.prototype.length = 0; +assert([12, 11].reduceRight(callbackfn, 11), '[12, 11].reduceRight(callbackfn, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..cd2f944a0b99882db071fd6a5630569d8c776c74 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-5.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Array-like object, 'length' + is an own data property that overrides an inherited accessor + property +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + value: 2, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert(SendableArray.prototype.reduceRight.call(child, callbackfn), 'SendableArray.prototype.reduceRight.call(child, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-6.js new file mode 100644 index 0000000000000000000000000000000000000000..8ebb401e66c7c17418c915785be810b4edb3564f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-6.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Array-like object, 'length' + is an inherited data property +---*/ + +var accessed = false; +var proto = { + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 12; +child[1] = 11; +child[2] = 9; +function callbackfn1(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +assert(SendableArray.prototype.reduceRight.call(child, callbackfn1, 11), 'SendableArray.prototype.reduceRight.call(child, callbackfn1, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-7.js new file mode 100644 index 0000000000000000000000000000000000000000..c2db4dd7128ebcf0c51fbc9bc718d841aff7f672 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-7.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Array-like object, 'length' + is an own accessor property +---*/ + +var accessed = true; +var obj = {}; +obj[0] = 12; +obj[1] = 11; +obj[2] = 9; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +Object.defineProperty(obj, "length", { + get: function() { + return 2; + }, + configurable: true +}); +assert(SendableArray.prototype.reduceRight.call(obj, callbackfn, 11), 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-8.js new file mode 100644 index 0000000000000000000000000000000000000000..4d2e0e4f213c7e4e9175a99bdadaddd072c668bc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-8.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Array-like object, 'length' + is an own accessor property that overrides an inherited data + property +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert(SendableArray.prototype.reduceRight.call(child, callbackfn, 11), 'SendableArray.prototype.reduceRight.call(child, callbackfn, 11) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-9.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-9.js new file mode 100644 index 0000000000000000000000000000000000000000..1179a8156f41947775c32353fdb1990c215af3bb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-2-9.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Array-like object, 'length' + is an own accessor property that overrides an inherited accessor + property +---*/ + +var accessed = false; +function callbackfn1(prevVal, curVal, idx, obj) { + accessed = true; + return obj.length === 2; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 12; +child[1] = 11; +child[2] = 9; +assert(SendableArray.prototype.reduceRight.call(child, callbackfn1, 111), 'SendableArray.prototype.reduceRight.call(child, callbackfn1, 111) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-1.js new file mode 100644 index 0000000000000000000000000000000000000000..624d13b52910e29433c721a0a99883bcc266bb9e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-1.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight - value of 'length' is undefined +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + length: undefined +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-10.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-10.js new file mode 100644 index 0000000000000000000000000000000000000000..1bfca3a272a588c9457a3fc3a49970873e629c96 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-10.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a number (value + is NaN) +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + length: NaN +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-11.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-11.js new file mode 100644 index 0000000000000000000000000000000000000000..ca992186d07fb42f6ebd8e7e94b5ecacda31d90d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-11.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a string + containing a positive number +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: "2" +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert(testResult2, 'testResult2 !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-12.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-12.js new file mode 100644 index 0000000000000000000000000000000000000000..61c51837a5be36e4f6cf2c342d9731f2423bd099 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-12.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a string + containing a negative number +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var obj = { + 0: 11, + 1: 12, + 2: 9, + length: "-4294967294" +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert.sameValue(testResult2, false, 'testResult2'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-13.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-13.js new file mode 100644 index 0000000000000000000000000000000000000000..52d574a0ed6acf2ff320e8bce2625f76aa745a15 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-13.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a string + containing a decimal number +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: "2.5" +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert(testResult2, 'testResult2 !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-14.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-14.js new file mode 100644 index 0000000000000000000000000000000000000000..9cc8125f136f72a1a16be2bd4c37d3c64214303a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-14.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a string + containing -Infinity +---*/ + +var accessed2 = false; +function callbackfn2(prevVal, curVal, idx, obj) { + accessed2 = true; +} +var obj2 = { + 0: 9, + length: "-Infinity" +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj2, callbackfn2, 2), 2, 'SendableArray.prototype.reduceRight.call(obj2, callbackfn2, 2)'); +assert.sameValue(accessed2, false, 'accessed2'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-15.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-15.js new file mode 100644 index 0000000000000000000000000000000000000000..659530b6f3bb9c57aa7ee3ee54ae7429641634e0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-15.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a string + containing an exponential number +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: "2E0" +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert(testResult2, 'testResult2 !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-16.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-16.js new file mode 100644 index 0000000000000000000000000000000000000000..35d81a6889fe7b471ea1aef866b9d89f39b06e4a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-16.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a string + containing a hex number +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: "0x0002" +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert(testResult2, 'testResult2 !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-17.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-17.js new file mode 100644 index 0000000000000000000000000000000000000000..905837c6a8ad14f81336494623732a72c32e3eee --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-17.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a string + containing a number with leading zeros +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: "0002.00" +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert(testResult2, 'testResult2 !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-18.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-18.js new file mode 100644 index 0000000000000000000000000000000000000000..c1e2fc50f9ede115446506bc3983002aba2e12c9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-18.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a string that + can't convert to a number +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + 1: 8, + length: "two" +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 11), 11, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 11)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-19.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-19.js new file mode 100644 index 0000000000000000000000000000000000000000..fc13c1c7b7ec7de318c6af36c3e50a5a9b2a6306 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-19.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is an object which + has an own toString method +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var toStringAccessed = false; +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: { + toString: function() { + toStringAccessed = true; + return '2'; + } + } +}; +// objects inherit the default valueOf() method from Object +// that simply returns itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert(testResult2, 'testResult2 !== true'); +assert(toStringAccessed, 'toStringAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-2.js new file mode 100644 index 0000000000000000000000000000000000000000..dd0b29305597733780643a867e1c81e93b11ca78 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to an Array-like object, + 'length' is 0 (length overridden to false(type conversion)) +---*/ + +var accessed = false; +function callbackfn(preVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + length: false +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-20.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-20.js new file mode 100644 index 0000000000000000000000000000000000000000..1ab2f64b36a84ef24834abb9e13bdccb501d599a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-20.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is an Object which + has an own valueOf method +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var valueOfAccessed = false; +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: { + valueOf: function() { + valueOfAccessed = true; + return 2; + } + } +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert(testResult2, 'testResult2 !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-21.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-21.js new file mode 100644 index 0000000000000000000000000000000000000000..0ff7a07672a194cdb3c820f2e7c5e28592ec2abf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-21.js @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - 'length' is an object that has an + own valueOf method that returns an object and toString method that + returns a string +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var toStringAccessed = false; +var valueOfAccessed = false; +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: { + valueOf: function() { + valueOfAccessed = true; + return {}; + }, + toString: function() { + toStringAccessed = true; + return '2'; + } + } +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert(testResult2, 'testResult2 !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert(toStringAccessed, 'toStringAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-22.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-22.js new file mode 100644 index 0000000000000000000000000000000000000000..9bb8ad46431bc9e7c271c2a2982765693f0f8cb7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-22.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError exception when + 'length' is an object with toString and valueOf methods that don�t + return primitive values +---*/ + +var accessed = false; +var toStringAccessed = false; +var valueOfAccessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 11, + 1: 12, + length: { + valueOf: function() { + valueOfAccessed = true; + return {}; + }, + toString: function() { + toStringAccessed = true; + return {}; + } + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +}); +assert(toStringAccessed, 'toStringAccessed !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-23.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-23.js new file mode 100644 index 0000000000000000000000000000000000000000..10602e96792992f2165602423c11ff1e48a106f5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-23.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight uses inherited valueOf method when + 'length' is an object with an own toString and inherited valueOf + methods +---*/ + +var testResult1 = true; +var testResult2 = false; +var valueOfAccessed = false; +var toStringAccessed = false; +var proto = { + valueOf: function() { + valueOfAccessed = true; + return 2; + } +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +Object.defineProperty(child, "toString", { + value: function() { + toStringAccessed = true; + return '1'; + } +}); +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: child +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert(testResult2, 'testResult2 !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(toStringAccessed, false, 'toStringAccessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-24.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-24.js new file mode 100644 index 0000000000000000000000000000000000000000..c816208e6d86dc8e6fcaa1b7636809b5e32da840 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-24.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a positive + non-integer, ensure truncation occurs in the proper direction +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: 2.685 +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert(testResult2, 'testResult2 !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-25.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-25.js new file mode 100644 index 0000000000000000000000000000000000000000..6a0b7d006331b79fd8c54c88c4239ba4bac452fe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-25.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a negative + non-integer +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var obj = { + 0: 12, + 1: 11, + 2: 9, + length: -4294967294.5 +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert.sameValue(testResult2, false, 'testResult2'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-3.js new file mode 100644 index 0000000000000000000000000000000000000000..f4b1ee665f7ae18705f95106c2159a775a1d3526 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a number (value + is 0) +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + length: 0 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-4.js new file mode 100644 index 0000000000000000000000000000000000000000..4dcd7caa789b22620a2fdcf1f1ffefb109123e8a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-4.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a number (value + is +0) +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + length: +0 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-5.js new file mode 100644 index 0000000000000000000000000000000000000000..f52af506bae59f07adafdf23f5f5dfa48f830793 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-5.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a number (value + is -0) +---*/ + +var accessed = false; +function callbackfn(preVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + length: -0 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-6.js new file mode 100644 index 0000000000000000000000000000000000000000..03b5b8d1fe3b259028fc239eab2f6d64f6ab9f85 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-6.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a number (value + is positive) +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var obj = { + 1: 11, + 2: 9, + length: 2 +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert(testResult2, 'testResult2 !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-7.js new file mode 100644 index 0000000000000000000000000000000000000000..e4b850a3b9caa52fa495b70fc9403fed2dc4ac47 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-7.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a number (value + is negative) +---*/ + +var testResult1 = true; +var testResult2 = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx > 1) { + testResult1 = false; + } + if (idx === 1) { + testResult2 = true; + } + return false; +} +var obj = { + 1: 11, + 2: 9, + length: -4294967294 +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +assert(testResult1, 'testResult1 !== true'); +assert.sameValue(testResult2, false, 'testResult2'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-9.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-9.js new file mode 100644 index 0000000000000000000000000000000000000000..ee3f5bd7257d1f5f7a072f19c611e988e5593445 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-3-9.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'length' is a number (value + is -Infinity) +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; +} +var obj = { + 0: 9, + length: -Infinity +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 1), 1, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 1)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..94d854e3f892afeec7342a5d0ce9c01d3d87375b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if callbackfn is + undefined +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduceRight(); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-10.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-10.js new file mode 100644 index 0000000000000000000000000000000000000000..6c5ac7ada2e949894c88535004399a7974f19106 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-10.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - the exception is not thrown if + exception was thrown by step 2 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduceRight.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-11.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-11.js new file mode 100644 index 0000000000000000000000000000000000000000..a44c23aed2346d18dfe0b1f6ed11c0816a9aefa8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-11.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - the exception is not thrown if + exception was thrown by step 3 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + throw new Test262Error(); + } + }; + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduceRight.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-12.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-12.js new file mode 100644 index 0000000000000000000000000000000000000000..9358981adbab0d9e0464182195d5f033aa04bfc0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-12.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight - 'callbackfn' is a function +---*/ + +var initialValue = 0; +function callbackfn(accum, val, idx, obj) { + accum += val; + return accum; +} +assert.sameValue([11, 9].reduceRight(callbackfn, initialValue), 20, '[11, 9].reduceRight(callbackfn, initialValue)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-15.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-15.js new file mode 100644 index 0000000000000000000000000000000000000000..f518599e24b381f408a4b1e992a9424609ffabdf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-15.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - calling with no callbackfn is the + same as passing undefined for callbackfn +---*/ + +var obj = { + 10: 10 +}; +var lengthAccessed = false; +var loopAccessed = false; +Object.defineProperty(obj, "length", { + get: function() { + lengthAccessed = true; + return 20; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + loopAccessed = true; + return 10; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduceRight.call(obj, undefined); +}); +assert(lengthAccessed, 'lengthAccessed !== true'); +assert.sameValue(loopAccessed, false, 'loopAccessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-2.js new file mode 100644 index 0000000000000000000000000000000000000000..e88027a3941ef6e7b0916a6d304e1e51df5be5d8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws ReferenceError if callbackfn is + unreferenced +---*/ + +var arr = new SendableArray(10); +assert.throws(ReferenceError, function() { + arr.reduceRight(foo); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..fd59ac0dd909f4cea1c2dc4c2c329b497fc56643 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-3.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight throws TypeError if callbackfn is null +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduceRight(null); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..e25cf3e750f05e4d4fd51bb006b6de0e461e2b9d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-4.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if callbackfn is + boolean +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduceRight(true); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-5.js new file mode 100644 index 0000000000000000000000000000000000000000..981494bcd4936329c071ebf47705458a1d9a1211 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-5.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if callbackfn is + number +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduceRight(5); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-6.js new file mode 100644 index 0000000000000000000000000000000000000000..2c4836e373eae6fb846ff46f629948c6b31c50f6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-6.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if callbackfn is + string +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduceRight("abc"); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-7.js new file mode 100644 index 0000000000000000000000000000000000000000..9049367c65ac0d230cffd5f41b725bb137aeee34 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-7.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if callbackfn is + Object without [[Call]] internal method +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduceRight(new Object()); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-8.js new file mode 100644 index 0000000000000000000000000000000000000000..a99101dbb1a05d3ba35fbcd54d2528371f70e751 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-8.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - side effects produced by step 2 are + visible when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + accessed = true; + return 2; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduceRight.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-9.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-9.js new file mode 100644 index 0000000000000000000000000000000000000000..6fd755c50c19aa89f2b6772aeb124c976a31592f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-4-9.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - side effects produced by step 3 are + visible when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + accessed = true; + return "2"; + } + }; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduceRight.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..a54e069d6c220df25120ef9a716cfc51d6a2f9b6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if 'length' is 0 + (empty array), no initVal +---*/ + +function cb() {} +assert.throws(TypeError, function() { + [].reduceRight(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-10.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-10.js new file mode 100644 index 0000000000000000000000000000000000000000..ec343eb3b31a2ac53cfb8bac046ec3d5d87aa321 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-10.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - side-effects produced by step 2 when + an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + accessed = true; + return 0; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduceRight.call(obj, function() {}); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-11.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-11.js new file mode 100644 index 0000000000000000000000000000000000000000..c22004fe12948b3726426888a1a2fc4d9f599460 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-11.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - side-effects produced by step 3 when + an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + accessed = true; + return "0"; + } + }; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduceRight.call(obj, function() {}); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-12.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-12.js new file mode 100644 index 0000000000000000000000000000000000000000..3be3aa2a5576daaefd7521e0b3893c6a8c13e3de --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-12.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - the exception is not thrown if + exception was thrown by step 2 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduceRight.call(obj, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-13.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-13.js new file mode 100644 index 0000000000000000000000000000000000000000..f58e532acbc67f805d98b34f847c0da7ef7637b6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-13.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - the exception is not thrown if + exception was thrown by step 3 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + throw new Test262Error(); + } + }; + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduceRight.call(obj, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-2.js new file mode 100644 index 0000000000000000000000000000000000000000..a9cd275e1ab45f0123f04a5c3b3628ea8a798ed2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if 'length' is 0 + (subclassed Array, length overridden to null (type conversion)), + no initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = null; +function cb() {} +assert.throws(TypeError, function() { + f.reduceRight(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-3.js new file mode 100644 index 0000000000000000000000000000000000000000..56f630b36e0daa8f2290dabfa5c244c3e3d8d84d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-3.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if 'length' is 0 + (subclassed Array, length overridden to false (type conversion)), + no initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = false; +function cb() {} +assert.throws(TypeError, function() { + f.reduceRight(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-4.js new file mode 100644 index 0000000000000000000000000000000000000000..538688af14460bafa74af7ad66ac838851048c08 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if 'length' is 0 + (subclassed Array, length overridden to 0 (type conversion)), no + initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 0; +function cb() {} +assert.throws(TypeError, function() { + f.reduceRight(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-5.js new file mode 100644 index 0000000000000000000000000000000000000000..3a6a56bb345547f0bf8a2cdbc57c011f73feacb1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-5.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if 'length' is 0 + (subclassed Array, length overridden to '0' (type conversion)), no + initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = '0'; +function cb() {} +assert.throws(TypeError, function() { + f.reduceRight(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-6.js new file mode 100644 index 0000000000000000000000000000000000000000..6bba5583f1efd1e2bd668e35ca29e99f8fdd6a42 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if 'length' is 0 + (subclassed Array, length overridden with obj with valueOf), no + initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + valueOf: function() { + return 0; + } +}; +f.length = o; +function cb() {} +assert.throws(TypeError, function() { + f.reduceRight(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-7.js new file mode 100644 index 0000000000000000000000000000000000000000..01ace1beed637d1e806af6bae1bf9df6528027fe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-7.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if 'length' is 0 + (subclassed Array, length overridden with obj w/o valueOf + (toString)), no initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + toString: function() { + return '0'; + } +}; +f.length = o; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +function cb() {} +assert.throws(TypeError, function() { + f.reduceRight(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-8.js new file mode 100644 index 0000000000000000000000000000000000000000..b292dcc1fb0a45dcc5c40fe98bee4942ad8a4a51 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-8.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError if 'length' is 0 + (subclassed Array, length overridden with []), no initVal +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = []; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +function cb() {} +assert.throws(TypeError, function() { + f.reduceRight(cb); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-9.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-9.js new file mode 100644 index 0000000000000000000000000000000000000000..7d516df1ee20aa6d3c22723ab6502249c0ce43a6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-5-9.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - 'initialValue' is returned if 'len' + is 0 and 'initialValue' is present +---*/ + +var initialValue = 10; +assert.sameValue([].reduceRight(function() {}, initialValue), initialValue, '[].reduceRight(function () { }, initialValue)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-1.js new file mode 100644 index 0000000000000000000000000000000000000000..e185d842066f4bc080ba3d74ad242a148eba5757 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight returns initialValue if 'length' is 0 + and initialValue is present (empty array) +---*/ + +function cb() {} +assert.sameValue([].reduceRight(cb, 1), 1, '[].reduceRight(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-10.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-10.js new file mode 100644 index 0000000000000000000000000000000000000000..a73b2e6dcf4b7d7b09c54c44404c7e60aa75ce0d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-10.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight - 'initialValue' is present +---*/ + +var str = "initialValue is present"; +assert.sameValue([].reduceRight(function() {}, str), str, '[].reduceRight(function () { }, str)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-11.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-11.js new file mode 100644 index 0000000000000000000000000000000000000000..efa909614177690bf6d3d6d53a97e46bd006e7c1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-11.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight - 'initialValue' is not present +---*/ + +var str = "initialValue is not present"; +assert.sameValue([str].reduceRight(function() {}), str, '[str].reduceRight(function () { })'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-2.js new file mode 100644 index 0000000000000000000000000000000000000000..2d46cdec9e75a437a2e277bcb6e09f65fbc22eb9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight returns initialValue if 'length' is 0 + and initialValue is present (subclassed Array, length overridden + to null (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = null; +function cb() {} +assert.sameValue(f.reduceRight(cb, 1), 1, 'f.reduceRight(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-3.js new file mode 100644 index 0000000000000000000000000000000000000000..34a57cf4caa4fc2d204b1f6c2751a6257d5ee4e4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-3.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight returns initialValue if 'length' is 0 + and initialValue is present (subclassed Array, length overridden + to false (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = false; +function cb() {} +assert.sameValue(f.reduceRight(cb, 1), 1, 'f.reduceRight(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-4.js new file mode 100644 index 0000000000000000000000000000000000000000..480e688788576d7eb6ecbc29870e5ec61a8f5e06 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight returns initialValue if 'length' is 0 + and initialValue is present (subclassed Array, length overridden + to 0 (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 0; +function cb() {} +assert.sameValue(f.reduceRight(cb, 1), 1, 'f.reduceRight(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-5.js new file mode 100644 index 0000000000000000000000000000000000000000..dae32eae32d6d03cecfaadaf16a9ded5854c0aa0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-5.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight returns initialValue if 'length' is 0 + and initialValue is present (subclassed Array, length overridden + to '0' (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = '0'; +function cb() {} +assert.sameValue(f.reduceRight(cb, 1), 1, 'f.reduceRight(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-6.js new file mode 100644 index 0000000000000000000000000000000000000000..c286a242a4b3a7b5f60ba51f74cc22dbe61e41d6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-6.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight returns initialValue if 'length' is 0 + and initialValue is present (subclassed Array, length overridden + with obj with valueOf) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + valueOf: function() { + return 0; + } +}; +f.length = o; +function cb() {} +assert.sameValue(f.reduceRight(cb, 1), 1, 'f.reduceRight(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-7.js new file mode 100644 index 0000000000000000000000000000000000000000..d7acc1caefcb1d0097032bdb0fa6b4ba9adc71cb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-7.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight returns initialValue if 'length' is 0 + and initialValue is present (subclassed Array, length overridden + with obj w/o valueOf (toString)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + toString: function() { + return '0'; + } +}; +f.length = o; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +function cb() {} +assert.sameValue(f.reduceRight(cb, 1), 1, 'f.reduceRight(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-8.js new file mode 100644 index 0000000000000000000000000000000000000000..b537aaffd8f92b441b19b88987c6b8ff23cc4eab --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-8.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight returns initialValue if 'length' is 0 + and initialValue is present (subclassed Array, length overridden + with []) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = []; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +function cb() {} +assert.sameValue(f.reduceRight(cb, 1), 1, 'f.reduceRight(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-9.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-9.js new file mode 100644 index 0000000000000000000000000000000000000000..479092a0c4cf63c1446fe88ede5f366affd4d0ec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-7-9.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight returns initialValue if 'length' is 0 + and initialValue is present (subclassed Array, length overridden + with [0]) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = [0]; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +function cb() {} +assert.sameValue(f.reduceRight(cb, 1), 1, 'f.reduceRight(cb,1)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..1b1b28f7191663d848465d80d9555f367c7444a7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-1.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - no observable effects occur if 'len' + is 0 +---*/ + +var accessed = false; +var obj = { + length: 0 +}; +Object.defineProperty(obj, "0", { + get: function() { + accessed = true; + return 10; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduceRight.call(obj, function() {}); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-2.js new file mode 100644 index 0000000000000000000000000000000000000000..35b68af6bb2dc8afe5dff01613a6436dec5ae1e3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-2.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - modifications to length don't change + number of iterations in step 9 +---*/ + +var called = 0; +function callbackfn(prevVal, curVal, idx, obj) { + called++; + return prevVal + curVal; +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "4", { + get: function() { + arr.length = 2; + return 10; + }, + configurable: true +}); +var preVal = arr.reduceRight(callbackfn); +assert.sameValue(preVal, 11, 'preVal'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-3.js new file mode 100644 index 0000000000000000000000000000000000000000..8e908a87c82a289438e4bf6071be1e7acb8986df --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-3.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - while loop is breaken once + 'kPresent' is true +---*/ + +var called = 0; +var testResult = false; +var firstCalled = 0; +var secondCalled = 0; +function callbackfn(prevVal, val, idx, obj) { + if (called === 0) { + testResult = (idx === 1); + } + called++; +} +var arr = [, , , ]; +Object.defineProperty(arr, "1", { + get: function() { + firstCalled++; + return 9; + }, + configurable: true +}); +Object.defineProperty(arr, "2", { + get: function() { + secondCalled++; + return 11; + }, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); +assert.sameValue(firstCalled, 1, 'firstCalled'); +assert.sameValue(secondCalled, 1, 'secondCalled'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-ii-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..38e6c069216afe35b6794b97c604901efe9c5cf8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-ii-1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - added properties in step 2 are + visible here +---*/ + +var obj = {}; +function callbackfn(prevVal, curVal, idx, obj) {} +Object.defineProperty(obj, "length", { + get: function() { + obj[2] = "accumulator"; + return 3; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn), "accumulator", 'Array.prototype.reduceRight.call(obj, callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-ii-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-ii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..6341909f142451e420fc148e2bbea37bfc02e310 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-ii-2.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleted properties in step 2 are + visible here +---*/ + +var obj = { + 2: "accumulator", + 3: "another" +}; +Object.defineProperty(obj, "length", { + get: function() { + delete obj[2]; + return 5; + }, + configurable: true +}); +assert.notSameValue(SendableArray.prototype.reduceRight.call(obj, function() {}), "accumulator", 'SendableArray.prototype.reduceRight.call(obj, function () { })'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..1f55460bb019fd943f8c2287f8f79891b4339ae5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-1.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 0) { + testResult = (prevVal === 1); + } +} +var obj = { + 0: 0, + 1: 1, + length: 2 +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-10.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..df44993fa27bd547f4f203e7a6287a956121c008 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-10.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 2) { + testResult = (curVal === 2); + } +} +var arr = [0, 1, , 3]; +Object.defineProperty(arr, "2", { + get: function() { + return 2; + }, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-11.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..5c108de8106b7fde52093959003c55ab5cc55c65 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-11.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property that overrides an inherited data property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "20"); + } +} +var proto = { + 0: 0, + 1: 1, + 2: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +Object.defineProperty(child, "2", { + get: function() { + return "20"; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-12.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..7776c0008a8ef75e101dfaa898f7633607be2932 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-12.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property that overrides an inherited data property on an + Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "20"); + } +} +SendableArray.prototype[2] = 2; +var arr = [0, 1]; +Object.defineProperty(arr, "2", { + get: function() { + return "20"; + }, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-13.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..31a957b83b3da30d799445f01cd8b455175b430f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-13.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property that overrides an inherited accessor property on + an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "20"); + } +} +var proto = { + 0: 0, + 1: 1 +}; +Object.defineProperty(proto, "2", { + get: function() { + return 2; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +Object.defineProperty(child, "2", { + get: function() { + return "20"; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-14.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-14.js new file mode 100644 index 0000000000000000000000000000000000000000..87e1e2953bdc38ee99abeb9d8b5674aa5ff21f6e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-14.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property that overrides an inherited accessor property on + an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "20"); + } +} +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return 2; + }, + configurable: true +}); +var arr = [0, 1, , ]; +Object.defineProperty(arr, "2", { + get: function() { + return "20"; + }, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-15.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..9e5607914676c23bded09303ac4a765c14ee9ab8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-15.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + accessor property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 2); + } +} +var proto = { + 0: 0, + 1: 1 +}; +Object.defineProperty(proto, "2", { + get: function() { + return 2; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +SendableArray.prototype.reduceRight.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-16.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-16.js new file mode 100644 index 0000000000000000000000000000000000000000..68df5974022dd2bca85fdb5df18e20a75df83736 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-16.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 2); + } +} +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return 2; + }, + configurable: true +}); +var arr = [0, 1, , ]; +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-17.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-17.js new file mode 100644 index 0000000000000000000000000000000000000000..873b52dcfd9042d0493311cad325bed5ccdc6670 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-17.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property without a get function on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof prevVal === "undefined"); + } +} +var obj = { + 0: 0, + 1: 1, + length: 3 +}; +Object.defineProperty(obj, "2", { + set: function() {}, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-18.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-18.js new file mode 100644 index 0000000000000000000000000000000000000000..2717fa89d42a8b92f7ec86fdd12179f0638fceda --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-18.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property without a get function on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof prevVal === "undefined"); + } +} +var arr = [0, 1]; +Object.defineProperty(arr, "2", { + set: function() {}, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-19.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-19.js new file mode 100644 index 0000000000000000000000000000000000000000..61b0f7137b85da1de7c8a0b0f241bf55938a55ad --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-19.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property without a get function that overrides an + inherited accessor property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof prevVal === "undefined"); + } +} +Object.prototype[2] = 2; +var obj = { + 0: 0, + 1: 1, + length: 3 +}; +Object.defineProperty(obj, "2", { + set: function() {}, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..5363de10f3290d92811f3501958488e2615f1c65 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 2); + } +} +var arr = [0, 1, 2]; +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-20.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-20.js new file mode 100644 index 0000000000000000000000000000000000000000..e1da6c0da2e97a157702177f439d51f8330354ec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-20.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property without a get function that overrides an + inherited accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof prevVal === "undefined"); + } +} +SendableArray.prototype[2] = 2; +var arr = [0, 1]; +Object.defineProperty(arr, "2", { + set: function() {}, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-21.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-21.js new file mode 100644 index 0000000000000000000000000000000000000000..315b4845d852772e2a612514727b1624b89fdead --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-21.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + accessor property without a get function on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof prevVal === "undefined"); + } +} +var proto = { + 0: 0, + 1: 1 +}; +Object.defineProperty(proto, "2", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +SendableArray.prototype.reduceRight.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-22.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-22.js new file mode 100644 index 0000000000000000000000000000000000000000..1fb0ce6a56338618f41c882cd240534831ccc001 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-22.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + accessor property without a get function on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof prevVal === "undefined"); + } +} +Object.defineProperty(SendableArray.prototype, "2", { + set: function() {}, + configurable: true +}); +var arr = [0, 1, , ]; +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-25.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-25.js new file mode 100644 index 0000000000000000000000000000000000000000..2b2249800f404d687466022a9455d0b922e5e779 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-25.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - This object is the Arguments object + which implements its own property get method (number of arguments + is less than number of parameters) +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 0) { + testResult = (prevVal === 1); + } +} +var func = function(a, b, c) { + SendableArray.prototype.reduceRight.call(arguments, callbackfn); +}; +func(0, 1); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-26.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-26.js new file mode 100644 index 0000000000000000000000000000000000000000..43c22e89dd80fc910963a0b4c24f742233f29676 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-26.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - This object is the Arguments object + which implements its own property get method (number of arguments + equals number of parameters) +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 2); + } +} +var func = function(a, b, c) { + SendableArray.prototype.reduceRight.call(arguments, callbackfn); +}; +func(0, 1, 2); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-27.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-27.js new file mode 100644 index 0000000000000000000000000000000000000000..a8bf73ebe6c376c1e204e2ecc67fcf6c71830b6b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-27.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - This object is the Arguments object + which implements its own property get method (number of arguments + is greater than number of parameters) +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 2) { + testResult = (prevVal === 3); + } +} +var func = function(a, b, c) { + SendableArray.prototype.reduceRight.call(arguments, callbackfn); +}; +func(0, 1, 2, 3); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-28.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-28.js new file mode 100644 index 0000000000000000000000000000000000000000..b102f0cd1a8ca91ca3141c3b44367b528444cd8b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-28.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to String object, which + implements its own property get method +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "2"); + } +} +var str = new String("012"); +SendableArray.prototype.reduceRight.call(str, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-29.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-29.js new file mode 100644 index 0000000000000000000000000000000000000000..13ec864cb27a20d519cb994103c1a4fd30614f71 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-29.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Function object which + implements its own property get method +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 2); + } +} +var obj = function(a, b, c) { + return a + b + c; +}; +obj[0] = 0; +obj[1] = 1; +obj[2] = 2; +SendableArray.prototype.reduceRight.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..0611f34d9938e18df1ed96a089fe943b18b7861c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-3.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property that overrides an inherited data property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "20"); + } +} +var proto = { + 0: 0, + 1: 1, + 2: 2, + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[1] = "10"; +child[2] = "20"; +child.length = 3; +SendableArray.prototype.reduceRight.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-30.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-30.js new file mode 100644 index 0000000000000000000000000000000000000000..71c7e4e0242ea9a86bd016cc961602a9f626b487 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-30.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element changed by getter on current + iteration is observed in subsequent iterations on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1 && prevVal === 2); + } +} +var arr = [0]; +var preIterVisible = false; +Object.defineProperty(arr, "1", { + get: function() { + if (preIterVisible) { + return 1; + } else { + return "20"; + } + }, + configurable: true +}); +Object.defineProperty(arr, "2", { + get: function() { + preIterVisible = true; + return 2; + }, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-31.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-31.js new file mode 100644 index 0000000000000000000000000000000000000000..e1882af20b227fe9aa63834e4f3a45752620719d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-31.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element changed by getter on current + iteration is observed subsequetly on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 2 && curVal === 1); + } +} +var obj = { + 0: 0, + length: 3 +}; +var preIterVisible = false; +Object.defineProperty(obj, "1", { + get: function() { + if (preIterVisible) { + return 1; + } else { + return "20"; + } + }, + configurable: true +}); +Object.defineProperty(obj, "2", { + get: function() { + preIterVisible = true; + return 2; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-32.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-32.js new file mode 100644 index 0000000000000000000000000000000000000000..a011d397c0e99ff59b6a02ebb32bcf76b6558b99 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-32.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - Exception in getter terminate + iteration on an Array-like object +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx <= 1) { + accessed = true; + } +} +var obj = { + 0: 0, + 1: 1, + length: 3 +}; +Object.defineProperty(obj, "2", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + SendableArray.prototype.reduceRight.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-33.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-33.js new file mode 100644 index 0000000000000000000000000000000000000000..abd31a8f98cb4423f9737457894f6e220f28ad69 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-33.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - Exception in getter terminate + iteration on an Array +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx <= 1) { + accessed = true; + } +} +var arr = [0, 1]; +Object.defineProperty(arr, "2", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + arr.reduceRight(callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..5265778bc0b7587cbab072a7ccc1fdcea4770c0b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 2); + } +} +SendableArray.prototype[2] = "11"; +[0, 1, 2].reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..560f96f37271dc16ee8efa42168d48bb3acb69a0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-5.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === "20"); + } +} +var proto = {}; +Object.defineProperty(proto, "2", { + get: function() { + return 11; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +child[0] = "0"; +child[1] = "1"; +Object.defineProperty(proto, "2", { + value: "20", + configurable: true +}); +SendableArray.prototype.reduceRight.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..cb2f08978d30d747a8784251607f8f4c88c29012 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property that overrides an inherited accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 2); + } +} +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return "2"; + }, + configurable: true +}); +[0, 1, 2].reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..b32e632da574dfb05ac9d80b255158f15d50eb61 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-7.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + data property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 2); + } +} +var proto = { + 0: 0, + 1: 1, + 2: 2, + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +SendableArray.prototype.reduceRight.call(child, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..9488ef5db9fbeede08a1962bd58fc1901c60b853 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-8.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + data property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 2); + } +} +SendableArray.prototype[0] = 0; +SendableArray.prototype[1] = 1; +SendableArray.prototype[2] = 2; +[, , , ].reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-9.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..ad3408fc801e98822da2e9dc42dc4fb3cf89a3ba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-b-iii-1-9.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 2); + } +} +var obj = { + 0: 0, + 1: 1, + length: 3 +}; +Object.defineProperty(obj, "2", { + get: function() { + return 2; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-1.js new file mode 100644 index 0000000000000000000000000000000000000000..f85e98a8ff889c9eb55846599ebbbc7c08e9acba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-1.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError when Array is empty + and initialValue is not present +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{} +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.reduceRight(callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-2.js new file mode 100644 index 0000000000000000000000000000000000000000..2bfe02085c6244c92e5f020945010b2ee8ed7d68 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError when elements + assigned values are deleted by reducign array length and + initialValue is not present +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{} +var arr = new SendableArray(10); +arr[9] = 1; +arr.length = 5; +assert.throws(TypeError, function() { + arr.reduceRight(callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-3.js new file mode 100644 index 0000000000000000000000000000000000000000..b4d2711377b0b519f946eb8d9c04bea4f47bdf26 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-3.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight throws TypeError when elements + assigned values are deleted and initialValue is not present +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{} +var arr = [1, 2, 3, 4, 5]; +delete arr[0]; +delete arr[1]; +delete arr[2]; +delete arr[3]; +delete arr[4]; +assert.throws(TypeError, function() { + arr.reduceRight(callbackfn); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-4.js new file mode 100644 index 0000000000000000000000000000000000000000..f06b518690e45cb3fd41e3b737efabbffb71d9be --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight doesn't throw error when array has no + own properties but prototype contains a single property +---*/ + +var arr = [, , , ]; +try { + SendableArray.prototype[1] = "prototype"; + arr.reduceRight(function() {}); +} finally { + delete SendableArray.prototype[1]; +} diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-5.js new file mode 100644 index 0000000000000000000000000000000000000000..4c77cc1ba6bd05aa1209d1d455d656c1f38bc439 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-5.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - side effects produced by step 2 are + visible when an exception occurs +---*/ + +var obj = {}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + accessed = true; + return 2; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduceRight.call(obj, function() {}); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-6.js new file mode 100644 index 0000000000000000000000000000000000000000..b56c83a69a2ba73346e183ac045590183f337c71 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-6.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - side effects produced by step 3 are + visible when an exception occurs +---*/ + +var obj = {}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + accessed = true; + return "2"; + } + }; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.reduceRight.call(obj, function() {}); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-7.js new file mode 100644 index 0000000000000000000000000000000000000000..3481ce46263d83322540d0a3748fcec820793731 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-7.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - the exception is not thrown if + exception was thrown by step 2 +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduceRight.call(obj, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-8.js new file mode 100644 index 0000000000000000000000000000000000000000..aa7170d21781ca42c02246abb54c0efcd4e9b64d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-8-c-8.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - the exception is not thrown if + exception was thrown by step 3 +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + throw new Test262Error(); + } + }; + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.reduceRight.call(obj, function() {}); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-1.js new file mode 100644 index 0000000000000000000000000000000000000000..95e13c08937b53464ce3ffd8949b1448977532e2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight doesn't consider new elements which + index is larger than array original length added to array after it + is called, consider new elements which index is smaller than array + length +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + arr[5] = 6; + arr[2] = 3; + return prevVal + curVal; +} +var arr = ['1', 2, , 4, '5']; +assert.sameValue(arr.reduceRight(callbackfn), "54321", 'arr.reduceRight(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-2.js new file mode 100644 index 0000000000000000000000000000000000000000..62e1104d24d7a47865d8a68b84aa72dd5b5eeca9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight considers new value of elements in + array after it is called +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + arr[3] = -2; + arr[0] = -1; + return prevVal + curVal; +} +var arr = [1, 2, 3, 4, 5]; +assert.sameValue(arr.reduceRight(callbackfn), 13, 'arr.reduceRight(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-3.js new file mode 100644 index 0000000000000000000000000000000000000000..48eeff452c2bd1ae4edb85c61b70d7276f14bfe6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-3.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight doesn't consider unvisited deleted + elements in array after the call +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + delete arr[1]; + delete arr[4]; + return prevVal + curVal; +} +var arr = ['1', 2, 3, 4, 5]; +// two elements deleted +assert.sameValue(arr.reduceRight(callbackfn), "121", 'arr.reduceRight(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-4.js new file mode 100644 index 0000000000000000000000000000000000000000..8159572549a61b54c23fbe76e0f4adcb09d807c5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight doesn't consider unvisited deleted + elements when Array.length is decreased +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + arr.length = 2; + return prevVal + curVal; +} +var arr = [1, 2, 3, 4, 5]; +assert.sameValue(arr.reduceRight(callbackfn), 12, 'arr.reduceRight(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-5.js new file mode 100644 index 0000000000000000000000000000000000000000..f9f054972e01578e6693f32ac13450bf879c8aa2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-5.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - callbackfn not called for array with + one element +---*/ + +var callCnt = 0; +function callbackfn(prevVal, curVal, idx, obj) +{ + callCnt++; + return 2; +} +var arr = [1]; +assert.sameValue(arr.reduceRight(callbackfn), 1, 'arr.reduceRight(callbackfn)'); +assert.sameValue(callCnt, 0, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-6.js new file mode 100644 index 0000000000000000000000000000000000000000..9e8288f21f056ec7e6f60842a4aa9baa6f1165b4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-6.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight visits deleted element in array after + the call when same index is also present in prototype +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + delete arr[1]; + delete arr[2]; + return prevVal + curVal; +} +SendableArray.prototype[2] = 6; +var arr = ['1', 2, 3, 4, 5]; +var res = arr.reduceRight(callbackfn); +delete SendableArray.prototype[2]; +//one element deleted +assert.sameValue(res, "151", 'res'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-7.js new file mode 100644 index 0000000000000000000000000000000000000000..d83b491d052c1ccfdffef27c9c653ec744b478b2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-7.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight not affect call when the array is + deleted during the call +---*/ + +function callbackfn(prevVal, curVal, idx, obj) { + delete o.arr; + return prevVal + curVal; +} +var o = new Object(); +o.arr = ['1', 2, 3, 4, 5]; +assert.sameValue(o.arr.reduceRight(callbackfn), "141", 'o.arr.reduceRight(callbackfn)'); +assert.sameValue(o.hasOwnProperty("arr"), false, 'o.hasOwnProperty("arr")'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-8.js new file mode 100644 index 0000000000000000000000000000000000000000..a1ae120a7a19d4bb39269d7c9dba9bd16629f856 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-8.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - no observable effects occur if 'len' + is 0 +---*/ + +var accessed = false; +var callbackAccessed = false; +function callbackfn() { + callbackAccessed = true; +} +var obj = { + length: 0 +}; +Object.defineProperty(obj, "5", { + get: function() { + accessed = true; + return 10; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert.sameValue(accessed, false, 'accessed'); +assert.sameValue(callbackAccessed, false, 'callbackAccessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-9.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-9.js new file mode 100644 index 0000000000000000000000000000000000000000..11e24e09a952cfb725675de6517906e8073f53db --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-9.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - modifications to length will change + number of iterations +---*/ + +var called = 0; +function callbackfn(preVal, val, idx, obj) { + called++; +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "4", { + get: function() { + arr.length = 2; + }, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert.sameValue(called, 3, 'called'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..aff534e37f8056ca58b2480d271bceaab0b1c02e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight returns initialvalue when Array is + empty and initialValue is not present +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{} +var arr = new SendableArray(10); +assert.sameValue(arr.reduceRight(callbackfn, 5), 5, 'arr.reduceRight(callbackfn,5)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-10.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-10.js new file mode 100644 index 0000000000000000000000000000000000000000..ba64c54089a36ae7e00e26978233efd69ca715a7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-10.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting property of prototype in + step 8 causes deleted index property not to be visited on an + Array-like Object +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(preVal, val, idx, obj) { + accessed = true; + if (idx === 3) { + testResult = false; + } +} +var obj = { + 2: 2, + length: 20 +}; +Object.defineProperty(obj, "5", { + get: function() { + delete Object.prototype[3]; + return 0; + }, + configurable: true +}); +Object.prototype[3] = 1; +SendableArray.prototype.reduceRight.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-11.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-11.js new file mode 100644 index 0000000000000000000000000000000000000000..725fd9284fb4144fc62c666ac226082de48d1044 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-11.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting property of prototype in + step 8 causes deleted index property not to be visited on an Array +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var arr = [0, , , ]; +Object.defineProperty(arr, "3", { + get: function() { + delete SendableArray.prototype[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-12.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-12.js new file mode 100644 index 0000000000000000000000000000000000000000..43b623f3012182594aeda822efa0316fce81aca5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-12.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting own property with prototype + property in step 8 causes prototype index property to be visited + on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1 && curVal === 1) { + testResult = true; + } +} +var obj = { + 0: 0, + 1: 111, + length: 10 +}; +Object.defineProperty(obj, "4", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +SendableArray.prototype.reduceRight.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-13.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-13.js new file mode 100644 index 0000000000000000000000000000000000000000..096661c4b3c36753386cc793782373c78595f19e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-13.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting own property with prototype + property in step 8 causes prototype index property to be visited + on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1 && curVal === 1) { + testResult = true; + } +} +var arr = [0, 111]; +Object.defineProperty(arr, "2", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-14.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-14.js new file mode 100644 index 0000000000000000000000000000000000000000..01064621f88f31a97ae556b8d774ba977c4a6fc1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-14.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - decreasing length of array in step 8 + causes deleted index property not to be visited +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (idx === 2) { + testResult = false; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "3", { + get: function() { + arr.length = 2; + return 0; + }, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-15.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-15.js new file mode 100644 index 0000000000000000000000000000000000000000..87b4f5d27bb35168764cdb542c0d73ad4acebe1c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-15.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - decreasing length of array with + prototype property in step 8 causes prototype index property to be + visited +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 2 && curVal === "prototype") { + testResult = true; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return "prototype"; + }, + configurable: true +}); +Object.defineProperty(arr, "3", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-16.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-16.js new file mode 100644 index 0000000000000000000000000000000000000000..8ab43cf8708ae24ff4b4ea34acd36084e97cbe3c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-16.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - decreasing length of array in step 8 + does not delete non-configurable properties +flags: [noStrict] +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 2 && curVal === "unconfigurable") { + testResult = true; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "2", { + get: function() { + return "unconfigurable"; + }, + configurable: false +}); +Object.defineProperty(arr, "3", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-17.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-17.js new file mode 100644 index 0000000000000000000000000000000000000000..3b3f5ab618f4f6d98f028909886eaedfe4edf9d9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-17.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - properties added into own object are + visited on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 0 && curVal === 0) { + testResult = true; + } +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + get: function() { + Object.defineProperty(obj, "0", { + get: function() { + return 0; + }, + configurable: true + }); + return 1; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-18.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-18.js new file mode 100644 index 0000000000000000000000000000000000000000..ea7308fd73813e5060949c2be58cbf82ca53d871 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-18.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - properties added into own object are + visited on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1 && curVal === 1) { + testResult = true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "2", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-19.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-19.js new file mode 100644 index 0000000000000000000000000000000000000000..cf8c3a132add4d5f2ed3c2e78576d09c4a11d165 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-19.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - properties added to prototype are + visited on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1 && curVal === 6.99) { + testResult = true; + } +} +var obj = { + length: 6 +}; +Object.defineProperty(obj, "2", { + get: function() { + Object.defineProperty(Object.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-2.js new file mode 100644 index 0000000000000000000000000000000000000000..b71381ed3c95cf22c9f9ccdca6b74ed95fa2753a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-2.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - added properties in step 2 are + visible here +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 2 && curVal === "2") { + testResult = true; + } +} +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + obj[2] = "2"; + return 3; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-20.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-20.js new file mode 100644 index 0000000000000000000000000000000000000000..69a427de1be466c09ba9458d36474ac5ef5e8921 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-20.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - properties added to prototype can be + visited on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1 && curVal === 6.99) { + testResult = true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "2", { + get: function() { + Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-21.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-21.js new file mode 100644 index 0000000000000000000000000000000000000000..1abcaa88f148cdcb108d6f4a9facbe8d22d6c4fe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-21.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting own property causes deleted + index property not to be visited on an Array-like object +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var obj = { + 0: 10, + length: 10 +}; +Object.defineProperty(obj, "1", { + get: function() { + return 6.99; + }, + configurable: true +}); +Object.defineProperty(obj, "5", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-22.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-22.js new file mode 100644 index 0000000000000000000000000000000000000000..84d64a4eb1ecc1eec996f53f0d14bbc85976fa08 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-22.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting own property causes deleted + index property not to be visited on an Array +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var arr = [1, 2, 4]; +Object.defineProperty(arr, "1", { + get: function() { + return "6.99"; + }, + configurable: true +}); +Object.defineProperty(arr, "2", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-23.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-23.js new file mode 100644 index 0000000000000000000000000000000000000000..dbf0ab8a62204bbe349404ad1419ce985bea712e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-23.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting property of prototype + causes deleted index property not to be visited on an Array-like + Object +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (idx === 3) { + testResult = false; + } +} +var obj = { + 2: 2, + length: 20 +}; +Object.defineProperty(obj, "5", { + get: function() { + delete Object.prototype[3]; + return 0; + }, + configurable: true +}); +Object.prototype[3] = 1; +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-24.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-24.js new file mode 100644 index 0000000000000000000000000000000000000000..40b1feff44bf1bc709ca85827f222eca950bae64 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-24.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting property of prototype + causes deleted index property not to be visited on an Array +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var arr = [0, , , ]; +Object.defineProperty(arr, "3", { + get: function() { + delete SendableArray.prototype[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-25.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-25.js new file mode 100644 index 0000000000000000000000000000000000000000..3e9ef799be2bb1be48d8e7b00d266e9aaaf2f4de --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-25.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting own property with prototype + property causes prototype index property to be visited on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1 && curVal === 1) { + testResult = true; + } +} +var obj = { + 0: 0, + 1: 111, + 4: 10, + length: 10 +}; +Object.defineProperty(obj, "4", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-26.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-26.js new file mode 100644 index 0000000000000000000000000000000000000000..9996e4672734dc0f276d9c029b6fadf807559a3f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-26.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting own property with prototype + property causes prototype index property to be visited on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1 && curVal === 1) { + testResult = true; + } +} +var arr = [0, 111]; +Object.defineProperty(arr, "2", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-27.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-27.js new file mode 100644 index 0000000000000000000000000000000000000000..e5adc799879b342c4ce2e8b9a2cfba61c2fb5257 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-27.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - decreasing length of array causes + deleted index property not to be visited +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (idx === 2) { + testResult = false; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "3", { + get: function() { + arr.length = 2; + return 0; + }, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-28.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-28.js new file mode 100644 index 0000000000000000000000000000000000000000..e58c95485513260598a25263cb8c96a33a77becb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-28.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - decreasing length of array with + prototype property causes prototype index property to be visited +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 2 && curVal === "prototype") { + testResult = true; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return "prototype"; + }, + configurable: true +}); +Object.defineProperty(arr, "3", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-29.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-29.js new file mode 100644 index 0000000000000000000000000000000000000000..15f874d1cc1ad3fd15bbca4c4bfa6a8fc95a922a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-29.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - decreasing length of array does not + delete non-configurable properties +flags: [noStrict] +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 2 && curVal === "unconfigurable") { + testResult = true; + } +} +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "2", { + get: function() { + return "unconfigurable"; + }, + configurable: false +}); +Object.defineProperty(arr, "3", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-3.js new file mode 100644 index 0000000000000000000000000000000000000000..bd6158ccbfb1e477320f2e18b4fa77f7d39257e1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-3.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleted properties in step 2 are + visible here +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(preVal, curVal, idx, obj) { + accessed = true; + if (idx === 2) { + testResult = false; + } +} +var obj = { + 2: "2", + 3: 10 +}; +Object.defineProperty(obj, "length", { + get: function() { + delete obj[2]; + return 5; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(accessed, 'accessed !== true'); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-4.js new file mode 100644 index 0000000000000000000000000000000000000000..f8f14183cd4f75a349824222c3de465d41149fdd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-4.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - properties added into own object in + step 8 can be visited on an Array-like object +---*/ + +var testResult = false; +function callbackfn(preVal, curVal, idx, obj) { + if (idx === 0 && curVal === 0) { + testResult = true; + } +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + get: function() { + Object.defineProperty(obj, "0", { + get: function() { + return 0; + }, + configurable: true + }); + return 1; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-5.js new file mode 100644 index 0000000000000000000000000000000000000000..fc6d287de670b57837fc6a2ec4317fd424109e50 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-5.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - properties added into own object in + step 8 can be visited on an Array +---*/ + +var testResult = false; +function callbackfn(preVal, curVal, idx, obj) { + if (idx === 1 && curVal === 1) { + testResult = true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "2", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-6.js new file mode 100644 index 0000000000000000000000000000000000000000..b2d7f315a1954910589d9d75d8c22586fbfa2662 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-6.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - properties added to prototype in + step 8 visited on an Array-like object +---*/ + +var testResult = false; +function callbackfn(preVal, curVal, idx, obj) { + if (idx === 1 && curVal === 6.99) { + testResult = true; + } +} +var obj = { + length: 6 +}; +Object.defineProperty(obj, "2", { + get: function() { + Object.defineProperty(Object.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-7.js new file mode 100644 index 0000000000000000000000000000000000000000..370b889918d51af2bb3679cfa01ce6705ac9391d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-7.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - properties added to prototype in + step 8 visited on an Array +---*/ + +var testResult = false; +function callbackfn(preVal, curVal, idx, obj) { + if (idx === 1 && curVal === 6.99) { + testResult = true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "2", { + get: function() { + Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-8.js new file mode 100644 index 0000000000000000000000000000000000000000..9e87fdb900ecfcb09888dbffbc31a9edd0b95085 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-8.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting own property in step 8 + causes deleted index property not to be visited on an Array-like + object +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(preVal, val, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var obj = { + 0: 10, + length: 10 +}; +Object.defineProperty(obj, "1", { + get: function() { + return 6.99; + }, + configurable: true +}); +Object.defineProperty(obj, "5", { + get: function() { + delete obj[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-9.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-9.js new file mode 100644 index 0000000000000000000000000000000000000000..db22f1a17b73fd8c48f083a4eee8bb16d849c803 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-b-9.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - deleting own property in step 8 + causes deleted index property not to be visited on an Array +---*/ + +var accessed = false; +var testResult = true; +function callbackfn(preVal, curVal, idx, obj) { + accessed = true; + if (idx === 1) { + testResult = false; + } +} +var arr = [0]; +Object.defineProperty(arr, "1", { + get: function() { + return "6.99"; + }, + configurable: true +}); +Object.defineProperty(arr, "2", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-1.js new file mode 100644 index 0000000000000000000000000000000000000000..4bf6cd7083720ab1d8a139462524b56c58c1df1a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - callbackfn not called for indexes + never been assigned values +---*/ + +var callCnt = 0; +function callbackfn(prevVal, curVal, idx, obj) +{ + callCnt++; + return curVal; +} +var arr = new SendableArray(10); +arr[0] = arr[1] = undefined; //explicitly assigning a value +assert.sameValue(arr.reduceRight(callbackfn), undefined, 'arr.reduceRight(callbackfn)'); +assert.sameValue(callCnt, 1, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-1.js new file mode 100644 index 0000000000000000000000000000000000000000..04d4b5a8d6961a64922799d0f168b917110c9f41 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-1.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 0) { + testResult = (curVal === 0); + } +} +var obj = { + 0: 0, + 1: 1, + 2: 2, + length: 2 +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-10.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-10.js new file mode 100644 index 0000000000000000000000000000000000000000..7efef39e83bf46a6f3e6d052c176dbfed6edf94d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-10.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-11.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-11.js new file mode 100644 index 0000000000000000000000000000000000000000..543d04f93e19a0f502d360f4454bbdb93a4682a3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-11.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property that overrides an inherited data property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "1"); + } +} +var proto = { + 0: 0, + 1: 11, + 2: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +Object.defineProperty(child, "1", { + get: function() { + return "1"; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(child, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-12.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-12.js new file mode 100644 index 0000000000000000000000000000000000000000..f54f93ef72559fa99fdde6a2b541afef228752fb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-12.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property that overrides an inherited data property on an + Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "1"); + } +} +SendableArray.prototype[1] = 11; +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + get: function() { + return "1"; + }, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-13.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-13.js new file mode 100644 index 0000000000000000000000000000000000000000..f9de2afd08159ad6128f2af66268e793c5fafb90 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-13.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property that overrides an inherited accessor property on + an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "1"); + } +} +var proto = { + 0: 0, + 2: 2 +}; +Object.defineProperty(proto, "1", { + get: function() { + return 11; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +Object.defineProperty(child, "1", { + get: function() { + return "1"; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(child, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-14.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-14.js new file mode 100644 index 0000000000000000000000000000000000000000..a8a54e8548815ababf2ca3c05a969ed9a9c11a24 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-14.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property that overrides an inherited accessor property on + an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "1"); + } +} +Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 11; + }, + configurable: true +}); +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + get: function() { + return "1"; + }, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-15.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-15.js new file mode 100644 index 0000000000000000000000000000000000000000..35bfbc7465d2de6888010254ccc4bf05faf2154d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-15.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + accessor property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var proto = { + 0: 0, + 2: 2 +}; +Object.defineProperty(proto, "1", { + get: function() { + return 1; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +SendableArray.prototype.reduceRight.call(child, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-16.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-16.js new file mode 100644 index 0000000000000000000000000000000000000000..4196ca7bcea2a952e3c34a28754d013276837fe6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-16.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 1; + }, + configurable: true +}); +var arr = [0, , 2]; +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-17.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-17.js new file mode 100644 index 0000000000000000000000000000000000000000..bb1ca2a79837a7f01eba6ad2a736e604da52874a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-17.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property without a get function on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof curVal === "undefined"); + } +} +var obj = { + 0: 0, + 2: 2, + length: 3 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-18.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-18.js new file mode 100644 index 0000000000000000000000000000000000000000..ea14d80f500631d562ac0a4f1c5d8a7397aae319 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-18.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property without a get function on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof curVal === "undefined"); + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + set: function() {}, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-19.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-19.js new file mode 100644 index 0000000000000000000000000000000000000000..9e27dc23c377b80b1e4ef05b3eef7f6c67ada810 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-19.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property without a get function that overrides an + inherited accessor property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof curVal === "undefined"); + } +} +Object.prototype[1] = 1; +var obj = { + 0: 0, + 2: 2, + length: 3 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-2.js new file mode 100644 index 0000000000000000000000000000000000000000..0900095687254d376d9dd5d97fc3ade830734b11 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var arr = [0, 1, 2]; +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-20.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-20.js new file mode 100644 index 0000000000000000000000000000000000000000..a79c25e8eef61c38d2c5b3bd60292df33010deb5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-20.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property without a get function that overrides an + inherited accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof curVal === "undefined"); + } +} +SendableArray.prototype[1] = 1; +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + set: function() {}, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-21.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-21.js new file mode 100644 index 0000000000000000000000000000000000000000..3d6dbb13dad371f2f929534a4485f447f4ab665e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-21.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + accessor property without a get function on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof curVal === "undefined"); + } +} +var proto = { + 0: 0, + 2: 2 +}; +Object.defineProperty(proto, "1", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +SendableArray.prototype.reduceRight.call(child, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-22.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-22.js new file mode 100644 index 0000000000000000000000000000000000000000..40b0728612720423457e575d07bd5856ce06b7af --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-22.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + accessor property without a get function on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (typeof curVal === "undefined"); + } +} +Object.defineProperty(SendableArray.prototype, "1", { + set: function() {}, + configurable: true +}); +var arr = [0, , 2]; +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-25.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-25.js new file mode 100644 index 0000000000000000000000000000000000000000..f0113dd47c738dca4874f7837b846c3e24c99bfb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-25.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - This object is the Arguments object + which implements its own property get method (number of arguments + is less than number of parameters) +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var func = function(a, b, c) { + SendableArray.prototype.reduceRight.call(arguments, callbackfn, "initialValue"); +}; +func(0, 1); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-26.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-26.js new file mode 100644 index 0000000000000000000000000000000000000000..eff18d708831bc88596e2ca19d85494b697b519c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-26.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - This object is the Arguments object + which implements its own property get method (number of arguments + equals number of parameters) +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 2) { + testResult = (curVal === 2); + } +} +var func = function(a, b, c) { + SendableArray.prototype.reduceRight.call(arguments, callbackfn, "initialValue"); +}; +func(0, 1, 2); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-27.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-27.js new file mode 100644 index 0000000000000000000000000000000000000000..828ac6fa1a95d80c85b286a8a45f35ac352e458a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-27.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - This object is the Arguments object + which implements its own property get method (number of arguments + is greater than number of parameters) +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 3) { + testResult = (curVal === 3); + } +} +var func = function(a, b, c) { + SendableArray.prototype.reduceRight.call(arguments, callbackfn, "initialValue"); +}; +func(0, 1, 2, 3); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-28.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-28.js new file mode 100644 index 0000000000000000000000000000000000000000..a8ca2110782f769ac254c62100916be377b4b173 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-28.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to String object, which + implements its own property get method +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "1"); + } +} +var str = new String("012"); +SendableArray.prototype.reduceRight.call(str, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-29.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-29.js new file mode 100644 index 0000000000000000000000000000000000000000..bb5347240482c2fc2f60ddd20f45196fd67c8a09 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-29.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight applied to Function object which + implements its own property get method +---*/ + +var testResult = false; +var initialValue = 0; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var obj = function(a, b, c) { + return a + b + c; +}; +obj[0] = 0; +obj[1] = 1; +obj[2] = 2; +obj[3] = 3; +SendableArray.prototype.reduceRight.call(obj, callbackfn, initialValue); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-3.js new file mode 100644 index 0000000000000000000000000000000000000000..8e9614f1bb400592173db95d999ec3c41caa6a76 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-3.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property that overrides an inherited data property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === "1"); + } +} +var proto = { + 0: 10, + 1: 11, + 2: 12, + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[1] = "1"; +child[2] = "2"; +child.length = 3; +SendableArray.prototype.reduceRight.call(child, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-30.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-30.js new file mode 100644 index 0000000000000000000000000000000000000000..1600327aedcc630c75f61de6c24c2d68f15df044 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-30.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element changed by getter on + previous iterations is observed on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var arr = [, , ]; +var preIterVisible = false; +Object.defineProperty(arr, "2", { + get: function() { + preIterVisible = true; + return 0; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + if (preIterVisible) { + return 1; + } else { + return "11"; + } + }, + configurable: true +}); +arr.reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-31.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-31.js new file mode 100644 index 0000000000000000000000000000000000000000..0c28ff48878e0f5bdcaf618cb77505c747928326 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-31.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element changed by getter on + previous iterations is observed on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var obj = { + length: 3 +}; +var preIterVisible = false; +Object.defineProperty(obj, "2", { + get: function() { + preIterVisible = true; + return 0; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + if (preIterVisible) { + return 1; + } else { + return "11"; + } + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-32.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-32.js new file mode 100644 index 0000000000000000000000000000000000000000..a7a5f34791a2261759c50b62250406f5a3a2e0c7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-32.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - unnhandled exceptions happened in + getter terminate iteration on an Array-like object +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx <= 1) { + accessed = true; + } +} +var obj = { + 0: 0, + 2: 2, + length: 3 +}; +Object.defineProperty(obj, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-33.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-33.js new file mode 100644 index 0000000000000000000000000000000000000000..b6a71d7e4f669203904900d05a10e72205abb380 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-33.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - unnhandled exceptions happened in + getter terminate iteration on an Array +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx <= 1) { + accessed = true; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "1", { + get: function() { + throw new Test262Error("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + arr.reduceRight(callbackfn, "initialValue"); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-4.js new file mode 100644 index 0000000000000000000000000000000000000000..68136cc2980e6e087fa5f90be62c5a7047ab5e01 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +SendableArray.prototype[1] = "11"; +[0, 1, 2].reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-5.js new file mode 100644 index 0000000000000000000000000000000000000000..c2866f972d16c7b525565122f19aacde3d0cd3d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-5.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 0) { + testResult = (curVal === "0"); + } +} +var proto = {}; +Object.defineProperty(proto, "0", { + get: function() { + return 10; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +Object.defineProperty(child, "0", { + value: "0", + configurable: true +}); +child[1] = "1"; +SendableArray.prototype.reduceRight.call(child, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-6.js new file mode 100644 index 0000000000000000000000000000000000000000..e68d80e5da693347f35436045cb246955b97092a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own data + property that overrides an inherited accessor property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return "11"; + }, + configurable: true +}); +[0, 1, 2].reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-7.js new file mode 100644 index 0000000000000000000000000000000000000000..0041840278ca3917a48b447ea0599287f7954225 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-7.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + data property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var proto = { + 0: 0, + 1: 1, + 2: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 3; +SendableArray.prototype.reduceRight.call(child, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-8.js new file mode 100644 index 0000000000000000000000000000000000000000..000f9e0cc0dc27877b2ed4052691182907dae318 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-8.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is inherited + data property on an Array +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +SendableArray.prototype[0] = 0; +SendableArray.prototype[1] = 1; +SendableArray.prototype[2] = 2; +[, , , ].reduceRight(callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-9.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-9.js new file mode 100644 index 0000000000000000000000000000000000000000..4930eb7755ab96fb799b1a031d5ceac254fea922 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-i-9.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element to be retrieved is own + accessor property on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (curVal === 1); + } +} +var obj = { + 0: 0, + 2: 2, + length: 3 +}; +Object.defineProperty(obj, "1", { + get: function() { + return 1; + }, + configurable: true +}); +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-1.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..2391adba19d990f5097520e7c49293bd89a92299 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - callbackfn called with correct + parameters (initialvalue not passed) +---*/ + +function callbackfn(prevVal, curVal, idx, obj) +{ + if (idx + 1 < obj.length && obj[idx] === curVal && obj[idx + 1] === prevVal) + return curVal; + else + return false; +} +var arr = [0, 1, true, null, new Object(), "five"]; +assert.sameValue(arr.reduceRight(callbackfn), 0, 'arr.reduceRight(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-10.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..e9503077fb10bbcad25c46594841926a50f4cb13 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-10.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - callbackfn is called with 1 formal + parameter +---*/ + +var called = 0; +function callbackfn(prevVal) { + called++; + return prevVal; +} +assert.sameValue([11, 12].reduceRight(callbackfn, 100), 100, '[11, 12].reduceRight(callbackfn, 100)'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-11.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..6a6c42f188126481abae6a0d959f3e7da271623c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-11.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - callbackfn is called with 2 formal + parameter +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal) { + if (prevVal === 100) { + testResult = true; + } + return curVal > 10; +} +assert.sameValue([11].reduceRight(callbackfn, 100), true, '[11].reduceRight(callbackfn, 100)'); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-12.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-12.js new file mode 100644 index 0000000000000000000000000000000000000000..9d12b9075852b64bbc1cfffb41ba8120f919612f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-12.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - callbackfn is called with 3 formal + parameter +---*/ + +var testResult = false; +var arr = [11, 12, 13]; +var initVal = 6.99; +function callbackfn(prevVal, curVal, idx) { + if (idx === 2) { + testResult = (prevVal === initVal); + } + return curVal > 10 && arguments[3][idx] === curVal; +} +assert.sameValue(arr.reduceRight(callbackfn, initVal), true, 'arr.reduceRight(callbackfn, initVal)'); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-13.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-13.js new file mode 100644 index 0000000000000000000000000000000000000000..5a69e5abc0b1bde3e4656244866d9c7346edc531 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-13.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - callbackfn is called with 4 formal + parameter +---*/ + +var arr = [11, 12, 13]; +var initVal = 6.99; +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 2) { + testResult = (prevVal === initVal); + } + return curVal > 10 && obj[idx] === curVal; +} +assert.sameValue(arr.reduceRight(callbackfn, initVal), true, 'arr.reduceRight(callbackfn, initVal)'); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-14.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-14.js new file mode 100644 index 0000000000000000000000000000000000000000..e18aa6321798d64a7a10f384a9708af6a9b05069 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-14.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight - callbackfn uses arguments +---*/ + +function callbackfn() { + return arguments[0] === 100 && arguments[3][arguments[2]] === arguments[1]; +} +assert.sameValue([11].reduceRight(callbackfn, 100), true, '[11].reduceRight(callbackfn, 100)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-16.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-16.js new file mode 100644 index 0000000000000000000000000000000000000000..f953aa7ed9ddbebb55e746768a589d78668b8572 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-16.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - non-indexed properties are not + called on an Array-like object +---*/ + +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (prevVal === 8 || curVal === 8) { + testResult = true; + } +} +var obj = { + 0: 11, + 10: 12, + non_index_property: 8, + length: 20 +}; +SendableArray.prototype.reduceRight.call(obj, callbackfn, "initialValue"); +assert.sameValue(testResult, false, 'testResult'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-17.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-17.js new file mode 100644 index 0000000000000000000000000000000000000000..bf1bff4326c284f04889566ec9e34eea9371734f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-17.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - 'accumulator' used for current + iteration is the result of previous iteration on an Array +---*/ + +var arr = [11, 12, 13]; +var testResult = true; +var initVal = 6.99; +var preResult = initVal; +function callbackfn(prevVal, curVal, idx, obj) { + if (prevVal !== preResult) { + testResult = false; + } + preResult = curVal; + return curVal; +} +arr.reduceRight(callbackfn, initVal); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-18.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-18.js new file mode 100644 index 0000000000000000000000000000000000000000..a8b1e6b80981289237ede47fafee29735e4bcac8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-18.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - 'accumulator' used for first + iteration is the value of 'initialValue' when it is present on an + Array +---*/ + +var arr = [11, 12]; +var testResult = false; +var initVal = 6.99; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === initVal); + } + return curVal; +} +arr.reduceRight(callbackfn, initVal); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-19.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-19.js new file mode 100644 index 0000000000000000000000000000000000000000..7e32c8fced57f94aeabdd5a856a9c052a1944785 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-19.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - value of 'accumulator' used for + first iteration is the value of max index property which is not + undefined when 'initialValue' is not present on an Array +---*/ + +var arr = [11, 12, 13]; +var testResult = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === 1) { + testResult = (prevVal === 13); + } + return curVal; +} +arr.reduceRight(callbackfn); +assert(testResult, 'testResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-2.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..a4dd33cad9da6f27028205d1cc1fda0da2ef9f90 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-2.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - callbackfn called with correct + parameters (initialvalue passed) +---*/ + +var bParCorrect = false; +var arr = [0, 1, true, null, new Object(), "five"]; +var initialValue = 5.5; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx === obj.length - 1 && obj[idx] === curVal && prevVal === initialValue) + return curVal; + else if (idx + 1 < obj.length && obj[idx] === curVal && obj[idx + 1] === prevVal) + return curVal; + else + return false; +} +assert.sameValue(arr.reduceRight(callbackfn, initialValue), 0, 'arr.reduceRight(callbackfn, initialValue)'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-20.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-20.js new file mode 100644 index 0000000000000000000000000000000000000000..4290381163d75fd76747a33de33887512100291c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-20.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight - undefined can be used as accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return typeof prevVal === "undefined"; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, undefined), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, undefined)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-21.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-21.js new file mode 100644 index 0000000000000000000000000000000000000000..de6d28ceac4c54d1b0ccaf70eb50b8a1c7feaca2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-21.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight - null can be used as accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === null; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, null), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, null)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-22.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-22.js new file mode 100644 index 0000000000000000000000000000000000000000..ca3c22032af2703a07efa425d6399a307804f4fc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-22.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - boolean primitive can be used as + accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === false; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, false), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, false)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-23.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-23.js new file mode 100644 index 0000000000000000000000000000000000000000..45466ccdc6e4d3491f4c579680baa4c42211e74d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-23.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - number primitive can be used as + accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === 12; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 12), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 12)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-24.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-24.js new file mode 100644 index 0000000000000000000000000000000000000000..cee60ead634700fcf6692e2c6d20e29242b1e5dd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-24.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - string primitive can be used as + accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === "hello_"; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, "hello_"), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, "hello_")'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-25.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-25.js new file mode 100644 index 0000000000000000000000000000000000000000..24f22ea7d810934ac43b82d10cb1c6ad388a8876 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-25.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - Function Object can be used as + accumulator +---*/ + +var accessed = false; +var objFunction = function() {}; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objFunction; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, objFunction), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, objFunction)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-26.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-26.js new file mode 100644 index 0000000000000000000000000000000000000000..3bbc094e72fe5abefed9ed50e074188fe07b2a5d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-26.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - Array Object can be used as + accumulator +---*/ + +var accessed = false; +var objArray = []; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objArray; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, objArray), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, objArray)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-27.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-27.js new file mode 100644 index 0000000000000000000000000000000000000000..a5cce0c30dbb5d39f9956412b7d09007c288a67c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-27.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - String Object can be used as + accumulator +---*/ + +var accessed = false; +var objString = new String(); +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objString; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, objString), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, objString)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-28.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-28.js new file mode 100644 index 0000000000000000000000000000000000000000..12df13d402e8c20b00f1e9780382693a20130776 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-28.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - Boolean Object can be used as + accumulator +---*/ + +var accessed = false; +var objBoolean = new Boolean(); +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objBoolean; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, objBoolean), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, objBoolean)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-29.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-29.js new file mode 100644 index 0000000000000000000000000000000000000000..0cbe6d3af409b68e0edc2f2f9873a65027cb78a2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-29.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - Number Object can be used as + accumulator +---*/ + +var accessed = false; +var objNumber = new Number(); +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objNumber; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, objNumber), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, objNumber)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-3.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-3.js new file mode 100644 index 0000000000000000000000000000000000000000..a70cc45042153ec8c5f0a412fa3d8dbbba3fd5bd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight - callbackfn takes 4 arguments +---*/ + +var bCalled = false; +function callbackfn(prevVal, curVal, idx, obj) +{ + bCalled = true; + if (prevVal === true && arguments.length === 4) + return true; + else + return false; +} +var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +assert.sameValue(arr.reduceRight(callbackfn, true), true, 'arr.reduceRight(callbackfn,true)'); +assert.sameValue(bCalled, true, 'bCalled'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-30.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-30.js new file mode 100644 index 0000000000000000000000000000000000000000..af7c0ddcd05dbea16fd50c0f18aa2c4bd360ac8e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-30.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - the Math Object can be used as + accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === Math; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, Math), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, Math)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-31.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-31.js new file mode 100644 index 0000000000000000000000000000000000000000..e6f7a8eb092fc6347d8234f7ee3100032d926342 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-31.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - Date Object can be used as + accumulator +---*/ + +var accessed = false; +var objDate = new Date(0); +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objDate; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, objDate), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, objDate)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-32.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-32.js new file mode 100644 index 0000000000000000000000000000000000000000..1246cbb79cea6271e368216c6ed8e396e9c17c24 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-32.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - RegExp Object can be used as + accumulator +---*/ + +var accessed = false; +var objRegExp = new RegExp(); +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objRegExp; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, objRegExp), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, objRegExp)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-33.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-33.js new file mode 100644 index 0000000000000000000000000000000000000000..2c8543df770caac7c2149d45dde5fed3c7db6fe4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-33.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: Array.prototype.reduceRight - the JSON can be used as accumulator +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === JSON; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, JSON), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, JSON)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-34.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-34.js new file mode 100644 index 0000000000000000000000000000000000000000..b946013e1ec461d5f762debde8f4f1e3b1ad45d9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-34.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - Error Object can be used as + accumulator +---*/ + +var accessed = false; +var objError = new RangeError(); +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === objError; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, objError), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, objError)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-35.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-35.js new file mode 100644 index 0000000000000000000000000000000000000000..b1d6572c30892466ef0ccba988f3049508a15d34 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-35.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - the Arguments object can be used as + accumulator +---*/ + +var accessed = false; +var arg; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === arg; +} +var obj = { + 0: 11, + length: 1 +}; +(function fun() { + arg = arguments; +}(10, 11, 12, 13)); +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, arg), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, arg)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-36.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-36.js new file mode 100644 index 0000000000000000000000000000000000000000..df046ca42955349542df6635db752982068a211e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-36.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - the global object can be used as + accumulator +---*/ + +var global = this; +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + return prevVal === global; +} +var obj = { + 0: 11, + length: 1 +}; +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, this), true, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, this)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-4.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..afd4ec09024f00fcd76777e5114e4a0d6d16d7e2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-4.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - k values are passed in acending + numeric order +---*/ + +var arr = [0, 1, 2, 3, 4, 5]; +var lastIdx = arr.length - 1; +var accessed = false; +var result = true; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (lastIdx !== idx) { + result = false; + } else { + lastIdx--; + } +} +arr.reduceRight(callbackfn, 1); +assert(result, 'result !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-5.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..54d2c99d690e57e83ffe32879b7317c261d43047 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-5.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - k values are accessed during each + iteration and not prior to starting the loop on an Array +---*/ + +var arr = [11, 12, 13, 14]; +var kIndex = []; +var result = true; +var called = 0; +//By below way, we could verify that k would be setted as 0, 1, ..., length - 1 in order, and each value will be setted one time. +function callbackfn(preVal, curVal, idx, o) { + //Each position should be visited one time, which means k is accessed one time during iterations. + called++; + if (typeof kIndex[idx] === "undefined") { + //when current position is visited, its next index should has been visited. + if (idx !== arr.length - 1 && typeof kIndex[idx + 1] === "undefined") { + result = false; + } + kIndex[idx] = 1; + } else { + result = false; + } +} +arr.reduceRight(callbackfn, 1); +assert(result, 'result !== true'); +assert.sameValue(called, 4, 'called'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-6.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-6.js new file mode 100644 index 0000000000000000000000000000000000000000..aa63d49089f150add1a385faf266a8539862d01c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-6.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - undefined passed as thisValue to + strict callbackfn +flags: [noStrict] +---*/ + +var innerThisCorrect = false; +function callbackfn(prevVal, curVal, idx, obj) +{ + "use strict"; + innerThisCorrect = this === undefined; + return true; +} +[0].reduceRight(callbackfn, true); +assert(innerThisCorrect, 'innerThisCorrect !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-7.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..177288ad3ca0184b840d47ad1c60557bcc432763 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-7.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - unhandled exceptions happened in + callbackfn terminate iteration +---*/ + +var accessed = false; +function callbackfn(prevVal, curVal, idx, obj) { + if (idx < 10) { + accessed = true; + } + if (idx === 10) { + throw new Test262Error("Exception occurred in callbackfn"); + } +} +var obj = { + 0: 11, + 4: 10, + 10: 8, + length: 20 +}; +assert.throws(Test262Error, function() { + SendableArray.prototype.reduceRight.call(obj, callbackfn, 1); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-8.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..c72347334d33f5b73a00742bb016a74411d2bb10 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-8.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - element changed by callbackfn on + previous iterations is observed +---*/ + +var accessed = false; +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +function callbackfn(prevVal, curVal, idx, obj) { + accessed = true; + if (idx === 1) { + obj[idx - 1] = 8; + } + return curVal > 10; +} +assert.sameValue(SendableArray.prototype.reduceRight.call(obj, callbackfn, 1), false, 'SendableArray.prototype.reduceRight.call(obj, callbackfn, 1)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-9.js b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..a2f8977ac3918ec7122e0cbf4a97be1a954230a4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/15.4.4.22-9-c-ii-9.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight - callbackfn is called with 0 formal + parameter +---*/ + +var called = 0; +function callbackfn() { + called++; + return true; +} +assert.sameValue([11, 12].reduceRight(callbackfn, 11), true, '[11, 12].reduceRight(callbackfn, 11)'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/call-with-boolean.js b/test/sendable/builtins/Array/prototype/reduceRight/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..7b9dd5987f6f5c3c584f0c3a1c826e113b3275fd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceRight +description: Array.prototype.reduceRight applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.reduceRight.call(true, () => {}, -1), + -1, + 'SendableArray.prototype.reduceRight.call(true, () => {}, -1) must return -1' +); +assert.sameValue( + SendableArray.prototype.reduceRight.call(false, () => {}, -1), + -1, + 'SendableArray.prototype.reduceRight.call(false, () => {}, -1) must return -1' +); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/callbackfn-resize-arraybuffer.js b/test/sendable/builtins/Array/prototype/reduceRight/callbackfn-resize-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..229dd6b5902d19632311a3ada87354258b530036 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/callbackfn-resize-arraybuffer.js @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: TypedArray instance buffer can be resized during iteration +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 3}); + var sample = new TA(buffer); + var expectedPrevsShrink, expectedNextsShrink, expectedIndicesShrink, expectedArraysShrink; + var expectedPrevsGrow, expectedNextsGrow, expectedIndicesGrow, expectedArraysGrow; + var prevs, nexts, indices, arrays, result; + prevs = []; + nexts = []; + indices = []; + arrays = []; + result = SendableArray.prototype.reduceRight.call(sample, function(prev, next, index, array) { + if (prevs.length === 0) { + try { + buffer.resize(BPE); + expectedPrevsShrink = [262, 2]; + expectedNextsShrink = [0, 0]; + expectedIndicesShrink = [2, 0]; + expectedArraysShrink = [sample, sample]; + expectedPrevsGrow = [262]; + expectedNextsGrow = [0]; + expectedIndicesGrow = [0]; + expectedArraysGrow = [sample]; + } catch (_) { + expectedPrevsShrink = expectedPrevsGrow = [262, 2, 1]; + expectedNextsShrink = expectedNextsGrow = [0, 0, 0]; + expectedIndicesShrink = expectedIndicesGrow = [2, 1, 0]; + expectedArraysShrink = expectedArraysGrow = [sample, sample, sample]; + } + } + prevs.push(prev); + nexts.push(next); + indices.push(index); + arrays.push(array); + return index; + }, 262); + assert.compareArray(prevs, expectedPrevsShrink, 'prevs (shrink)'); + assert.compareArray(nexts, expectedNextsShrink, 'nexts (shrink)'); + assert.compareArray(indices, expectedIndicesShrink, 'indices (shrink)'); + assert.compareArray(arrays, expectedArraysShrink, 'arrays (shrink)'); + assert.sameValue(result, 0, 'result (shrink)'); + prevs = []; + nexts = []; + indices = []; + arrays = []; + result = SendableArray.prototype.reduceRight.call(sample, function(prev, next, index, array) { + if (prevs.length === 0) { + try { + buffer.resize(3 * BPE); + } catch (_) {} + } + prevs.push(prev); + nexts.push(next); + indices.push(index); + arrays.push(array); + return index; + }, 262); + assert.compareArray(prevs, expectedPrevsGrow, 'prevs (grow)'); + assert.compareArray(nexts, expectedNextsGrow, 'nexts (grow)'); + assert.compareArray(indices, expectedIndicesGrow, 'indices (grow)'); + assert.compareArray(arrays, expectedArraysGrow, 'arrays (grow)'); + assert.sameValue(result, expectedIndicesGrow[expectedIndicesGrow.length - 1], 'result (grow)'); +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/length-near-integer-limit.js b/test/sendable/builtins/Array/prototype/reduceRight/length-near-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..8567f4b495ada766730ff6b9d806e6e8e149499a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/length-near-integer-limit.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Elements are processed in an array-like object + whose "length" property is near the integer limit. +includes: [compareArray.js] +---*/ + +var arrayLike = { + length: Number.MAX_SAFE_INTEGER, +}; +arrayLike[Number.MAX_SAFE_INTEGER - 1] = 1; +arrayLike[Number.MAX_SAFE_INTEGER - 3] = 3; +var accumulator = function(acc, el, index) { + acc.push([el, index]); + + if (el === 3) { + throw acc; + } + + return acc; +}; +try { + SendableArray.prototype.reduceRight.call(arrayLike, accumulator, []); + throw new Test262Error("should not be called"); +} catch (acc) { + assert.sameValue(acc.length, 2, 'The value of acc.length is expected to be 2'); + assert.compareArray( + acc[0], + [1, Number.MAX_SAFE_INTEGER - 1], + 'The value of acc[0] is expected to be [1, Number.MAX_SAFE_INTEGER - 1]' + ); + assert.compareArray( + acc[1], + [3, Number.MAX_SAFE_INTEGER - 3], + 'The value of acc[1] is expected to be [3, Number.MAX_SAFE_INTEGER - 3]' + ); +} diff --git a/test/sendable/builtins/Array/prototype/reduceRight/length.js b/test/sendable/builtins/Array/prototype/reduceRight/length.js new file mode 100644 index 0000000000000000000000000000000000000000..78fdb0c40a81506c4a35d9632bf83469b0a8c732 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/length.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + The "length" property of Array.prototype.reduceRight +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.reduceRight, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/name.js b/test/sendable/builtins/Array/prototype/reduceRight/name.js new file mode 100644 index 0000000000000000000000000000000000000000..2c5950c8e34620e45d89bf4942bc1c96bf8d4481 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.prototype.reduceRight.name is "reduceRight". +info: | + Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.reduceRight, "name", { + value: "reduceRight", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/not-a-constructor.js b/test/sendable/builtins/Array/prototype/reduceRight/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..7cf37a5c43a5ae114dd74cdbce98b409f3880ee6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.reduceRight does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.reduceRight), + false, + 'isConstructor(SendableArray.prototype.reduceRight) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.reduceRight(() => {}, []); +}); + diff --git a/test/sendable/builtins/Array/prototype/reduceRight/prop-desc.js b/test/sendable/builtins/Array/prototype/reduceRight/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..4b5df73614c4d46cb98e9d1dba28afeaf964e015 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + "reduceRight" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.reduceRight, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "reduceRight", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/reduceRight/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/reduceRight/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..9caa21a08780c7acb2aa104f4f4196180cd0b0cd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.p.reduceRight behaves correctly on TypedArrays backed by resizable + buffers that are grown mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeBufferMidIteration(acc, n) { + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduceRight.call(fixedLength, ResizeBufferMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduceRight.call(fixedLengthWithOffset, ResizeBufferMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduceRight.call(lengthTracking, ResizeBufferMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduceRight.call(lengthTrackingWithOffset, ResizeBufferMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/reduceRight/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/reduceRight/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..72a92e5bb12ba0a893acc3701697deadda271af7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-%array%.prototype.reduceright +description: > + Array.p.reduceRight behaves correctly when the backing resizable buffer is + shrunk mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(acc, n) { + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduceRight.call(fixedLength, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduceRight.call(fixedLengthWithOffset, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + // Unaffected by the shrinking, since we've already iterated past the point. + SendableArray.prototype.reduceRight.call(lengthTracking, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 1; + resizeTo = 2 * ctor.BYTES_PER_ELEMENT; + SendableArray.prototype.reduceRight.call(lengthTracking, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 2, + 0 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + // Unaffected by the shrinking, since we've already iterated past the point. + SendableArray.prototype.reduceRight.call(lengthTrackingWithOffset, ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/reduceRight/resizable-buffer.js b/test/sendable/builtins/Array/prototype/reduceRight/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..a7531ffee42f4c0d66604af694d6d95c5112ca71 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reduceRight/resizable-buffer.js @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reduceright +description: > + Array.p.reduceRight behaves correctly on TypedArrays backed by resizable + buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + function ReduceRightCollecting(array) { + const reduceRightValues = []; + SendableArray.prototype.reduceRight.call(array, (acc, n) => { + reduceRightValues.push(n); + }, 'initial value'); + reduceRightValues.reverse(); + return ToNumbers(reduceRightValues); + } + assert.compareArray(ReduceRightCollecting(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceRightCollecting(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ReduceRightCollecting(lengthTracking), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceRightCollecting(lengthTrackingWithOffset), [ + 4, + 6 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + assert.compareArray(ReduceRightCollecting(fixedLength), []); + assert.compareArray(ReduceRightCollecting(fixedLengthWithOffset), []); + assert.compareArray(ReduceRightCollecting(lengthTracking), [ + 0, + 2, + 4 + ]); + assert.compareArray(ReduceRightCollecting(lengthTrackingWithOffset), [4]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ReduceRightCollecting(fixedLength), []); + assert.compareArray(ReduceRightCollecting(fixedLengthWithOffset), []); + assert.compareArray(ReduceRightCollecting(lengthTracking), [0]); + // Shrink to zero. + rab.resize(0); + assert.compareArray(ReduceRightCollecting(fixedLength), []); + assert.compareArray(ReduceRightCollecting(fixedLengthWithOffset), []); + assert.compareArray(ReduceRightCollecting(lengthTrackingWithOffset), []); + assert.compareArray(ReduceRightCollecting(lengthTracking), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + assert.compareArray(ReduceRightCollecting(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceRightCollecting(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ReduceRightCollecting(lengthTracking), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(ReduceRightCollecting(lengthTrackingWithOffset), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A1_T1.js b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..5faee83187166897242117a40f610f4e3ffd78cc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A1_T1.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The elements of the array are rearranged so as to reverse their order. + The object is returned as the result of the call +esid: sec-array.prototype.reverse +description: Checking case when reverse is given no arguments or one argument +---*/ + +var x = []; +var reverse = x.reverse(); +if (reverse !== x) { + throw new Test262Error('#1: x = []; x.reverse() === x. Actual: ' + (reverse)); +} +x = []; +x[0] = 1; +var reverse = x.reverse(); +if (reverse !== x) { + throw new Test262Error('#2: x = []; x[0] = 1; x.reverse() === x. Actual: ' + (reverse)); +} +x = new SendableArray(1, 2); +var reverse = x.reverse(); +if (reverse !== x) { + throw new Test262Error('#3: x = new Array(1,2); x.reverse() === x. Actual: ' + (reverse)); +} +if (x[0] !== 2) { + throw new Test262Error('#4: x = new Array(1,2); x.reverse(); x[0] === 2. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#5: x = new Array(1,2); x.reverse(); x[1] === 1. Actual: ' + (x[1])); +} +if (x.length !== 2) { + throw new Test262Error('#6: x = new Array(1,2); x.reverse(); x.length === 2. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A1_T2.js b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..2cfa17df192f15423f53403fe66b618f073c2bd1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A1_T2.js @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The elements of the array are rearranged so as to reverse their order. + The object is returned as the result of the call +esid: sec-array.prototype.reverse +description: Checking this algorithm, elements are objects and primitives +---*/ + +var x = []; +x[0] = true; +x[2] = Infinity; +x[4] = undefined; +x[5] = undefined; +x[8] = "NaN"; +x[9] = "-1"; +var reverse = x.reverse(); +if (reverse !== x) { + throw new Test262Error('#1: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse() === x. Actual: ' + (reverse)); +} +if (x[0] !== "-1") { + throw new Test262Error('#2: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x[0] === "-1". Actual: ' + (x[0])); +} +if (x[1] !== "NaN") { + throw new Test262Error('#3: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x[1] === "NaN". Actual: ' + (x[1])); +} +if (x[2] !== undefined) { + throw new Test262Error('#4: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x[2] === undefined. Actual: ' + (x[2])); +} +if (x[3] !== undefined) { + throw new Test262Error('#5: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x[3] === undefined. Actual: ' + (x[3])); +} +if (x[4] !== undefined) { + throw new Test262Error('#6: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x[4] === undefined. Actual: ' + (x[4])); +} +if (x[5] !== undefined) { + throw new Test262Error('#7: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x[5] === undefined. Actual: ' + (x[5])); +} +if (x[6] !== undefined) { + throw new Test262Error('#8: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x[6] === undefined. Actual: ' + (x[6])); +} +if (x[7] !== Infinity) { + throw new Test262Error('#9: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x[7] === Infinity. Actual: ' + (x[7])); +} +if (x[8] !== undefined) { + throw new Test262Error('#10: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x[8] === undefined. Actual: ' + (x[8])); +} +if (x[9] !== true) { + throw new Test262Error('#11: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x[9] === true. Actual: ' + (x[9])); +} +x.length = 9; +var reverse = x.reverse(); +if (reverse !== x) { + throw new Test262Error('#1: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x.length = 9; x.reverse() === x. Actual: ' + (reverse)); +} +if (x[0] !== undefined) { + throw new Test262Error('#12: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x.length = 9; x.reverse(); x[0] === undefined. Actual: ' + (x[0])); +} +if (x[1] !== Infinity) { + throw new Test262Error('#13: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x.length = 9; x.reverse(); x[1] === Infinity. Actual: ' + (x[1])); +} +if (x[2] !== undefined) { + throw new Test262Error('#14: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x.length = 9; x.reverse(); x[2] === undefined. Actual: ' + (x[2])); +} +if (x[3] !== undefined) { + throw new Test262Error('#15: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x.length = 9; x.reverse(); x[3] === undefined. Actual: ' + (x[3])); +} +if (x[4] !== undefined) { + throw new Test262Error('#16: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x.length = 9; x.reverse(); x[4] === undefined. Actual: ' + (x[4])); +} +if (x[5] !== undefined) { + throw new Test262Error('#17: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x.length = 9; x.reverse(); x[5] === undefined. Actual: ' + (x[5])); +} +if (x[6] !== undefined) { + throw new Test262Error('#18: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x.length = 9; x.reverse(); x[6] === undefined. Actual: ' + (x[6])); +} +if (x[7] !== "NaN") { + throw new Test262Error('#19: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x.length = 9; x.reverse(); x[7] === "NaN". Actual: ' + (x[7])); +} +if (x[8] !== "-1") { + throw new Test262Error('#20: x = []; x[0] = true; x[2] = Infinity; x[4] = undefined; x[5] = undefined; x[8] = "NaN"; x[9] = "-1"; x.reverse(); x.length = 9; x.reverse(); x[8] === "-1". Actual: ' + (x[8])); +} diff --git a/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A2_T1.js b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..7834e098c84675cd562391c003ba00b0daeb6d89 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A2_T1.js @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The reverse function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.reverse +description: > + Checking this for Object object, elements are objects and + primitives, length is integer +---*/ + +var obj = {}; +obj.length = 10; +obj.reverse = SendableArray.prototype.reverse; +obj[0] = true; +obj[2] = Infinity; +obj[4] = undefined; +obj[5] = undefined; +obj[8] = "NaN"; +obj[9] = "-1"; +var reverse = obj.reverse(); +if (reverse !== obj) { + throw new Test262Error('#1: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse() === obj. Actual: ' + (reverse)); +} +if (obj[0] !== "-1") { + throw new Test262Error('#2: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[0] === "-1". Actual: ' + (obj[0])); +} +if (obj[1] !== "NaN") { + throw new Test262Error('#3: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[1] === "NaN". Actual: ' + (obj[1])); +} +if (obj[2] !== undefined) { + throw new Test262Error('#4: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[2] === undefined. Actual: ' + (obj[2])); +} +if (obj[3] !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[3] === undefined. Actual: ' + (obj[3])); +} +if (obj[4] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[4] === undefined. Actual: ' + (obj[4])); +} +if (obj[5] !== undefined) { + throw new Test262Error('#7: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[5] === undefined. Actual: ' + (obj[5])); +} +if (obj[6] !== undefined) { + throw new Test262Error('#8: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[6] === undefined. Actual: ' + (obj[6])); +} +if (obj[7] !== Infinity) { + throw new Test262Error('#9: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[7] === Infinity. Actual: ' + (obj[7])); +} +if (obj[8] !== undefined) { + throw new Test262Error('#10: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[8] === undefined. Actual: ' + (obj[8])); +} +if (obj[9] !== true) { + throw new Test262Error('#11: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[9] === true. Actual: ' + (obj[9])); +} +obj.length = 9; +var reverse = obj.reverse(); +if (reverse !== obj) { + throw new Test262Error('#1: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = 9; obj.reverse() === obj. Actual: ' + (reverse)); +} +if (obj[0] !== undefined) { + throw new Test262Error('#12: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = 9; obj.reverse(); obj[0] === undefined. Actual: ' + (obj[0])); +} +if (obj[1] !== Infinity) { + throw new Test262Error('#13: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = 9; obj.reverse(); obj[1] === Infinity. Actual: ' + (obj[1])); +} +if (obj[2] !== undefined) { + throw new Test262Error('#14: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = 9; obj.reverse(); obj[2] === undefined. Actual: ' + (obj[2])); +} +if (obj[3] !== undefined) { + throw new Test262Error('#15: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = 9; obj.reverse(); obj[3] === undefined. Actual: ' + (obj[3])); +} +if (obj[4] !== undefined) { + throw new Test262Error('#16: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = 9; obj.reverse(); obj[4] === undefined. Actual: ' + (obj[4])); +} +if (obj[5] !== undefined) { + throw new Test262Error('#17: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = 9; obj.reverse(); obj[5] === undefined. Actual: ' + (obj[5])); +} +if (obj[6] !== undefined) { + throw new Test262Error('#18: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = 9; obj.reverse(); obj[6] === undefined. Actual: ' + (obj[6])); +} +if (obj[7] !== "NaN") { + throw new Test262Error('#19: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = 9; obj.reverse(); obj[7] === "NaN". Actual: ' + (obj[7])); +} +if (obj[8] !== "-1") { + throw new Test262Error('#20: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = 9; obj.reverse(); obj[8] === "-1". Actual: ' + (obj[8])); +} diff --git a/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A2_T2.js b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..505340119e5718b8b49e00409fc35d47655ff429 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A2_T2.js @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The reverse function is intentionally generic. + It does not require that its this value be an SendableArray object +esid: sec-SendableArray.prototype.reverse +description: > + Checking this for Object object, elements are objects and + primitives, length is not integer +---*/ + +var obj = {}; +obj.length = 10.5; +obj.reverse = SendableArray.prototype.reverse; +obj[0] = true; +obj[2] = Infinity; +obj[4] = undefined; +obj[5] = undefined; +obj[8] = "NaN"; +obj[9] = "-1"; +var reverse = obj.reverse(); +if (reverse !== obj) { + throw new Test262Error('#1: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse() === obj. Actual: ' + (reverse)); +} +if (obj[0] !== "-1") { + throw new Test262Error('#2: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[0] === "-1". Actual: ' + (obj[0])); +} +if (obj[1] !== "NaN") { + throw new Test262Error('#3: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[1] === "NaN". Actual: ' + (obj[1])); +} +if (obj[2] !== undefined) { + throw new Test262Error('#4: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[2] === undefined. Actual: ' + (obj[2])); +} +if (obj[3] !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[3] === undefined. Actual: ' + (obj[3])); +} +if (obj[4] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[4] === undefined. Actual: ' + (obj[4])); +} +if (obj[5] !== undefined) { + throw new Test262Error('#7: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[5] === undefined. Actual: ' + (obj[5])); +} +if (obj[6] !== undefined) { + throw new Test262Error('#8: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[6] === undefined. Actual: ' + (obj[6])); +} +if (obj[7] !== Infinity) { + throw new Test262Error('#9: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[7] === Infinity. Actual: ' + (obj[7])); +} +if (obj[8] !== undefined) { + throw new Test262Error('#10: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[8] === undefined. Actual: ' + (obj[8])); +} +if (obj[9] !== true) { + throw new Test262Error('#11: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[9] === true. Actual: ' + (obj[9])); +} +obj.length = new Number(9.5); +var reverse = obj.reverse(); +if (reverse !== obj) { + throw new Test262Error('#1: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new Number(9.5); obj.reverse() === obj. Actual: ' + (reverse)); +} +if (obj[0] !== undefined) { + throw new Test262Error('#12: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new Number(9.5); obj.reverse(); obj[0] === undefined. Actual: ' + (obj[0])); +} +if (obj[1] !== Infinity) { + throw new Test262Error('#13: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new Number(9.5); obj.reverse(); obj[1] === Infinity. Actual: ' + (obj[1])); +} +if (obj[2] !== undefined) { + throw new Test262Error('#14: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new Number(9.5); obj.reverse(); obj[2] === undefined. Actual: ' + (obj[2])); +} +if (obj[3] !== undefined) { + throw new Test262Error('#15: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new Number(9.5); obj.reverse(); obj[3] === undefined. Actual: ' + (obj[3])); +} +if (obj[4] !== undefined) { + throw new Test262Error('#16: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new Number(9.5); obj.reverse(); obj[4] === undefined. Actual: ' + (obj[4])); +} +if (obj[5] !== undefined) { + throw new Test262Error('#17: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new Number(9.5); obj.reverse(); obj[5] === undefined. Actual: ' + (obj[5])); +} +if (obj[6] !== undefined) { + throw new Test262Error('#18: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new Number(9.5); obj.reverse(); obj[6] === undefined. Actual: ' + (obj[6])); +} +if (obj[7] !== "NaN") { + throw new Test262Error('#19: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new Number(9.5); obj.reverse(); obj[7] === "NaN". Actual: ' + (obj[7])); +} +if (obj[8] !== "-1") { + throw new Test262Error('#20: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = 10.5; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new Number(9.5); obj.reverse(); obj[8] === "-1". Actual: ' + (obj[8])); +} diff --git a/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A2_T3.js b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..e329ba8611d3dba4528dc143ab44fde6101419ca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A2_T3.js @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The reverse function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.reverse +description: > + Checking this for Object object, elements are objects and + primitives, length is string +---*/ + +var obj = {}; +obj.length = "10"; +obj.reverse = SendableArray.prototype.reverse; +obj[0] = true; +obj[2] = Infinity; +obj[4] = undefined; +obj[5] = undefined; +obj[8] = "NaN"; +obj[9] = "-1"; +var reverse = obj.reverse(); +if (reverse !== obj) { + throw new Test262Error('#1: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse() === obj. Actual: ' + (reverse)); +} +if (obj[0] !== "-1") { + throw new Test262Error('#2: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[0] === "-1". Actual: ' + (obj[0])); +} +if (obj[1] !== "NaN") { + throw new Test262Error('#3: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[1] === "NaN". Actual: ' + (obj[1])); +} +if (obj[2] !== undefined) { + throw new Test262Error('#4: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[2] === undefined. Actual: ' + (obj[2])); +} +if (obj[3] !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[3] === undefined. Actual: ' + (obj[3])); +} +if (obj[4] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[4] === undefined. Actual: ' + (obj[4])); +} +if (obj[5] !== undefined) { + throw new Test262Error('#7: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[5] === undefined. Actual: ' + (obj[5])); +} +if (obj[6] !== undefined) { + throw new Test262Error('#8: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[6] === undefined. Actual: ' + (obj[6])); +} +if (obj[7] !== Infinity) { + throw new Test262Error('#9: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[7] === Infinity. Actual: ' + (obj[7])); +} +if (obj[8] !== undefined) { + throw new Test262Error('#10: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[8] === undefined. Actual: ' + (obj[8])); +} +if (obj[9] !== true) { + throw new Test262Error('#11: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj[9] === true. Actual: ' + (obj[9])); +} +obj.length = new String("9"); +var reverse = obj.reverse(); +if (reverse !== obj) { + throw new Test262Error('#1: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new String("9"); obj.reverse() === obj. Actual: ' + (reverse)); +} +if (obj[0] !== undefined) { + throw new Test262Error('#12: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new String("9"); obj.reverse(); obj[0] === undefined. Actual: ' + (obj[0])); +} +if (obj[1] !== Infinity) { + throw new Test262Error('#13: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new String("9"); obj.reverse(); obj[1] === Infinity. Actual: ' + (obj[1])); +} +if (obj[2] !== undefined) { + throw new Test262Error('#14: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new String("9"); obj.reverse(); obj[2] === undefined. Actual: ' + (obj[2])); +} +if (obj[3] !== undefined) { + throw new Test262Error('#15: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new String("9"); obj.reverse(); obj[3] === undefined. Actual: ' + (obj[3])); +} +if (obj[4] !== undefined) { + throw new Test262Error('#16: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new String("9"); obj.reverse(); obj[4] === undefined. Actual: ' + (obj[4])); +} +if (obj[5] !== undefined) { + throw new Test262Error('#17: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new String("9"); obj.reverse(); obj[5] === undefined. Actual: ' + (obj[5])); +} +if (obj[6] !== undefined) { + throw new Test262Error('#18: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new String("9"); obj.reverse(); obj[6] === undefined. Actual: ' + (obj[6])); +} +if (obj[7] !== "NaN") { + throw new Test262Error('#19: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new String("9"); obj.reverse(); obj[7] === "NaN". Actual: ' + (obj[7])); +} +if (obj[8] !== "-1") { + throw new Test262Error('#20: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj.length = "10"; obj[0] = true; obj[2] = Infinity; obj[4] = undefined; obj[5] = undefined; obj[8] = "NaN"; obj[9] = "-1"; obj.reverse(); obj.length = new String("9"); obj.reverse(); obj[8] === "-1". Actual: ' + (obj[8])); +} diff --git a/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A3_T3.js b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..761d068d88766f551a7c979cd5e8bbe8a8961edb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A3_T3.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.reverse +description: length = -4294967294 +---*/ + +var obj = {}; +obj.reverse = SendableArray.prototype.reverse; +obj[0] = "x"; +obj[1] = "y"; +obj[2] = "z"; +obj.length = -4294967294; +var reverse = obj.reverse(); +if (reverse !== obj) { + throw new Test262Error('#1: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj[0] = "x"; obj[1] = "y"; obj[2] = "z"; obj.length = -4294967294; obj.reverse() === obj. Actual: ' + (reverse)); +} +if (obj.length !== -4294967294) { + throw new Test262Error('#2: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj[0] = "x"; obj[1] = "y"; obj[2] = "z"; obj.length = -4294967294; obj.reverse(); obj.length === -4294967294. Actual: ' + (obj.length)); +} +if (obj[0] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj[0] = "x"; obj[1] = "y"; obj[2] = "z"; obj.length = -4294967294; obj.reverse(); obj[0] === "x". Actual: ' + (obj[0])); +} +if (obj[1] !== "y") { + throw new Test262Error('#4: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj[0] = "x"; obj[1] = "y"; obj[2] = "z"; obj.length = -4294967294; obj.reverse(); obj[1] === "y". Actual: ' + (obj[1])); +} +if (obj[2] !== "z") { + throw new Test262Error('#5: var obj = {}; obj.reverse = SendableArray.prototype.reverse; obj[0] = "x"; obj[1] = "y"; obj[2] = "z"; obj.length = -4294967294; obj.reverse(); obj[2] === "z". Actual: ' + (obj[2])); +} diff --git a/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A4_T1.js b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A4_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..5c7618e60cd31c040818c6ea05aece1e59262f5c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A4_T1.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]], [[Delete]] from not an inherited property" +esid: sec-array.prototype.reverse +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[1] = 1; +var x = [0]; +x.length = 2; +x.reverse(); +if (x[0] !== 1) { + throw new Test262Error('#1: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; x.reverse(); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== 0) { + throw new Test262Error('#2: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; x.reverse(); x[1] === 0. Actual: ' + (x[1])); +} +x.length = 0; +if (x[0] !== undefined) { + throw new Test262Error('#3: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; x.reverse(); x.length = 0; x[0] === undefined. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#4: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; x.reverse(); x.length = 0; x[1] === 1. Actual: ' + (x[1])); +} +Object.prototype[1] = 1; +Object.prototype.length = 2; +Object.prototype.reverse = SendableArray.prototype.reverse; +x = { + 0: 0 +}; +x.reverse(); +if (x[0] !== 1) { + throw new Test262Error('#5: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.reverse = SendableArray.prototype.reverse; x = {0:0}; x.reverse(); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 0) { + throw new Test262Error('#6: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.reverse = SendableArray.prototype.reverse; x = {0:0}; x.reverse(); x[1] === 0. Actual: ' + (x[1])); +} +delete x[0]; +delete x[1]; +if (x[0] !== undefined) { + throw new Test262Error('#7: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.reverse = SendableArray.prototype.reverse; x = {0:0}; x.reverse(); delete x[0]; delete x[1]; x[0] === undefined. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#8: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.reverse = SendableArray.prototype.reverse; x = {0:0}; x.reverse(); delete x[0]; delete x[1]; x[1] === 1. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A4_T2.js b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A4_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..6fc4f4dddc569c48f91564d1d356a82683055b7a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/S15.4.4.8_A4_T2.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]], [[Delete]] from not an inherited property" +esid: sec-array.prototype.reverse +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[1] = -1; +var x = [0, 1]; +x.length = 2; +x.reverse(); +if (x[0] !== 1) { + throw new Test262Error('#1: SendableArray.prototype[1] = -1; x = [0,1]; x.length = 2; x.reverse(); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== 0) { + throw new Test262Error('#2: SendableArray.prototype[1] = -1; x = [0,1]; x.length = 2; x.reverse(); x[1] === 0. Actual: ' + (x[1])); +} +x.length = 0; +if (x[0] !== undefined) { + throw new Test262Error('#3: SendableArray.prototype[1] = -1; x = [0,1]; x.length = 2; x.reverse(); x.length = 0; x[0] === undefined. Actual: ' + (x[0])); +} +if (x[1] !== -1) { + throw new Test262Error('#4: SendableArray.prototype[1] = -1; x = [0,1]; x.length = 2; x.reverse(); x.length = 0; x[1] === -1. Actual: ' + (x[1])); +} +Object.prototype[1] = -1; +Object.prototype.length = 2; +Object.prototype.reverse = SendableArray.prototype.reverse; +x = { + 0: 0, + 1: 1 +}; +x.reverse(); +if (x[0] !== 1) { + throw new Test262Error('#5: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.reverse = SendableArray.prototype.reverse; x = {0:0,1:1}; x.reverse(); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 0) { + throw new Test262Error('#6: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.reverse = SendableArray.prototype.reverse; x = {0:0,1:1}; x.reverse(); x[1] === 0. Actual: ' + (x[1])); +} +delete x[0]; +delete x[1]; +if (x[0] !== undefined) { + throw new Test262Error('#7: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.reverse = SendableArray.prototype.reverse; x = {0:0,1:1}; x.reverse(); delete x[0]; delete x[1]; x[0] === undefined. Actual: ' + (x[0])); +} +if (x[1] !== -1) { + throw new Test262Error('#8: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.reverse = SendableArray.prototype.reverse; x = {0:0,1:1}; x.reverse(); delete x[0]; delete x[1]; x[1] === -1. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/reverse/array-has-one-entry.js b/test/sendable/builtins/Array/prototype/reverse/array-has-one-entry.js new file mode 100644 index 0000000000000000000000000000000000000000..74f80db3f0308a426fe09f0ad7e4eb3893e4ad59 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/array-has-one-entry.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reverse +description: Array.prototype.reverse should not iterate items if there is only one entry +info: | + Array.prototype.reverse ( ) + Let O be ToObject(this value). + Let len be LengthOfArrayLike(O). + Let middle be floor(len / 2). + Let lower be 0. + Repeat, while lower ≠ middle, + Return O. +---*/ + +let a = [1]; +Object.freeze(a); +a.reverse(); diff --git a/test/sendable/builtins/Array/prototype/reverse/call-with-boolean.js b/test/sendable/builtins/Array/prototype/reverse/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..f1eb487243dd6e5012d778fe4a96b8d86b8a81df --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reverse +description: Array.prototype.reverse applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.reverse.call(true) instanceof Boolean, + true, + 'The result of `(SendableArray.prototype.reverse.call(true) instanceof Boolean)` is true' +); +assert.sameValue( + SendableArray.prototype.reverse.call(false) instanceof Boolean, + true, + 'The result of `(SendableArray.prototype.reverse.call(false) instanceof Boolean)` is true' +); diff --git a/test/sendable/builtins/Array/prototype/reverse/get_if_present_with_delete.js b/test/sendable/builtins/Array/prototype/reverse/get_if_present_with_delete.js new file mode 100644 index 0000000000000000000000000000000000000000..083ed13f9e7cb9bbb4cd9650d60b2d26d62ddf27 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/get_if_present_with_delete.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Array.prototype.reverse only gets present properties - delete property with getter +---*/ + +var array = ["first", "second"]; +Object.defineProperty(array, 0, { + get: function() { + array.length = 0; + return "first"; + } +}); +array.reverse(); +assert.sameValue((0 in array), false, "Indexed property '0' not present"); +assert.sameValue((1 in array), true, "Indexed property '1' present"); +assert.sameValue(array[1], "first", "Indexed property '1' value correct"); diff --git a/test/sendable/builtins/Array/prototype/reverse/length-exceeding-integer-limit-with-object.js b/test/sendable/builtins/Array/prototype/reverse/length-exceeding-integer-limit-with-object.js new file mode 100644 index 0000000000000000000000000000000000000000..aa4f7314e4b21f1a4cfe5480353da085ab683542 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/length-exceeding-integer-limit-with-object.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reverse +description: > + Ensure reverse() implementation correctly handles length exceeding 2^53-1 with plain objects. +---*/ + +function StopReverse() {} +// Object with large "length" property and no indexed properties in the uint32 range. +var arrayLike = { + get "9007199254740990" () { + throw new StopReverse(); + }, + get "9007199254740991" () { + throw new Test262Error("Get 9007199254740991"); + }, + get "9007199254740992" () { + throw new Test262Error("Get 9007199254740992"); + }, + length: 2 ** 53 + 2, +}; +assert.throws(StopReverse, function() { + SendableArray.prototype.reverse.call(arrayLike); +}); diff --git a/test/sendable/builtins/Array/prototype/reverse/length-exceeding-integer-limit-with-proxy.js b/test/sendable/builtins/Array/prototype/reverse/length-exceeding-integer-limit-with-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..785303b6591d0ee809a42f9dc8245a4571af4217 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/length-exceeding-integer-limit-with-proxy.js @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reverse +description: > + Ensure correct MOP operations are called when length exceeds 2^53-1. +includes: [compareArray.js, proxyTrapsHelper.js] +features: [exponentiation] +---*/ + +function StopReverse() {} +var arrayLike = { + 0: "zero", + /* 1: hole, */ + 2: "two", + /* 3: hole, */ + get 4() { + throw new StopReverse(); + }, + 9007199254740987: "2**53-5", + /* 9007199254740988: hole, */ + /* 9007199254740989: hole, */ + 9007199254740990: "2**53-2", + length: 2 ** 53 + 2, +}; +var traps = []; +var proxy = new Proxy(arrayLike, allowProxyTraps({ + getOwnPropertyDescriptor(t, pk) { + traps.push(`GetOwnPropertyDescriptor:${String(pk)}`); + return Reflect.getOwnPropertyDescriptor(t, pk); + }, + defineProperty(t, pk, desc) { + traps.push(`DefineProperty:${String(pk)}`); + return Reflect.defineProperty(t, pk, desc); + }, + has(t, pk) { + traps.push(`Has:${String(pk)}`); + return Reflect.has(t, pk); + }, + get(t, pk, r) { + traps.push(`Get:${String(pk)}`); + return Reflect.get(t, pk, r); + }, + set(t, pk, v, r) { + traps.push(`Set:${String(pk)}`); + return Reflect.set(t, pk, v, r); + }, + deleteProperty(t, pk) { + traps.push(`Delete:${String(pk)}`); + return Reflect.deleteProperty(t, pk); + }, +})) +// Uses a separate exception than Test262Error, so that errors from allowProxyTraps +// are properly propagated. +assert.throws(StopReverse, function() { + SendableArray.prototype.reverse.call(proxy); +}, 'SendableArray.prototype.reverse.call(proxy) throws a StopReverse exception'); +assert.compareArray(traps, [ + // Initial get length operation. + "Get:length", + // Lower and upper index are both present. + "Has:0", + "Get:0", + "Has:9007199254740990", + "Get:9007199254740990", + "Set:0", + "GetOwnPropertyDescriptor:0", + "DefineProperty:0", + "Set:9007199254740990", + "GetOwnPropertyDescriptor:9007199254740990", + "DefineProperty:9007199254740990", + // Lower and upper index are both absent. + "Has:1", + "Has:9007199254740989", + // Lower index is present, upper index is absent. + "Has:2", + "Get:2", + "Has:9007199254740988", + "Delete:2", + "Set:9007199254740988", + "GetOwnPropertyDescriptor:9007199254740988", + "DefineProperty:9007199254740988", + // Lower index is absent, upper index is present. + "Has:3", + "Has:9007199254740987", + "Get:9007199254740987", + "Set:3", + "GetOwnPropertyDescriptor:3", + "DefineProperty:3", + "Delete:9007199254740987", + // Stop exception. + "Has:4", + "Get:4", +], 'The value of traps is expected to be [\n // Initial get length operation.\n "Get:length",\n\n // Lower and upper index are both present.\n "Has:0",\n "Get:0",\n "Has:9007199254740990",\n "Get:9007199254740990",\n "Set:0",\n "GetOwnPropertyDescriptor:0",\n "DefineProperty:0",\n "Set:9007199254740990",\n "GetOwnPropertyDescriptor:9007199254740990",\n "DefineProperty:9007199254740990",\n\n // Lower and upper index are both absent.\n "Has:1",\n "Has:9007199254740989",\n\n // Lower index is present, upper index is absent.\n "Has:2",\n "Get:2",\n "Has:9007199254740988",\n "Delete:2",\n "Set:9007199254740988",\n "GetOwnPropertyDescriptor:9007199254740988",\n "DefineProperty:9007199254740988",\n\n // Lower index is absent, upper index is present.\n "Has:3",\n "Has:9007199254740987",\n "Get:9007199254740987",\n "Set:3",\n "GetOwnPropertyDescriptor:3",\n "DefineProperty:3",\n "Delete:9007199254740987",\n\n // Stop exception.\n "Has:4",\n "Get:4",\n]'); +assert.sameValue(arrayLike.length, 2 ** 53 + 2, 'The value of arrayLike.length is expected to be 2 ** 53 + 2'); +assert.sameValue(arrayLike[0], "2**53-2", 'The value of arrayLike[0] is expected to be "2**53-2"'); +assert.sameValue(1 in arrayLike, false, 'The result of evaluating (1 in arrayLike) is expected to be false'); +assert.sameValue(2 in arrayLike, false, 'The result of evaluating (2 in arrayLike) is expected to be false'); +assert.sameValue(arrayLike[3], "2**53-5", 'The value of arrayLike[3] is expected to be "2**53-5"'); +assert.sameValue(9007199254740987 in arrayLike, false, 'The result of evaluating (9007199254740987 in arrayLike) is expected to be false'); +assert.sameValue(arrayLike[9007199254740988], "two", 'The value of arrayLike[9007199254740988] is expected to be "two"'); +assert.sameValue(9007199254740989 in arrayLike, false, 'The result of evaluating (9007199254740989 in arrayLike) is expected to be false'); +assert.sameValue(arrayLike[9007199254740990], "zero", 'The value of arrayLike[9007199254740990] is expected to be "zero"'); diff --git a/test/sendable/builtins/Array/prototype/reverse/length.js b/test/sendable/builtins/Array/prototype/reverse/length.js new file mode 100644 index 0000000000000000000000000000000000000000..42b444b3342b8a25cefc91917abfe2297d669a96 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/length.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reverse +description: > + The "length" property of Array.prototype.reverse +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.reverse, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/reverse/name.js b/test/sendable/builtins/Array/prototype/reverse/name.js new file mode 100644 index 0000000000000000000000000000000000000000..9d926ead0b0760fab833e8d5a74c728038f9e270 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reverse +description: > + Array.prototype.reverse.name is "reverse". +info: | + Array.prototype.reverse ( ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.reverse, "name", { + value: "reverse", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/reverse/not-a-constructor.js b/test/sendable/builtins/Array/prototype/reverse/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..c4a1a573a6aec6beb9c742d8ba87bbb734e24617 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.reverse does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.reverse), + false, + 'isConstructor(SendableArray.prototype.reverse) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.reverse(); +}); + diff --git a/test/sendable/builtins/Array/prototype/reverse/prop-desc.js b/test/sendable/builtins/Array/prototype/reverse/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..f19cc81c4cbd7eceab672322e8b0f1eb340484cc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reverse +description: > + "reverse" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.reverse, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "reverse", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/reverse/resizable-buffer.js b/test/sendable/builtins/Array/prototype/reverse/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..82acf9320861a1c780b0d7a4d68f689c3b7f8f2c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/reverse/resizable-buffer.js @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.reverse +description: > + Array.p.reverse behaves correctly on TypedArrays backed by resizable buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const wholeArrayView = new ctor(rab); + function WriteData() { + // Write some data into the array. + for (let i = 0; i < wholeArrayView.length; ++i) { + wholeArrayView[i] = MayNeedBigInt(wholeArrayView, 2 * i); + } + } + WriteData(); + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + SendableArray.prototype.reverse.call(fixedLength); + assert.compareArray(ToNumbers(wholeArrayView), [ + 6, + 4, + 2, + 0 + ]); + SendableArray.prototype.reverse.call(fixedLengthWithOffset); + assert.compareArray(ToNumbers(wholeArrayView), [ + 6, + 4, + 0, + 2 + ]); + SendableArray.prototype.reverse.call(lengthTracking); + assert.compareArray(ToNumbers(wholeArrayView), [ + 2, + 0, + 4, + 6 + ]); + SendableArray.prototype.reverse.call(lengthTrackingWithOffset); + assert.compareArray(ToNumbers(wholeArrayView), [ + 2, + 0, + 6, + 4 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + WriteData(); + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + SendableArray.prototype.reverse.call(fixedLength); + assert.compareArray(ToNumbers(wholeArrayView), [ + 0, + 2, + 4 + ]); + SendableArray.prototype.reverse.call(fixedLengthWithOffset); + assert.compareArray(ToNumbers(wholeArrayView), [ + 0, + 2, + 4 + ]); + SendableArray.prototype.reverse.call(lengthTracking); + assert.compareArray(ToNumbers(wholeArrayView), [ + 4, + 2, + 0 + ]); + SendableArray.prototype.reverse.call(lengthTrackingWithOffset); + assert.compareArray(ToNumbers(wholeArrayView), [ + 4, + 2, + 0 + ]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + WriteData(); + SendableArray.prototype.reverse.call(fixedLength); + assert.compareArray(ToNumbers(wholeArrayView), [0]); + SendableArray.prototype.reverse.call(fixedLengthWithOffset); + assert.compareArray(ToNumbers(wholeArrayView), [0]); + SendableArray.prototype.reverse.call(lengthTrackingWithOffset); + assert.compareArray(ToNumbers(wholeArrayView), [0]); + SendableArray.prototype.reverse.call(lengthTracking); + assert.compareArray(ToNumbers(wholeArrayView), [0]); + // Shrink to zero. + rab.resize(0); + SendableArray.prototype.reverse.call(fixedLength); + assert.compareArray(ToNumbers(wholeArrayView), []); + SendableArray.prototype.reverse.call(fixedLengthWithOffset); + assert.compareArray(ToNumbers(wholeArrayView), []); + SendableArray.prototype.reverse.call(lengthTrackingWithOffset); + assert.compareArray(ToNumbers(wholeArrayView), []); + SendableArray.prototype.reverse.call(lengthTracking); + assert.compareArray(ToNumbers(wholeArrayView), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + WriteData(); + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + SendableArray.prototype.reverse.call(fixedLength); + assert.compareArray(ToNumbers(wholeArrayView), [ + 6, + 4, + 2, + 0, + 8, + 10 + ]); + SendableArray.prototype.reverse.call(fixedLengthWithOffset); + assert.compareArray(ToNumbers(wholeArrayView), [ + 6, + 4, + 0, + 2, + 8, + 10 + ]); + SendableArray.prototype.reverse.call(lengthTracking); + assert.compareArray(ToNumbers(wholeArrayView), [ + 10, + 8, + 2, + 0, + 4, + 6 + ]); + SendableArray.prototype.reverse.call(lengthTrackingWithOffset); + assert.compareArray(ToNumbers(wholeArrayView), [ + 10, + 8, + 6, + 4, + 0, + 2 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A1.1_T1.js b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A1.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..bda77705cf82b44bf08e0555c6d93a4acce7cba4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A1.1_T1.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If length equal zero, call the [[Put]] method of this object + with arguments "length" and 0 and return undefined +esid: sec-array.prototype.shift +description: Checking this algorithm +---*/ + +var x = new SendableArray(); +var shift = x.shift(); +if (shift !== undefined) { + throw new Test262Error('#1: var x = new SendableArray(); x.shift() === undefined. Actual: ' + (shift)); +} +if (x.length !== 0) { + throw new Test262Error('#2: var x = new SendableArray(); x.shift(); x.length === 0. Actual: ' + (x.length)); +} +var x = Array(1, 2, 3); +x.length = 0; +var shift = x.shift(); +if (shift !== undefined) { + throw new Test262Error('#2: var x = SendableArray(1,2,3); x.length = 0; x.shift() === undefined. Actual: ' + (shift)); +} +if (x.length !== 0) { + throw new Test262Error('#4: var x = new SendableArray(1,2,3); x.length = 0; x.shift(); x.length === 0. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A1.2_T1.js b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A1.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..0671731dbca2b617aa7f971c6297756e75ef58e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A1.2_T1.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The first element of the array is removed from the array and + returned +esid: sec-array.prototype.shift +description: Checking this use new Array() and [] +---*/ + +var x = new SendableArray(0, 1, 2, 3); +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#1: x = new SendableArray(0,1,2,3); x.shift() === 0. Actual: ' + (shift)); +} +if (x.length !== 3) { + throw new Test262Error('#2: x = new SendableArray(0,1,2,3); x.shift(); x.length == 3'); +} +if (x[0] !== 1) { + throw new Test262Error('#3: x = new SendableArray(0,1,2,3); x.shift(); x[0] == 1'); +} +if (x[1] !== 2) { + throw new Test262Error('#4: x = new SendableArray(0,1,2,3); x.shift(); x[1] == 2'); +} +x = []; +x[0] = 0; +x[3] = 3; +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#5: x = []; x[0] = 0; x[3] = 3; x.shift() === 0. Actual: ' + (shift)); +} +if (x.length !== 3) { + throw new Test262Error('#6: x = []; x[0] = 0; x[3] = 3; x.shift(); x.length == 3'); +} +if (x[0] !== undefined) { + throw new Test262Error('#7: x = []; x[0] = 0; x[3] = 3; x.shift(); x[0] == undefined'); +} +if (x[12] !== undefined) { + throw new Test262Error('#8: x = []; x[0] = 0; x[3] = 3; x.shift(); x[1] == undefined'); +} +x.length = 1; +var shift = x.shift(); +if (shift !== undefined) { + throw new Test262Error('#9: x = []; x[0] = 0; x[3] = 3; x.shift(); x.length = 1; x.shift() === undefined. Actual: ' + (shift)); +} +if (x.length !== 0) { + throw new Test262Error('#10: x = []; x[0] = 0; x[3] = 3; x.shift(); x.length = 1; x.shift(); x.length === 0. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T1.js b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..19355c9c0ae912392ff34fb9b031b272fe29d1d9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T1.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The shift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.shift +description: > + If ToUint32(length) equal zero, call the [[Put]] method of this + object with arguments "length" and 0 and return undefined +---*/ + +var obj = {}; +obj.shift = SendableArray.prototype.shift; +if (obj.length !== undefined) { + throw new Test262Error('#0: var obj = {}; obj.length === undefined. Actual: ' + (obj.length)); +} else { + var shift = obj.shift(); + if (shift !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.shift = SendableArray.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); + } + if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); + } +} +obj.length = undefined; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#3: var obj = {}; obj.length = undefined; obj.shift = SendableArray.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 0) { + throw new Test262Error('#4: var obj = {}; obj.length = undefined; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} +obj.length = null +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.length = null; obj.shift = SendableArray.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 0) { + throw new Test262Error('#6: var obj = {}; obj.length = null; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T2.js b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..ea2704b6f2848ccda09c043e1922fe7724fbc126 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T2.js @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The shift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.shift +description: > + If ToUint32(length) equal zero, call the [[Put]] method of this + object with arguments "length" and 0 and return undefined +---*/ + +var obj = {}; +obj.shift = SendableArray.prototype.shift; +obj.length = NaN; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.length = NaN; obj.shift = SendableArray.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.length = NaN; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} +obj.length = Number.NEGATIVE_INFINITY; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.shift = SendableArray.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 0) { + throw new Test262Error('#6: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} +obj.length = -0; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#7: var obj = {}; obj.length = -0; obj.shift = SendableArray.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 0) { + throw new Test262Error('#8: var obj = {}; obj.length = -0; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} else { + if (1 / obj.length !== Number.POSITIVE_INFINITY) { + throw new Test262Error('#8: var obj = {}; obj.length = -0; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === +0. Actual: ' + (obj.length)); + } +} +obj.length = 0.5; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#9: var obj = {}; obj.length = 0.5; obj.shift = SendableArray.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 0) { + throw new Test262Error('#10: var obj = {}; obj.length = 0.5; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} +obj.length = new Number(0); +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#11: var obj = {}; obj.length = new Number(0); obj.shift = SendableArray.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 0) { + throw new Test262Error('#12: var obj = {}; obj.length = new Number(0); obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T3.js b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..baa0ba259a116b2da1259233395e899f235b802c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T3.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The shift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.shift +description: > + The first element of the array is removed from the array and + returned +---*/ + +var obj = {}; +obj.shift = SendableArray.prototype.shift; +obj.length = 2.5; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.length = 2.5; obj.shift = SendableArray.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 1) { + throw new Test262Error('#2: var obj = {}; obj.length = 2.5; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === 1. Actual: ' + (obj.length)); +} +obj.length = new Number(2); +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#11: var obj = {}; obj.length = new Number(2); obj.shift = SendableArray.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 1) { + throw new Test262Error('#12: var obj = {}; obj.length = new Number(2); obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === 1. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T4.js b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..306f3db2695a8bd4ee619826c78945381e80bb7a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T4.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The shift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.shift +description: > + The first element of the array is removed from the array and + returned +---*/ + +var obj = {}; +obj["0"] = 0; +obj["3"] = 3; +obj.shift = SendableArray.prototype.shift; +obj.length = 4; +var shift = obj.shift(); +if (shift !== 0) { + throw new Test262Error('#1: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = SendableArray.prototype.shift; obj.shift() === 0. Actual: ' + (shift)); +} +if (obj.length !== 3) { + throw new Test262Error('#2: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.length === 3. Actual: ' + (obj.length)); +} +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#3: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 2) { + throw new Test262Error('#4: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.shift(); obj.length === 2. Actual: ' + (obj.length)); +} +obj.length = 1; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#5: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.shift(); obj.length = 1; obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 0) { + throw new Test262Error('#6: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = SendableArray.prototype.shift; obj.shift(); obj.shift(); obj.length = 1; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} diff --git a/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T5.js b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..510feca2996c86eddee31ecf8d5901102f8dbb3e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A2_T5.js @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The shift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.shift +description: > + Operator use ToNumber from length. If Type(value) is Object, + evaluate ToPrimitive(value, Number) +---*/ + +var obj = {}; +obj.shift = SendableArray.prototype.shift; +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + } +}; +var shift = obj.shift(); +assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + }, + toString() { + return 0 + } +}; +var shift = obj.shift(); +assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + }, + toString() { + return {} + } +}; +var shift = obj.shift(); +assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); +try { + obj[0] = -1; + obj.length = { + valueOf() { + return 1 + }, + toString() { + throw "error" + } + }; + var shift = obj.shift(); + assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); +} +catch (e) { + assert.notSameValue(e, "error", 'The value of e is not "error"'); +} +obj[0] = -1; +obj.length = { + toString() { + return 0 + } +}; +var shift = obj.shift(); +assert.sameValue(shift, undefined, 'The value of shift is expected to equal undefined'); +obj[0] = -1; +obj.length = { + valueOf() { + return {} + }, + toString() { + return 0 + } +} +var shift = obj.shift(); +assert.sameValue(shift, undefined, 'The value of shift is expected to equal undefined'); +try { + obj[0] = -1; + obj.length = { + valueOf() { + throw "error" + }, + toString() { + return 0 + } + }; + var shift = obj.shift(); + throw new Test262Error('#7.1: obj[0] = -1; obj.length = {valueOf() {throw "error"}, toString() {return 0}}; obj.shift() throw "error". Actual: ' + (shift)); +} +catch (e) { + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); +} +try { + obj[0] = -1; + obj.length = { + valueOf() { + return {} + }, + toString() { + return {} + } + }; + var shift = obj.shift(); + throw new Test262Error('#8.1: obj[0] = -1; obj.length = {valueOf() {return {}}, toString() {return {}}} obj.shift() throw TypeError. Actual: ' + (shift)); +} +catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A3_T3.js b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..1c3bc5648e2438ed5bcae0ae7e8c11d5438f9a3c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A3_T3.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.shift +description: length is arbitrarily +---*/ + +var obj = {}; +obj.shift = SendableArray.prototype.shift; +obj[0] = "x"; +obj[1] = "y"; +obj.length = -4294967294; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.shift = SendableArray.prototype.shift; obj[0] = "x"; obj[1] = "y"; obj.length = -4294967294; obj.shift() === undefined. Actual: ' + (shift)); +} +if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.shift = SendableArray.prototype.shift; obj[0] = "x"; obj[1] = "y"; obj.length = -4294967294; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} +if (obj[0] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.shift = SendableArray.prototype.shift; obj[0] = "x"; obj[1] = "y"; obj.length = -4294967294; obj.shift(); obj[0] === "x". Actual: ' + (obj[0])); +} +if (obj[1] !== "y") { + throw new Test262Error('#4: var obj = {}; obj.shift = SendableArray.prototype.shift; obj[0] = "x" obj[1] = "y"; obj.length = -4294967294; obj.shift(); obj[1] === "y". Actual: ' + (obj[1])); +} diff --git a/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A4_T1.js b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A4_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..904ec174f3daf0fa80883d5b884a1d0c04e6bcd6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A4_T1.js @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]], [[Delete]] from not an inherited property" +esid: sec-array.prototype.shift +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[1] = 1; +var x = [0]; +x.length = 2; +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#1: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; x.shift() === 0. Actual: ' + (shift)); +} +if (x[0] !== 1) { + throw new Test262Error('#2: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; x.shift(); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#3: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; x.shift(); x[1] === 1. Actual: ' + (x[1])); +} +Object.prototype[1] = 1; +Object.prototype.length = 2; +Object.prototype.shift = SendableArray.prototype.shift; +x = { + 0: 0 +}; +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#4: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.shift = SendableArray.prototype.shift; x = {0:0}; x.shift() === 0. Actual: ' + (shift)); +} +if (x[0] !== 1) { + throw new Test262Error('#5: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.shift = SendableArray.prototype.shift; x = {0:0}; x.shift(); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#6: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.shift = SendableArray.prototype.shift; x = {0:0}; x.shift(); x[1] === 1. Actual: ' + (x[1])); +} +if (x.length !== 1) { + throw new Test262Error('#7: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.shift = SendableArray.prototype.shift; x = {0:0}; x.shift(); x.length === 1. Actual: ' + (x.length)); +} +delete x.length; +if (x.length !== 2) { + throw new Test262Error('#8: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.shift = SendableArray.prototype.shift; x = {0:0}; x.shift(); delete x; x.length === 2. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A4_T2.js b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A4_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..07e18514a4cc13087ff13d2a224f65ebfd5f2581 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/S15.4.4.9_A4_T2.js @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]], [[Delete]] from not an inherited property" +esid: sec-array.prototype.shift +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[1] = -1; +var x = [0, 1]; +x.length = 2; +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#1: SendableArray.prototype[1] = -1; x = [0,1]; x.length = 2; x.shift() === 0. Actual: ' + (shift)); +} +if (x[0] !== 1) { + throw new Test262Error('#2: SendableArray.prototype[1] = -1; x = [0,1]; x.length = 2; x.shift(); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== -1) { + throw new Test262Error('#3: SendableArray.prototype[1] = -1; x = [0,1]; x.length = 2; x.shift(); x[1] === -1. Actual: ' + (x[1])); +} +Object.prototype[1] = -1; +Object.prototype.length = 2; +Object.prototype.shift = SendableArray.prototype.shift; +x = { + 0: 0, + 1: 1 +}; +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#4: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.shift = SendableArray.prototype.shift; x = {0:0,1:1}; x.shift() === 0. Actual: ' + (shift)); +} +if (x[0] !== 1) { + throw new Test262Error('#5: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.shift = SendableArray.prototype.shift; x = {0:0,1:1}; x.shift(); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== -1) { + throw new Test262Error('#6: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.shift = SendableArray.prototype.shift; x = {0:0,1:1}; x.shift(); x[1] === -1. Actual: ' + (x[1])); +} +if (x.length !== 1) { + throw new Test262Error('#7: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.shift = SendableArray.prototype.shift; x = {0:0,1:1}; x.shift(); x.length === 1. Actual: ' + (x.length)); +} +delete x.length; +if (x.length !== 2) { + throw new Test262Error('#8: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.shift = SendableArray.prototype.shift; x = {0:0,1:1}; x.shift(); delete x; x.length === 2. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/shift/call-with-boolean.js b/test/sendable/builtins/Array/prototype/shift/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..9d9dc97547315d269d06c6eb0d22b8872d60aeef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.shift +description: Array.prototype.shift applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.shift.call(true), + undefined, + 'SendableArray.prototype.shift.call(true) must return undefined' +); +assert.sameValue( + SendableArray.prototype.shift.call(false), + undefined, + 'SendableArray.prototype.shift.call(false) must return undefined' +); diff --git a/test/sendable/builtins/Array/prototype/shift/length.js b/test/sendable/builtins/Array/prototype/shift/length.js new file mode 100644 index 0000000000000000000000000000000000000000..b8d8db61b7f5abcc4db6556f2e8992f1246942d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/length.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.shift +description: > + The "length" property of Array.prototype.shift +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.shift, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/shift/name.js b/test/sendable/builtins/Array/prototype/shift/name.js new file mode 100644 index 0000000000000000000000000000000000000000..612e85671bbc675892552b47d07e71b74d9aef6c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.shift +description: > + Array.prototype.shift.name is "shift". +info: | + Array.prototype.shift ( ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.shift, "name", { + value: "shift", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/shift/not-a-constructor.js b/test/sendable/builtins/Array/prototype/shift/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..45bf3973596e0f488ddf0844f28ec9b527d6bfb0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.shift does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.shift), + false, + 'isConstructor(SendableArray.prototype.shift) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.shift(); +}); + diff --git a/test/sendable/builtins/Array/prototype/shift/prop-desc.js b/test/sendable/builtins/Array/prototype/shift/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..aaf4542b76e1e4522dd9ee96be5533bf609dde1b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.shift +description: > + "shift" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.shift, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "shift", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/shift/set-length-array-is-frozen.js b/test/sendable/builtins/Array/prototype/shift/set-length-array-is-frozen.js new file mode 100644 index 0000000000000000000000000000000000000000..275f405ac2327c6201e64a744184a847967e5ca5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/set-length-array-is-frozen.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.shift +description: > + A TypeError is thrown when "length" is [[Set]] on a frozen array. +---*/ + +var array = new SendableArray(1); +var arrayPrototypeGet0Calls = 0; +Object.defineProperty(SendableArray.prototype, "0", { + get() { + Object.freeze(array); + arrayPrototypeGet0Calls++; + }, +}); +assert.throws(TypeError, function() { + array.shift(); +}); +assert.sameValue(array.length, 1); +assert.sameValue(arrayPrototypeGet0Calls, 1); diff --git a/test/sendable/builtins/Array/prototype/shift/set-length-array-length-is-non-writable.js b/test/sendable/builtins/Array/prototype/shift/set-length-array-length-is-non-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..b8d0b2828a8be244503c162cc46159e0bb2e0a7b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/set-length-array-length-is-non-writable.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.shift +description: > + A TypeError is thrown when "length" is [[Set]] on an array with non-writable "length". +---*/ + +var array = new SendableArray(1); +var arrayPrototypeGet0Calls = 0; +Object.defineProperty(SendableArray.prototype, "0", { + get() { + Object.defineProperty(array, "length", { writable: false }); + arrayPrototypeGet0Calls++; + }, +}); +assert.throws(TypeError, function() { + array.shift(); +}); +assert.sameValue(array.length, 1); +assert.sameValue(arrayPrototypeGet0Calls, 1); diff --git a/test/sendable/builtins/Array/prototype/shift/set-length-zero-array-is-frozen.js b/test/sendable/builtins/Array/prototype/shift/set-length-zero-array-is-frozen.js new file mode 100644 index 0000000000000000000000000000000000000000..f2cd9820dad99b9238e333bba63bb51ee8d6c2f7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/set-length-zero-array-is-frozen.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.shift +description: > + A TypeError is thrown when "length" is [[Set]] on an empty frozen array. +---*/ + +var array = []; +Object.freeze(array); +assert.throws(TypeError, function() { + array.shift(); +}); diff --git a/test/sendable/builtins/Array/prototype/shift/set-length-zero-array-length-is-non-writable.js b/test/sendable/builtins/Array/prototype/shift/set-length-zero-array-length-is-non-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..e22cac1f70adf63f1d29376b6b02636e7406a24c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/set-length-zero-array-length-is-non-writable.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.shift +description: > + A TypeError is thrown when "length" is [[Set]] on an empty array with non-writable "length". +---*/ + +var array = []; +Object.defineProperty(array, "length", { writable: false }); +assert.throws(TypeError, function() { + array.shift(); +}); diff --git a/test/sendable/builtins/Array/prototype/shift/throws-when-this-value-length-is-writable-false.js b/test/sendable/builtins/Array/prototype/shift/throws-when-this-value-length-is-writable-false.js new file mode 100644 index 0000000000000000000000000000000000000000..1907bd497faaf5e7f3874a83755a08e39f8e346b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/shift/throws-when-this-value-length-is-writable-false.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.shift +description: > + Array#shift throws TypeError if this value's "length" property was defined with [[Writable]]: false. +---*/ + +assert.throws(TypeError, () => { + SendableArray.prototype.shift.call(''); +}, "SendableArray.prototype.shift.call('')"); +assert.throws(TypeError, () => { + SendableArray.prototype.shift.call('abc'); +}, "SendableArray.prototype.shift.call('abc')"); +assert.throws(TypeError, () => { + SendableArray.prototype.shift.call(function() {}); +}, "SendableArray.prototype.shift.call(function() {})"); +assert.throws(TypeError, () => { + SendableArray.prototype.shift.call(Object.defineProperty({}, 'length', {writable: false})); +}, "SendableArray.prototype.shift.call(Object.defineProperty({}, 'length', {writable: false}))"); diff --git a/test/sendable/builtins/Array/prototype/slice/15.4.4.10-10-c-ii-1.js b/test/sendable/builtins/Array/prototype/slice/15.4.4.10-10-c-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..a9f9f13730311c91b15b3b34ea4cc64f12c5f95d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/15.4.4.10-10-c-ii-1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + Array.prototype.slice will slice a string from start to end when + index property (read-only) exists in Array.prototype (Step 10.c.ii) +---*/ + +var arrObj = [1, 2, 3]; +Object.defineProperty(SendableArray.prototype, "0", { + value: "test", + writable: false, + configurable: true +}); +var newArr = arrObj.slice(0, 1); +assert(newArr.hasOwnProperty("0"), 'newArr.hasOwnProperty("0") !== true'); +assert.sameValue(newArr[0], 1, 'newArr[0]'); +assert.sameValue(typeof newArr[1], "undefined", 'typeof newArr[1]'); diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T1.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..b699d21ea69fed9b11af3f72294fcbf9612d6417 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T1.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If end is positive, use min(end, length) +esid: sec-array.prototype.slice +description: length > end > start = 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(0, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(0,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(0,3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(0,3); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(0,3); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(0,3); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var x = [0,1,2,3,4]; var arr = x.slice(0,3); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T2.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..4ef859564202bef2aec973f4ab7024dee9ff6c71 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T2.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If end is positive, use min(end, length) +esid: sec-array.prototype.slice +description: length > end = start > 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(3, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(3,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(3,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(3,3); arr[0] === undefined. Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T3.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..d2b3c39a3f814b186fff60ef6a2b332b4b080576 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T3.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If end is positive, use min(end, length) +esid: sec-array.prototype.slice +description: length > start > end > 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(4, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(4,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(4,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(4,3); arr[0] === undefined. Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T4.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..321854c70a7bba55d7260511f63bb4d2c753b178 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T4.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If end is positive, use min(end, length) +esid: sec-array.prototype.slice +description: length = end = start > 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(5, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(5,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(5,5); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(5,5); arr[0] === undefined. Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T5.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..7c03cdd83a0dd367fa7d18dcab369ec6cdbe6a3b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T5.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If end is positive, use min(end, length) +esid: sec-array.prototype.slice +description: length = end > start > 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(3, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(3,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 2) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(3,5); arr.length === 2. Actual: ' + (arr.length)); +} +if (arr[0] !== 3) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(3,5); arr[0] === 3. Actual: ' + (arr[0])); +} +if (arr[1] !== 4) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(3,5); arr[1] === 4. Actual: ' + (arr[1])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(3,5); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T6.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..10a237f8ec8754da3ea4826f35ae88ea72a38ee0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T6.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If end is positive, use min(end, length) +esid: sec-array.prototype.slice +description: length > end > start > 0; +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(2, 4); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(2,4); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 2) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(2,4); arr.length === 2. Actual: ' + (arr.length)); +} +if (arr[0] !== 2) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(2,4); arr[0] === 2. Actual: ' + (arr[0])); +} +if (arr[1] !== 3) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(2,4); arr[1] === 3. Actual: ' + (arr[1])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(2,4); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T7.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T7.js new file mode 100644 index 0000000000000000000000000000000000000000..b32385b55bd43bab60ccc09dfe909790f0add53a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.1_T7.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If end is positive, use min(end, length) +esid: sec-array.prototype.slice +description: end > length > start > 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(3, 6); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(3,6); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 2) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(3,6); arr.length === 2. Actual: ' + (arr.length)); +} +if (arr[0] !== 3) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(3,6); arr[0] === 3. Actual: ' + (arr[0])); +} +if (arr[1] !== 4) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(3,6); arr[1] === 4. Actual: ' + (arr[1])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(3,6); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T1.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..4f683025e7af93d72c7345d3d2eb63a2a991f9e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T1.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If end is positive, use min(end, length) +esid: sec-array.prototype.slice +description: length > end = abs(start), start < 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(-3, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(-3,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 1) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(-3,3); arr.length === 1. Actual: ' + (arr.length)); +} +if (arr[0] !== 2) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(-3,3); arr[0] === 2. Actual: ' + (arr[0])); +} +if (arr[1] !== undefined) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(-3,3); arr[1] === undefined. Actual: ' + (arr[1])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T2.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..58bbc89e5253f2e5f0bef0ba277f94aa6598faae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T2.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If end is positive, use min(end, length) +esid: sec-array.prototype.slice +description: length = end > abs(start), start < 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(-1, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(-1,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 1) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(-1,5); arr.length === 1. Actual: ' + (arr.length)); +} +if (arr[0] !== 4) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(-1,5); arr[0] === 4. Actual: ' + (arr[0])); +} +if (arr[1] !== undefined) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(-1,5); arr[1] === undefined. Actual: ' + (arr[1])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T3.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..5148721838aeb77b44fc02e6b9b5b7e304f0a506 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T3.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If end is positive, use min(end, length) +esid: sec-array.prototype.slice +description: abs(start) = length > end > 0, start < 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(-5, 1); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(-5,1); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 1) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(-5,1); arr.length === 1. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(-5,1); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== undefined) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(-5,1); arr[1] === undefined. Actual: ' + (arr[1])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T4.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..8fb05b22605e52404665dc97480b6a2fa3c31703 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.2_T4.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If end is positive, use min(end, length) +esid: sec-array.prototype.slice +description: abs(start) > length = end > 0, start < 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(-9, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(-9,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 5) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(-9,5); arr.length === 5. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(-9,5); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(-9,5); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(-9,5); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3,4]; var arr = x.slice(-9,5); arr[3] === 3. Actual: ' + (arr[3])); +} +if (arr[4] !== 4) { + throw new Test262Error('#7: var x = [0,1,2,3,4]; var arr = x.slice(-9,5); arr[4] === 4. Actual: ' + (arr[4])); +} +if (arr[5] !== undefined) { + throw new Test262Error('#8: var x = [0,1,2,3,4]; var arr = x.slice(-9,5); arr[5] === undefined. Actual: ' + (arr[5])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T1.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..aa810dc156418d93105a3d60cdc7e8ebbc6d754a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T1.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If end is negative, use max(end + length, 0) +esid: sec-array.prototype.slice +description: length > abs(end) > start = 0, end < 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(0, -2); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(0,-2); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(0,-2); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(0,-2); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(0,-2); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(0,-2); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var x = [0,1,2,3,4]; var arr = x.slice(0,-2); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T2.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..acbd56b0de5d5f608607eb3c6b7570be0fa3d4df --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T2.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If end is negative, use max(end + length, 0) +esid: sec-array.prototype.slice +description: length > abs(end) > start > 0, end < 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(1, -4); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(1,-4); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(1,-4); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(1,-4); arr[0] === undefined. Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T3.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..ad8b42ba98fe60521af3bd0aa19e0e4556ded98d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T3.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If end is negative, use max(end + length, 0) +esid: sec-array.prototype.slice +description: length = abs(end) > start = 0, end < 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(0, -5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(0,-5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(0,-5); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(0,-5); arr[0] === undefined. Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T4.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..9dde77108a747270ccfdea78ae52ae64c0f71379 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.3_T4.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If end is negative, use max(end + length, 0) +esid: sec-array.prototype.slice +description: abs(end) > length > start > 0, end < 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(4, -9); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(4,-9); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(4,-9); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(4,-9); arr[0] === undefined. Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T1.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..d1eeefbf21c659a2cd91b0bc8e3880f193bec8d3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T1.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If end is negative, use max(end + length, 0) +esid: sec-array.prototype.slice +description: -length = start < end < 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(-5, -2); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(-5,-2); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(-5,-2); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(-5,-2); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(-5,-2); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(-5,-2); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var x = [0,1,2,3,4]; var arr = x.slice(-5,-2); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T2.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..ee9d5ff1e0cdc8bdbfbcafc7f48021f36401b1ce --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T2.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If end is negative, use max(end + length, 0) +esid: sec-array.prototype.slice +description: -length < start < end < 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(-3, -1); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(-3,-1); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 2) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(-3,-1); arr.length === 2. Actual: ' + (arr.length)); +} +if (arr[0] !== 2) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(-3,-1); arr[0] === 2. Actual: ' + (arr[0])); +} +if (arr[1] !== 3) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(-3,-1); arr[1] === 3. Actual: ' + (arr[1])); +} +if (arr[2] !== undefined) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(-3,-1); arr[2] === undefined. Actual: ' + (arr[2])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T3.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..493b089c8b4f740b7caeef5125927f4376bc6a7a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T3.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If end is negative, use max(end + length, 0) +esid: sec-array.prototype.slice +description: start < -length < end < 0 +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(-9, -1); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(-9,-1); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 4) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(-9,-1); arr.length === 4. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(-9,-1); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(-9,-1); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(-9,-1); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3,4]; var arr = x.slice(-9,-1); arr[3] === 3. Actual: ' + (arr[3])); +} +if (arr[4] !== undefined) { + throw new Test262Error('#7: var x = [0,1,2,3,4]; var arr = x.slice(-9,-1); arr[4] === undefined. Actual: ' + (arr[4])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T4.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..875c65df7b2e57f5a70a508229274138cbd8ee04 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.4_T4.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If end is negative, use max(end + length, 0) +esid: sec-array.prototype.slice +description: start = end < -length +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(-6, -6); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(-6,-6); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(-6,-6); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(-6,-6); arr[0] === undefined. Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.5_T1.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.5_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..bfb1e151da57a7a3903cf17753b0babd89774972 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.5_T1.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: If end is undefined use length +esid: sec-array.prototype.slice +description: end === undefined +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(3, undefined); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(3, undefined); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 2) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(3, undefined); arr.length === 2. Actual: ' + (arr.length)); +} +if (arr[0] !== 3) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(3, undefined); arr[0] === 3. Actual: ' + (arr[0])); +} +if (arr[1] !== 4) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(3, undefined); arr[1] === 4. Actual: ' + (arr[1])); +} +if (arr[2] !== undefined) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(3, undefined); arr[2] === undefined. Actual: ' + (arr[2])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.5_T2.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.5_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..6ece01610f5abff6cc9019baafcb1abee82f59ae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A1.5_T2.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: If end is undefined use length +esid: sec-array.prototype.slice +description: end is absent +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(-2); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(-2); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 2) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(-2); arr.length === 2. Actual: ' + (arr.length)); +} +if (arr[0] !== 3) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(-2); arr[0] === 3. Actual: ' + (arr[0])); +} +if (arr[1] !== 4) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(-2); arr[1] === 4. Actual: ' + (arr[1])); +} +if (arr[2] !== undefined) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(-2); arr[2] === undefined. Actual: ' + (arr[2])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T1.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..3af3a1935a5a45459845ddd0cdf8b65972dc3c0e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T1.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from start +esid: sec-array.prototype.slice +description: start is not integer +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(2.5, 4); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(2.5,4); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 2) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(2.5,4); arr.length === 2. Actual: ' + (arr.length)); +} +if (arr[0] !== 2) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(2.5,4); arr[0] === 2. Actual: ' + (arr[0])); +} +if (arr[1] !== 3) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(2.5,4); arr[1] === 3. Actual: ' + (arr[1])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(2.5,4); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T2.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..ed50994a04470c2bdeba2d956c5578b479348743 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T2.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from start +esid: sec-array.prototype.slice +description: start = NaN +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(NaN, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(NaN,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(NaN,3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(NaN,3); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(NaN,3); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(NaN,3); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var x = [0,1,2,3,4]; var arr = x.slice(NaN,3); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T3.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..dfcf07d59351ca873ef17427d6629affd3f0331a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T3.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from start +esid: sec-array.prototype.slice +description: start = Infinity +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(Number.POSITIVE_INFINITY, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(Number.POSITIVE_INFINITY,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(Number.POSITIVE_INFINITY,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(Number.POSITIVE_INFINITY,3); arr[0] === undefined. Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T4.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..8eb3c56bf887b326faa609a493ee37e08d712b69 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T4.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from start +esid: sec-array.prototype.slice +description: start = -Infinity +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(Number.NEGATIVE_INFINITY, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(Number.NEGATIVE_INFINITY,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(Number.NEGATIVE_INFINITY,3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(Number.NEGATIVE_INFINITY,3); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(Number.NEGATIVE_INFINITY,3); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(Number.NEGATIVE_INFINITY,3); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var x = [0,1,2,3,4]; var arr = x.slice(Number.NEGATIVE_INFINITY,3); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T5.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..04ee6050e3d5d1e08185d8bed880e4feed6d3a5f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.1_T5.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from start +esid: sec-array.prototype.slice +description: ToInteger use ToNumber +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice({ + valueOf: function() { + return 0 + }, + toString: function() { + return 3 + } +}, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice({valueOf: function() {return 0}, toString: function() {return 3}},3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice({valueOf: function() {return 0}, toString: function() {return 3}},3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice({valueOf: function() {return 0}, toString: function() {return 3}},3); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice({valueOf: function() {return 0}, toString: function() {return 3}},3); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice({valueOf: function() {return 0}, toString: function() {return 3}},3); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var x = [0,1,2,3,4]; var arr = x.slice({valueOf: function() {return 0}, toString: function() {return 3}},3); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T1.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..de6b7fd4c4a0efbe7d5112854c552ccda32b4677 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T1.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from end +esid: sec-array.prototype.slice +description: end is not integer +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(2, 4.5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(2,4.5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 2) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(2,4.5); arr.length === 2. Actual: ' + (arr.length)); +} +if (arr[0] !== 2) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(2,4.5); arr[0] === 2. Actual: ' + (arr[0])); +} +if (arr[1] !== 3) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(2,4.5); arr[1] === 3. Actual: ' + (arr[1])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(2,4.5); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T2.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..d5c9a6d180ee1f8c96f07591e5958b69cf802925 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T2.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from end +esid: sec-array.prototype.slice +description: end = NaN +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(0, NaN); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(0,NaN); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(0,NaN); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(0,NaN); arr[0] === undefined. Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T3.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..d7ff39454a4457c315146b0926060d49b89a368c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T3.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from end +esid: sec-array.prototype.slice +description: end = Infinity +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(0, Number.POSITIVE_INFINITY); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(0,Number.POSITIVE_INFINITY); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 5) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(0,Number.POSITIVE_INFINITY); arr.length === 5. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(0,Number.POSITIVE_INFINITY); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(0,Number.POSITIVE_INFINITY); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(0,Number.POSITIVE_INFINITY); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3,4]; var arr = x.slice(0,Number.POSITIVE_INFINITY); arr[3] === 3. Actual: ' + (arr[3])); +} +if (arr[4] !== 4) { + throw new Test262Error('#7: var x = [0,1,2,3,4]; var arr = x.slice(0,Number.POSITIVE_INFINITY); arr[4] === 4. Actual: ' + (arr[4])); +} +if (arr[5] !== undefined) { + throw new Test262Error('#8: var x = [0,1,2,3,4]; var arr = x.slice(0,Number.POSITIVE_INFINITY); arr[5] === undefined. Actual: ' + (arr[5])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T4.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..5a837ca2b6978c78ca1e2993c7d2ede9da544bb4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T4.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from end +esid: sec-array.prototype.slice +description: end = -Infinity +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(0, Number.NEGATIVE_INFINITY); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(0,Number.NEGATIVE_INFINITY); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(0,Number.NEGATIVE_INFINITY); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(0,Number.NEGATIVE_INFINITY); arr[0] === undefined. Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T5.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..9f03e5d0a30a6025f111c063d648c52051123395 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2.2_T5.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from end +esid: sec-array.prototype.slice +description: ToInteger use ToNumber +---*/ + +var x = [0, 1, 2, 3, 4]; +var arr = x.slice(0, { + valueOf: function() { + return 3 + }, + toString: function() { + return 0 + } +}); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3,4]; var arr = x.slice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3,4]; var arr = x.slice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3,4]; var arr = x.slice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3,4]; var arr = x.slice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3,4]; var arr = x.slice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var x = [0,1,2,3,4]; var arr = x.slice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T1.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..cedcb9fff92d994cab74ff79b2757c3d9c8829b0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T1.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The slice function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.slice +description: > + If start is positive, use min(start, length). If end is positive, + use min(end, length) +---*/ + +var obj = {}; +obj.slice = SendableArray.prototype.slice; +obj[0] = 0; +obj[1] = 1; +obj[2] = 2; +obj[3] = 3; +obj[4] = 4; +obj.length = 5; +var arr = obj.slice(0, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var obj = {}; obj.slice = Array.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var obj = {}; obj.slice = Array.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var obj = {}; obj.slice = Array.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,3); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var obj = {}; obj.slice = Array.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,3); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var obj = {}; obj.slice = Array.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,3); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.slice = Array.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,3); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T2.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..32e6cfb6b35d1482360dd1520e058d4801475158 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T2.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The slice function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.slice +description: > + If start is negative, use max(start + length, 0). If end is + positive, use min(end, length) +---*/ + +var obj = {}; +obj.slice = SendableArray.prototype.slice; +obj[0] = 0; +obj[1] = 1; +obj[2] = 2; +obj[3] = 3; +obj[4] = 4; +obj.length = 5; +var arr = obj.slice(-5, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "SendableArray" + "]") { + throw new Test262Error('#1: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,3); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,3); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,3); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,3); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T3.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..5a431e085c5d7ebb1004d16f035c8ae77e917595 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T3.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The slice function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.slice +description: > + If start is positive, use min(start, length). If end is negative, + use max(end + length, 0) +---*/ + +var obj = {}; +obj.slice = SendableArray.prototype.slice; +obj[0] = 0; +obj[1] = 1; +obj[2] = 2; +obj[3] = 3; +obj[4] = 4; +obj.length = 5; +var arr = obj.slice(0, -2); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "SendableArray" + "]") { + throw new Test262Error('#1: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,-2); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,-2); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,-2); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,-2); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,-2); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(0,-2); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T4.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..5dcaef639721d0085c1fa254d76a1ad7adf0a91c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T4.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The slice function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.slice +description: > + If start is negative, use max(start + length, 0). If end is + negative, use max(end + length, 0) +---*/ + +var obj = {}; +obj.slice = SendableArray.prototype.slice; +obj[0] = 0; +obj[1] = 1; +obj[2] = 2; +obj[3] = 3; +obj[4] = 4; +obj.length = 5; +var arr = obj.slice(-5, -2); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "SendableArray" + "]") { + throw new Test262Error('#1: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,-2); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,-2); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,-2); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,-2); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,-2); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(-5,-2); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T5.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..085db7726989639615330bbe6ff1bd0b08ecd3e2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T5.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The slice function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.slice +description: If end is undefined use length +---*/ + +var obj = {}; +obj.slice = SendableArray.prototype.slice; +obj[0] = 0; +obj[1] = 1; +obj[2] = 2; +obj[3] = 3; +obj[4] = 4; +obj.length = 5; +var arr = obj.slice(2); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "SendableArray" + "]") { + throw new Test262Error('#1: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 2) { + throw new Test262Error('#3: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2); arr[0] === 2. Actual: ' + (arr[0])); +} +if (arr[1] !== 3) { + throw new Test262Error('#4: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2); arr[1] === 3. Actual: ' + (arr[1])); +} +if (arr[2] !== 4) { + throw new Test262Error('#5: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2); arr[2] === 4. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T6.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..07399af9b4ac903bad311ab89978830aa1fff16e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A2_T6.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The slice function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.slice +description: If end is undefined use length +---*/ + +var obj = {}; +obj.slice = SendableArray.prototype.slice; +obj[0] = 0; +obj[1] = 1; +obj[2] = 2; +obj[3] = 3; +obj[4] = 4; +obj.length = 5; +var arr = obj.slice(2, undefined); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "SendableArray" + "]") { + throw new Test262Error('#1: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2, undefined); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2, undefined); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 2) { + throw new Test262Error('#3: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2, undefined); arr[0] === 2. Actual: ' + (arr[0])); +} +if (arr[1] !== 3) { + throw new Test262Error('#4: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2, undefined); arr[1] === 3. Actual: ' + (arr[1])); +} +if (arr[2] !== 4) { + throw new Test262Error('#5: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2, undefined); arr[2] === 4. Actual: ' + (arr[2])); +} +if (arr[3] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[0] = 0; obj[1] = 1; obj[2] = 2; obj[3] = 3; obj[4] = 4; obj.length = 5; var arr = obj.slice(2, undefined); arr[3] === undefined. Actual: ' + (arr[3])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A3_T1.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..c1a3ec3ad074822209c71addb8312e309d98a982 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A3_T1.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.slice +description: length = 4294967296 +---*/ + +assert.throws(RangeError, () => { + var obj = {}; + obj.slice = SendableArray.prototype.slice; + obj[0] = "x"; + obj[4294967295] = "y"; + obj.length = 4294967296; + obj.slice(0, 4294967296); +}); diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A3_T2.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..064dfc336becdfe990ba25b08cddcb110cfc62ff --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A3_T2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.slice +description: length = 4294967297 +---*/ + +assert.throws(RangeError, () => { + var obj = {}; + obj.slice = SendableArray.prototype.slice; + obj[0] = "x"; + obj[4294967296] = "y"; + obj.length = 4294967297; + obj.slice(0, 4294967297); +}); diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A3_T3.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..5a111f15a1f116d7f83fad031923c10ad22b0287 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A3_T3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToUint32(length) for non Array objects +esid: sec-array.prototype.slice +description: length = -1 +---*/ + +var obj = {}; +obj.slice = SendableArray.prototype.slice; +obj[4294967294] = "x"; +obj.length = -1; +var arr = obj.slice(4294967294, 4294967295); +if (arr.length !== 0) { + throw new Test262Error('#1: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[4294967294] = "x"; obj.length = 4294967295; var arr = obj.slice(4294967294,4294967295); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#3: var obj = {}; obj.slice = SendableArray.prototype.slice; obj[4294967294] = "x"; obj.length = 4294967295; var arr = obj.slice(4294967294,4294967295); arr[0] === undefined. Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A4_T1.js b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A4_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..e1f06243d92dd6a08ce7f02832b508614ab79fce --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/S15.4.4.10_A4_T1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]] from not an inherited property" +esid: sec-array.prototype.slice +description: "[[Prototype]] of Array instance is Array.prototype" +---*/ + +SendableArray.prototype[1] = 1; +var x = [0]; +x.length = 2; +var arr = x.slice(); +if (arr[0] !== 0) { + throw new Test262Error('#1: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; var arr = x.slice(); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#2: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; var arr = x.slice(); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr.hasOwnProperty('1') !== true) { + throw new Test262Error('#3: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; var arr = x.slice(); arr.hasOwnProperty(\'1\') === true. Actual: ' + (arr.hasOwnProperty('1'))); +} diff --git a/test/sendable/builtins/Array/prototype/slice/call-with-boolean.js b/test/sendable/builtins/Array/prototype/slice/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..0cb879d173aabdbc7dde77784f320d4da7f4dba3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/call-with-boolean.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: Array.prototype.slice applied to boolean primitive +includes: [compareArray.js] +---*/ + +assert.compareArray(SendableArray.prototype.slice.call(true), [], 'SendableArray.prototype.slice.call(true) must return []'); +assert.compareArray(SendableArray.prototype.slice.call(false), [], 'SendableArray.prototype.slice.call(false) must return []'); diff --git a/test/sendable/builtins/Array/prototype/slice/coerced-start-end-grow.js b/test/sendable/builtins/Array/prototype/slice/coerced-start-end-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..6c1184615399dedacbe2c044cd294531d62e1a11 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/coerced-start-end-grow.js @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + Array.p.slice behaves correctly on TypedArrays backed by resizable buffers that + are grown by argument coercion. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// The start argument grows the resizable array buffer rab. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i + 1); + } + const evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTracking, evil)), [ + 1, + 2, + 3, + 4 + ]); + assert.sameValue(rab.byteLength, 6 * ctor.BYTES_PER_ELEMENT); +} + +// The end argument grows the resizable array buffer rab. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i + 1); + } + const evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return 5; + } + }; + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTracking,4,evil)), [ + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTracking,3,evil)), [ + 4, + 0 + ]); + assert.sameValue(rab.byteLength, 6 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/Array/prototype/slice/coerced-start-end-shrink.js b/test/sendable/builtins/Array/prototype/slice/coerced-start-end-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..697908655f45810366dd1bca005d750284d3f5d1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/coerced-start-end-shrink.js @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + Array.p.slice behaves correctly on TypedArrays backed by resizable buffers that + are shrunk by argument coercion. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// The start argument shrinks the resizable array buffer rab. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLength, evil)), [ + undefined, + undefined, + undefined, + undefined + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLength, evil)), [ + ]); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i + 1); + } + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTracking, evil)), [ + 1, + 2, + undefined, + undefined + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTracking, evil)), [ + 1, + 2 + ]); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); +} + +// The end argument shrinks the resizable array buffer rab. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 3; + } + }; + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLength, 2, evil)), [ + undefined + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLength, 2, evil)), [ + ]); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i + 1); + } + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 3; + } + }; + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTracking, 1, evil)), [ + 2, + undefined + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTracking, 1, evil)), [ + 2 + ]); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/Array/prototype/slice/create-ctor-non-object.js b/test/sendable/builtins/Array/prototype/slice/create-ctor-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..705f69bc76dd765bc6d50443ecd72b12d496fd4e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-ctor-non-object.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + Behavior when `constructor` property is neither an Object nor undefined +---*/ + +var a = []; +a.constructor = null; +assert.throws(TypeError, function() { + a.slice(); +}, 'null value'); +a = []; +a.constructor = 1; +assert.throws(TypeError, function() { + a.slice(); +}, 'number value'); +a = []; +a.constructor = 'string'; +assert.throws(TypeError, function() { + a.slice(); +}, 'string value'); +a = []; +a.constructor = true; +assert.throws(TypeError, function() { + a.slice(); +}, 'boolean value'); diff --git a/test/sendable/builtins/Array/prototype/slice/create-ctor-poisoned.js b/test/sendable/builtins/Array/prototype/slice/create-ctor-poisoned.js new file mode 100644 index 0000000000000000000000000000000000000000..4d043896e9490082ca3cb791ecee88d0cbd1352f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-ctor-poisoned.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: Abrupt completion from `constructor` property access +info: | +---*/ + +var a = []; +Object.defineProperty(a, 'constructor', { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + a.slice(); +}); diff --git a/test/sendable/builtins/Array/prototype/slice/create-non-array-invalid-len.js b/test/sendable/builtins/Array/prototype/slice/create-non-array-invalid-len.js new file mode 100644 index 0000000000000000000000000000000000000000..c3f989ec125bbe8d85189ea69563484fd53d64c3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-non-array-invalid-len.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: Abrupt completion from creating a new array +---*/ + +var callCount = 0; +var maxLength = Math.pow(2, 32); +var obj = Object.defineProperty({}, 'length', { + get: function() { + return maxLength; + }, + set: function() { + callCount += 1; + } +}); +assert.throws(RangeError, function() { + SendableArray.prototype.slice.call(obj); +}); +assert.sameValue( + callCount, + 0, + 'RangeError thrown during SendableArray creation, not property modification' +); diff --git a/test/sendable/builtins/Array/prototype/slice/create-non-array.js b/test/sendable/builtins/Array/prototype/slice/create-non-array.js new file mode 100644 index 0000000000000000000000000000000000000000..d90eaf51c7d558117d97ccb0c21c586ea2dcb646 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-non-array.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: Constructor is ignored for non-Array values +---*/ + +var obj = { + length: 0 +}; +var callCount = 0; +var result; +Object.defineProperty(obj, 'constructor', { + get: function() { + callCount += 1; + } +}); +result = SendableArray.prototype.slice.call(obj); +assert.sameValue(callCount, 0, '`constructor` property not accessed'); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert(SendableArray.isArray(result), 'result is an SendableArray exotic object'); diff --git a/test/sendable/builtins/Array/prototype/slice/create-proto-from-ctor-realm-array.js b/test/sendable/builtins/Array/prototype/slice/create-proto-from-ctor-realm-array.js new file mode 100644 index 0000000000000000000000000000000000000000..a6cd13db7dae4723a96d3473711950503ca19d93 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-proto-from-ctor-realm-array.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: Prefer Array constructor of current realm record +---*/ + +var array = []; +var callCount = 0; +var OArray = $262.createRealm().global.SendableArray; +var speciesDesc = { + get: function() { + callCount += 1; + } +}; +var result; +array.constructor = OArray; +Object.defineProperty(SendableArray, Symbol.species, speciesDesc); +Object.defineProperty(OArray, Symbol.species, speciesDesc); +result = array.slice(); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert.sameValue(callCount, 0, 'Species constructor is not referenced'); diff --git a/test/sendable/builtins/Array/prototype/slice/create-proto-from-ctor-realm-non-array.js b/test/sendable/builtins/Array/prototype/slice/create-proto-from-ctor-realm-non-array.js new file mode 100644 index 0000000000000000000000000000000000000000..695af42dcda0f6976edd380a188e643a60571387 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-proto-from-ctor-realm-non-array.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: Accept non-Array constructors from other realms +---*/ + +var array = []; +var callCount = 0; +var CustomCtor = function() {}; +var OObject = $262.createRealm().global.Object; +var speciesDesc = { + get: function() { + callCount += 1; + } +}; +var result; +array.constructor = OObject; +OObject[Symbol.species] = CustomCtor; +Object.defineProperty(SendableArray, Symbol.species, speciesDesc); +result = array.slice(); +assert.sameValue(Object.getPrototypeOf(result), CustomCtor.prototype); +assert.sameValue(callCount, 0, 'SendableArray species constructor is not referenced'); diff --git a/test/sendable/builtins/Array/prototype/slice/create-proxied-array-invalid-len.js b/test/sendable/builtins/Array/prototype/slice/create-proxied-array-invalid-len.js new file mode 100644 index 0000000000000000000000000000000000000000..21bf227b04f7db5ccd9189efe0956c54a56cf169 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-proxied-array-invalid-len.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + Ensure a RangeError is thrown when a proxied array returns an invalid array length. +features: [Proxy] +---*/ + +var array = []; +var maxLength = Math.pow(2, 32); +var callCount = 0; +var proxy = new Proxy(array, { + get: function(_, name) { + if (name === 'length') { + return maxLength; + } + return array[name]; + }, + set: function() { + callCount += 1; + return true; + } +}); +assert.throws(RangeError, function() { + SendableArray.prototype.slice.call(proxy); +}); +assert.sameValue( + callCount, + 0, + 'RangeError thrown during array creation, not property modification' +); diff --git a/test/sendable/builtins/Array/prototype/slice/create-proxy.js b/test/sendable/builtins/Array/prototype/slice/create-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..0c1de8e21cbbed82bb00a6ed1546bdee1f11b106 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-proxy.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: Species constructor of a Proxy object whose target is an array +features: [Proxy, Symbol.species] +---*/ + +var array = []; +var proxy = new Proxy(new Proxy(array, {}), {}); +var Ctor = function() {}; +var result; +array.constructor = function() {}; +array.constructor[Symbol.species] = Ctor; +result = SendableArray.prototype.slice.call(proxy); +assert.sameValue(Object.getPrototypeOf(result), Ctor.prototype); diff --git a/test/sendable/builtins/Array/prototype/slice/create-revoked-proxy.js b/test/sendable/builtins/Array/prototype/slice/create-revoked-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..8472c56935f88685dadfc26aaffb519b89e109bc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-revoked-proxy.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: Abrupt completion from constructor that is a revoked Proxy object +features: [Proxy] +---*/ + +var o = Proxy.revocable([], {}); +var callCount = 0; +Object.defineProperty(o.proxy, 'constructor', { + get: function() { + callCount += 1; + } +}); +o.revoke(); +assert.throws(TypeError, function() { + SendableArray.prototype.slice.call(o.proxy); +}); +assert.sameValue(callCount, 0, '`constructor` property not accessed'); diff --git a/test/sendable/builtins/Array/prototype/slice/create-species-abrupt.js b/test/sendable/builtins/Array/prototype/slice/create-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..e2676dc658b88cc27caa2d027195ebfd4518c117 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-species-abrupt.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: Species constructor returns an abrupt completion +features: [Symbol.species] +---*/ + +var Ctor = function() { + throw new Test262Error(); +}; +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; +assert.throws(Test262Error, function() { + a.slice(); +}); diff --git a/test/sendable/builtins/Array/prototype/slice/create-species-neg-zero.js b/test/sendable/builtins/Array/prototype/slice/create-species-neg-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..1007d2fd3d8afa3eb1287e7a8110bf612c2591be --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-species-neg-zero.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: The value `-0` is converted to `0` +features: [Symbol.species] +---*/ + +var args; +var Ctor = function() { + args = arguments; +}; +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; +a.slice(0, -0); +assert.sameValue(args.length, 1); +assert.sameValue(args[0], 0); diff --git a/test/sendable/builtins/Array/prototype/slice/create-species-non-ctor.js b/test/sendable/builtins/Array/prototype/slice/create-species-non-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..225fa13f5116cb6f03d1a1a5aa1416c8aa20e6b8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-species-non-ctor.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + Behavior when the @@species attribute is a non-constructor object +includes: [isConstructor.js] +features: [Symbol.species, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(parseInt), + false, + 'precondition: isConstructor(parseInt) must return false' +); +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = parseInt; +assert.throws(TypeError, function() { + a.slice(); +}, 'a.slice() throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/slice/create-species-null.js b/test/sendable/builtins/Array/prototype/slice/create-species-null.js new file mode 100644 index 0000000000000000000000000000000000000000..e0e0f48e3bec67c84bc9690b2eb9c394eec5478a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-species-null.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + A null value for the @@species constructor is interpreted as `undefined` +features: [Symbol.species] +---*/ + +var a = []; +var result; +a.constructor = {}; +a.constructor[Symbol.species] = null; +result = a.slice(); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert(SendableArray.isArray(result), 'result is an SendableArray exotic object'); diff --git a/test/sendable/builtins/Array/prototype/slice/create-species-poisoned.js b/test/sendable/builtins/Array/prototype/slice/create-species-poisoned.js new file mode 100644 index 0000000000000000000000000000000000000000..4b7fe9b9c5ef65c915fac844afe2dd9c8614ca31 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-species-poisoned.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: Abrupt completion from `@@species` property access +features: [Symbol.species] +---*/ + +var a = []; +a.constructor = {}; +Object.defineProperty(a.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + a.slice(); +}); diff --git a/test/sendable/builtins/Array/prototype/slice/create-species-undef.js b/test/sendable/builtins/Array/prototype/slice/create-species-undef.js new file mode 100644 index 0000000000000000000000000000000000000000..871f2163fe84b2d2a45e0a7eabd3f5161e58e0ce --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-species-undef.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + An undefined value for the @@species constructor triggers the creation of + an Array exotic object +features: [Symbol.species] +---*/ + +var a = []; +var result; +a.constructor = {}; +a.constructor[Symbol.species] = undefined; +result = a.slice(); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert(SendableArray.isArray(result), 'result is an SendableArray exotic object'); diff --git a/test/sendable/builtins/Array/prototype/slice/create-species.js b/test/sendable/builtins/Array/prototype/slice/create-species.js new file mode 100644 index 0000000000000000000000000000000000000000..b51f823644aab7a6e00e3ebd2d098a34abc583b1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/create-species.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: Species constructor is used to create a new instance +features: [Symbol.species] +---*/ + +var thisValue, args, result; +var callCount = 0; +var instance = []; +var Ctor = function() { + callCount += 1; + thisValue = this; + args = arguments; + return instance; +}; +var a = [1, 2, 3, 4, 5]; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; +result = a.slice(1, -1); +assert.sameValue(callCount, 1, 'Constructor invoked exactly once'); +assert.sameValue(Object.getPrototypeOf(thisValue), Ctor.prototype); +assert.sameValue(args.length, 1, 'Constructor invoked with a single argument'); +assert.sameValue(args[0], 3); +assert.sameValue(result, instance); diff --git a/test/sendable/builtins/Array/prototype/slice/length-exceeding-integer-limit-proxied-array.js b/test/sendable/builtins/Array/prototype/slice/length-exceeding-integer-limit-proxied-array.js new file mode 100644 index 0000000000000000000000000000000000000000..1a370a780245cf912ecb363f182a29f30039f06c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/length-exceeding-integer-limit-proxied-array.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.slice +description: > + Length property is clamped to 2^53-1, test with indices near 2^53-1 and negative indices + and a proxy to an array. +info: | + 2. Let len be ? ToLength(? Get(O, "length")). + 3. Let relativeStart be ? ToInteger(start). + 4. If relativeStart < 0, let k be max((len + relativeStart), 0); + else let k be min(relativeStart, len). + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToInteger(end). + 6. If relativeEnd < 0, let final be max((len + relativeEnd), 0); + else let final be min(relativeEnd, len). +includes: [compareArray.js] +features: [exponentiation] +---*/ + +var array = []; +array["9007199254740988"] = "9007199254740988"; +array["9007199254740989"] = "9007199254740989"; +array["9007199254740990"] = "9007199254740990"; +array["9007199254740991"] = "9007199254740991"; +// Create a proxy to an array object, so IsArray returns true, but we can still +// return a length value exceeding the integer limit. +var proxy = new Proxy(array, { + get(t, pk, r) { + if (pk === "length") + return 2 ** 53 + 2; + return Reflect.get(t, pk, r); + } +}); +var result = SendableArray.prototype.slice.call(proxy, 9007199254740989); +assert.compareArray(result, ["9007199254740989", "9007199254740990"], + 'The value of result is expected to be ["9007199254740989", "9007199254740990"]'); +var result = SendableArray.prototype.slice.call(proxy, 9007199254740989, 9007199254740990); +assert.compareArray(result, ["9007199254740989"], + 'The value of result is expected to be ["9007199254740989"]'); +var result = SendableArray.prototype.slice.call(proxy, 9007199254740989, 9007199254740996); +assert.compareArray(result, ["9007199254740989", "9007199254740990"], + 'The value of result is expected to be ["9007199254740989", "9007199254740990"]'); +var result = SendableArray.prototype.slice.call(proxy, -2); +assert.compareArray(result, ["9007199254740989", "9007199254740990"], + 'The value of result is expected to be ["9007199254740989", "9007199254740990"]'); +var result = SendableArray.prototype.slice.call(proxy, -2, -1); +assert.compareArray(result, ["9007199254740989"], + 'The value of result is expected to be ["9007199254740989"]'); diff --git a/test/sendable/builtins/Array/prototype/slice/length-exceeding-integer-limit.js b/test/sendable/builtins/Array/prototype/slice/length-exceeding-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..a49fc971eb5ac7ca39f83ec082857343d825b93b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/length-exceeding-integer-limit.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + Length property is clamped to 2^53-1, test with indices near 2^53-1 and negative indices. +info: | + 2. Let len be ? ToLength(? Get(O, "length")). + 3. Let relativeStart be ? ToInteger(start). + 4. If relativeStart < 0, let k be max((len + relativeStart), 0); + else let k be min(relativeStart, len). + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToInteger(end). + 6. If relativeEnd < 0, let final be max((len + relativeEnd), 0); + else let final be min(relativeEnd, len). +includes: [compareArray.js] +features: [exponentiation] +---*/ + +var arrayLike = { + "9007199254740988": "9007199254740988", + "9007199254740989": "9007199254740989", + "9007199254740990": "9007199254740990", + "9007199254740991": "9007199254740991", + length: 2 ** 53 + 2, +}; +var result = SendableArray.prototype.slice.call(arrayLike, 9007199254740989); +assert.compareArray(result, ["9007199254740989", "9007199254740990"], + 'The value of result is expected to be ["9007199254740989", "9007199254740990"]'); +var result = SendableArray.prototype.slice.call(arrayLike, 9007199254740989, 9007199254740990); +assert.compareArray(result, ["9007199254740989"], + 'The value of result is expected to be ["9007199254740989"]'); +var result = SendableArray.prototype.slice.call(arrayLike, 9007199254740989, 9007199254740996); +assert.compareArray(result, ["9007199254740989", "9007199254740990"], + 'The value of result is expected to be ["9007199254740989", "9007199254740990"]'); +var result = SendableArray.prototype.slice.call(arrayLike, -2); +assert.compareArray(result, ["9007199254740989", "9007199254740990"], + 'The value of result is expected to be ["9007199254740989", "9007199254740990"]'); +var result = SendableArray.prototype.slice.call(arrayLike, -2, -1); +assert.compareArray(result, ["9007199254740989"], + 'The value of result is expected to be ["9007199254740989"]'); diff --git a/test/sendable/builtins/Array/prototype/slice/length.js b/test/sendable/builtins/Array/prototype/slice/length.js new file mode 100644 index 0000000000000000000000000000000000000000..1abc72fc61bd2e6fcb42f99064fc69fc2e7a2d74 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/length.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + The "length" property of Array.prototype.slice +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.slice, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/slice/name.js b/test/sendable/builtins/Array/prototype/slice/name.js new file mode 100644 index 0000000000000000000000000000000000000000..35f233ce194517685f7d30bfea1b630483731ba4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + Array.prototype.slice.name is "slice". +info: | + Array.prototype.slice (start, end) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.slice, "name", { + value: "slice", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/slice/not-a-constructor.js b/test/sendable/builtins/Array/prototype/slice/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..13636497bfdf375a8b675e774c3f736531792d84 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.slice does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.slice), + false, + 'isConstructor(SendableArray.prototype.slice) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.slice(); +}); + diff --git a/test/sendable/builtins/Array/prototype/slice/prop-desc.js b/test/sendable/builtins/Array/prototype/slice/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..137676a7e8b95d6fdead57e5e3c972bd972cff9d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + "slice" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.slice, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "slice", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/slice/resizable-buffer.js b/test/sendable/builtins/Array/prototype/slice/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..d96f5f57b97587bfc16486aaa1e6f50fab7cdee7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/resizable-buffer.js @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + Array.p.slice behaves correctly on TypedArrays backed by resizable buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + const fixedLengthSlice = SendableArray.prototype.slice.call(fixedLength); + assert.compareArray(ToNumbers(fixedLengthSlice), [ + 0, + 1, + 2, + 3 + ]); + const fixedLengthWithOffsetSlice = SendableArray.prototype.slice.call(fixedLengthWithOffset); + assert.compareArray(ToNumbers(fixedLengthWithOffsetSlice), [ + 2, + 3 + ]); + const lengthTrackingSlice = SendableArray.prototype.slice.call(lengthTracking); + assert.compareArray(ToNumbers(lengthTrackingSlice), [ + 0, + 1, + 2, + 3 + ]); + const lengthTrackingWithOffsetSlice = SendableArray.prototype.slice.call(lengthTrackingWithOffset); + assert.compareArray(ToNumbers(lengthTrackingWithOffsetSlice), [ + 2, + 3 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLength)), []); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLengthWithOffset)), []); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTracking)), [ + 0, + 1, + 2 + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTrackingWithOffset)), [2]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLength)), []); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLengthWithOffset)), []); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTracking)), [0]); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTrackingWithOffset)), []); + // Shrink to zero. + rab.resize(0); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLength)), []); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLengthWithOffset)), []); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTracking)), []); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTrackingWithOffset)), []); + // Verify that the previously created slices aren't affected by the + // shrinking. + assert.compareArray(ToNumbers(fixedLengthSlice), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(ToNumbers(fixedLengthWithOffsetSlice), [ + 2, + 3 + ]); + assert.compareArray(ToNumbers(lengthTrackingSlice), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(ToNumbers(lengthTrackingWithOffsetSlice), [ + 2, + 3 + ]); + // Grow so that all TAs are back in-bounds. New memory is zeroed. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLength)), [ + 0, + 0, + 0, + 0 + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(fixedLengthWithOffset)), [ + 0, + 0 + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTracking)), [ + 0, + 0, + 0, + 0, + 0, + 0 + ]); + assert.compareArray(ToNumbers(SendableArray.prototype.slice.call(lengthTrackingWithOffset)), [ + 0, + 0, + 0, + 0 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/slice/target-array-non-extensible.js b/test/sendable/builtins/Array/prototype/slice/target-array-non-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..fb3fd737b557a308108086bcee116cca62d106a7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/target-array-non-extensible.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + TypeError is thrown if CreateDataProperty fails. + (result object is non-extensible) +features: [Symbol.species] +---*/ + +var A = function(_length) { + this.length = 0; + Object.preventExtensions(this); +}; +var arr = [1]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.slice(0, 1); +}); diff --git a/test/sendable/builtins/Array/prototype/slice/target-array-with-non-configurable-property.js b/test/sendable/builtins/Array/prototype/slice/target-array-with-non-configurable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..e02fb356c33514e160ae66b09e19f89b11a2f103 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/target-array-with-non-configurable-property.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + TypeError is thrown if CreateDataProperty fails. + (result object's "0" is non-configurable) +features: [Symbol.species] +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + set: function(_value) {}, + configurable: false, + }); +}; +var arr = [1]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.slice(0, 1); +}); diff --git a/test/sendable/builtins/Array/prototype/slice/target-array-with-non-writable-property.js b/test/sendable/builtins/Array/prototype/slice/target-array-with-non-writable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..2df0c2ed3243cc4345e2a4a6c7aed48dd470d676 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/slice/target-array-with-non-writable-property.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.slice +description: > + Non-writable properties are overwritten by CreateDataPropertyOrThrow. +features: [Symbol.species] +includes: [propertyHelper.js] +---*/ + +var a = [1]; +a.constructor = {}; +a.constructor[Symbol.species] = function(len) { + var q = new SendableArray(0); + Object.defineProperty(q, 0, { + value: 0, writable: false, configurable: true, enumerable: false, + }); + return q; +}; +var r = a.slice(0); +verifyProperty(r, 0, { + value: 1, writable: true, configurable: true, enumerable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-1.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-1.js new file mode 100644 index 0000000000000000000000000000000000000000..1a3946bf5e2d8452d7da6af8a1e3826551b17d11 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to undefined throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.some.call(undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-10.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-10.js new file mode 100644 index 0000000000000000000000000000000000000000..e4d287e5be369f78e553880871d6dd4fc6696da8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-10.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to the Math object +---*/ + +function callbackfn(val, idx, obj) { + return '[object Math]' === Object.prototype.toString.call(obj); +} +Math.length = 1; +Math[0] = 1; +assert(SendableArray.prototype.some.call(Math, callbackfn), 'SendableArray.prototype.some.call(Math, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-11.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-11.js new file mode 100644 index 0000000000000000000000000000000000000000..3e32aee7371c287c231a0553d4aaa48f662a6fba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-11.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to Date object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Date; +} +var obj = new Date(0); +obj.length = 2; +obj[0] = 11; +obj[1] = 9; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-12.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-12.js new file mode 100644 index 0000000000000000000000000000000000000000..d05926ebc4a6491934887b28dcf73378c4d13576 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-12.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to RegExp object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof RegExp; +} +var obj = new RegExp(); +obj.length = 2; +obj[0] = 11; +obj[1] = 9; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-13.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-13.js new file mode 100644 index 0000000000000000000000000000000000000000..da560b1ea122b977ba0b996212b6350f8a6b876d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-13.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to the JSON object +---*/ + +function callbackfn(val, idx, obj) { + return '[object JSON]' === Object.prototype.toString.call(obj); +} +JSON.length = 1; +JSON[0] = 1; +assert(SendableArray.prototype.some.call(JSON, callbackfn), 'SendableArray.prototype.some.call(JSON, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-14.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-14.js new file mode 100644 index 0000000000000000000000000000000000000000..1f723ab798c9c142bc6cb16ce7d6379209915ba6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-14.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to Error object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Error; +} +var obj = new Error(); +obj.length = 1; +obj[0] = 1; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-15.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-15.js new file mode 100644 index 0000000000000000000000000000000000000000..72a21318f09589f80b86062f9e9f361d3f4e7a10 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-15.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to the Arguments object +---*/ + +function callbackfn(val, idx, obj) { + return '[object Arguments]' === Object.prototype.toString.call(obj); +} +var obj = (function() { + return arguments; +}("a", "b")); +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-2.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-2.js new file mode 100644 index 0000000000000000000000000000000000000000..9676e1599e3f812ba41c1ec16133547261ddf92b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-2.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to null throws a TypeError +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.some.call(null); +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-3.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-3.js new file mode 100644 index 0000000000000000000000000000000000000000..7b290d78bbb95bdd974cd9a7964e50402c85e106 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-3.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to boolean primitive +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Boolean; +} +Boolean.prototype[0] = 1; +Boolean.prototype.length = 1; +assert(SendableArray.prototype.some.call(false, callbackfn), 'SendableArray.prototype.some.call(false, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-4.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-4.js new file mode 100644 index 0000000000000000000000000000000000000000..f658e4383e6e26a5f076b8a4fa04f09857994b02 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-4.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to Boolean object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Boolean; +} +var obj = new Boolean(true); +obj.length = 2; +obj[0] = 11; +obj[1] = 9; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-5.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-5.js new file mode 100644 index 0000000000000000000000000000000000000000..b3b372a056802c1912d345f42f3de1ca73d2e420 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-5.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to number primitive +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Number; +} +Number.prototype[1] = true; +Number.prototype.length = 2; +assert(SendableArray.prototype.some.call(5, callbackfn), 'SendableArray.prototype.some.call(5, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-6.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-6.js new file mode 100644 index 0000000000000000000000000000000000000000..bc371d39723b7021fda5bc765e102fc6da4508d8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-6.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to Number object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Number; +} +var obj = new Number(-128); +obj.length = 2; +obj[0] = 11; +obj[1] = 9; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-7.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-7.js new file mode 100644 index 0000000000000000000000000000000000000000..583d2d89afed63dbb92b5e89454ae22325727b42 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-7.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to applied to string primitive +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof String; +} +assert(SendableArray.prototype.some.call("hello\nw_orld\\!", callbackfn), 'SendableArray.prototype.some.call("hello\nw_orld\\!", callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-8.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-8.js new file mode 100644 index 0000000000000000000000000000000000000000..97e3f47ac921b19cbbd7a775930760b6aa722f3f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-8.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to String object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof String; +} +var obj = new String("hello\nw_orld\\!"); +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-9.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-9.js new file mode 100644 index 0000000000000000000000000000000000000000..6103fdf1b21fe8862ec7a51c4190416a5841530f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-1-9.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to Function object +---*/ + +function callbackfn(val, idx, obj) { + return obj instanceof Function; +} +var obj = function(a, b) { + return a + b; +}; +obj[0] = 11; +obj[1] = 9; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-1.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..1eb5376a45d5c84071624b8da3ae55462425bb54 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-1.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is own data property on an + Array-like object +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: 2 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-10.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-10.js new file mode 100644 index 0000000000000000000000000000000000000000..d2136402c00593bcb5e883fec80af70153992ea0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-10.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is an inherited accessor property + on an Array-like object +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 9; +child[1] = 11; +child[2] = 12; +assert(SendableArray.prototype.some.call(child, callbackfn1), 'SendableArray.prototype.some.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(child, callbackfn2), false, 'SendableArray.prototype.some.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-11.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-11.js new file mode 100644 index 0000000000000000000000000000000000000000..c5d0c913bfafbec5972dce667db9b21dbe44547c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-11.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is an own accessor property + without a get function on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-12.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-12.js new file mode 100644 index 0000000000000000000000000000000000000000..3cb6c3792a9da970ceb077315042c289be54d875 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-12.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is own accessor property without a + get function that overrides an inherited accessor property on an + Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +Object.defineProperty(Object.prototype, "length", { + get: function() { + return 2; + }, + configurable: true +}); +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + set: function() {}, + configurable: true +}); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-13.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-13.js new file mode 100644 index 0000000000000000000000000000000000000000..90340b20640b62285dc8887c094c3fd17c0e2a1e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-13.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is inherited accessor property + without a get function on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var proto = {}; +Object.defineProperty(proto, "length", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 11; +child[1] = 12; +assert.sameValue(SendableArray.prototype.some.call(child, callbackfn), false, 'SendableArray.prototype.some.call(child, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-14.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-14.js new file mode 100644 index 0000000000000000000000000000000000000000..e5dfa3266c739124e3b85903265f492ee22be624 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-14.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' property doesn't exist on an + Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + 1: 12 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-17.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-17.js new file mode 100644 index 0000000000000000000000000000000000000000..bc760fa7796b69ddc01d964137e06cfdcc904cff --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-17.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some applied to the Arguments object which + implements its own property get method +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var func = function(a, b) { + arguments[2] = 12; + return SendableArray.prototype.some.call(arguments, callbackfn1) && + !SendableArray.prototype.some.call(arguments, callbackfn2); +}; +assert(func(9, 11), 'func(9, 11) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-18.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-18.js new file mode 100644 index 0000000000000000000000000000000000000000..01bc8979615d63735527a040809b7637ab07ac6a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-18.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some applied to String object which implements its + own property get method +---*/ + +function callbackfn1(val, idx, obj) { + return parseInt(val, 10) > 1; +} +function callbackfn2(val, idx, obj) { + return parseInt(val, 10) > 2; +} +var str = new String("12"); +String.prototype[2] = "3"; +assert(SendableArray.prototype.some.call(str, callbackfn1), 'SendableArray.prototype.some.call(str, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(str, callbackfn2), false, 'SendableArray.prototype.some.call(str, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-19.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-19.js new file mode 100644 index 0000000000000000000000000000000000000000..e6239947df40432ba77acdddc12fbc93560fd488 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-19.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some applied to Function object which implements + its own property get method +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var fun = function(a, b) { + return a + b; +}; +fun[0] = 9; +fun[1] = 11; +fun[2] = 12; +assert(SendableArray.prototype.some.call(fun, callbackfn1), 'SendableArray.prototype.some.call(fun, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(fun, callbackfn2), false, 'SendableArray.prototype.some.call(fun, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-2.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..09705d53bb7a355efa3db41f8c1cf856e607e3f0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - 'length' is own data property on an Array +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +SendableArray.prototype[2] = 12; +assert([9, 11].some(callbackfn1), '[9, 11].some(callbackfn1) !== true'); +assert.sameValue([9, 11].some(callbackfn2), false, '[9, 11].some(callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-3.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..fe603934f3ec0d259e6f7fab34fe0880e9157bba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-3.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is an own data property that + overrides an inherited data property on an Array-like object +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +child[0] = 9; +child[1] = 11; +child[2] = 12; +assert(SendableArray.prototype.some.call(child, callbackfn1), 'SendableArray.prototype.some.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(child, callbackfn2), false, 'SendableArray.prototype.some.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-4.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..ba1fa23d3e1184621972a52a7025d0b43c2a1275 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-4.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is an own data property that + overrides an inherited data property on an array +---*/ + +var arrProtoLen = 0; +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +arrProtoLen = SendableArray.prototype.length; +SendableArray.prototype.length = 0; +SendableArray.prototype[2] = 12; +assert([9, 11].some(callbackfn1), '[9, 11].some(callbackfn1) !== true'); +assert.sameValue([9, 11].some(callbackfn2), false, '[9, 11].some(callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-5.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..fb7c1c00308b861ea1abdb81c094ab667f108a05 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-5.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is an own data property that + overrides an inherited accessor property on an Array-like object +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + value: 2, + configurable: true +}); +child[0] = 9; +child[1] = 11; +child[2] = 12; +assert(SendableArray.prototype.some.call(child, callbackfn1), 'SendableArray.prototype.some.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(child, callbackfn2), false, 'SendableArray.prototype.some.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-6.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-6.js new file mode 100644 index 0000000000000000000000000000000000000000..c3243d1245deb9242c3b66932cf54ecfce28a0d3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-6.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is an inherited data property on + an Array-like object +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = { + length: 2 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[0] = 9; +child[1] = 11; +child[2] = 12; +assert(SendableArray.prototype.some.call(child, callbackfn1), 'SendableArray.prototype.some.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(child, callbackfn2), false, 'SendableArray.prototype.some.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-7.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-7.js new file mode 100644 index 0000000000000000000000000000000000000000..1e92791bfd93aa94f7a1e0fc297371cd6b675675 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-7.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is an own accessor property on an + Array-like object +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + return 2; + }, + configurable: true +}); +obj[0] = 9; +obj[1] = 11; +obj[2] = 12; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-8.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-8.js new file mode 100644 index 0000000000000000000000000000000000000000..966b88dcf8c98aca8c132b7d70f4d3c6fdb8cc71 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-8.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is an own accessor property that + overrides an inherited data property on an Array-like object +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = { + length: 3 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 9; +child[1] = 11; +child[2] = 12; +assert(SendableArray.prototype.some.call(child, callbackfn1), 'SendableArray.prototype.some.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(child, callbackfn2), false, 'SendableArray.prototype.some.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-9.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-9.js new file mode 100644 index 0000000000000000000000000000000000000000..22580c5b57dcfe309759aa0575d89d42f93f7a6d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-2-9.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is an own accessor property that + overrides an inherited accessor property on an Array-like object +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var proto = {}; +Object.defineProperty(proto, "length", { + get: function() { + return 3; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +Object.defineProperty(child, "length", { + get: function() { + return 2; + }, + configurable: true +}); +child[0] = 9; +child[1] = 11; +child[2] = 12; +assert(SendableArray.prototype.some.call(child, callbackfn1), 'SendableArray.prototype.some.call(child, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(child, callbackfn2), false, 'SendableArray.prototype.some.call(child, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-1.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-1.js new file mode 100644 index 0000000000000000000000000000000000000000..24223f2fcfc94059a4cbfe466f258d5ea44af9fe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - value of 'length' is undefined +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + length: undefined +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-10.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-10.js new file mode 100644 index 0000000000000000000000000000000000000000..8b32fadb6bee47277092015a09b7c6aff2f10977 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-10.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - value of 'length' is a number (value is NaN) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + length: NaN +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-11.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-11.js new file mode 100644 index 0000000000000000000000000000000000000000..5e75e9bdf3a80049986edc4a857aaedd815ebef4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-11.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is a string containing a positive + number +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: "2" +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-12.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-12.js new file mode 100644 index 0000000000000000000000000000000000000000..abbede395df3007256a2d19bc4ae258834386b69 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-12.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is a string containing a negative + number +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: "-4294967294" +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn1), false, 'SendableArray.prototype.some.call(obj, callbackfn1)'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-13.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-13.js new file mode 100644 index 0000000000000000000000000000000000000000..21b318649c684bbb3a62042459351e1a760976eb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-13.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is a string containing a decimal + number +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: "2.5" +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-14.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-14.js new file mode 100644 index 0000000000000000000000000000000000000000..868901b3034637d7fdcde97c61c6679a003d27d2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-14.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - 'length' is a string containing +/-Infinity +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var objOne = { + 0: 11, + length: "Infinity" +}; +var objTwo = { + 0: 11, + length: "+Infinity" +}; +var objThree = { + 0: 11, + length: "-Infinity" +}; +assert(SendableArray.prototype.some.call(objOne, callbackfn), 'SendableArray.prototype.some.call(objOne, callbackfn) !== true'); +assert(SendableArray.prototype.some.call(objTwo, callbackfn), 'SendableArray.prototype.some.call(objTwo, callbackfn) !== true'); +assert.sameValue(SendableArray.prototype.some.call(objThree, callbackfn), false, 'SendableArray.prototype.some.call(objThree, callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-15.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-15.js new file mode 100644 index 0000000000000000000000000000000000000000..09b014d6ccbee8af7075983c93b4876de9e4d5ad --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-15.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is a string containing an + exponential number +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: "2E0" +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-16.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-16.js new file mode 100644 index 0000000000000000000000000000000000000000..ad6089fb0ede2db79a46da13a6ad970904ad503d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-16.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - 'length' is a string containing a hex number +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: "0x0002" +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-17.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-17.js new file mode 100644 index 0000000000000000000000000000000000000000..291937214428d061c634df55e66c4205d498fc2a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-17.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is a string containing a number + with leading zeros +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: "0002.00" +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-18.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-18.js new file mode 100644 index 0000000000000000000000000000000000000000..49afa0dec7c0912489ac593d2d0b0d69bc503ab3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-18.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - value of 'length' is a string that can't + convert to a number +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + 1: 21, + length: "two" +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-19.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-19.js new file mode 100644 index 0000000000000000000000000000000000000000..9c17fc9d972aea4d15469bf0dd6da534b4ba93fb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-19.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - value of 'length' is an Object which has an + own toString method +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var toStringAccessed = false; +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: { + toString: function() { + toStringAccessed = true; + return '2'; + } + } +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); +assert(toStringAccessed, 'toStringAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-2.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-2.js new file mode 100644 index 0000000000000000000000000000000000000000..b2c65704ac9a3770c08a46110e7d12b94b04e3a6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-2.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some on an Array-like object if 'length' is 1 + (length overridden to true(type conversion)) +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 11, + 1: 12, + length: true +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-20.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-20.js new file mode 100644 index 0000000000000000000000000000000000000000..5e85fdc32a2289588805467762abbf6f81ba9604 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-20.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - value of 'length' is an Object which has an + own valueOf method +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var valueOfAccessed = false; +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: { + valueOf: function() { + valueOfAccessed = true; + return 2; + } + } +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-21.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-21.js new file mode 100644 index 0000000000000000000000000000000000000000..26aaabc901c38cc4d8ff9348f93e15424caf49bc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-21.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'length' is an object that has an own + valueOf method that returns an object and toString method that + returns a string +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var toStringAccessed = false; +var valueOfAccessed = false; +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: { + valueOf: function() { + valueOfAccessed = true; + return {}; + }, + toString: function() { + toStringAccessed = true; + return '2'; + } + } +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert(toStringAccessed, 'toStringAccessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-22.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-22.js new file mode 100644 index 0000000000000000000000000000000000000000..b92ed8587ba9fbc6b3c6cd1be422078a22bdd85f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-22.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some throws TypeError exception when 'length' is + an object with toString and valueOf methods that don�t return + primitive values +---*/ + +var callbackfnAccessed = false; +var toStringAccessed = false; +var valueOfAccessed = false; +function callbackfn(val, idx, obj) { + callbackfnAccessed = true; + return val > 10; +} +var obj = { + 0: 11, + 1: 12, + length: { + valueOf: function() { + valueOfAccessed = true; + return {}; + }, + toString: function() { + toStringAccessed = true; + return {}; + } + } +}; +assert.throws(TypeError, function() { + SendableArray.prototype.some.call(obj, callbackfn); +}); +assert(toStringAccessed, 'toStringAccessed !== true'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(callbackfnAccessed, false, 'callbackfnAccessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-23.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-23.js new file mode 100644 index 0000000000000000000000000000000000000000..6378a04c4467f33d2e4a3f686e61ae5a62a4c439 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-23.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some uses inherited valueOf method when 'length' + is an object with an own toString and inherited valueOf methods +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var valueOfAccessed = false; +var toStringAccessed = false; +var proto = { + valueOf: function() { + valueOfAccessed = true; + return 2; + } +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.toString = function() { + toStringAccessed = true; + return '1'; +}; +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: child +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); +assert(valueOfAccessed, 'valueOfAccessed !== true'); +assert.sameValue(toStringAccessed, false, 'toStringAccessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-24.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-24.js new file mode 100644 index 0000000000000000000000000000000000000000..fe62a6328f098ce95b6c2ec4425c3b60bf4a3c21 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-24.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - value of 'length' is a positive + non-integer, ensure truncation occurs in the proper direction +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 9, + 10: 11, + 11: 12, + length: 11.5 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-25.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-25.js new file mode 100644 index 0000000000000000000000000000000000000000..623dcb4c88c4d76ba0037382ab3cf890fe491fae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-25.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - value of 'length' is a negative non-integer +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: -4294967294.5 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn1), false, 'SendableArray.prototype.some.call(obj, callbackfn1)'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-28.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-28.js new file mode 100644 index 0000000000000000000000000000000000000000..d4f3df6af2795450fc3445e0ce07506adb8017d4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-28.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - value of 'length' is boundary value (2^32) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 12, + length: 4294967296 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-29.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-29.js new file mode 100644 index 0000000000000000000000000000000000000000..51eae07f240b36a0dfdea9948b43fa03442a660b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-29.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - value of 'length' is boundary value (2^32 + + 1) +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 11, + 1: 12, + length: 4294967297 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert(SendableArray.prototype.some.call(obj, callbackfn2), 'SendableArray.prototype.some.call(obj, callbackfn2) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-3.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-3.js new file mode 100644 index 0000000000000000000000000000000000000000..15b236024c60a10fdb440ba23e7f5e5e3d1f37d7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-3.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - value of 'length' is a number (value is 0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + length: 0 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-4.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-4.js new file mode 100644 index 0000000000000000000000000000000000000000..8e6e3946b9a523e2d03afee6cd0f3fddfe103e46 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - value of 'length' is a number (value is +0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + length: +0 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-5.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-5.js new file mode 100644 index 0000000000000000000000000000000000000000..c7913be053d38156d54900c604bf2b1932227f50 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-5.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - value of 'length' is a number (value is -0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + length: -0 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-6.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-6.js new file mode 100644 index 0000000000000000000000000000000000000000..41d848b450dfdf3fe267e7460c40e5213b626c44 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - value of 'length' is a number (value is + positive) +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: 2 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn1), 'SendableArray.prototype.some.call(obj, callbackfn1) !== true'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-7.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-7.js new file mode 100644 index 0000000000000000000000000000000000000000..9a585d1d76e418d8f0b0e36d1df337797949a40d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-7.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - value of 'length' is a number (value is + negative) +---*/ + +function callbackfn1(val, idx, obj) { + return val > 10; +} +function callbackfn2(val, idx, obj) { + return val > 11; +} +var obj = { + 0: 9, + 1: 11, + 2: 12, + length: -4294967294 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn1), false, 'SendableArray.prototype.some.call(obj, callbackfn1)'); +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn2), false, 'SendableArray.prototype.some.call(obj, callbackfn2)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-8.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-8.js new file mode 100644 index 0000000000000000000000000000000000000000..0ebe4c5883df42bb83fdafc860d6d4ced669ab6a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-8.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - value of 'length' is a number (value is + Infinity) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + length: Infinity +}; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-9.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-9.js new file mode 100644 index 0000000000000000000000000000000000000000..0f4dec26a6d7a2242676904b6e14614269741edc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-3-9.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - value of 'length' is a number (value is + -Infinity) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + length: -Infinity +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-1.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..b7130ec1ea4bc458dad3cba9d53a08303a82d4d2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-1.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some throws TypeError if callbackfn is undefined +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.some(); +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-10.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-10.js new file mode 100644 index 0000000000000000000000000000000000000000..cccbd1a8ea3d0dff475a34b346e36039641fb946 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-10.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - the exception is not thrown if exception + was thrown by step 2 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.some.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-11.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-11.js new file mode 100644 index 0000000000000000000000000000000000000000..e8b936295b42d42b80b7618347eaab5608760645 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-11.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - the exception is not thrown if exception + was thrown by step 3 +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + throw new Test262Error(); + } + }; + }, + configurable: true +}); +assert.throws(Test262Error, function() { + SendableArray.prototype.some.call(obj, undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-12.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-12.js new file mode 100644 index 0000000000000000000000000000000000000000..85aa538e53d161cccda866a002271adb786e0a2b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-12.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - 'callbackfn' is a function +---*/ + +function callbackfn(val, idx, obj) { + return val > 10; +} +assert([9, 11].some(callbackfn), '[9, 11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-15.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-15.js new file mode 100644 index 0000000000000000000000000000000000000000..6eaff9c0cd8978a792b4d318e30ce19233d15a6a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-15.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - calling with no callbackfn is the same as + passing undefined for callbackfn +---*/ + +var obj = {}; +var lengthAccessed = false; +var loopAccessed = false; +Object.defineProperty(obj, "length", { + get: function() { + lengthAccessed = true; + return 20; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + loopAccessed = true; + return 10; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.some.call(obj); +}); +assert(lengthAccessed, 'lengthAccessed !== true'); +assert.sameValue(loopAccessed, false, 'loopAccessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-2.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-2.js new file mode 100644 index 0000000000000000000000000000000000000000..3f2193f567ac05952995c36c8f83a41c7cadf718 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-2.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some throws ReferenceError if callbackfn is + unreferenced +---*/ + +var arr = new SendableArray(10); +assert.throws(ReferenceError, function() { + arr.some(foo); +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-3.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..d22b64e41753e8a4c7b9add9c3fa57009349bed3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-3.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some throws TypeError if callbackfn is null +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.some(null); +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-4.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..637afe49e79358e89bc50456111aec7d67053a6b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-4.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some throws TypeError if callbackfn is boolean +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.some(true); +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-5.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-5.js new file mode 100644 index 0000000000000000000000000000000000000000..7458782c8c4e6ccf9efe1418085184a4ee06dc6d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-5.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some throws TypeError if callbackfn is number +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.some(5); +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-6.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-6.js new file mode 100644 index 0000000000000000000000000000000000000000..057e9e4404a9ec961c3f771eece44e9e133aea12 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-6.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some throws TypeError if callbackfn is string +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.some("abc"); +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-7.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-7.js new file mode 100644 index 0000000000000000000000000000000000000000..0d08cb61d3b73026c67036135ed3b31f9fd0fd74 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-7.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some throws TypeError if callbackfn is Object + without a Call internal method +---*/ + +var arr = new SendableArray(10); +assert.throws(TypeError, function() { + arr.some(new Object()); +}); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-8.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-8.js new file mode 100644 index 0000000000000000000000000000000000000000..7db27e3c4baccc2d97c054e08d0d29be2da628a9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-8.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - side effects produced by step 2 are visible + when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + accessed = true; + return 2; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.some.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-9.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-9.js new file mode 100644 index 0000000000000000000000000000000000000000..0ef1a45e4060b49f3aa9dbe4f921b2d272776e4c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-4-9.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - side effects produced by step 3 are visible + when an exception occurs +---*/ + +var obj = { + 0: 11, + 1: 12 +}; +var accessed = false; +Object.defineProperty(obj, "length", { + get: function() { + return { + toString: function() { + accessed = true; + return "2"; + } + }; + }, + configurable: true +}); +assert.throws(TypeError, function() { + SendableArray.prototype.some.call(obj, null); +}); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-1.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-1.js new file mode 100644 index 0000000000000000000000000000000000000000..d570659ba049d444f327f602e74a2a493ef2b278 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-1.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - thisArg is passed +flags: [noStrict] +---*/ + +(function() { + this._15_4_4_17_5_1 = false; + var _15_4_4_17_5_1 = true; + function callbackfn(val, idx, obj) { + return this._15_4_4_17_5_1; + } + var arr = [1]; + assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); +})(); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-10.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-10.js new file mode 100644 index 0000000000000000000000000000000000000000..374ff524755b7826f03e5289aa10972086c2d1c1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-10.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - Array Object can be used as thisArg +---*/ + +var objArray = []; +function callbackfn(val, idx, obj) { + return this === objArray; +} +assert([11].some(callbackfn, objArray), '[11].some(callbackfn, objArray) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-11.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-11.js new file mode 100644 index 0000000000000000000000000000000000000000..6fbed3b5748dab9449d46c47e32ab71d29c11116 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-11.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - String object can be used as thisArg +---*/ + +var objString = new String(); +function callbackfn(val, idx, obj) { + return this === objString; +} +assert([11].some(callbackfn, objString), '[11].some(callbackfn, objString) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-12.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-12.js new file mode 100644 index 0000000000000000000000000000000000000000..c8c697edd61100c89b07303038f0f92b7dc53477 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-12.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - Boolean object can be used as thisArg +---*/ + +var objBoolean = new Boolean(); +function callbackfn(val, idx, obj) { + return this === objBoolean; +} +assert([11].some(callbackfn, objBoolean), '[11].some(callbackfn, objBoolean) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-13.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-13.js new file mode 100644 index 0000000000000000000000000000000000000000..7bd399df6b40742f9a20aba212d81540ac66004a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-13.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - Number object can be used as thisArg +---*/ + +var objNumber = new Number(); +function callbackfn(val, idx, obj) { + return this === objNumber; +} +assert([11].some(callbackfn, objNumber), '[11].some(callbackfn, objNumber) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-14.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-14.js new file mode 100644 index 0000000000000000000000000000000000000000..cf801802d3cb31f5c05f03ba9712bac2234708f3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-14.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - the Math object can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this === Math; +} +assert([11].some(callbackfn, Math), '[11].some(callbackfn, Math) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-15.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-15.js new file mode 100644 index 0000000000000000000000000000000000000000..0885a14b95de1630cd4e556e943add974fdfde35 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-15.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - Date object can be used as thisArg +---*/ + +var objDate = new Date(0); +function callbackfn(val, idx, obj) { + return this === objDate; +} +assert([11].some(callbackfn, objDate), '[11].some(callbackfn, objDate) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-16.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-16.js new file mode 100644 index 0000000000000000000000000000000000000000..484aa352637c67d33f1d9e32439c4fd35194fa06 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-16.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - RegExp object can be used as thisArg +---*/ + +var objRegExp = new RegExp(); +function callbackfn(val, idx, obj) { + return this === objRegExp; +} +assert([11].some(callbackfn, objRegExp), '[11].some(callbackfn, objRegExp) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-17.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-17.js new file mode 100644 index 0000000000000000000000000000000000000000..148ac9e205a5f02f3cdbdef910be337548a98a11 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-17.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - the JSON object can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this === JSON; +} +assert([11].some(callbackfn, JSON), '[11].some(callbackfn, JSON) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-18.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-18.js new file mode 100644 index 0000000000000000000000000000000000000000..84cc0b1f11e453bdb90b18a2d8c3f8a3d8bb838e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-18.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - Error object can be used as thisArg +---*/ + +var objError = new RangeError(); +function callbackfn(val, idx, obj) { + return this === objError; +} +assert([11].some(callbackfn, objError), '[11].some(callbackfn, objError) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-19.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-19.js new file mode 100644 index 0000000000000000000000000000000000000000..2ee7f7a309931e6c7036adcd3f1a82368fd3f58a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-19.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - the Arguments object can be used as thisArg +---*/ + +var arg; +function callbackfn(val, idx, obj) { + return this === arg; +} +(function fun() { + arg = arguments; +}(1, 2, 3)); +assert([11].some(callbackfn, arg), '[11].some(callbackfn, arg) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-2.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-2.js new file mode 100644 index 0000000000000000000000000000000000000000..e895ef79554f3b930b0d305c455d6dbfe661b0d3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - thisArg is Object +---*/ + +var res = false; +var o = new Object(); +o.res = true; +function callbackfn(val, idx, obj) +{ + return this.res; +} +var arr = [1]; +assert.sameValue(arr.some(callbackfn, o), true, 'arr.some(callbackfn, o)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-21.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-21.js new file mode 100644 index 0000000000000000000000000000000000000000..71926d82347dea79d9ab946d7e7189161974e3f2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-21.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - the global object can be used as thisArg +---*/ + +var global = this; +function callbackfn(val, idx, obj) { + return this === global; +} +assert([11].some(callbackfn, this), '[11].some(callbackfn, global) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-22.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-22.js new file mode 100644 index 0000000000000000000000000000000000000000..da9128b3cccaa36a90c17118b3fc7a6d2ce08c67 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-22.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - boolean primitive can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === false; +} +assert([11].some(callbackfn, false), '[11].some(callbackfn, false) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-23.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-23.js new file mode 100644 index 0000000000000000000000000000000000000000..ef05380fa9943170775d19bdec33734f98c512d7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-23.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - number primitive can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === 101; +} +assert([11].some(callbackfn, 101), '[11].some(callbackfn, 101) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-24.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-24.js new file mode 100644 index 0000000000000000000000000000000000000000..b2aac2c7a4e5bd3e1ce86c746ec621fba91e8c9f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-24.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - string primitive can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === "abc"; +} +assert([11].some(callbackfn, "abc"), '[11].some(callbackfn, "abc") !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-25.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-25.js new file mode 100644 index 0000000000000000000000000000000000000000..74fc7a0e3c18c3b930770cf408f0911945570c56 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-25.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - thisArg not passed +flags: [noStrict] +---*/ + +function innerObj() { + this._15_4_4_17_5_25 = true; + var _15_4_4_17_5_25 = false; + function callbackfn(val, idx, obj) { + return this._15_4_4_17_5_25; + } + var arr = [1]; + this.retVal = !arr.some(callbackfn); +} +assert(new innerObj().retVal, 'new innerObj().retVal !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-3.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-3.js new file mode 100644 index 0000000000000000000000000000000000000000..c7dedef4588d820a1ca4160ef78b74003310adfc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-3.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - thisArg is Array +---*/ + +var res = false; +var a = new SendableArray(); +a.res = true; +function callbackfn(val, idx, obj) +{ + return this.res; +} +var arr = [1]; +assert.sameValue(arr.some(callbackfn, a), true, 'arr.some(callbackfn, a)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-4.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-4.js new file mode 100644 index 0000000000000000000000000000000000000000..ce5639febbb18515140e5fa8d6adb1efcec798a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-4.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - thisArg is object from object + template(prototype) +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +foo.prototype.res = true; +var f = new foo(); +var arr = [1]; +assert.sameValue(arr.some(callbackfn, f), true, 'arr.some(callbackfn,f)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-5.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-5.js new file mode 100644 index 0000000000000000000000000000000000000000..71b4d773db603a21a1e4ff2f535d1e3dd02ac8f0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-5.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - thisArg is object from object template +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +var f = new foo(); +f.res = true; +var arr = [1]; +assert.sameValue(arr.some(callbackfn, f), true, 'arr.some(callbackfn,f)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-6.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-6.js new file mode 100644 index 0000000000000000000000000000000000000000..1c2e11a88d6eba7373b36b642a0eb29a49b9bbd6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-6.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - thisArg is function +---*/ + +var res = false; +function callbackfn(val, idx, obj) +{ + return this.res; +} +function foo() {} +foo.res = true; +var arr = [1]; +assert.sameValue(arr.some(callbackfn, foo), true, 'arr.some(callbackfn,foo)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-7.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-7.js new file mode 100644 index 0000000000000000000000000000000000000000..d06295dbf46da858745ef02191d22b8e58c2413a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-7.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - built-in functions can be used as thisArg +---*/ + +function callbackfn(val, idx, obj) { + return this === eval; +} +assert([11].some(callbackfn, eval), '[11].some(callbackfn, eval) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-8.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-8.js new file mode 100644 index 0000000000000000000000000000000000000000..2fb83e67806e753e4279240663aab6f10f7aafce --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-8.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - thisArg not passed to strict callbackfn +flags: [noStrict] +---*/ + +var innerThisCorrect = false; +function callbackfn(val, idx, obj) { + "use strict"; + innerThisCorrect = this === undefined; + return true; +} +[1].some(callbackfn); +assert(innerThisCorrect, 'innerThisCorrect !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-9.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-9.js new file mode 100644 index 0000000000000000000000000000000000000000..8ced7e61b7a91f2893f1e58fc5585e67f66cdcd0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-5-9.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - Function Object can be used as thisArg +---*/ + +var objFunction = function() {}; +function callbackfn(val, idx, obj) { + return this === objFunction; +} +assert([11].some(callbackfn, objFunction), '[11].some(callbackfn, objFunction) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-1.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-1.js new file mode 100644 index 0000000000000000000000000000000000000000..3f25b7deb24f8bac15a290d46690872ce42341a9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some considers new elements added to array after + it is called +---*/ + +var calledForThree = false; +function callbackfn(val, idx, obj) +{ + arr[2] = 3; + if (val !== 3) + calledForThree = true; + + return false; +} +var arr = [1, 2, , 4, 5]; +var val = arr.some(callbackfn); +assert(calledForThree, 'calledForThree !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-2.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-2.js new file mode 100644 index 0000000000000000000000000000000000000000..8a701810d1a772272a0d1e56a5953593caeaf130 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-2.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some considers new value of elements in array + after it is called +---*/ + +function callbackfn(val, idx, obj) +{ + arr[4] = 6; + if (val < 6) + return false; + else + return true; +} +var arr = [1, 2, 3, 4, 5]; +assert.sameValue(arr.some(callbackfn), true, 'arr.some(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-3.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-3.js new file mode 100644 index 0000000000000000000000000000000000000000..7ce6349bdf990d3fef3aca44dbb81b2eba48bae9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-3.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some doesn't visit deleted elements in array after + it is called +---*/ + +function callbackfn(val, idx, obj) +{ + delete arr[2]; + if (val !== 3) + return false; + else + return true; +} +var arr = [1, 2, 3, 4, 5]; +assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-4.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-4.js new file mode 100644 index 0000000000000000000000000000000000000000..730fbf5b925fe97dd24368d5914a1e9187a16c79 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-4.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some doesn't visit deleted elements when + Array.length is decreased +---*/ + +function callbackfn(val, idx, obj) +{ + arr.length = 3; + if (val < 4) + return false; + else + return true; +} +var arr = [1, 2, 3, 4, 6]; +assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-5.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-5.js new file mode 100644 index 0000000000000000000000000000000000000000..2232bde8a87296447e8da7e4dea5b81f3369a95a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-5.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some doesn't consider newly added elements in + sparse array +---*/ + +function callbackfn(val, idx, obj) +{ + arr[1000] = 5; + if (val < 5) + return false; + else + return true; +} +var arr = new SendableArray(10); +arr[1] = 1; +arr[2] = 2; +assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-6.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-6.js new file mode 100644 index 0000000000000000000000000000000000000000..d5d5ec9723d66eff789f51345bbb8e4792444084 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-6.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some visits deleted element in array after the + call when same index is also present in prototype +---*/ + +function callbackfn(val, idx, obj) +{ + delete arr[4]; + if (val < 5) + return false; + else + return true; +} +SendableArray.prototype[4] = 5; +var arr = [1, 2, 3, 4, 5]; +var res = arr.some(callbackfn); +delete SendableArray.prototype[4]; +assert.sameValue(res, true, 'res'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-8.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-8.js new file mode 100644 index 0000000000000000000000000000000000000000..de4f15abce0076a289eb04871f72be6257075050 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-8.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - no observable effects occur if length is 0 +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return val > 10; +} +var obj = { + 0: 11, + 1: 12, + length: 0 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-9.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-9.js new file mode 100644 index 0000000000000000000000000000000000000000..2700538cf47c3fd52d29946c629dac849edc653b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-9.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - modifications to length don't change number + of iterations +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + return val > 10; +} +var obj = { + 0: 9, + 2: 12, + length: 3 +}; +Object.defineProperty(obj, "1", { + get: function() { + obj.length = 2; + return 8; + }, + configurable: true +}); +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); +assert.sameValue(called, 3, 'called'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-1.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-1.js new file mode 100644 index 0000000000000000000000000000000000000000..a934afd2083186564dabd443febc2bc28aae3afc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - callbackfn not called for indexes never + been assigned values +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; + return false; +} +var arr = new SendableArray(10); +arr[1] = undefined; +arr.some(callbackfn); +assert.sameValue(callCnt, 1, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-10.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-10.js new file mode 100644 index 0000000000000000000000000000000000000000..8cd37486b9834c0540ef8a54fa51aeec224b1b53 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-10.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - deleting property of prototype causes + prototype index property not to be visited on an Array-like Object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx === 1; +} +var arr = { + 2: 2, + length: 20 +}; +Object.defineProperty(arr, "0", { + get: function() { + delete Object.prototype[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +assert.sameValue(SendableArray.prototype.some.call(arr, callbackfn), false, 'SendableArray.prototype.some.call(arr, callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-11.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-11.js new file mode 100644 index 0000000000000000000000000000000000000000..8a0c553618155aba02a732f6287ec073e7d2b244 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-11.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - deleting property of prototype causes + prototype index property not to be visited on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx === 1; +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + delete SendableArray.prototype[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-12.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-12.js new file mode 100644 index 0000000000000000000000000000000000000000..c232adb1d48c33982e1252bd92fa10d6695ddb57 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-12.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - deleting own property with prototype + property causes prototype index property to be visited on an + Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + return true; + } else { + return false; + } +} +var arr = { + 0: 0, + 1: 111, + 2: 2, + length: 10 +}; +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +Object.prototype[1] = 1; +assert(SendableArray.prototype.some.call(arr, callbackfn), 'SendableArray.prototype.some.call(arr, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-13.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-13.js new file mode 100644 index 0000000000000000000000000000000000000000..68a1b8eeea4d63e8fc4e449fe7d0247237633649 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-13.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - deleting own property with prototype + property causes prototype index property to be visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + return true; + } else { + return false; + } +} +var arr = [0, 111, 2]; +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +SendableArray.prototype[1] = 1; +assert(arr.some(callbackfn), 'arr.some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-14.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-14.js new file mode 100644 index 0000000000000000000000000000000000000000..6923bd3ef7c579bdc7917913f40283a0b81d871d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-14.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - decreasing length of array causes index + property not to be visited +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx === 3; +} +var arr = [0, 1, 2, "last"]; +Object.defineProperty(arr, "0", { + get: function() { + arr.length = 3; + return 0; + }, + configurable: true +}); +assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-15.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-15.js new file mode 100644 index 0000000000000000000000000000000000000000..ef883fa762448a158fd4f8ecb980336ade21b164 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-15.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - decreasing length of array with prototype + property causes prototype index property to be visited +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "prototype") { + return true; + } else { + return false; + } +} +var arr = [0, 1, 2]; +Object.defineProperty(SendableArray.prototype, "2", { + get: function() { + return "prototype"; + }, + configurable: true +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +assert(arr.some(callbackfn), 'arr.some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-16.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-16.js new file mode 100644 index 0000000000000000000000000000000000000000..cc1219330ff59061a1d419bea1592be2709d4a83 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-16.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - decreasing length of array does not delete + non-configurable properties +flags: [noStrict] +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "unconfigurable") { + return true; + } else { + return false; + } +} +var arr = [0, 1, 2]; +Object.defineProperty(arr, "2", { + get: function() { + return "unconfigurable"; + }, + configurable: false +}); +Object.defineProperty(arr, "1", { + get: function() { + arr.length = 2; + return 1; + }, + configurable: true +}); +assert(arr.some(callbackfn), 'arr.some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-2.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-2.js new file mode 100644 index 0000000000000000000000000000000000000000..1f3d5e2585c30a786138cc46cb02035b3a45e5b6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-2.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - added properties in step 2 are visible here +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 2 && val === "length") { + return true; + } else { + return false; + } +} +var arr = {}; +Object.defineProperty(arr, "length", { + get: function() { + arr[2] = "length"; + return 3; + }, + configurable: true +}); +assert(SendableArray.prototype.some.call(arr, callbackfn), 'SendableArray.prototype.some.call(arr, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-3.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-3.js new file mode 100644 index 0000000000000000000000000000000000000000..c65da3ed46c53c303cec1d8b69db3df0d981d345 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-3.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - deleted properties in step 2 are visible + here +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx === 2; +} +var arr = { + 2: 6.99, + 8: 19 +}; +Object.defineProperty(arr, "length", { + get: function() { + delete arr[2]; + return 10; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.some.call(arr, callbackfn), false, 'SendableArray.prototype.some.call(arr, callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-4.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-4.js new file mode 100644 index 0000000000000000000000000000000000000000..40d116f5414f089ac022b282ce8c74c06baba79a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-4.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - properties added into own object after + current position are visited on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + return true; + } else { + return false; + } +} +var arr = { + length: 2 +}; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert(SendableArray.prototype.some.call(arr, callbackfn), 'SendableArray.prototype.some.call(arr, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-5.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-5.js new file mode 100644 index 0000000000000000000000000000000000000000..20ad59fb183bdb67a38b558dd3417abec88cddbe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-5.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - properties added into own object after + current position are visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 1) { + return true; + } else { + return false; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(arr, "1", { + get: function() { + return 1; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert(arr.some(callbackfn), 'arr.some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-6.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-6.js new file mode 100644 index 0000000000000000000000000000000000000000..33fbf4cec39c9f1c8803ba52e04f98a69b6c85b9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-6.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - properties can be added to prototype after + current position are visited on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 6.99) { + return true; + } else { + return false; + } +} +var arr = { + length: 2 +}; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(Object.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert(SendableArray.prototype.some.call(arr, callbackfn), 'SendableArray.prototype.some.call(arr, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-7.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-7.js new file mode 100644 index 0000000000000000000000000000000000000000..1e1a33e8d9d253de9c26094a0ccc2b32629bcc72 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-7.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - properties can be added to prototype after + current position are visited on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1 && val === 6.99) { + return true; + } else { + return false; + } +} +var arr = [0, , 2]; +Object.defineProperty(arr, "0", { + get: function() { + Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 6.99; + }, + configurable: true + }); + return 0; + }, + configurable: true +}); +assert(arr.some(callbackfn), 'arr.some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-8.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-8.js new file mode 100644 index 0000000000000000000000000000000000000000..c59c9b775ece4365f9d784c32050381f7975ee0b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-8.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - deleting own property causes index property + not to be visited on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx === 1; +} +var arr = { + length: 2 +}; +Object.defineProperty(arr, "1", { + get: function() { + return 6.99; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +assert.sameValue(SendableArray.prototype.some.call(arr, callbackfn), false, 'SendableArray.prototype.some.call(arr, callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-9.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-9.js new file mode 100644 index 0000000000000000000000000000000000000000..ae1ecd0d15c14b04cb8cd1ffe77d9c7d7e120060 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-b-9.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - deleting own property causes index property + not to be visited on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return idx === 1; +} +var arr = [1, 2]; +Object.defineProperty(arr, "1", { + get: function() { + return "6.99"; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + delete arr[1]; + return 0; + }, + configurable: true +}); +assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-1.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-1.js new file mode 100644 index 0000000000000000000000000000000000000000..b46d14fd2a74f72b34922250b3ba443cd6aa7907 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own data + property on an Array-like object +---*/ + +var kValue = {}; +function callbackfn(val, idx, obj) { + if (idx === 5) { + return val === kValue; + } + return false; +} +var obj = { + 5: kValue, + length: 100 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-10.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-10.js new file mode 100644 index 0000000000000000000000000000000000000000..c78ec9d5063929b15f86f8c107f805076fb9c350 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-10.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own accessor + property on an Array +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 10) { + return val === kValue; + } + return false; +} +var arr = []; +Object.defineProperty(arr, "10", { + get: function() { + return kValue; + }, + configurable: true +}); +assert(arr.some(callbackfn), 'arr.some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-11.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-11.js new file mode 100644 index 0000000000000000000000000000000000000000..00ebf0feb10b8b3c96c52b1c58c80f1439ad214f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-11.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own accessor + property that overrides an inherited data property on an + Array-like object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val === kValue; + } + return false; +} +var proto = { + 1: 6 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +Object.defineProperty(child, "1", { + get: function() { + return kValue; + }, + configurable: true +}); +assert(SendableArray.prototype.some.call(child, callbackfn), 'SendableArray.prototype.some.call(child, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-12.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-12.js new file mode 100644 index 0000000000000000000000000000000000000000..ab08be15a5be49ea18f8e307ab1c621bf0b48ced --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-12.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own accessor + property that overrides an inherited data property on an Array +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val === kValue; + } + return false; +} +var arr = []; +SendableArray.prototype[1] = 100; +Object.defineProperty(arr, "1", { + get: function() { + return kValue; + }, + configurable: true +}); +assert(arr.some(callbackfn), 'arr.some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-13.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-13.js new file mode 100644 index 0000000000000000000000000000000000000000..36e5728ba772cb25e8b020aa5d1fb85d948e2aae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-13.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own accessor + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val === kValue; + } + return false; +} +var proto = {}; +Object.defineProperty(proto, "1", { + get: function() { + return 5; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +Object.defineProperty(child, "1", { + get: function() { + return kValue; + }, + configurable: true +}); +assert(SendableArray.prototype.some.call(child, callbackfn), 'SendableArray.prototype.some.call(child, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-14.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-14.js new file mode 100644 index 0000000000000000000000000000000000000000..878172d451b03e4bf6c3aaff0206fc9bc788ef60 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-14.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own accessor + property that overrides an inherited accessor property on an Array +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val === kValue; + } + return false; +} +var arr = []; +Object.defineProperty(arr, "1", { + get: function() { + return kValue; + }, + configurable: true +}); +Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return 10; + }, + configurable: true +}); +assert(arr.some(callbackfn), 'arr.some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-15.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-15.js new file mode 100644 index 0000000000000000000000000000000000000000..3c0658d6a41453796dfb64b45129f286ea98d105 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-15.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is inherited + accessor property on an Array-like object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val === kValue; + } + return false; +} +var proto = {}; +Object.defineProperty(proto, "1", { + get: function() { + return kValue; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 20; +assert(SendableArray.prototype.some.call(child, callbackfn), 'SendableArray.prototype.some.call(child, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-16.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-16.js new file mode 100644 index 0000000000000000000000000000000000000000..471b856489f1204d7d358514b4c909c5db20708d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-16.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is inherited + accessor property on an Array +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val === kValue; + } + return false; +} +Object.defineProperty(SendableArray.prototype, "1", { + get: function() { + return kValue; + }, + configurable: true +}); +assert([, , ].some(callbackfn), '[, , ].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-17.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-17.js new file mode 100644 index 0000000000000000000000000000000000000000..2f326d1285c7b6dfd2527e1b35742369db34b070 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-17.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own accessor + property without a get function on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return typeof val === "undefined"; + } + return false; +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-18.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-18.js new file mode 100644 index 0000000000000000000000000000000000000000..2c3d5b3433fb2e7690b98e0fbf0ac9666a606883 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-18.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own accessor + property without a get function on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return typeof val === "undefined"; + } + return false; +} +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +assert(arr.some(callbackfn), 'arr.some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-19.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-19.js new file mode 100644 index 0000000000000000000000000000000000000000..06476493140936a897808d6821a62d94eb695843 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-19.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return typeof val === "undefined"; + } + return false; +} +var obj = { + length: 2 +}; +Object.defineProperty(obj, "1", { + set: function() {}, + configurable: true +}); +Object.prototype[1] = 10; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-2.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-2.js new file mode 100644 index 0000000000000000000000000000000000000000..8bc3342520ae2c2e0d4e43851233855c02a6c11d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own data + property on an Array +---*/ + +var kValue = {}; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return kValue === val; + } + return false; +} +assert([kValue].some(callbackfn), '[kValue].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-20.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-20.js new file mode 100644 index 0000000000000000000000000000000000000000..9f81032f973fa78b8664b47a77de36e17f062c9e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-20.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own accessor + property without a get function that overrides an inherited + accessor property on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return typeof val === "undefined"; + } + return false; +} +var arr = []; +Object.defineProperty(arr, "0", { + set: function() {}, + configurable: true +}); +SendableArray.prototype[0] = 100; +assert(arr.some(callbackfn), 'arr.some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-21.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-21.js new file mode 100644 index 0000000000000000000000000000000000000000..5ed78f368cb78724d2d3bb96e9f307a9391802e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-21.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is inherited + accessor property without a get function on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return typeof val === "undefined"; + } + return false; +} +var proto = {}; +Object.defineProperty(proto, "1", { + set: function() {}, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +assert(SendableArray.prototype.some.call(child, callbackfn), 'SendableArray.prototype.some.call(child, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-22.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-22.js new file mode 100644 index 0000000000000000000000000000000000000000..1f52c39e0a09cd56435cfbd809127c4fea2a83ce --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-22.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is inherited + accessor property without a get function on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return typeof val === "undefined"; + } + return false; +} +Object.defineProperty(SendableArray.prototype, "0", { + set: function() {}, + configurable: true +}); +assert([, ].some(callbackfn), '[, ].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-25.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-25.js new file mode 100644 index 0000000000000000000000000000000000000000..c430f12010dd950b36dfd0f7ab920eba50c2ecf4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-25.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - This object is the Arguments object which + implements its own property get method (number of arguments is + less than number of parameters) +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === 11; + } + return false; +} +var func = function(a, b) { + return SendableArray.prototype.some.call(arguments, callbackfn); +}; +assert(func(11), 'func(11) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-26.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-26.js new file mode 100644 index 0000000000000000000000000000000000000000..4ac376f8ab6ab8e6cfc56ff55c8f7b7801cfcf0f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-26.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - This object is the Arguments object which + implements its own property get method (number of arguments equals + number of parameters) +---*/ + +var firstResult = false; +var secondResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + firstResult = (val === 11); + return false; + } else if (idx === 1) { + secondResult = (val === 9); + return false; + } else { + return true; + } +} +var func = function(a, b) { + return SendableArray.prototype.some.call(arguments, callbackfn); +}; +assert.sameValue(func(11, 9), false, 'func(11, 9)'); +assert(firstResult, 'firstResult !== true'); +assert(secondResult, 'secondResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-27.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-27.js new file mode 100644 index 0000000000000000000000000000000000000000..973ab329d38713c74e5b886895d59e2d72f7d6b7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-27.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - This object is the Arguments object which + implements its own property get method (number of arguments is + greater than number of parameters) +---*/ + +var firstResult = false; +var secondResult = false; +var thirdResult = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + firstResult = (val === 11); + return false; + } else if (idx === 1) { + secondResult = (val === 12); + return false; + } else if (idx === 2) { + thirdResult = (val === 9); + return false; + } else { + return true; + } +} +var func = function(a, b) { + return SendableArray.prototype.some.call(arguments, callbackfn); +}; +assert.sameValue(func(11, 12, 9), false, 'func(11, 12, 9)'); +assert(firstResult, 'firstResult !== true'); +assert(secondResult, 'secondResult !== true'); +assert(thirdResult, 'thirdResult !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-28.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-28.js new file mode 100644 index 0000000000000000000000000000000000000000..5ba4afb739c74c2925c96ec676cbdccc8e7b8494 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-28.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element changed by getter on previous + iterations is observed on an Array +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val === 12; + } + return false; +} +var arr = []; +var helpVerifyVar = 11; +Object.defineProperty(arr, "1", { + get: function() { + return helpVerifyVar; + }, + set: function(args) { + helpVerifyVar = args; + }, + configurable: true +}); +Object.defineProperty(arr, "0", { + get: function() { + arr[1] = 12; + return 9; + }, + configurable: true +}); +assert(arr.some(callbackfn), 'arr.some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-29.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-29.js new file mode 100644 index 0000000000000000000000000000000000000000..8908cdf819956ccfbc24adfc6548573368b80397 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-29.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element changed by getter on previous + iterations on an Array-like object +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 1) { + return val === 12; + } + return false; +} +var obj = { + length: 2 +}; +var helpVerifyVar = 11; +Object.defineProperty(obj, "1", { + get: function() { + return helpVerifyVar; + }, + set: function(args) { + helpVerifyVar = args; + }, + configurable: true +}); +Object.defineProperty(obj, "0", { + get: function() { + obj[1] = 12; + return 11; + }, + configurable: true +}); +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-3.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-3.js new file mode 100644 index 0000000000000000000000000000000000000000..ec33d6c0cace242c75154e6ddf8fa6078d540d94 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-3.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own data + property that overrides an inherited data property on an + Array-like object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 5) { + return val === kValue; + } + return false; +} +var proto = { + 5: 100 +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child[5] = kValue; +child.length = 10; +assert(SendableArray.prototype.some.call(child, callbackfn), 'SendableArray.prototype.some.call(child, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-30.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-30.js new file mode 100644 index 0000000000000000000000000000000000000000..883529bd7ccf8c17ff8e403bd87c18cadf972a64 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-30.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - unhandled exceptions happened in getter + terminate iteration on an Array-like object +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 1) { + accessed = true; + } + return true; +} +var obj = { + length: 20 +}; +Object.defineProperty(obj, "1", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + SendableArray.prototype.some.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-31.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-31.js new file mode 100644 index 0000000000000000000000000000000000000000..636f7a57a2be0868320830dcb40ca44b45480682 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-31.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - unhandled exceptions happened in getter + terminate iteration on an Array +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 0) { + accessed = true; + } + return true; +} +var arr = []; +arr[10] = 100; +Object.defineProperty(arr, "0", { + get: function() { + throw new RangeError("unhandle exception happened in getter"); + }, + configurable: true +}); +assert.throws(RangeError, function() { + arr.some(callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-4.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-4.js new file mode 100644 index 0000000000000000000000000000000000000000..358295663627eb74c69b1f121cf22139ae19a892 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-4.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own data + property that overrides an inherited data property on an Array +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +SendableArray.prototype[0] = 11; +assert([kValue].some(callbackfn), '[kValue].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-5.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-5.js new file mode 100644 index 0000000000000000000000000000000000000000..f042e752764534fd70f911d56f0b811dbfe84aa5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-5.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own data + property that overrides an inherited accessor property on an + Array-like object +---*/ + +var kValue = 1000; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +var proto = {}; +Object.defineProperty(proto, "0", { + get: function() { + return 5; + }, + configurable: true +}); +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 2; +Object.defineProperty(child, "0", { + value: kValue, + configurable: true +}); +assert(SendableArray.prototype.some.call(child, callbackfn), 'SendableArray.prototype.some.call(child, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-6.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-6.js new file mode 100644 index 0000000000000000000000000000000000000000..32016d6cf81dfd06742cc33cad4c70beac408bfd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-6.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own data + property that overrides an inherited accessor property on an Array +---*/ + +var kValue = 1000; +function callbackfn(val, idx, obj) { + if (idx === 0) { + return val === kValue; + } + return false; +} +Object.defineProperty(SendableArray.prototype, "0", { + get: function() { + return 9; + }, + configurable: true +}); +assert([kValue].some(callbackfn), '[kValue].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-7.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-7.js new file mode 100644 index 0000000000000000000000000000000000000000..2a6560b9e8fa635a1f30f9ab3ac90ac3d016219a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-7.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is inherited data + property on an Array-like object +---*/ + +var kValue = 'abc'; +function callbackfn(val, idx, obj) { + if (5 === idx) { + return kValue === val; + } + return false; +} +var proto = { + 5: kValue +}; +var Con = function() {}; +Con.prototype = proto; +var child = new Con(); +child.length = 10; +assert(SendableArray.prototype.some.call(child, callbackfn), 'SendableArray.prototype.some.call(child, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-8.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-8.js new file mode 100644 index 0000000000000000000000000000000000000000..7d8fa6dfe2bd899358ffd13a4a320a4f6e9ff619 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-8.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is inherited data + property on an Array +---*/ + +var kValue = {}; +function callbackfn(val, idx, obj) { + if (0 === idx) { + return kValue === val; + } + return false; +} +SendableArray.prototype[0] = kValue; +assert([, ].some(callbackfn), '[, ].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-9.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-9.js new file mode 100644 index 0000000000000000000000000000000000000000..fe6c81abdcf2fcf58dab720b8e4afa64d2d55ad2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-i-9.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element to be retrieved is own accessor + property on an Array-like object +---*/ + +var kValue = "abc"; +function callbackfn(val, idx, obj) { + if (idx === 10) { + return val === kValue; + } + return false; +} +var obj = { + length: 20 +}; +Object.defineProperty(obj, "10", { + get: function() { + return kValue; + }, + configurable: true +}); +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-1.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..d5fa27a0a1db4a3b8385ae6435a851a321974465 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-1.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - callbackfn called with correct parameters +---*/ + +function callbackfn(val, idx, obj) +{ + if (obj[idx] === val) + return false; + else + return true; +} +var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-10.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..9a4a185a027f217d179abdfcc4983174cd201c27 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-10.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - callbackfn is called with 1 formal parameter +---*/ + +function callbackfn(val) { + return val > 10; +} +assert([11, 12].some(callbackfn), '[11, 12].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-11.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..3a829fa0bd6876b228c52729d7e67a305144d7bd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-11.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - callbackfn is called with 2 formal parameter +---*/ + +function callbackfn(val, idx) { + return val > 10 && arguments[2][idx] === val; +} +assert([9, 12].some(callbackfn), '[9, 12].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-12.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-12.js new file mode 100644 index 0000000000000000000000000000000000000000..ec48f3d71a0cc85e5a2d73faa59b0763b11b04c5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-12.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - callbackfn is called with 3 formal parameter +---*/ + +function callbackfn(val, idx, obj) { + return val > 10 && obj[idx] === val; +} +assert([9, 12].some(callbackfn), '[9, 12].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-13.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-13.js new file mode 100644 index 0000000000000000000000000000000000000000..b7df3754c8530de065e869bc2d6766c82e0dba9b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-13.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - callbackfn that uses arguments object to + get parameter value +---*/ + +function callbackfn() { + return arguments[2][arguments[1]] === arguments[0]; +} +assert([9, 12].some(callbackfn), '[9, 12].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-16.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-16.js new file mode 100644 index 0000000000000000000000000000000000000000..2b02ab81feb15a67a1f3ccdd4971ba38e983e6eb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-16.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'this' of 'callback' is a Boolean object + when 'T' is not an object ('T' is a boolean primitive) +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === false; +} +var obj = { + 0: 11, + length: 1 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn, false), 'SendableArray.prototype.some.call(obj, callbackfn, false) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-17.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-17.js new file mode 100644 index 0000000000000000000000000000000000000000..8fa523f8492866604f487275ef4bf1b6f29da7c3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-17.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'this' of 'callbackfn' is a Number object + when T is not an object (T is a number primitive) +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === 5; +} +var obj = { + 0: 11, + length: 1 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn, 5), 'SendableArray.prototype.some.call(obj, callbackfn, 5) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-18.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-18.js new file mode 100644 index 0000000000000000000000000000000000000000..31c26402233df033cee51cbbfb600385c43c9642 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-18.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - 'this' of 'callbackfn' is an String object + when T is not an object (T is a string primitive) +---*/ + +function callbackfn(val, idx, obj) { + return this.valueOf() === "hello!"; +} +var obj = { + 0: 11, + 1: 9, + length: 2 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn, "hello!"), 'SendableArray.prototype.some.call(obj, callbackfn, "hello!") !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-19.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-19.js new file mode 100644 index 0000000000000000000000000000000000000000..13bce63b6124aca3150d36f3cc31ffd45fc3d9d3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-19.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - non-indexed properties are not called +---*/ + +var called = 0; +function callbackfn(val, idx, obj) { + called++; + return val === 11; +} +var obj = { + 0: 9, + 10: 8, + non_index_property: 11, + length: 20 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert.sameValue(called, 2, 'called'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-2.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..e7f7f15abb88ac1b764f8eb8f0d5640db0a9d976 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-2.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - callbackfn takes 3 arguments +---*/ + +function callbackfn(val, idx, obj) +{ + if (arguments.length === 3) //verify if callbackfn was called with 3 parameters + return false; + else + return true; +} +var arr = [0, 1, true, null, new Object(), "five"]; +arr[999999] = -6.6; +assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-20.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-20.js new file mode 100644 index 0000000000000000000000000000000000000000..2348a4de9bd0df4c40071334aa332493f2fbfb62 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-20.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - callbackfn called with correct parameters + (thisArg is correct) +---*/ + +var thisArg = { + threshold: 10 +}; +function callbackfn(val, idx, obj) { + return this === thisArg; +} +var obj = { + 0: 11, + length: 2 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn, thisArg), 'SendableArray.prototype.some.call(obj, callbackfn, thisArg) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-21.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-21.js new file mode 100644 index 0000000000000000000000000000000000000000..7f8d54e0b878f8a2225b9f63357bd56cba1e0e15 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-21.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - callbackfn called with correct parameters + (kValue is correct) +---*/ + +var firstIndex = false; +var secondIndex = false; +function callbackfn(val, idx, obj) { + if (idx === 0) { + firstIndex = (val === 11); + return false; + } + if (idx === 1) { + secondIndex = (val === 12); + return false; + } +} +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert(firstIndex, 'firstIndex !== true'); +assert(secondIndex, 'secondIndex !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-22.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-22.js new file mode 100644 index 0000000000000000000000000000000000000000..39a6c241ac92f85d0592e8a94aeb12abb629abb1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-22.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - callbackfn called with correct parameters + (the index k is correct) +---*/ + +var firstIndex = false; +var secondIndex = false; +function callbackfn(val, idx, obj) { + if (val === 11) { + firstIndex = (idx === 0); + return false; + } + if (val === 12) { + secondIndex = (idx === 1); + return false; + } +} +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert(firstIndex, 'firstIndex !== true'); +assert(secondIndex, 'secondIndex !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-23.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-23.js new file mode 100644 index 0000000000000000000000000000000000000000..cc15354aa6b746ca93b36a6ed14854f4090823ad --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-23.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - callbackfn called with correct parameters + (this object O is correct) +---*/ + +var obj = { + 0: 11, + 1: 12, + length: 2 +}; +function callbackfn(val, idx, o) { + return obj === o; +} +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-3.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-3.js new file mode 100644 index 0000000000000000000000000000000000000000..c6f4261eebfcfec34d7ccc69b80c228c7396cd26 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-3.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some immediately returns true if callbackfn + returns true +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; + if (idx > 5) + return true; + else + return false; +} +var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +assert.sameValue(arr.some(callbackfn), true, 'arr.some(callbackfn)'); +assert.sameValue(callCnt, 7, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-4.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..0e3c90a4088cc06ffe9e598f624075ff1cf6e250 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-4.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - k values are passed in ascending numeric + order +---*/ + +var arr = [0, 1, 2, 3, 4, 5]; +var lastIdx = 0; +var called = 0; +function callbackfn(val, idx, o) { + called++; + if (lastIdx !== idx) { + return true; + } else { + lastIdx++; + return false; + } +} +assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); +assert.sameValue(arr.length, called, 'arr.length'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-5.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..e2b690b94903ee0b4c9687908e0b7a9a3a5c2a11 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-5.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - k values are accessed during each iteration + and not prior to starting the loop +---*/ + +var kIndex = []; +//By below way, we could verify that k would be setted as 0, 1, ..., length - 1 in order, and each value will be setted one time. +function callbackfn(val, idx, obj) { + //Each position should be visited one time, which means k is accessed one time during iterations. + if (typeof kIndex[idx] === "undefined") { + //when current position is visited, its previous index should has been visited. + if (idx !== 0 && typeof kIndex[idx - 1] === "undefined") { + return true; + } + kIndex[idx] = 1; + return false; + } else { + return true; + } +} +assert.sameValue([11, 12, 13, 14].some(callbackfn, undefined), false, '[11, 12, 13, 14].some(callbackfn, undefined)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-6.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-6.js new file mode 100644 index 0000000000000000000000000000000000000000..24e8b6ab3a63728f5eab71ccaa97285b9de388dd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-6.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - arguments to callbackfn are self consistent +---*/ + +var obj = { + 0: 11, + length: 1 +}; +var thisArg = {}; +function callbackfn() { + return this === thisArg && arguments[0] === 11 && arguments[1] === 0 && arguments[2] === obj; +} +assert(SendableArray.prototype.some.call(obj, callbackfn, thisArg), 'SendableArray.prototype.some.call(obj, callbackfn, thisArg) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-7.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..ffc816698330fb5c7cb54740256b576984e0c089 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-7.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - unhandled exceptions happened in callbackfn + terminate iteration +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + if (idx > 0) { + accessed = true; + } + if (idx === 0) { + throw new Error("Exception occurred in callbackfn"); + } + return false; +} +var obj = { + 0: 9, + 1: 100, + 10: 11, + length: 20 +}; +assert.throws(Error, function() { + SendableArray.prototype.some.call(obj, callbackfn); +}); +assert.sameValue(accessed, false, 'accessed'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-8.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..098601b9b7b54e1d86f7c12fc13f9451f44de881 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-8.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - element changed by callbackfn on previous + iterations is observed +---*/ + +function callbackfn(val, idx, obj) { + if (idx === 0) { + obj[idx + 1] = 11; + } + return val > 10; +} +var obj = { + 0: 9, + 1: 8, + length: 2 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-9.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..e53f600034b6a1f645dc2a76475cd1dde5784a2e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-ii-9.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - callbackfn is called with 0 formal parameter +---*/ + +function callbackfn() { + return true; +} +assert([11, 12].some(callbackfn), '[11, 12].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-1.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..dfdeec74aaf587dbb91d66b73d4048af4a8fc2b8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-1.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - return value of callbackfn is undefined +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return undefined; +} +var obj = { + 0: 11, + length: 2 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-10.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-10.js new file mode 100644 index 0000000000000000000000000000000000000000..8774eec664b0f6e5a0f60c701b84b60ad83570aa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-10.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a number + (value is Infinity) +---*/ + +function callbackfn(val, idx, obj) { + return Infinity; +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-11.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-11.js new file mode 100644 index 0000000000000000000000000000000000000000..e3a57054b8335262c37613a5d72d4a0ad2af184e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-11.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a number + (value is -Infinity) +---*/ + +function callbackfn(val, idx, obj) { + return -Infinity; +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-12.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-12.js new file mode 100644 index 0000000000000000000000000000000000000000..e78e843c8d65937681056f1b170e807cca048d0b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-12.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a number + (value is NaN) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return NaN; +} +assert.sameValue([11].some(callbackfn), false, '[11].some(callbackfn)'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-13.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-13.js new file mode 100644 index 0000000000000000000000000000000000000000..9b7212e1a97f1e942a9bcb34e330694b272f65c9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-13.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is an empty + string +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return ""; +} +assert.sameValue([11].some(callbackfn), false, '[11].some(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-14.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-14.js new file mode 100644 index 0000000000000000000000000000000000000000..a8531a56cf752f6cfc14e53130ac8de7c6ea89e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-14.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a non-empty + string +---*/ + +function callbackfn(val, idx, obj) { + return "non-empty string"; +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-15.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-15.js new file mode 100644 index 0000000000000000000000000000000000000000..61dc5a8f4458968be72be67f501df9ffbbe6e51e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-15.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is Function + object +---*/ + +function callbackfn(val, idx, obj) { + return function() {}; +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-16.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-16.js new file mode 100644 index 0000000000000000000000000000000000000000..f360981141051272f9f4ae719c7539306ff57ce8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-16.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is an Array + object +---*/ + +function callbackfn(val, idx, obj) { + return new SendableArray(10); +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-17.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-17.js new file mode 100644 index 0000000000000000000000000000000000000000..122dcf56800ddbb452bc22454849ce2cf143cb2d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-17.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a String + object +---*/ + +function callbackfn(val, idx, obj) { + return new String(); +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-18.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-18.js new file mode 100644 index 0000000000000000000000000000000000000000..83fba8f9626e03399bc49b05d119f3a8198e7eb9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-18.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a Boolean + object +---*/ + +function callbackfn(val, idx, obj) { + return new Boolean(); +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-19.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-19.js new file mode 100644 index 0000000000000000000000000000000000000000..4809a5493f69f45934453b09987a7ad184b8cf70 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-19.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a Number + object +---*/ + +function callbackfn(val, idx, obj) { + return new Number(); +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-2.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-2.js new file mode 100644 index 0000000000000000000000000000000000000000..a2decc8b731208b20987a2e7963055b200a5aabb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-2.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - return value of callbackfn is null +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return null; +} +var obj = { + 0: 11, + length: 2 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-20.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-20.js new file mode 100644 index 0000000000000000000000000000000000000000..71eaf0e6bad8ad65c0cad43cd2f385ed09afe206 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-20.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is the Math + object +---*/ + +function callbackfn(val, idx, obj) { + return Math; +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-21.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-21.js new file mode 100644 index 0000000000000000000000000000000000000000..d50e2094d63de3909afc5166693e8a36dc78ae6a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-21.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - return value of callbackfn is a Date object +---*/ + +function callbackfn(val, idx, obj) { + return new Date(0); +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-22.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-22.js new file mode 100644 index 0000000000000000000000000000000000000000..bec6e46fe68a468de695707edceaf3675d32dc36 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-22.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a RegExp + object +---*/ + +function callbackfn(val, idx, obj) { + return new RegExp(); +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-23.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-23.js new file mode 100644 index 0000000000000000000000000000000000000000..cbe9c9511c1d6bbef86fa3105daca16dbbcf3925 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-23.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is the JSON + object +---*/ + +function callbackfn(val, idx, obj) { + return JSON; +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-24.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-24.js new file mode 100644 index 0000000000000000000000000000000000000000..6a1221c439963ba4e40c374c78ce47f353d85560 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-24.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is an Error + object +---*/ + +function callbackfn(val, idx, obj) { + return new EvalError(); +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-25.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-25.js new file mode 100644 index 0000000000000000000000000000000000000000..0bbcb60240a5d98803559aa296989bd9971832bd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-25.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is the Arguments + object +---*/ + +function callbackfn(val, idx, obj) { + return arguments; +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-26.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-26.js new file mode 100644 index 0000000000000000000000000000000000000000..cc1ef24c2bf55ebf597f41097525533ebd0accf1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-26.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is the global + object +---*/ + +var global = this; +function callbackfn(val, idx, obj) { + return global; +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-28.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-28.js new file mode 100644 index 0000000000000000000000000000000000000000..e9b5c8fbcf09bfe15cce5a75cc7b4312ff83cb52 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-28.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - true prevents further side effects +---*/ + +var result = false; +function callbackfn(val, idx, obj) { + if (idx > 1) { + result = true; + } + return val > 10; +} +var obj = { + length: 20 +}; +Object.defineProperty(obj, "0", { + get: function() { + return 8; + }, + configurable: true +}); +Object.defineProperty(obj, "1", { + get: function() { + return 11; + }, + configurable: true +}); +Object.defineProperty(obj, "2", { + get: function() { + result = true; + return 11; + }, + configurable: true +}); +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); +assert.sameValue(result, false, 'result'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-29.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-29.js new file mode 100644 index 0000000000000000000000000000000000000000..c5f77cc2a6a677702433c5ed3f097a2ee0e0ef13 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-29.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value (new Boolean(false)) of + callbackfn is treated as true value +---*/ + +function callbackfn() { + return new Boolean(false); +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-3.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-3.js new file mode 100644 index 0000000000000000000000000000000000000000..c2006b8e870337d72c7a8c1ffe95035fe7416fec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-3.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a boolean + (value is false) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return false; +} +var obj = { + 0: 11, + length: 2 +}; +assert.sameValue(SendableArray.prototype.some.call(obj, callbackfn), false, 'SendableArray.prototype.some.call(obj, callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-4.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-4.js new file mode 100644 index 0000000000000000000000000000000000000000..e9340f2834128f2b01f183cb4e3418fd399a014b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-4.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a boolean + (value is true) +---*/ + +function callbackfn(val, idx, obj) { + return true; +} +var obj = { + 0: 11, + length: 2 +}; +assert(SendableArray.prototype.some.call(obj, callbackfn), 'SendableArray.prototype.some.call(obj, callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-5.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-5.js new file mode 100644 index 0000000000000000000000000000000000000000..6b45b43bc9dcf4ccb8c12dcddd345ef179323da6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-5.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a number + (value is 0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return 0; +} +assert.sameValue([11].some(callbackfn), false, '[11].some(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-6.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-6.js new file mode 100644 index 0000000000000000000000000000000000000000..1f6ac137d8b08e05c088ff74c84b8f852266237c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-6.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a number + (value is +0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return +0; +} +assert.sameValue([11].some(callbackfn), false, '[11].some(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-7.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-7.js new file mode 100644 index 0000000000000000000000000000000000000000..5661d3f4650797ffe4ce2a0b2dadad50165098cc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-7.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a number + (value is -0) +---*/ + +var accessed = false; +function callbackfn(val, idx, obj) { + accessed = true; + return -0; +} +assert.sameValue([11].some(callbackfn), false, '[11].some(callbackfn)'); +assert(accessed, 'accessed !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-8.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-8.js new file mode 100644 index 0000000000000000000000000000000000000000..cfa2bc5148231cce45889fd608b41fbd8e895a59 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-8.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a number + (value is positive number) +---*/ + +function callbackfn(val, idx, obj) { + return 5; +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-9.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-9.js new file mode 100644 index 0000000000000000000000000000000000000000..c8ea7a652cd670b1819da591b4545ef5490f3e22 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-7-c-iii-9.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some - return value of callbackfn is a number + (value is negative number) +---*/ + +function callbackfn(val, idx, obj) { + return -5; +} +assert([11].some(callbackfn), '[11].some(callbackfn) !== true'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-1.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-1.js new file mode 100644 index 0000000000000000000000000000000000000000..e9a98f5b2fa45f8f99627b04e344830417e19c5e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-1.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some returns false if 'length' is 0 (empty array) +---*/ + +function cb() {} +var i = [].some(cb); +assert.sameValue(i, false, 'i'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-10.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-10.js new file mode 100644 index 0000000000000000000000000000000000000000..0ac262901ba0d04a73554d5e1146062f98caf4ac --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-10.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some - subclassed array when length is reduced +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 2; +function cb(val) +{ + if (val > 2) + return true; + else + return false; +} +var i = f.some(cb); +assert.sameValue(i, false, 'i'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-11.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-11.js new file mode 100644 index 0000000000000000000000000000000000000000..83d9d1a2201f1a8c7924ba54df5062c23ba5cd5e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-11.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some returns false when all calls to callbackfn + return false +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; + return false; +} +var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); +assert.sameValue(callCnt, 10, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-12.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-12.js new file mode 100644 index 0000000000000000000000000000000000000000..7f2271453af3b17e73c999ba4f4d61c9d6be0f75 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-12.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some doesn't mutate the array on which it is + called on +---*/ + +function callbackfn(val, idx, obj) +{ + return true; +} +var arr = [1, 2, 3, 4, 5]; +arr.some(callbackfn); +assert.sameValue(arr[0], 1, 'arr[0]'); +assert.sameValue(arr[1], 2, 'arr[1]'); +assert.sameValue(arr[2], 3, 'arr[2]'); +assert.sameValue(arr[3], 4, 'arr[3]'); +assert.sameValue(arr[4], 5, 'arr[4]'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-13.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-13.js new file mode 100644 index 0000000000000000000000000000000000000000..d0959a8e47db2a8e1d265d73dcbd99326589d4dc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-13.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some doesn't visit expandos +---*/ + +var callCnt = 0; +function callbackfn(val, idx, obj) +{ + callCnt++; + return false; +} +var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +arr["i"] = 10; +arr[true] = 11; +assert.sameValue(arr.some(callbackfn), false, 'arr.some(callbackfn)'); +assert.sameValue(callCnt, 10, 'callCnt'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-2.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-2.js new file mode 100644 index 0000000000000000000000000000000000000000..6dba23b9c8f7dbede99c081bb127d3f4f00e3cce --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-2.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some returns false if 'length' is 0 (subclassed + Array, length overridden to null (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = null; +function cb() {} +var i = f.some(cb); +assert.sameValue(i, false, 'i'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-3.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-3.js new file mode 100644 index 0000000000000000000000000000000000000000..6f785756ea065c9f62d6b60812293b777b92b159 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-3.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some returns false if 'length' is 0 (subclassed + Array, length overridden to false (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = false; +function cb() {} +var i = f.some(cb); +assert.sameValue(i, false, 'i'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-4.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-4.js new file mode 100644 index 0000000000000000000000000000000000000000..ced71ed42fe96527ef5296dd674b74a75e66c89c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-4.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some returns false if 'length' is 0 (subclassed + Array, length overridden to 0 (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = 0; +function cb() {} +var i = f.some(cb); +assert.sameValue(i, false, 'i'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-5.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-5.js new file mode 100644 index 0000000000000000000000000000000000000000..032ed8df8c585f093832356aae3a5d2636e9b99a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-5.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some returns false if 'length' is 0 (subclassed + Array, length overridden to '0' (type conversion)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = '0'; +function cb() {} +var i = f.some(cb); +assert.sameValue(i, false, 'i'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-6.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-6.js new file mode 100644 index 0000000000000000000000000000000000000000..048177103c70f6acfbee4d9490c17dc3e058e4fa --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-6.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some returns false if 'length' is 0 (subclassed + Array, length overridden with obj with valueOf) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + valueOf: function() { + return 0; + } +}; +f.length = o; +function cb() {} +var i = f.some(cb); +assert.sameValue(i, false, 'i'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-7.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-7.js new file mode 100644 index 0000000000000000000000000000000000000000..550f16d930f76a1b12ec6f15dcb10a11a2aa13c1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-7.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some returns false if 'length' is 0 (subclassed + Array, length overridden with obj w/o valueOf (toString)) +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +var o = { + toString: function() { + return '0'; + } +}; +f.length = o; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +function cb() {} +var i = f.some(cb); +assert.sameValue(i, false, 'i'); diff --git a/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-8.js b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-8.js new file mode 100644 index 0000000000000000000000000000000000000000..561650bf16280b6071316bab9967aeea181bfe25 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/15.4.4.17-8-8.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some returns false if 'length' is 0 (subclassed + Array, length overridden with [] +---*/ + +foo.prototype = new SendableArray(1, 2, 3); +function foo() {} +var f = new foo(); +f.length = []; +// objects inherit the default valueOf method of the Object object; +// that simply returns the itself. Since the default valueOf() method +// does not return a primitive value, ES next tries to convert the object +// to a number by calling its toString() method and converting the +// resulting string to a number. +// +// The toString( ) method on Array converts the array elements to strings, +// then returns the result of concatenating these strings, with commas in +// between. An array with no elements converts to the empty string, which +// converts to the number 0. If an array has a single element that is a +// number n, the array converts to a string representation of n, which is +// then converted back to n itself. If an array contains more than one element, +// or if its one element is not a number, the array converts to NaN. +function cb() {} +var i = f.some(cb); +assert.sameValue(i, false, 'i'); diff --git a/test/sendable/builtins/Array/prototype/some/call-with-boolean.js b/test/sendable/builtins/Array/prototype/some/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..412cd9f100a7a92f527b94a1beaefb295928af81 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: Array.prototype.some applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.some.call(true, () => {}), + false, + 'SendableArray.prototype.some.call(true, () => {}) must return false' +); +assert.sameValue( + SendableArray.prototype.some.call(false, () => {}), + false, + 'SendableArray.prototype.some.call(false, () => {}) must return false' +); diff --git a/test/sendable/builtins/Array/prototype/some/callbackfn-resize-arraybuffer.js b/test/sendable/builtins/Array/prototype/some/callbackfn-resize-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..b9b266369c6f49e1f9f80ffafb8bce20189b143f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/callbackfn-resize-arraybuffer.js @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: TypedArray instance buffer can be resized during iteration +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.some.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + assert.compareArray(elements, expectedElements, 'elements (shrink)'); + assert.compareArray(indices, expectedIndices, 'indices (shrink)'); + assert.compareArray(arrays, expectedArrays, 'arrays (shrink)'); + assert.sameValue(result, false, 'result (shrink)'); + elements = []; + indices = []; + arrays = []; + result = SendableArray.prototype.some.call(sample, function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, false, 'result (grow)'); +}); diff --git a/test/sendable/builtins/Array/prototype/some/length.js b/test/sendable/builtins/Array/prototype/some/length.js new file mode 100644 index 0000000000000000000000000000000000000000..1cdcb4cd63a6b09094e8353c23faa272b2e70e7e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/length.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + The "length" property of Array.prototype.some +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.some, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/some/name.js b/test/sendable/builtins/Array/prototype/some/name.js new file mode 100644 index 0000000000000000000000000000000000000000..436b1ca30a6d28ae7f19e295a608c46ef660af66 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.prototype.some.name is "some". +info: | + Array.prototype.some ( callbackfn [ , thisArg ] ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.some, "name", { + value: "some", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/some/not-a-constructor.js b/test/sendable/builtins/Array/prototype/some/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..17e4ef7b7c5746195665d03db75453b4158a3d52 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.some does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.prototype.some), false, 'isConstructor(SendableArray.prototype.some) must return false'); +assert.throws(TypeError, () => { + new SendableArray.prototype.some(() => {}); +}); + diff --git a/test/sendable/builtins/Array/prototype/some/prop-desc.js b/test/sendable/builtins/Array/prototype/some/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..4ae0ba8610896db1d313ff417d3fd04595d7095f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + "some" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.some, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "some", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/some/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/some/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..13d53fb8e33613644465e360f159f354f2b4ccdd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.p.some behaves correctly on TypedArrays backed by resizable buffers that + are grown mid-iteration. +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(!SendableArray.prototype.some.call(fixedLength, ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(!SendableArray.prototype.some.call(fixedLengthWithOffset, ResizeMidIteration)); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(!SendableArray.prototype.some.call(lengthTracking, ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + rab = rab; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(!SendableArray.prototype.some.call(lengthTrackingWithOffset, ResizeMidIteration)); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/some/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/some/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..5e41f076460bdaf5a97402561c684344d1c17527 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.p.some behaves correctly on TypedArrays backed by resizable buffers that + are shrunk mid-iteration. +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(!SendableArray.prototype.some.call(fixedLength, ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(!SendableArray.prototype.some.call(fixedLengthWithOffset, ResizeMidIteration)); + assert.compareArray(values, [4]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(!SendableArray.prototype.some.call(lengthTracking, ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(!SendableArray.prototype.some.call(lengthTrackingWithOffset, ResizeMidIteration)); + assert.compareArray(values, [4]); +} diff --git a/test/sendable/builtins/Array/prototype/some/resizable-buffer.js b/test/sendable/builtins/Array/prototype/some/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f9b2354e18f45ca44e914545200bc195b4feeb0d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/some/resizable-buffer.js @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.some +description: > + Array.p.some behaves correctly on TypedArrays backed by resizable buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + function div3(n) { + return Number(n) % 3 == 0; + } + function over10(n) { + return Number(n) > 10; + } + assert(SendableArray.prototype.some.call(fixedLength, div3)); + assert(!SendableArray.prototype.some.call(fixedLength, over10)); + assert(SendableArray.prototype.some.call(fixedLengthWithOffset, div3)); + assert(!SendableArray.prototype.some.call(fixedLengthWithOffset, over10)); + assert(SendableArray.prototype.some.call(lengthTracking, div3)); + assert(!SendableArray.prototype.some.call(lengthTracking, over10)); + assert(SendableArray.prototype.some.call(lengthTrackingWithOffset, div3)); + assert(!SendableArray.prototype.some.call(lengthTrackingWithOffset, over10)); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + assert(!SendableArray.prototype.some.call(fixedLength, div3)); + assert(!SendableArray.prototype.some.call(fixedLengthWithOffset, div3)); + assert(SendableArray.prototype.some.call(lengthTracking, div3)); + assert(!SendableArray.prototype.some.call(lengthTracking, over10)); + assert(!SendableArray.prototype.some.call(lengthTrackingWithOffset, div3)); + assert(!SendableArray.prototype.some.call(lengthTrackingWithOffset, over10)); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert(!SendableArray.prototype.some.call(fixedLength, div3)); + assert(!SendableArray.prototype.some.call(fixedLengthWithOffset, div3)); + assert(!SendableArray.prototype.some.call(lengthTrackingWithOffset, div3)); + assert(SendableArray.prototype.some.call(lengthTracking, div3)); + assert(!SendableArray.prototype.some.call(lengthTracking, over10)); + // Shrink to zero. + rab.resize(0); + assert(!SendableArray.prototype.some.call(fixedLength, div3)); + assert(!SendableArray.prototype.some.call(fixedLengthWithOffset, div3)); + assert(!SendableArray.prototype.some.call(lengthTrackingWithOffset, div3)); + assert(!SendableArray.prototype.some.call(lengthTracking, div3)); + assert(!SendableArray.prototype.some.call(lengthTracking, over10)); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + assert(SendableArray.prototype.some.call(fixedLength, div3)); + assert(!SendableArray.prototype.some.call(fixedLength, over10)); + assert(SendableArray.prototype.some.call(fixedLengthWithOffset, div3)); + assert(!SendableArray.prototype.some.call(fixedLengthWithOffset, over10)); + assert(SendableArray.prototype.some.call(lengthTracking, div3)); + assert(!SendableArray.prototype.some.call(lengthTracking, over10)); + assert(SendableArray.prototype.some.call(lengthTrackingWithOffset, div3)); + assert(!SendableArray.prototype.some.call(lengthTrackingWithOffset, over10)); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.1_T1.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..2d26baaaf965e206a4fb85f1882e5691cbc870fb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.1_T1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If this object does not have a property named by ToString(j), + and this object does not have a property named by ToString(k), return +0 +esid: sec-array.prototype.sort +description: If comparefn is undefined, use SortCompare operator +---*/ + +var x = new SendableArray(2); +x.sort(); +if (x.length !== 2) { + throw new Test262Error('#1: var x = new SendableArray(2); x.sort(); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== undefined) { + throw new Test262Error('#2: var x = new SendableArray(2); x.sort(); x[0] === undefined. Actual: ' + (x[0])); +} +if (x[1] !== undefined) { + throw new Test262Error('#3: var x = new SendableArray(2); x.sort(); x[1] === undefined. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.2_T1.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..f6e1d879650e9506309678bfeb179f01243e4232 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.2_T1.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If this object does not have a property named by + ToString(j), return 1. If this object does not have a property + named by ToString(k), return -1 +esid: sec-array.prototype.sort +description: If comparefn is undefined, use SortCompare operator +---*/ + +var x = new SendableArray(2); +x[1] = 1; +x.sort(); +if (x.length !== 2) { + throw new Test262Error('#1: var x = new SendableArray(2); x[1] = 1; x.sort(); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 1) { + throw new Test262Error('#2: var x = new SendableArray(2); x[1] = 1; x.sort(); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== undefined) { + throw new Test262Error('#3: var x = new SendableArray(2); x[1] = 1; x.sort(); x[1] === undefined. Actual: ' + (x[1])); +} +var x = new SendableArray(2); +x[0] = 1; +x.sort(); +if (x.length !== 2) { + throw new Test262Error('#4: var x = new SendableArray(2); x[0] = 1; x.sort(); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 1) { + throw new Test262Error('#5: var x = new SendableArray(2); x[0] = 1; x.sort(); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== undefined) { + throw new Test262Error('#6: var x = new SendableArray(2); x[0] = 1; x.sort(); x[1] === undefined. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.2_T2.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..6e6ad6181fb75aec5c651de7d9a6ae5b14ee3774 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.2_T2.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If this object does not have a property named by + ToString(j), return 1. If this object does not have a property + named by ToString(k), return -1 +esid: sec-array.prototype.sort +description: If comparefn is not undefined +---*/ + +var myComparefn = function(x, y) { + if (x === undefined) return -1; + if (y === undefined) return 1; + return 0; +} +var x = new SendableArray(2); +x[1] = 1; +x.sort(myComparefn); +if (x.length !== 2) { + throw new Test262Error('#1: var x = new SendableArray(2); x[1] = 1; x.sort(myComparefn); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 1) { + throw new Test262Error('#2: var x = new SendableArray(2); x[1] = 1; x.sort(myComparefn); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== undefined) { + throw new Test262Error('#3: var x = new SendableArray(2); x[1] = 1; x.sort(myComparefn); x[1] === undefined. Actual: ' + (x[1])); +} +var x = new SendableArray(2); +x[0] = 1; +x.sort(myComparefn); +if (x.length !== 2) { + throw new Test262Error('#4: var x = new SendableArray(2); x[0] = 1; x.sort(myComparefn); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 1) { + throw new Test262Error('#5: var x = new SendableArray(2); x[0] = 1; x.sort(myComparefn); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== undefined) { + throw new Test262Error('#6: var x = new SendableArray(2); x[0] = 1; x.sort(myComparefn); x[1] === undefined. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.3_T1.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..89efebda88eb018ac9198f998e3c305758d12af5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.3_T1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If [[Get]] ToString(j) and [[Get]] ToString(k) + are both undefined, return +0 +esid: sec-array.prototype.sort +description: If comparefn is undefined, use SortCompare operator +---*/ + +var x = new SendableArray(undefined, undefined); +x.sort(); +if (x.length !== 2) { + throw new Test262Error('#1: var x = new SendableArray(undefined, undefined); x.sort(); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== undefined) { + throw new Test262Error('#2: var x = new SendableArray(undefined, undefined); x.sort(); x[0] === undefined. Actual: ' + (x[0])); +} +if (x[1] !== undefined) { + throw new Test262Error('#3: var x = new SendableArray(undefined, undefined); x.sort(); x[1] === undefined. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.4_T1.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.4_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..0f3f6fd881e5b5582e8e775db6a6bc9b84e0c255 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.4_T1.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If [[Get]] ToString(j) is undefined, return 1. + If [[]Get] ToString(k) is undefined, return -1 +esid: sec-array.prototype.sort +description: If comparefn is undefined, use SortCompare operator +---*/ + +var x = new SendableArray(undefined, 1); +x.sort(); +if (x.length !== 2) { + throw new Test262Error('#1: var x = new SendableArray(undefined, 1); x.sort(); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 1) { + throw new Test262Error('#2: var x = new SendableArray(undefined, 1); x.sort(); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== undefined) { + throw new Test262Error('#3: var x = new SendableArray(undefined, 1); x.sort(); x[1] === undefined. Actual: ' + (x[1])); +} +var x = new SendableArray(1, undefined); +x.sort(); +if (x.length !== 2) { + throw new Test262Error('#4: var x = new SendableArray(1, undefined); x.sort(); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 1) { + throw new Test262Error('#5: var x = new SendableArray(1, undefined); x.sort(); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== undefined) { + throw new Test262Error('#6: var x = new SendableArray(1, undefined); x.sort(); x[1] === undefined. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.4_T2.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.4_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..76ce26e5ab6b3590e1efb3e1bbb234eb66ebda7a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.4_T2.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If [[Get]] ToString(j) is undefined, return 1. + If [[]Get] ToString(k) is undefined, return -1 +esid: sec-array.prototype.sort +description: If comparefn is not undefined +---*/ + +var myComparefn = function(x, y) { + if (x === undefined) return -1; + if (y === undefined) return 1; + return 0; +} +var x = new SendableArray(undefined, 1); +x.sort(myComparefn); +if (x.length !== 2) { + throw new Test262Error('#1: var x = new SendableArray(undefined, 1); x.sort(myComparefn); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 1) { + throw new Test262Error('#2: var x = new SendableArray(undefined, 1); x.sort(myComparefn); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== undefined) { + throw new Test262Error('#3: var x = new SendableArray(undefined, 1); x.sort(myComparefn); x[1] === undefined. Actual: ' + (x[1])); +} +var x = new SendableArray(1, undefined); +x.sort(myComparefn); +if (x.length !== 2) { + throw new Test262Error('#4: var x = new SendableArray(1, undefined); x.sort(myComparefn); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 1) { + throw new Test262Error('#5: var x = new SendableArray(1, undefined); x.sort(myComparefn); x[0] === 1. Actual: ' + (x[0])); +} +if (x[1] !== undefined) { + throw new Test262Error('#6: var x = new SendableArray(1, undefined); x.sort(myComparefn); x[1] === undefined. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.5_T1.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.5_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..32e947131d7e39d713c9bb8e8e3e0514c75fb49e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A1.5_T1.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: If comparefn is undefined, use SortCompare operator +esid: sec-array.prototype.sort +description: Checking sort() and sort(undefined) +---*/ + +var x = new SendableArray(1, 0); +x.sort(); +if (x.length !== 2) { + throw new Test262Error('#1: var x = new SendableArray(1,0); x.sort(); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#2: var x = new SendableArray(1,0); x.sort(); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#3: var x = new SendableArray(1,0); x.sort(); x[1] === 1. Actual: ' + (x[1])); +} +var x = new SendableArray(1, 0); +x.sort(undefined); +if (x.length !== 2) { + throw new Test262Error('#4: var x = new SendableArray(1,0); x.sort(undefined); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#5: var x = new SendableArray(1,0); x.sort(undefined); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#6: var x = new SendableArray(1,0); x.sort(undefined); x[1] === 1. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.1_T1.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..e311ddccd0f47ee9dc8172098b92b042e4f3643a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.1_T1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If ToString([[Get]] ToString(j)) < ToString([[Get]] ToString(k)), return -1. + If ToString([[Get]] ToString(j)) > ToString([[Get]] ToString(k)), return 1; + return -1 +esid: sec-array.prototype.sort +description: Checking ENGLISH ALPHABET +---*/ + +var alphabetR = ["z", "y", "x", "w", "v", "u", "t", "s", "r", "q", "p", "o", "n", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"]; +var alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]; +alphabetR.sort(); +var result = true; +for (var i = 0; i < 26; i++) { + if (alphabetR[i] !== alphabet[i]) result = false; +} +if (result !== true) { + throw new Test262Error('#1: CHECK ENGLISH ALPHABET'); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.1_T2.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..b177730a00f0bca37646c6ca24faba921da049dc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.1_T2.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If ToString([[Get]] ToString(j)) < ToString([[Get]] ToString(k)), return -1. + If ToString([[Get]] ToString(j)) > ToString([[Get]] ToString(k)), return 1; + return -1 +esid: sec-array.prototype.sort +description: Checking RUSSIAN ALPHABET +---*/ + +var alphabetR = ["ё", "я", "ю", "э", "ь", "ы", "ъ", "щ", "ш", "ч", "ц", "х", "ф", "у", "т", "с", "р", "П", "О", "Н", "М", "Л", "К", "Й", "И", "З", "Ж", "Е", "Д", "Г", "В", "Б", "А"]; +var alphabet = ["А", "Б", "В", "Г", "Д", "Е", "Ж", "З", "И", "Й", "К", "Л", "М", "Н", "О", "П", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "ъ", "ы", "ь", "э", "ю", "я", "ё"]; +alphabetR.sort(); +var result = true; +for (var i = 0; i < 26; i++) { + if (alphabetR[i] !== alphabet[i]) result = false; +} +if (result !== true) { + throw new Test262Error('#1: CHECK RUSSIAN ALPHABET'); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.1_T3.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..7b3376ac501e55275a7ddc2916add757a6eada57 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.1_T3.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If ToString([[Get]] ToString(j)) < ToString([[Get]] ToString(k)), return -1. + If ToString([[Get]] ToString(j)) > ToString([[Get]] ToString(k)), return 1; + return -1 +esid: sec-array.prototype.sort +description: Checking ToString operator +---*/ + +var obj = { + valueOf: function() { + return 1 + }, + toString: function() { + return -2 + } +}; +var alphabetR = [undefined, 2, 1, "X", -1, "a", true, obj, NaN, Infinity]; +var alphabet = [-1, obj, 1, 2, Infinity, NaN, "X", "a", true, undefined]; +alphabetR.sort(); +var result = true; +for (var i = 0; i < 10; i++) { + if (!(isNaN(alphabetR[i]) && isNaN(alphabet[i]))) { + if (alphabetR[i] !== alphabet[i]) result = false; + } +} +if (result !== true) { + throw new Test262Error('#1: Check ToString operator'); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.2_T1.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..d84218fd947421b0d012a5c238f0cd3e7d7900ba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.2_T1.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: My comparefn is inverse implementation comparefn +esid: sec-array.prototype.sort +description: Checking ENGLISH ALPHABET +---*/ + +var alphabetR = ["z", "y", "x", "w", "v", "u", "t", "s", "r", "q", "p", "o", "n", "M", "L", "K", "J", "I", "H", "G", "F", "E", "D", "C", "B", "A"]; +var alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]; +var myComparefn = function(x, y) { + var xS = String(x); + var yS = String(y); + if (xS < yS) return 1 + if (xS > yS) return -1; + return 0; +} +alphabet.sort(myComparefn); +var result = true; +for (var i = 0; i < 26; i++) { + if (alphabetR[i] !== alphabet[i]) result = false; +} +if (result !== true) { + throw new Test262Error('#1: CHECK ENGLISH ALPHABET'); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.2_T2.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..1c26122b3edac03a787a93ac742a98182841e90a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.2_T2.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: My comparefn is inverse implementation comparefn +esid: sec-array.prototype.sort +description: Checking RUSSIAN ALPHABET +---*/ + +var alphabetR = ["ё", "я", "ю", "э", "ь", "ы", "ъ", "щ", "ш", "ч", "ц", "х", "ф", "у", "т", "с", "р", "П", "О", "Н", "М", "Л", "К", "Й", "И", "З", "Ж", "Е", "Д", "Г", "В", "Б", "А"]; +var alphabet = ["А", "Б", "В", "Г", "Д", "Е", "Ж", "З", "И", "Й", "К", "Л", "М", "Н", "О", "П", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "ъ", "ы", "ь", "э", "ю", "я", "ё"]; +var myComparefn = function(x, y) { + var xS = String(x); + var yS = String(y); + if (xS < yS) return 1 + if (xS > yS) return -1; + return 0; +} +alphabet.sort(myComparefn); +var result = true; +for (var i = 0; i < 26; i++) { + if (alphabetR[i] !== alphabet[i]) result = false; +} +if (result !== true) { + throw new Test262Error('#1: CHECK RUSSIAN ALPHABET'); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.2_T3.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..60aedeebe120ac3eb1b35fdc1976616a9173d892 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A2.2_T3.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: My comparefn is inverse implementation comparefn +esid: sec-array.prototype.sort +description: Checking ToString operator +---*/ + +var obj = { + valueOf: function() { + return 1 + }, + toString: function() { + return -2 + } +}; +var alphabetR = [undefined, 2, 1, "X", -1, "a", true, obj, NaN, Infinity]; +var alphabet = [true, "a", "X", NaN, Infinity, 2, 1, obj, -1, undefined]; +var myComparefn = function(x, y) { + var xS = String(x); + var yS = String(y); + if (xS < yS) return 1 + if (xS > yS) return -1; + return 0; +} +alphabetR.sort(myComparefn); +var result = true; +for (var i = 0; i < 10; i++) { + if (!(isNaN(alphabetR[i]) && isNaN(alphabet[i]))) { + if (alphabetR[i] !== alphabet[i]) result = false; + } +} +if (result !== true) { + throw new Test262Error('#1: Check ToString operator'); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A3_T1.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..0ef14ac3044e15d778b3d9c07dd9da422cca442e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A3_T1.js @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The sort function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.sort +description: If comparefn is undefined, use SortCompare operator +---*/ + +var obj = { + valueOf: function() { + return 1 + }, + toString: function() { + return -2 + } +}; +var alphabetR = { + 0: undefined, + 1: 2, + 2: 1, + 3: "X", + 4: -1, + 5: "a", + 6: true, + 7: obj, + 8: NaN, + 9: Infinity +}; +alphabetR.sort = SendableArray.prototype.sort; +alphabetR.length = 10; +var alphabet = [-1, obj, 1, 2, Infinity, NaN, "X", "a", true, undefined]; +alphabetR.sort(); +alphabetR.getClass = Object.prototype.toString; +if (alphabetR.getClass() !== "[object " + "Object" + "]") { + throw new Test262Error('#0: alphabetR.sort() is Object object, not SendableArray object'); +} +var result = true; +for (var i = 0; i < 10; i++) { + if (!(isNaN(alphabetR[i]) && isNaN(alphabet[i]))) { + if (alphabetR[i] !== alphabet[i]) result = false; + } +} +if (result !== true) { + throw new Test262Error('#1: Check ToString operator'); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A3_T2.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..b940487d447ff2f26e31a0d9efd41bdfffd35619 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A3_T2.js @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The sort function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.sort +description: If comparefn is not undefined +---*/ + +var obj = { + valueOf: function() { + return 1 + }, + toString: function() { + return -2 + } +}; +var alphabetR = { + 0: undefined, + 1: 2, + 2: 1, + 3: "X", + 4: -1, + 5: "a", + 6: true, + 7: obj, + 8: NaN, + 9: Infinity +}; +alphabetR.sort = SendableArray.prototype.sort; +alphabetR.length = 10; +var alphabet = [true, "a", "X", NaN, Infinity, 2, 1, obj, -1, undefined]; +var myComparefn = function(x, y) { + var xS = String(x); + var yS = String(y); + if (xS < yS) return 1 + if (xS > yS) return -1; + return 0; +} +alphabetR.sort(myComparefn); +alphabetR.getClass = Object.prototype.toString; +if (alphabetR.getClass() !== "[object " + "Object" + "]") { + throw new Test262Error('#0: alphabetR.sort() is Object object, not SendableArray object'); +} +var result = true; +for (var i = 0; i < 10; i++) { + if (!(isNaN(alphabetR[i]) && isNaN(alphabet[i]))) { + if (alphabetR[i] !== alphabet[i]) result = false; + } +} +if (result !== true) { + throw new Test262Error('#1: Check ToString operator'); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A4_T3.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A4_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..64b9e389a95e167d2b647bfc3de23b7d18665afb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A4_T3.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.sort +description: length = -4294967294 +---*/ + +var obj = {}; +obj.sort = SendableArray.prototype.sort; +obj[0] = "z"; +obj[1] = "y"; +obj[2] = "x"; +obj.length = -4294967294; +if (obj.sort() !== obj) { + throw new Test262Error('#1: var obj = {}; obj.sort = SendableArray.prototype.sort; obj[0] = "z"; obj[1] = "y"; obj[2] = "x"; obj.length = -4294967294; obj.sort() === obj. Actual: ' + (obj.sort())); +} +if (obj.length !== -4294967294) { + throw new Test262Error('#2: var obj = {}; obj.sort = SendableArray.prototype.sort; obj[0] = "z"; obj[1] = "y"; obj[2] = "x"; obj.length = -4294967294; obj.sort(); obj.length === -4294967294. Actual: ' + (obj.length)); +} +if (obj[0] !== "z") { + throw new Test262Error('#3: var obj = {}; obj.sort = SendableArray.prototype.sort; obj[0] = "z"; obj[1] = "y"; obj[2] = "x"; obj.length = -4294967294; obj.sort(); obj[0] === "z". Actual: ' + (obj[0])); +} +if (obj[1] !== "y") { + throw new Test262Error('#4: var obj = {}; obj.sort = SendableArray.prototype.sort; obj[0] = "z"; obj[1] = "y"; obj[2] = "x"; obj.length = -4294967294; obj.sort(); obj[1] === "y". Actual: ' + (obj[1])); +} +if (obj[2] !== "x") { + throw new Test262Error('#5: var obj = {}; obj.sort = SendableArray.prototype.sort; obj[0] = "z"; obj[1] = "y"; obj[2] = "x"; obj.length = -4294967294; obj.sort(); obj[2] === "x". Actual: ' + (obj[2])); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A5_T1.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A5_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..25a0cea085454d4742adcb12bf53691226adfee7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A5_T1.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Array.sort should not eat exceptions +esid: sec-array.prototype.sort +description: comparefn function throw "error" +---*/ + +assert.throws(Test262Error, () => { + var myComparefn = function(x, y) { + throw new Test262Error(); + } + var x = [1, 0]; + x.sort(myComparefn); +}); diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A6_T2.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A6_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..8560449e6cb6627f4156e47c20b72ce6b71b843f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A6_T2.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]], [[Delete]] from not an inherited property" +esid: sec-array.prototype.sort +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[1] = -1; +var x = [1, 0]; +x.length = 2; +x.sort(); +if (x[0] !== 0) { + throw new Test262Error('#1: SendableArray.prototype[1] = -1; x = [1,0]; x.length = 2; x.sort(); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#2: SendableArray.prototype[1] = -1; x = [1,0]; x.length = 2; x.sort(); x[1] === 1. Actual: ' + (x[1])); +} +x.length = 0; +if (x[0] !== undefined) { + throw new Test262Error('#3: SendableArray.prototype[1] = -1; x = [1,0]; x.length = 2; x.sort(); x.length = 0; x[0] === undefined. Actual: ' + (x[0])); +} +if (x[1] !== -1) { + throw new Test262Error('#4: SendableArray.prototype[1] = -1; x = [1,0]; x.length = 2; x.sort(); x.length = 0; x[1] === -1. Actual: ' + (x[1])); +} +Object.prototype[1] = -1; +Object.prototype.length = 2; +Object.prototype.sort = SendableArray.prototype.sort; +x = { + 0: 1, + 1: 0 +}; +x.sort(); +if (x[0] !== 0) { + throw new Test262Error('#5: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.sort = SendableArray.prototype.sort; x = {0:1,1:0}; x.sort(); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#6: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.sort = SendableArray.prototype.sort; x = {0:1,1:0}; x.sort(); x[1] === 1. Actual: ' + (x[1])); +} +delete x[0]; +delete x[1]; +if (x[0] !== undefined) { + throw new Test262Error('#7: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.sort = SendableArray.prototype.sort; x = {0:1,1:0}; x.sort(); delete x[0]; delete x[1]; x[0] === undefined. Actual: ' + (x[0])); +} +if (x[1] !== -1) { + throw new Test262Error('#8: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.sort = SendableArray.prototype.sort; x = {0:1,1:0}; x.sort(); delete x[0]; delete x[1]; x[1] === -1. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A8.js b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A8.js new file mode 100644 index 0000000000000000000000000000000000000000..65153e55af7e88448bd1fde7c3940c6eb8a65591 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/S15.4.4.11_A8.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Call the comparefn passing undefined as the this value (step 13b) +esid: sec-array.prototype.sort +description: comparefn tests that its this value is undefined +flags: [noStrict] +---*/ + +var global = this; +[2, 3].sort(function(x, y) { + "use strict"; + if (this === global) { + throw new Test262Error('#1: Sort leaks global'); + } + if (this !== undefined) { + throw new Test262Error('#2: Sort comparefn should be called with this===undefined. ' + + 'Actual: ' + this); + } + return x - y; +}); diff --git a/test/sendable/builtins/Array/prototype/sort/bug_596_1.js b/test/sendable/builtins/Array/prototype/sort/bug_596_1.js new file mode 100644 index 0000000000000000000000000000000000000000..1bebbba7bacead966cb5c7e47da8f82d0adf4401 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/bug_596_1.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + The SortCompare abstract operation calls ToString() for identical + elements (step 14/15) +author: Thomas Dahlstrom (tdahlstrom@gmail.com) +---*/ + +var counter = 0; +var object = { + toString: function() { + counter++; + return ""; + } +}; +[object, object].sort(); +if (counter < 2) { + // sort calls ToString() for each element at least once + throw new Test262Error('#1: [object, object].sort(); counter < 2. Actual: ' + (counter)); +} diff --git a/test/sendable/builtins/Array/prototype/sort/bug_596_2.js b/test/sendable/builtins/Array/prototype/sort/bug_596_2.js new file mode 100644 index 0000000000000000000000000000000000000000..d32cc7b4545dc6f636f5d7697693847d183979a0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/bug_596_2.js @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Array.prototype.sort does not change non-existent elements to + undefined elements, that means holes are preserved (cf. spec text + about [[Delete]] and sparse arrays) +author: Thomas Dahlstrom (tdahlstrom@gmail.com) +---*/ + +var array = ['a', , void 0]; +//CHECK#1 +if (array.length !== 3) { + throw new Test262Error('#1: array.length !== 3. Actual: ' + (array.length)) +} +//CHECK#2 +if (array.hasOwnProperty('0') !== true) { + throw new Test262Error("#2: array.hasOwnProperty('0'). Actual: " + array.hasOwnProperty('0')); +} +//CHECK#3 +if (array.hasOwnProperty('1') !== false) { + throw new Test262Error("#3: array.hasOwnProperty('1'). Actual: " + array.hasOwnProperty('1')); +} +//CHECK#4 +if (array.hasOwnProperty('2') !== true) { + throw new Test262Error("#4: array.hasOwnProperty('2'). Actual: " + array.hasOwnProperty('2')); +} +array.sort(); +//CHECK#5 +if (array.length !== 3) { + throw new Test262Error('#5: array.length !== 3. Actual: ' + (array.length)) +} +//CHECK#6 +if (array.hasOwnProperty('0') !== true) { + throw new Test262Error("#6: array.hasOwnProperty('0'). Actual: " + array.hasOwnProperty('0')); +} +//CHECK#7 +if (array.hasOwnProperty('1') !== true) { + throw new Test262Error("#7: array.hasOwnProperty('1'). Actual: " + array.hasOwnProperty('1')); +} +//CHECK#8 +if (array.hasOwnProperty('2') !== false) { + throw new Test262Error("#8: array.hasOwnProperty('2'). Actual: " + array.hasOwnProperty('2')); +} diff --git a/test/sendable/builtins/Array/prototype/sort/call-with-primitive.js b/test/sendable/builtins/Array/prototype/sort/call-with-primitive.js new file mode 100644 index 0000000000000000000000000000000000000000..29dc70337a626951f3b90fd278cf0fb02f477774 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/call-with-primitive.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + This value is coerced to an object. +info: | + Array.prototype.sort ( comparefn ) + [...] + 2. Let obj be ? ToObject(this value). + [...] + 12. Return obj. +features: [Symbol, BigInt] +---*/ + +assert.throws(TypeError, function() { + [].sort.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + [].sort.call(null); +}, "null"); +assert([].sort.call(false) instanceof Boolean, "boolean"); +assert([].sort.call(0) instanceof Number, "number"); +assert([].sort.call("") instanceof String, "string"); +assert([].sort.call(Symbol()) instanceof Symbol, "symbol"); +assert([].sort.call(0n) instanceof BigInt, "bigint"); diff --git a/test/sendable/builtins/Array/prototype/sort/comparefn-grow.js b/test/sendable/builtins/Array/prototype/sort/comparefn-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..8c1d1923e7ee5fe2764170eafb2147f5406ad72a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/comparefn-grow.js @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Array.p.sort behaves correctly on TypedArrays backed by resizable buffers which + are grown by the comparison callback. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function ResizeAndCompare(rab, resizeTo) { + return (a, b) => { + rab.resize(resizeTo); + if (a < b) { + return -1; + } + if (a > b) { + return 1; + } + return 0; + } +} +function WriteUnsortedData(taFull) { + for (let i = 0; i < taFull.length; ++i) { + taFull[i] = MayNeedBigInt(taFull, 10 - i); + } +} +// Fixed length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 6 * ctor.BYTES_PER_ELEMENT; + const fixedLength = new ctor(rab, 0, 4); + const taFull = new ctor(rab, 0); + WriteUnsortedData(taFull); + SendableArray.prototype.sort.call(fixedLength, ResizeAndCompare(rab, resizeTo)); + // Growing doesn't affect the sorting. + assert.compareArray(ToNumbers(taFull), [ + 7, + 8, + 9, + 10, + 0, + 0 + ]); +} +// Length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 6 * ctor.BYTES_PER_ELEMENT; + const lengthTracking = new ctor(rab, 0); + const taFull = new ctor(rab, 0); + WriteUnsortedData(taFull); + SendableArray.prototype.sort.call(lengthTracking, ResizeAndCompare(rab, resizeTo)); + // Growing doesn't affect the sorting. Only the elements that were part of + // the original TA are sorted. + assert.compareArray(ToNumbers(taFull), [ + 7, + 8, + 9, + 10, + 0, + 0 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/sort/comparefn-nonfunction-call-throws.js b/test/sendable/builtins/Array/prototype/sort/comparefn-nonfunction-call-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9b300e8070b709e7c1d4a27c223affddc3faab3c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/comparefn-nonfunction-call-throws.js @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: throws on a non-undefined non-function +info: | + 22.1.3.25 Array.prototype.sort ( comparefn ) + Upon entry, the following steps are performed to initialize evaluation + of the sort function: + 1. If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception. +features: [Symbol] +---*/ + +var sample = [1]; +var poisoned = { + get length() { + throw new Test262Error("IsCallable(comparefn) should be observed before this.length"); + } +}; +assert.throws(TypeError, function() { + sample.sort(null); +}, "sample.sort(null);"); +assert.throws(TypeError, function() { + [].sort.call(poisoned, null); +}, "[].sort.call(poisoned, null);"); +assert.throws(TypeError, function() { + sample.sort(true); +}, "sample.sort(true);"); +assert.throws(TypeError, function() { + [].sort.call(poisoned, true); +}, "[].sort.call(poisoned, true);"); +assert.throws(TypeError, function() { + sample.sort(false); +}, "sample.sort(false);"); +assert.throws(TypeError, function() { + [].sort.call(poisoned, false); +}, "[].sort.call(poisoned, false);"); +assert.throws(TypeError, function() { + sample.sort(''); +}, "sample.sort('');"); +assert.throws(TypeError, function() { + [].sort.call(poisoned, ''); +}, "[].sort.call(poisoned, '');"); +assert.throws(TypeError, function() { + sample.sort(/a/g); +}, "sample.sort(/a/g);"); +assert.throws(TypeError, function() { + [].sort.call(poisoned, /a/g); +}, "[].sort.call(poisoned, /a/g);"); +assert.throws(TypeError, function() { + sample.sort(42); +}, "sample.sort(42);"); +assert.throws(TypeError, function() { + [].sort.call(poisoned, 42); +}, "[].sort.call(poisoned, 42);"); +assert.throws(TypeError, function() { + sample.sort([]); +}, "sample.sort([]);"); +assert.throws(TypeError, function() { + [].sort.call(poisoned, []); +}, "[].sort.call(poisoned, []);"); +assert.throws(TypeError, function() { + sample.sort({}); +}, "sample.sort({});"); +assert.throws(TypeError, function() { + [].sort.call(poisoned, {}); +}, "[].sort.call(poisoned, {});"); +assert.throws(TypeError, function() { + sample.sort(Symbol()); +}, "sample.sort(Symbol());"); +assert.throws(TypeError, function() { + [].sort.call(poisoned, Symbol()); +}, "[].sort.call(poisoned, Symbol());"); diff --git a/test/sendable/builtins/Array/prototype/sort/comparefn-resizable-buffer.js b/test/sendable/builtins/Array/prototype/sort/comparefn-resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..8ffdc5d917aa552f3b1201be3fe953ce7c653215 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/comparefn-resizable-buffer.js @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Array.p.sort behaves correctly on TypedArrays backed by resizable buffers and + is passed a user-provided comparison callback. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const taFull = new ctor(rab, 0); + function WriteUnsortedData() { + // Write some data into the array. + for (let i = 0; i < taFull.length; ++i) { + taFull[i] = MayNeedBigInt(taFull, 10 - i); + } + } + function OddBeforeEvenComparison(a, b) { + // Sort all odd numbers before even numbers. + a = Number(a); + b = Number(b); + if (a % 2 == 1 && b % 2 == 0) { + return -1; + } + if (a % 2 == 0 && b % 2 == 1) { + return 1; + } + if (a < b) { + return -1; + } + if (a > b) { + return 1; + } + return 0; + } + // Orig. array: [10, 9, 8, 7] + // [10, 9, 8, 7] << fixedLength + // [8, 7] << fixedLengthWithOffset + // [10, 9, 8, 7, ...] << lengthTracking + // [8, 7, ...] << lengthTrackingWithOffset + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLength, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 7, + 9, + 8, + 10 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLengthWithOffset, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 7, + 8 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTracking, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 7, + 9, + 8, + 10 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTrackingWithOffset, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 7, + 8 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [10, 9, 8] + // [10, 9, 8, ...] << lengthTracking + // [8, ...] << lengthTrackingWithOffset + + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLength, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 8 + ]); + SendableArray.prototype.sort.call(fixedLengthWithOffset, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 8 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTracking, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 9, + 8, + 10 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTrackingWithOffset, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 8 + ]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLength, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [10]); + SendableArray.prototype.sort.call(fixedLengthWithOffset, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [10]); + SendableArray.prototype.sort.call(lengthTrackingWithOffset, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [10]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTracking, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [10]); + // Shrink to zero. + rab.resize(0); + SendableArray.prototype.sort.call(fixedLength, OddBeforeEvenComparison); + SendableArray.prototype.sort.call(fixedLengthWithOffset, OddBeforeEvenComparison); + SendableArray.prototype.sort.call(lengthTrackingWithOffset, OddBeforeEvenComparison); + SendableArray.prototype.sort.call(lengthTracking, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [10, 9, 8, 7, 6, 5] + // [10, 9, 8, 7] << fixedLength + // [8, 7] << fixedLengthWithOffset + // [10, 9, 8, 7, 6, 5, ...] << lengthTracking + // [8, 7, 6, 5, ...] << lengthTrackingWithOffset + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLength, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 7, + 9, + 8, + 10, + 6, + 5 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLengthWithOffset, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 7, + 8, + 6, + 5 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTracking, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 5, + 7, + 9, + 6, + 8, + 10 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTrackingWithOffset, OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 5, + 7, + 6, + 8 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/sort/comparefn-shrink.js b/test/sendable/builtins/Array/prototype/sort/comparefn-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..24368f82513e68e81e77e6250524c77b916b27a6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/comparefn-shrink.js @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Array.p.sort behaves correctly on TypedArrays backed by resizable buffers and + is shrunk by the comparison callback. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer, Array.prototype.includes] +---*/ + +function ResizeAndCompare(rab, resizeTo) { + return (a, b) => { + rab.resize(resizeTo); + if (a < b) { + return -1; + } + if (a > b) { + return 1; + } + return 0; + } +} +function WriteUnsortedData(taFull) { + for (let i = 0; i < taFull.length; ++i) { + taFull[i] = MayNeedBigInt(taFull, 10 - i); + } +} +// Fixed length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 2 * ctor.BYTES_PER_ELEMENT; + const fixedLength = new ctor(rab, 0, 4); + const taFull = new ctor(rab, 0); + WriteUnsortedData(taFull); + SendableArray.prototype.sort.call(fixedLength, ResizeAndCompare(rab, resizeTo)); + // The data is unchanged. + assert.compareArray(ToNumbers(taFull), [ + 10, + 9 + ]); +} +// Length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 2 * ctor.BYTES_PER_ELEMENT; + const lengthTracking = new ctor(rab, 0); + const taFull = new ctor(rab, 0); + WriteUnsortedData(taFull); + SendableArray.prototype.sort.call(lengthTracking, ResizeAndCompare(rab, resizeTo)); + // The sort result is implementation defined, but it contains 2 elements out + // of the 4 original ones. + const newData = ToNumbers(taFull); + assert.sameValue(newData.length, 2); + assert([ + 10, + 9, + 8, + 7 + ].includes(newData[0])); + assert([ + 10, + 9, + 8, + 7 + ].includes(newData[1])); +} diff --git a/test/sendable/builtins/Array/prototype/sort/length.js b/test/sendable/builtins/Array/prototype/sort/length.js new file mode 100644 index 0000000000000000000000000000000000000000..ffd4dcd019a46a23a12087d96403dd93eb1f2155 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/length.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + The "length" property of Array.prototype.sort +info: | + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.sort, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/sort/name.js b/test/sendable/builtins/Array/prototype/sort/name.js new file mode 100644 index 0000000000000000000000000000000000000000..4e2f3d7bdb8f931a464afb47c5be0ab2731f533c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Array.prototype.sort.name is "sort". +info: | + Array.prototype.sort (comparefn) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.sort, "name", { + value: "sort", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/sort/not-a-constructor.js b/test/sendable/builtins/Array/prototype/sort/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..60f52552937190314925ea76538c21a565523261 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/not-a-constructor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.sort does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArray.prototype.sort), false, 'isConstructor(SendableArray.prototype.sort) must return false'); +assert.throws(TypeError, () => { + new SendableArray.prototype.sort(); +}); + diff --git a/test/sendable/builtins/Array/prototype/sort/precise-comparefn-throws.js b/test/sendable/builtins/Array/prototype/sort/precise-comparefn-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..33f47a2df5d28ba345a173a2a4edaa910cf6bb09 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-comparefn-throws.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const logs = []; +Object.defineProperty(Object.prototype, '2', { + get() { + logs.push('get'); + return 4; + }, + set(v) { + logs.push(`set with ${v}`); + } +}); +const array = [undefined, 3, /*hole*/, 2, undefined, /*hole*/, 1]; +let count = 0; +try { + array.sort((a, b) => { + if (++count === 3) { + throw new Error('lolwat'); + } + return b - a; + }); +} catch (exception) { + logs.push(exception.message); +} +assert.sameValue(logs[0], 'get'); +assert.sameValue(logs[1], 'lolwat'); +assert.sameValue(logs.length, 2); +assert.sameValue(array[0], undefined); +assert.sameValue(array[1], 3); +assert.sameValue('2' in array, true); +assert.sameValue(array.hasOwnProperty('2'), false); +assert.sameValue(array[3], 2); +assert.sameValue(array[4], undefined); +assert.sameValue('5' in array, false); +assert.sameValue(array.hasOwnProperty('5'), false); +assert.sameValue(array[6], 1); +assert.sameValue(array.length, 7); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-getter-appends-elements.js b/test/sendable/builtins/Array/prototype/sort/precise-getter-appends-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..e5d935a0bd052523d68a5cc12375ac8f08120dff --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-getter-appends-elements.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + array.push('foo'); + array.push('bar'); + return this.foo; + }, + set(v) { + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue('2' in array, true); +assert.sameValue(array.hasOwnProperty('2'), true); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array[8], 'foo'); +assert.sameValue(array[9], 'bar'); +assert.sameValue(array.length, 10); +assert.sameValue(array.foo, 'c'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[10], 'foo'); +assert.sameValue(array[11], 'bar'); +assert.sameValue(array.length, 12); +assert.sameValue(array.foo, 'c'); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-getter-decreases-length.js b/test/sendable/builtins/Array/prototype/sort/precise-getter-decreases-length.js new file mode 100644 index 0000000000000000000000000000000000000000..5de39d66ae2fb9e4cf23c89b56fbfe5ee2c44bcd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-getter-decreases-length.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + array.length = array.length - 2; + return this.foo; + }, + set(v) { + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'b'); +assert.sameValue(array[1], 'c'); +assert.sameValue(array[3], undefined); +assert.sameValue(array[4], undefined); +assert.sameValue('5' in array, false); +assert.sameValue(array.hasOwnProperty('5'), false); +assert.sameValue(array.length, 6); +assert.sameValue(array.foo, undefined); +assert.sameValue(array[2], undefined); +assert.sameValue(array.length, 4); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-getter-deletes-predecessor.js b/test/sendable/builtins/Array/prototype/sort/precise-getter-deletes-predecessor.js new file mode 100644 index 0000000000000000000000000000000000000000..4b7e476a5693cecf4a40adb6ef6b3b0aecf13d18 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-getter-deletes-predecessor.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + delete array[1]; + return this.foo; + }, + set(v) { + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'c'); +assert.sameValue(array[2], 'c'); +assert.sameValue('1' in array, false); +assert.sameValue(array.hasOwnProperty(1), false); +assert.sameValue(array.length, 8); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-getter-deletes-successor.js b/test/sendable/builtins/Array/prototype/sort/precise-getter-deletes-successor.js new file mode 100644 index 0000000000000000000000000000000000000000..a81fd7534f64f3e234f32f81f4fdbc9f9d35afeb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-getter-deletes-successor.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + delete array[3]; + return this.foo; + }, + set(v) { + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'c'); +assert.sameValue(array[3], undefined); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue('6' in array, false); +assert.sameValue(array.hasOwnProperty('6'), false); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'd'); +assert.sameValue(array[2], 'd'); +assert.sameValue('3' in array, false); +assert.sameValue(array.hasOwnProperty(3), false); +assert.sameValue(array.length, 8); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-getter-increases-length.js b/test/sendable/builtins/Array/prototype/sort/precise-getter-increases-length.js new file mode 100644 index 0000000000000000000000000000000000000000..7b8242652f953876ad9ce9db9465b7ea851f8e27 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-getter-increases-length.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + array.length = array.length + 2; + return this.foo; + }, + set(v) { + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue('8' in array, false); +assert.sameValue(array.hasOwnProperty('8'), false); +assert.sameValue('9' in array, false); +assert.sameValue(array.hasOwnProperty('9'), false); +assert.sameValue(array.length, 10); +assert.sameValue(array.foo, 'c'); +assert.sameValue(array[2], 'c'); +assert.sameValue('10' in array, false); +assert.sameValue(array.hasOwnProperty('10'), false); +assert.sameValue('11' in array, false); +assert.sameValue(array.hasOwnProperty('11'), false); +assert.sameValue(array.length, 12); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-getter-pops-elements.js b/test/sendable/builtins/Array/prototype/sort/precise-getter-pops-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..12dbe59d887dfdabcfb7e45ee8c77bfe9121d672 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-getter-pops-elements.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + array.pop(); + array.pop(); + return this.foo; + }, + set(v) { + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'b'); +assert.sameValue(array[1], 'c'); +assert.sameValue(array[3], undefined); +assert.sameValue(array[4], undefined); +assert.sameValue('5' in array, false); +assert.sameValue(array.hasOwnProperty('5'), false); +assert.sameValue(array.length, 6); +assert.sameValue(array.foo, undefined); +assert.sameValue(array[2], undefined); +assert.sameValue(array.length, 4); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-getter-sets-predecessor.js b/test/sendable/builtins/Array/prototype/sort/precise-getter-sets-predecessor.js new file mode 100644 index 0000000000000000000000000000000000000000..05324675410454c1c79d33e4fa128bd25ba9c2b7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-getter-sets-predecessor.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + array[1] = 'foobar'; + return this.foo; + }, + set(v) { + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'c'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[1], 'foobar'); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-getter-sets-successor.js b/test/sendable/builtins/Array/prototype/sort/precise-getter-sets-successor.js new file mode 100644 index 0000000000000000000000000000000000000000..cd10de2506360bcb9bd706261b4f5caf1ec2c33e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-getter-sets-successor.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + array[3] = 'foobar'; + return this.foo; + }, + set(v) { + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'c'); +assert.sameValue(array[3], 'foobar'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'd'); +assert.sameValue(array[2], 'd'); +assert.sameValue(array[3], 'foobar'); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-prototype-accessors.js b/test/sendable/builtins/Array/prototype/sort/precise-prototype-accessors.js new file mode 100644 index 0000000000000000000000000000000000000000..0ffcf6d93de2983a71e38ec08f0ebbe2e1d34161 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-prototype-accessors.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const logs = []; +Object.defineProperty(Object.prototype, '2', { + get() { + logs.push('get'); + return 4; + }, + set(v) { + logs.push(`set with ${v}`); + } +}); +const array = [undefined, 3, /*hole*/, 2, undefined, /*hole*/, 1]; +array.sort(); +assert.sameValue(logs[0], 'get'); +assert.sameValue(logs[1], 'set with 3'); +assert.sameValue(logs.length, 2); +assert.sameValue(array[0], 1); +assert.sameValue(array[1], 2); +assert.sameValue('2' in array, true); +assert.sameValue(array.hasOwnProperty('2'), false); +assert.sameValue(array[3], 4); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue('6' in array, false); +assert.sameValue(array.hasOwnProperty('6'), false); +assert.sameValue(array.length, 7); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-prototype-element.js b/test/sendable/builtins/Array/prototype/sort/precise-prototype-element.js new file mode 100644 index 0000000000000000000000000000000000000000..7e1189131c54358df33cddc3cbd7b21cc979272e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-prototype-element.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +Object.prototype[2] = 4; +const array = [undefined, 3, /*hole*/, 2, undefined, /*hole*/, 1]; +array.sort(); +assert.sameValue(array[0], 1); +assert.sameValue(array[1], 2); +assert.sameValue(array[2], 3); +assert.sameValue(array[3], 4); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue('6' in array, false); +assert.sameValue(array.hasOwnProperty('6'), false); +assert.sameValue(array.length, 7); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-setter-appends-elements.js b/test/sendable/builtins/Array/prototype/sort/precise-setter-appends-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..7736a9689b2647ca015bfd379b9a3e8ea7fb3ea0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-setter-appends-elements.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + array.push('foo'); + array.push('bar'); + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array[8], 'foo'); +assert.sameValue(array[9], 'bar'); +assert.sameValue(array.length, 10); +assert.sameValue(array.foo, 'c'); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-setter-decreases-length.js b/test/sendable/builtins/Array/prototype/sort/precise-setter-decreases-length.js new file mode 100644 index 0000000000000000000000000000000000000000..2a3572e49d58b57dfe1fb54ace847a1e06160437 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-setter-decreases-length.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + array.length = array.length - 2; + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue(array.length, 7); +assert.sameValue(array.foo, 'c'); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-setter-deletes-predecessor.js b/test/sendable/builtins/Array/prototype/sort/precise-setter-deletes-predecessor.js new file mode 100644 index 0000000000000000000000000000000000000000..5b30081948b05d0e3adc463a2773bc4f8a14a420 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-setter-deletes-predecessor.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + delete array[1]; + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue('1' in array, false); +assert.sameValue(array.hasOwnProperty(1), false); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'c'); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-setter-deletes-successor.js b/test/sendable/builtins/Array/prototype/sort/precise-setter-deletes-successor.js new file mode 100644 index 0000000000000000000000000000000000000000..699e19b7757e75b36dca707957f4c67b86809545 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-setter-deletes-successor.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + delete array[3]; + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'c'); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-setter-increases-length.js b/test/sendable/builtins/Array/prototype/sort/precise-setter-increases-length.js new file mode 100644 index 0000000000000000000000000000000000000000..e2b3afbce8b82fa33a589365421f047f2e4907a3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-setter-increases-length.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + array.length = array.length + 2; + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue('8' in array, false); +assert.sameValue(array.hasOwnProperty('8'), false); +assert.sameValue('9' in array, false); +assert.sameValue(array.hasOwnProperty('9'), false); +assert.sameValue(array.length, 10); +assert.sameValue(array.foo, 'c'); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-setter-pops-elements.js b/test/sendable/builtins/Array/prototype/sort/precise-setter-pops-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..8873acb44d67042e2d61689f32d3c28fb03c4b58 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-setter-pops-elements.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + array.pop(); + array.pop(); + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue(array.length, 7); +assert.sameValue(array.foo, 'c'); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-setter-sets-predecessor.js b/test/sendable/builtins/Array/prototype/sort/precise-setter-sets-predecessor.js new file mode 100644 index 0000000000000000000000000000000000000000..86b028eb8a67b26149680e7fff97266fa17aa88e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-setter-sets-predecessor.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + array[1] = 'foobar'; + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'foobar'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'c'); diff --git a/test/sendable/builtins/Array/prototype/sort/precise-setter-sets-successor.js b/test/sendable/builtins/Array/prototype/sort/precise-setter-sets-successor.js new file mode 100644 index 0000000000000000000000000000000000000000..c92efc354631cd003272c05036c1b17f6b2ccd49 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/precise-setter-sets-successor.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Previously implementation-defined aspects of Array.prototype.sort. +info: | + Historically, many aspects of Array.prototype.sort remained + implementation-defined. https://github.com/tc39/ecma262/pull/1585 + described some behaviors more precisely, reducing the amount of cases + that result in an implementation-defined sort order. +---*/ + +const array = [undefined, 'c', /*hole*/, 'b', undefined, /*hole*/, 'a', 'd']; +Object.defineProperty(array, '2', { + get() { + return this.foo; + }, + set(v) { + array[3] = 'foobar'; + this.foo = v; + } +}); +array.sort(); +assert.sameValue(array[0], 'a'); +assert.sameValue(array[1], 'b'); +assert.sameValue(array[2], 'c'); +assert.sameValue(array[3], 'd'); +assert.sameValue(array[4], undefined); +assert.sameValue(array[5], undefined); +assert.sameValue(array[6], undefined); +assert.sameValue('7' in array, false); +assert.sameValue(array.hasOwnProperty('7'), false); +assert.sameValue(array.length, 8); +assert.sameValue(array.foo, 'c'); diff --git a/test/sendable/builtins/Array/prototype/sort/prop-desc.js b/test/sendable/builtins/Array/prototype/sort/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..4679f1a4547af65de09192ab6280d20133306982 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/prop-desc.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + "sort" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.sort, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "sort", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/sort/resizable-buffer-default-comparator.js b/test/sendable/builtins/Array/prototype/sort/resizable-buffer-default-comparator.js new file mode 100644 index 0000000000000000000000000000000000000000..33a211c6b04bee3ab056359a1f703fa67acfe171 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/resizable-buffer-default-comparator.js @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Array.p.sort behaves correctly on TypedArrays backed by resizable buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// The default comparison function for Array.prototype.sort is the string sort. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const taFull = new ctor(rab, 0); + function WriteUnsortedData() { + // Write some data into the array. + for (let i = 0; i < taFull.length; ++i) { + taFull[i] = MayNeedBigInt(taFull, 10 - 2 * i); + } + } + // Orig. array: [10, 8, 6, 4] + // [10, 8, 6, 4] << fixedLength + // [6, 4] << fixedLengthWithOffset + // [10, 8, 6, 4, ...] << lengthTracking + // [6, 4, ...] << lengthTrackingWithOffset + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLength); + assert.compareArray(ToNumbers(taFull), [ + 10, + 4, + 6, + 8 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLengthWithOffset); + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 4, + 6 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTracking); + assert.compareArray(ToNumbers(taFull), [ + 10, + 4, + 6, + 8 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTrackingWithOffset); + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 4, + 6 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [10, 8, 6] + // [10, 8, 6, ...] << lengthTracking + // [6, ...] << lengthTrackingWithOffset + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLength); // OOB -> NOOP + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 6 + ]); + SendableArray.prototype.sort.call(fixedLengthWithOffset); // OOB -> NOOP + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 6 + ]); + SendableArray.prototype.sort.call(lengthTracking); + assert.compareArray(ToNumbers(taFull), [ + 10, + 6, + 8 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTrackingWithOffset); + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 6 + ]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLength); // OOB -> NOOP + assert.compareArray(ToNumbers(taFull), [10]); + SendableArray.prototype.sort.call(fixedLengthWithOffset); // OOB -> NOOP + assert.compareArray(ToNumbers(taFull), [10]); + SendableArray.prototype.sort.call(lengthTrackingWithOffset); // OOB -> NOOP + assert.compareArray(ToNumbers(taFull), [10]); + SendableArray.prototype.sort.call(lengthTracking); + assert.compareArray(ToNumbers(taFull), [10]); + + // Shrink to zero. + rab.resize(0); + SendableArray.prototype.sort.call(fixedLength); // OOB -> NOOP + assert.compareArray(ToNumbers(taFull), []); + SendableArray.prototype.sort.call(fixedLengthWithOffset); // OOB -> NOOP + assert.compareArray(ToNumbers(taFull), []); + SendableArray.prototype.sort.call(lengthTrackingWithOffset); // OOB -> NOOP + assert.compareArray(ToNumbers(taFull), []); + SendableArray.prototype.sort.call(lengthTracking); + assert.compareArray(ToNumbers(taFull), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [10, 8, 6, 4, 2, 0] + // [10, 8, 6, 4] << fixedLength + // [6, 4] << fixedLengthWithOffset + // [10, 8, 6, 4, 2, 0, ...] << lengthTracking + // [6, 4, 2, 0, ...] << lengthTrackingWithOffset + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLength); + assert.compareArray(ToNumbers(taFull), [ + 10, + 4, + 6, + 8, + 2, + 0 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(fixedLengthWithOffset); + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 4, + 6, + 2, + 0 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTracking); + assert.compareArray(ToNumbers(taFull), [ + 0, + 10, + 2, + 4, + 6, + 8 + ]); + WriteUnsortedData(); + SendableArray.prototype.sort.call(lengthTrackingWithOffset); + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 0, + 2, + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/sort/stability-11-elements.js b/test/sendable/builtins/Array/prototype/sort/stability-11-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..a4a0f027a2638202acc67b5742a776026a563a44 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/stability-11-elements.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Stability of Array.prototype.sort for an array with 11 elements. +info: | + The sort is required to be stable (that is, elements that compare equal + remain in their original order). + The array length of 11 was chosen because V8 used an unstable + QuickSort for arrays with more than 10 elements until v7.0 (September + 2018). https://v8.dev/blog/array-sort +---*/ + +const array = [ + { name: 'A', rating: 2 }, + { name: 'B', rating: 3 }, + { name: 'C', rating: 2 }, + { name: 'D', rating: 4 }, + { name: 'E', rating: 3 }, + { name: 'F', rating: 3 }, + { name: 'G', rating: 4 }, + { name: 'H', rating: 3 }, + { name: 'I', rating: 2 }, + { name: 'J', rating: 2 }, + { name: 'K', rating: 2 }, +]; +assert.sameValue(array.length, 11); +// Sort the elements by `rating` in descending order. +// (This updates `array` in place.) +array.sort((a, b) => b.rating - a.rating); +const reduced = array.reduce((acc, element) => acc + element.name, ''); +assert.sameValue(reduced, 'DGBEFHACIJK'); diff --git a/test/sendable/builtins/Array/prototype/sort/stability-2048-elements.js b/test/sendable/builtins/Array/prototype/sort/stability-2048-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..03070e37b8d663525ab0539c9cd5f7fc5d5639d0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/stability-2048-elements.js @@ -0,0 +1,2090 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Stability of Array.prototype.sort for an array with 2048 elements. +info: | + The sort is required to be stable (that is, elements that compare equal + remain in their original order). + The array length of 2048 was chosen because as of late 2018, Chakra + uses merge sort for arrays with 2048 or more elements. It uses + insertion sort for smaller arrays. + https://github.com/Microsoft/ChakraCore/pull/5724/files#diff-85203ec16f5961eb4c18e4253bb42140R337 +---*/ + +const array = [ + { name: 'A000', rating: 2 }, + { name: 'A001', rating: 2 }, + { name: 'A002', rating: 2 }, + { name: 'A003', rating: 2 }, + { name: 'A004', rating: 2 }, + { name: 'A005', rating: 2 }, + { name: 'A006', rating: 2 }, + { name: 'A007', rating: 2 }, + { name: 'A008', rating: 2 }, + { name: 'A009', rating: 2 }, + { name: 'A010', rating: 2 }, + { name: 'A011', rating: 2 }, + { name: 'A012', rating: 2 }, + { name: 'A013', rating: 2 }, + { name: 'A014', rating: 2 }, + { name: 'A015', rating: 2 }, + { name: 'A016', rating: 2 }, + { name: 'A017', rating: 2 }, + { name: 'A018', rating: 2 }, + { name: 'A019', rating: 2 }, + { name: 'A020', rating: 2 }, + { name: 'A021', rating: 2 }, + { name: 'A022', rating: 2 }, + { name: 'A023', rating: 2 }, + { name: 'A024', rating: 2 }, + { name: 'A025', rating: 2 }, + { name: 'A026', rating: 2 }, + { name: 'A027', rating: 2 }, + { name: 'A028', rating: 2 }, + { name: 'A029', rating: 2 }, + { name: 'A030', rating: 2 }, + { name: 'A031', rating: 2 }, + { name: 'A032', rating: 2 }, + { name: 'A033', rating: 2 }, + { name: 'A034', rating: 2 }, + { name: 'A035', rating: 2 }, + { name: 'A036', rating: 2 }, + { name: 'A037', rating: 2 }, + { name: 'A038', rating: 2 }, + { name: 'A039', rating: 2 }, + { name: 'A040', rating: 2 }, + { name: 'A041', rating: 2 }, + { name: 'A042', rating: 2 }, + { name: 'A043', rating: 2 }, + { name: 'A044', rating: 2 }, + { name: 'A045', rating: 2 }, + { name: 'A046', rating: 2 }, + { name: 'A047', rating: 2 }, + { name: 'A048', rating: 2 }, + { name: 'A049', rating: 2 }, + { name: 'A050', rating: 2 }, + { name: 'A051', rating: 2 }, + { name: 'A052', rating: 2 }, + { name: 'A053', rating: 2 }, + { name: 'A054', rating: 2 }, + { name: 'A055', rating: 2 }, + { name: 'A056', rating: 2 }, + { name: 'A057', rating: 2 }, + { name: 'A058', rating: 2 }, + { name: 'A059', rating: 2 }, + { name: 'A060', rating: 2 }, + { name: 'A061', rating: 2 }, + { name: 'A062', rating: 2 }, + { name: 'A063', rating: 2 }, + { name: 'A064', rating: 2 }, + { name: 'A065', rating: 2 }, + { name: 'A066', rating: 2 }, + { name: 'A067', rating: 2 }, + { name: 'A068', rating: 2 }, + { name: 'A069', rating: 2 }, + { name: 'A070', rating: 2 }, + { name: 'A071', rating: 2 }, + { name: 'A072', rating: 2 }, + { name: 'A073', rating: 2 }, + { name: 'A074', rating: 2 }, + { name: 'A075', rating: 2 }, + { name: 'A076', rating: 2 }, + { name: 'A077', rating: 2 }, + { name: 'A078', rating: 2 }, + { name: 'A079', rating: 2 }, + { name: 'A080', rating: 2 }, + { name: 'A081', rating: 2 }, + { name: 'A082', rating: 2 }, + { name: 'A083', rating: 2 }, + { name: 'A084', rating: 2 }, + { name: 'A085', rating: 2 }, + { name: 'A086', rating: 2 }, + { name: 'A087', rating: 2 }, + { name: 'A088', rating: 2 }, + { name: 'A089', rating: 2 }, + { name: 'A090', rating: 2 }, + { name: 'A091', rating: 2 }, + { name: 'A092', rating: 2 }, + { name: 'A093', rating: 2 }, + { name: 'A094', rating: 2 }, + { name: 'A095', rating: 2 }, + { name: 'A096', rating: 2 }, + { name: 'A097', rating: 2 }, + { name: 'A098', rating: 2 }, + { name: 'A099', rating: 2 }, + { name: 'A100', rating: 2 }, + { name: 'A101', rating: 2 }, + { name: 'A102', rating: 2 }, + { name: 'A103', rating: 2 }, + { name: 'A104', rating: 2 }, + { name: 'A105', rating: 2 }, + { name: 'A106', rating: 2 }, + { name: 'A107', rating: 2 }, + { name: 'A108', rating: 2 }, + { name: 'A109', rating: 2 }, + { name: 'A110', rating: 2 }, + { name: 'A111', rating: 2 }, + { name: 'A112', rating: 2 }, + { name: 'A113', rating: 2 }, + { name: 'A114', rating: 2 }, + { name: 'A115', rating: 2 }, + { name: 'A116', rating: 2 }, + { name: 'A117', rating: 2 }, + { name: 'A118', rating: 2 }, + { name: 'A119', rating: 2 }, + { name: 'A120', rating: 2 }, + { name: 'A121', rating: 2 }, + { name: 'A122', rating: 2 }, + { name: 'A123', rating: 2 }, + { name: 'A124', rating: 2 }, + { name: 'A125', rating: 2 }, + { name: 'A126', rating: 2 }, + { name: 'A127', rating: 2 }, + { name: 'A128', rating: 2 }, + { name: 'A129', rating: 2 }, + { name: 'A130', rating: 2 }, + { name: 'A131', rating: 2 }, + { name: 'A132', rating: 2 }, + { name: 'A133', rating: 2 }, + { name: 'A134', rating: 2 }, + { name: 'A135', rating: 2 }, + { name: 'A136', rating: 2 }, + { name: 'A137', rating: 2 }, + { name: 'A138', rating: 2 }, + { name: 'A139', rating: 2 }, + { name: 'A140', rating: 2 }, + { name: 'A141', rating: 2 }, + { name: 'A142', rating: 2 }, + { name: 'A143', rating: 2 }, + { name: 'A144', rating: 2 }, + { name: 'A145', rating: 2 }, + { name: 'A146', rating: 2 }, + { name: 'A147', rating: 2 }, + { name: 'A148', rating: 2 }, + { name: 'A149', rating: 2 }, + { name: 'A150', rating: 2 }, + { name: 'A151', rating: 2 }, + { name: 'A152', rating: 2 }, + { name: 'A153', rating: 2 }, + { name: 'A154', rating: 2 }, + { name: 'A155', rating: 2 }, + { name: 'A156', rating: 2 }, + { name: 'A157', rating: 2 }, + { name: 'A158', rating: 2 }, + { name: 'A159', rating: 2 }, + { name: 'A160', rating: 2 }, + { name: 'A161', rating: 2 }, + { name: 'A162', rating: 2 }, + { name: 'A163', rating: 2 }, + { name: 'A164', rating: 2 }, + { name: 'A165', rating: 2 }, + { name: 'A166', rating: 2 }, + { name: 'A167', rating: 2 }, + { name: 'A168', rating: 2 }, + { name: 'A169', rating: 2 }, + { name: 'A170', rating: 2 }, + { name: 'A171', rating: 2 }, + { name: 'A172', rating: 2 }, + { name: 'A173', rating: 2 }, + { name: 'A174', rating: 2 }, + { name: 'A175', rating: 2 }, + { name: 'A176', rating: 2 }, + { name: 'A177', rating: 2 }, + { name: 'A178', rating: 2 }, + { name: 'A179', rating: 2 }, + { name: 'A180', rating: 2 }, + { name: 'A181', rating: 2 }, + { name: 'A182', rating: 2 }, + { name: 'A183', rating: 2 }, + { name: 'A184', rating: 2 }, + { name: 'A185', rating: 2 }, + { name: 'A186', rating: 2 }, + { name: 'B000', rating: 3 }, + { name: 'B001', rating: 3 }, + { name: 'B002', rating: 3 }, + { name: 'B003', rating: 3 }, + { name: 'B004', rating: 3 }, + { name: 'B005', rating: 3 }, + { name: 'B006', rating: 3 }, + { name: 'B007', rating: 3 }, + { name: 'B008', rating: 3 }, + { name: 'B009', rating: 3 }, + { name: 'B010', rating: 3 }, + { name: 'B011', rating: 3 }, + { name: 'B012', rating: 3 }, + { name: 'B013', rating: 3 }, + { name: 'B014', rating: 3 }, + { name: 'B015', rating: 3 }, + { name: 'B016', rating: 3 }, + { name: 'B017', rating: 3 }, + { name: 'B018', rating: 3 }, + { name: 'B019', rating: 3 }, + { name: 'B020', rating: 3 }, + { name: 'B021', rating: 3 }, + { name: 'B022', rating: 3 }, + { name: 'B023', rating: 3 }, + { name: 'B024', rating: 3 }, + { name: 'B025', rating: 3 }, + { name: 'B026', rating: 3 }, + { name: 'B027', rating: 3 }, + { name: 'B028', rating: 3 }, + { name: 'B029', rating: 3 }, + { name: 'B030', rating: 3 }, + { name: 'B031', rating: 3 }, + { name: 'B032', rating: 3 }, + { name: 'B033', rating: 3 }, + { name: 'B034', rating: 3 }, + { name: 'B035', rating: 3 }, + { name: 'B036', rating: 3 }, + { name: 'B037', rating: 3 }, + { name: 'B038', rating: 3 }, + { name: 'B039', rating: 3 }, + { name: 'B040', rating: 3 }, + { name: 'B041', rating: 3 }, + { name: 'B042', rating: 3 }, + { name: 'B043', rating: 3 }, + { name: 'B044', rating: 3 }, + { name: 'B045', rating: 3 }, + { name: 'B046', rating: 3 }, + { name: 'B047', rating: 3 }, + { name: 'B048', rating: 3 }, + { name: 'B049', rating: 3 }, + { name: 'B050', rating: 3 }, + { name: 'B051', rating: 3 }, + { name: 'B052', rating: 3 }, + { name: 'B053', rating: 3 }, + { name: 'B054', rating: 3 }, + { name: 'B055', rating: 3 }, + { name: 'B056', rating: 3 }, + { name: 'B057', rating: 3 }, + { name: 'B058', rating: 3 }, + { name: 'B059', rating: 3 }, + { name: 'B060', rating: 3 }, + { name: 'B061', rating: 3 }, + { name: 'B062', rating: 3 }, + { name: 'B063', rating: 3 }, + { name: 'B064', rating: 3 }, + { name: 'B065', rating: 3 }, + { name: 'B066', rating: 3 }, + { name: 'B067', rating: 3 }, + { name: 'B068', rating: 3 }, + { name: 'B069', rating: 3 }, + { name: 'B070', rating: 3 }, + { name: 'B071', rating: 3 }, + { name: 'B072', rating: 3 }, + { name: 'B073', rating: 3 }, + { name: 'B074', rating: 3 }, + { name: 'B075', rating: 3 }, + { name: 'B076', rating: 3 }, + { name: 'B077', rating: 3 }, + { name: 'B078', rating: 3 }, + { name: 'B079', rating: 3 }, + { name: 'B080', rating: 3 }, + { name: 'B081', rating: 3 }, + { name: 'B082', rating: 3 }, + { name: 'B083', rating: 3 }, + { name: 'B084', rating: 3 }, + { name: 'B085', rating: 3 }, + { name: 'B086', rating: 3 }, + { name: 'B087', rating: 3 }, + { name: 'B088', rating: 3 }, + { name: 'B089', rating: 3 }, + { name: 'B090', rating: 3 }, + { name: 'B091', rating: 3 }, + { name: 'B092', rating: 3 }, + { name: 'B093', rating: 3 }, + { name: 'B094', rating: 3 }, + { name: 'B095', rating: 3 }, + { name: 'B096', rating: 3 }, + { name: 'B097', rating: 3 }, + { name: 'B098', rating: 3 }, + { name: 'B099', rating: 3 }, + { name: 'B100', rating: 3 }, + { name: 'B101', rating: 3 }, + { name: 'B102', rating: 3 }, + { name: 'B103', rating: 3 }, + { name: 'B104', rating: 3 }, + { name: 'B105', rating: 3 }, + { name: 'B106', rating: 3 }, + { name: 'B107', rating: 3 }, + { name: 'B108', rating: 3 }, + { name: 'B109', rating: 3 }, + { name: 'B110', rating: 3 }, + { name: 'B111', rating: 3 }, + { name: 'B112', rating: 3 }, + { name: 'B113', rating: 3 }, + { name: 'B114', rating: 3 }, + { name: 'B115', rating: 3 }, + { name: 'B116', rating: 3 }, + { name: 'B117', rating: 3 }, + { name: 'B118', rating: 3 }, + { name: 'B119', rating: 3 }, + { name: 'B120', rating: 3 }, + { name: 'B121', rating: 3 }, + { name: 'B122', rating: 3 }, + { name: 'B123', rating: 3 }, + { name: 'B124', rating: 3 }, + { name: 'B125', rating: 3 }, + { name: 'B126', rating: 3 }, + { name: 'B127', rating: 3 }, + { name: 'B128', rating: 3 }, + { name: 'B129', rating: 3 }, + { name: 'B130', rating: 3 }, + { name: 'B131', rating: 3 }, + { name: 'B132', rating: 3 }, + { name: 'B133', rating: 3 }, + { name: 'B134', rating: 3 }, + { name: 'B135', rating: 3 }, + { name: 'B136', rating: 3 }, + { name: 'B137', rating: 3 }, + { name: 'B138', rating: 3 }, + { name: 'B139', rating: 3 }, + { name: 'B140', rating: 3 }, + { name: 'B141', rating: 3 }, + { name: 'B142', rating: 3 }, + { name: 'B143', rating: 3 }, + { name: 'B144', rating: 3 }, + { name: 'B145', rating: 3 }, + { name: 'B146', rating: 3 }, + { name: 'B147', rating: 3 }, + { name: 'B148', rating: 3 }, + { name: 'B149', rating: 3 }, + { name: 'B150', rating: 3 }, + { name: 'B151', rating: 3 }, + { name: 'B152', rating: 3 }, + { name: 'B153', rating: 3 }, + { name: 'B154', rating: 3 }, + { name: 'B155', rating: 3 }, + { name: 'B156', rating: 3 }, + { name: 'B157', rating: 3 }, + { name: 'B158', rating: 3 }, + { name: 'B159', rating: 3 }, + { name: 'B160', rating: 3 }, + { name: 'B161', rating: 3 }, + { name: 'B162', rating: 3 }, + { name: 'B163', rating: 3 }, + { name: 'B164', rating: 3 }, + { name: 'B165', rating: 3 }, + { name: 'B166', rating: 3 }, + { name: 'B167', rating: 3 }, + { name: 'B168', rating: 3 }, + { name: 'B169', rating: 3 }, + { name: 'B170', rating: 3 }, + { name: 'B171', rating: 3 }, + { name: 'B172', rating: 3 }, + { name: 'B173', rating: 3 }, + { name: 'B174', rating: 3 }, + { name: 'B175', rating: 3 }, + { name: 'B176', rating: 3 }, + { name: 'B177', rating: 3 }, + { name: 'B178', rating: 3 }, + { name: 'B179', rating: 3 }, + { name: 'B180', rating: 3 }, + { name: 'B181', rating: 3 }, + { name: 'B182', rating: 3 }, + { name: 'B183', rating: 3 }, + { name: 'B184', rating: 3 }, + { name: 'B185', rating: 3 }, + { name: 'B186', rating: 3 }, + { name: 'C000', rating: 2 }, + { name: 'C001', rating: 2 }, + { name: 'C002', rating: 2 }, + { name: 'C003', rating: 2 }, + { name: 'C004', rating: 2 }, + { name: 'C005', rating: 2 }, + { name: 'C006', rating: 2 }, + { name: 'C007', rating: 2 }, + { name: 'C008', rating: 2 }, + { name: 'C009', rating: 2 }, + { name: 'C010', rating: 2 }, + { name: 'C011', rating: 2 }, + { name: 'C012', rating: 2 }, + { name: 'C013', rating: 2 }, + { name: 'C014', rating: 2 }, + { name: 'C015', rating: 2 }, + { name: 'C016', rating: 2 }, + { name: 'C017', rating: 2 }, + { name: 'C018', rating: 2 }, + { name: 'C019', rating: 2 }, + { name: 'C020', rating: 2 }, + { name: 'C021', rating: 2 }, + { name: 'C022', rating: 2 }, + { name: 'C023', rating: 2 }, + { name: 'C024', rating: 2 }, + { name: 'C025', rating: 2 }, + { name: 'C026', rating: 2 }, + { name: 'C027', rating: 2 }, + { name: 'C028', rating: 2 }, + { name: 'C029', rating: 2 }, + { name: 'C030', rating: 2 }, + { name: 'C031', rating: 2 }, + { name: 'C032', rating: 2 }, + { name: 'C033', rating: 2 }, + { name: 'C034', rating: 2 }, + { name: 'C035', rating: 2 }, + { name: 'C036', rating: 2 }, + { name: 'C037', rating: 2 }, + { name: 'C038', rating: 2 }, + { name: 'C039', rating: 2 }, + { name: 'C040', rating: 2 }, + { name: 'C041', rating: 2 }, + { name: 'C042', rating: 2 }, + { name: 'C043', rating: 2 }, + { name: 'C044', rating: 2 }, + { name: 'C045', rating: 2 }, + { name: 'C046', rating: 2 }, + { name: 'C047', rating: 2 }, + { name: 'C048', rating: 2 }, + { name: 'C049', rating: 2 }, + { name: 'C050', rating: 2 }, + { name: 'C051', rating: 2 }, + { name: 'C052', rating: 2 }, + { name: 'C053', rating: 2 }, + { name: 'C054', rating: 2 }, + { name: 'C055', rating: 2 }, + { name: 'C056', rating: 2 }, + { name: 'C057', rating: 2 }, + { name: 'C058', rating: 2 }, + { name: 'C059', rating: 2 }, + { name: 'C060', rating: 2 }, + { name: 'C061', rating: 2 }, + { name: 'C062', rating: 2 }, + { name: 'C063', rating: 2 }, + { name: 'C064', rating: 2 }, + { name: 'C065', rating: 2 }, + { name: 'C066', rating: 2 }, + { name: 'C067', rating: 2 }, + { name: 'C068', rating: 2 }, + { name: 'C069', rating: 2 }, + { name: 'C070', rating: 2 }, + { name: 'C071', rating: 2 }, + { name: 'C072', rating: 2 }, + { name: 'C073', rating: 2 }, + { name: 'C074', rating: 2 }, + { name: 'C075', rating: 2 }, + { name: 'C076', rating: 2 }, + { name: 'C077', rating: 2 }, + { name: 'C078', rating: 2 }, + { name: 'C079', rating: 2 }, + { name: 'C080', rating: 2 }, + { name: 'C081', rating: 2 }, + { name: 'C082', rating: 2 }, + { name: 'C083', rating: 2 }, + { name: 'C084', rating: 2 }, + { name: 'C085', rating: 2 }, + { name: 'C086', rating: 2 }, + { name: 'C087', rating: 2 }, + { name: 'C088', rating: 2 }, + { name: 'C089', rating: 2 }, + { name: 'C090', rating: 2 }, + { name: 'C091', rating: 2 }, + { name: 'C092', rating: 2 }, + { name: 'C093', rating: 2 }, + { name: 'C094', rating: 2 }, + { name: 'C095', rating: 2 }, + { name: 'C096', rating: 2 }, + { name: 'C097', rating: 2 }, + { name: 'C098', rating: 2 }, + { name: 'C099', rating: 2 }, + { name: 'C100', rating: 2 }, + { name: 'C101', rating: 2 }, + { name: 'C102', rating: 2 }, + { name: 'C103', rating: 2 }, + { name: 'C104', rating: 2 }, + { name: 'C105', rating: 2 }, + { name: 'C106', rating: 2 }, + { name: 'C107', rating: 2 }, + { name: 'C108', rating: 2 }, + { name: 'C109', rating: 2 }, + { name: 'C110', rating: 2 }, + { name: 'C111', rating: 2 }, + { name: 'C112', rating: 2 }, + { name: 'C113', rating: 2 }, + { name: 'C114', rating: 2 }, + { name: 'C115', rating: 2 }, + { name: 'C116', rating: 2 }, + { name: 'C117', rating: 2 }, + { name: 'C118', rating: 2 }, + { name: 'C119', rating: 2 }, + { name: 'C120', rating: 2 }, + { name: 'C121', rating: 2 }, + { name: 'C122', rating: 2 }, + { name: 'C123', rating: 2 }, + { name: 'C124', rating: 2 }, + { name: 'C125', rating: 2 }, + { name: 'C126', rating: 2 }, + { name: 'C127', rating: 2 }, + { name: 'C128', rating: 2 }, + { name: 'C129', rating: 2 }, + { name: 'C130', rating: 2 }, + { name: 'C131', rating: 2 }, + { name: 'C132', rating: 2 }, + { name: 'C133', rating: 2 }, + { name: 'C134', rating: 2 }, + { name: 'C135', rating: 2 }, + { name: 'C136', rating: 2 }, + { name: 'C137', rating: 2 }, + { name: 'C138', rating: 2 }, + { name: 'C139', rating: 2 }, + { name: 'C140', rating: 2 }, + { name: 'C141', rating: 2 }, + { name: 'C142', rating: 2 }, + { name: 'C143', rating: 2 }, + { name: 'C144', rating: 2 }, + { name: 'C145', rating: 2 }, + { name: 'C146', rating: 2 }, + { name: 'C147', rating: 2 }, + { name: 'C148', rating: 2 }, + { name: 'C149', rating: 2 }, + { name: 'C150', rating: 2 }, + { name: 'C151', rating: 2 }, + { name: 'C152', rating: 2 }, + { name: 'C153', rating: 2 }, + { name: 'C154', rating: 2 }, + { name: 'C155', rating: 2 }, + { name: 'C156', rating: 2 }, + { name: 'C157', rating: 2 }, + { name: 'C158', rating: 2 }, + { name: 'C159', rating: 2 }, + { name: 'C160', rating: 2 }, + { name: 'C161', rating: 2 }, + { name: 'C162', rating: 2 }, + { name: 'C163', rating: 2 }, + { name: 'C164', rating: 2 }, + { name: 'C165', rating: 2 }, + { name: 'C166', rating: 2 }, + { name: 'C167', rating: 2 }, + { name: 'C168', rating: 2 }, + { name: 'C169', rating: 2 }, + { name: 'C170', rating: 2 }, + { name: 'C171', rating: 2 }, + { name: 'C172', rating: 2 }, + { name: 'C173', rating: 2 }, + { name: 'C174', rating: 2 }, + { name: 'C175', rating: 2 }, + { name: 'C176', rating: 2 }, + { name: 'C177', rating: 2 }, + { name: 'C178', rating: 2 }, + { name: 'C179', rating: 2 }, + { name: 'C180', rating: 2 }, + { name: 'C181', rating: 2 }, + { name: 'C182', rating: 2 }, + { name: 'C183', rating: 2 }, + { name: 'C184', rating: 2 }, + { name: 'C185', rating: 2 }, + { name: 'C186', rating: 2 }, + { name: 'D000', rating: 4 }, + { name: 'D001', rating: 4 }, + { name: 'D002', rating: 4 }, + { name: 'D003', rating: 4 }, + { name: 'D004', rating: 4 }, + { name: 'D005', rating: 4 }, + { name: 'D006', rating: 4 }, + { name: 'D007', rating: 4 }, + { name: 'D008', rating: 4 }, + { name: 'D009', rating: 4 }, + { name: 'D010', rating: 4 }, + { name: 'D011', rating: 4 }, + { name: 'D012', rating: 4 }, + { name: 'D013', rating: 4 }, + { name: 'D014', rating: 4 }, + { name: 'D015', rating: 4 }, + { name: 'D016', rating: 4 }, + { name: 'D017', rating: 4 }, + { name: 'D018', rating: 4 }, + { name: 'D019', rating: 4 }, + { name: 'D020', rating: 4 }, + { name: 'D021', rating: 4 }, + { name: 'D022', rating: 4 }, + { name: 'D023', rating: 4 }, + { name: 'D024', rating: 4 }, + { name: 'D025', rating: 4 }, + { name: 'D026', rating: 4 }, + { name: 'D027', rating: 4 }, + { name: 'D028', rating: 4 }, + { name: 'D029', rating: 4 }, + { name: 'D030', rating: 4 }, + { name: 'D031', rating: 4 }, + { name: 'D032', rating: 4 }, + { name: 'D033', rating: 4 }, + { name: 'D034', rating: 4 }, + { name: 'D035', rating: 4 }, + { name: 'D036', rating: 4 }, + { name: 'D037', rating: 4 }, + { name: 'D038', rating: 4 }, + { name: 'D039', rating: 4 }, + { name: 'D040', rating: 4 }, + { name: 'D041', rating: 4 }, + { name: 'D042', rating: 4 }, + { name: 'D043', rating: 4 }, + { name: 'D044', rating: 4 }, + { name: 'D045', rating: 4 }, + { name: 'D046', rating: 4 }, + { name: 'D047', rating: 4 }, + { name: 'D048', rating: 4 }, + { name: 'D049', rating: 4 }, + { name: 'D050', rating: 4 }, + { name: 'D051', rating: 4 }, + { name: 'D052', rating: 4 }, + { name: 'D053', rating: 4 }, + { name: 'D054', rating: 4 }, + { name: 'D055', rating: 4 }, + { name: 'D056', rating: 4 }, + { name: 'D057', rating: 4 }, + { name: 'D058', rating: 4 }, + { name: 'D059', rating: 4 }, + { name: 'D060', rating: 4 }, + { name: 'D061', rating: 4 }, + { name: 'D062', rating: 4 }, + { name: 'D063', rating: 4 }, + { name: 'D064', rating: 4 }, + { name: 'D065', rating: 4 }, + { name: 'D066', rating: 4 }, + { name: 'D067', rating: 4 }, + { name: 'D068', rating: 4 }, + { name: 'D069', rating: 4 }, + { name: 'D070', rating: 4 }, + { name: 'D071', rating: 4 }, + { name: 'D072', rating: 4 }, + { name: 'D073', rating: 4 }, + { name: 'D074', rating: 4 }, + { name: 'D075', rating: 4 }, + { name: 'D076', rating: 4 }, + { name: 'D077', rating: 4 }, + { name: 'D078', rating: 4 }, + { name: 'D079', rating: 4 }, + { name: 'D080', rating: 4 }, + { name: 'D081', rating: 4 }, + { name: 'D082', rating: 4 }, + { name: 'D083', rating: 4 }, + { name: 'D084', rating: 4 }, + { name: 'D085', rating: 4 }, + { name: 'D086', rating: 4 }, + { name: 'D087', rating: 4 }, + { name: 'D088', rating: 4 }, + { name: 'D089', rating: 4 }, + { name: 'D090', rating: 4 }, + { name: 'D091', rating: 4 }, + { name: 'D092', rating: 4 }, + { name: 'D093', rating: 4 }, + { name: 'D094', rating: 4 }, + { name: 'D095', rating: 4 }, + { name: 'D096', rating: 4 }, + { name: 'D097', rating: 4 }, + { name: 'D098', rating: 4 }, + { name: 'D099', rating: 4 }, + { name: 'D100', rating: 4 }, + { name: 'D101', rating: 4 }, + { name: 'D102', rating: 4 }, + { name: 'D103', rating: 4 }, + { name: 'D104', rating: 4 }, + { name: 'D105', rating: 4 }, + { name: 'D106', rating: 4 }, + { name: 'D107', rating: 4 }, + { name: 'D108', rating: 4 }, + { name: 'D109', rating: 4 }, + { name: 'D110', rating: 4 }, + { name: 'D111', rating: 4 }, + { name: 'D112', rating: 4 }, + { name: 'D113', rating: 4 }, + { name: 'D114', rating: 4 }, + { name: 'D115', rating: 4 }, + { name: 'D116', rating: 4 }, + { name: 'D117', rating: 4 }, + { name: 'D118', rating: 4 }, + { name: 'D119', rating: 4 }, + { name: 'D120', rating: 4 }, + { name: 'D121', rating: 4 }, + { name: 'D122', rating: 4 }, + { name: 'D123', rating: 4 }, + { name: 'D124', rating: 4 }, + { name: 'D125', rating: 4 }, + { name: 'D126', rating: 4 }, + { name: 'D127', rating: 4 }, + { name: 'D128', rating: 4 }, + { name: 'D129', rating: 4 }, + { name: 'D130', rating: 4 }, + { name: 'D131', rating: 4 }, + { name: 'D132', rating: 4 }, + { name: 'D133', rating: 4 }, + { name: 'D134', rating: 4 }, + { name: 'D135', rating: 4 }, + { name: 'D136', rating: 4 }, + { name: 'D137', rating: 4 }, + { name: 'D138', rating: 4 }, + { name: 'D139', rating: 4 }, + { name: 'D140', rating: 4 }, + { name: 'D141', rating: 4 }, + { name: 'D142', rating: 4 }, + { name: 'D143', rating: 4 }, + { name: 'D144', rating: 4 }, + { name: 'D145', rating: 4 }, + { name: 'D146', rating: 4 }, + { name: 'D147', rating: 4 }, + { name: 'D148', rating: 4 }, + { name: 'D149', rating: 4 }, + { name: 'D150', rating: 4 }, + { name: 'D151', rating: 4 }, + { name: 'D152', rating: 4 }, + { name: 'D153', rating: 4 }, + { name: 'D154', rating: 4 }, + { name: 'D155', rating: 4 }, + { name: 'D156', rating: 4 }, + { name: 'D157', rating: 4 }, + { name: 'D158', rating: 4 }, + { name: 'D159', rating: 4 }, + { name: 'D160', rating: 4 }, + { name: 'D161', rating: 4 }, + { name: 'D162', rating: 4 }, + { name: 'D163', rating: 4 }, + { name: 'D164', rating: 4 }, + { name: 'D165', rating: 4 }, + { name: 'D166', rating: 4 }, + { name: 'D167', rating: 4 }, + { name: 'D168', rating: 4 }, + { name: 'D169', rating: 4 }, + { name: 'D170', rating: 4 }, + { name: 'D171', rating: 4 }, + { name: 'D172', rating: 4 }, + { name: 'D173', rating: 4 }, + { name: 'D174', rating: 4 }, + { name: 'D175', rating: 4 }, + { name: 'D176', rating: 4 }, + { name: 'D177', rating: 4 }, + { name: 'D178', rating: 4 }, + { name: 'D179', rating: 4 }, + { name: 'D180', rating: 4 }, + { name: 'D181', rating: 4 }, + { name: 'D182', rating: 4 }, + { name: 'D183', rating: 4 }, + { name: 'D184', rating: 4 }, + { name: 'D185', rating: 4 }, + { name: 'D186', rating: 4 }, + { name: 'E000', rating: 3 }, + { name: 'E001', rating: 3 }, + { name: 'E002', rating: 3 }, + { name: 'E003', rating: 3 }, + { name: 'E004', rating: 3 }, + { name: 'E005', rating: 3 }, + { name: 'E006', rating: 3 }, + { name: 'E007', rating: 3 }, + { name: 'E008', rating: 3 }, + { name: 'E009', rating: 3 }, + { name: 'E010', rating: 3 }, + { name: 'E011', rating: 3 }, + { name: 'E012', rating: 3 }, + { name: 'E013', rating: 3 }, + { name: 'E014', rating: 3 }, + { name: 'E015', rating: 3 }, + { name: 'E016', rating: 3 }, + { name: 'E017', rating: 3 }, + { name: 'E018', rating: 3 }, + { name: 'E019', rating: 3 }, + { name: 'E020', rating: 3 }, + { name: 'E021', rating: 3 }, + { name: 'E022', rating: 3 }, + { name: 'E023', rating: 3 }, + { name: 'E024', rating: 3 }, + { name: 'E025', rating: 3 }, + { name: 'E026', rating: 3 }, + { name: 'E027', rating: 3 }, + { name: 'E028', rating: 3 }, + { name: 'E029', rating: 3 }, + { name: 'E030', rating: 3 }, + { name: 'E031', rating: 3 }, + { name: 'E032', rating: 3 }, + { name: 'E033', rating: 3 }, + { name: 'E034', rating: 3 }, + { name: 'E035', rating: 3 }, + { name: 'E036', rating: 3 }, + { name: 'E037', rating: 3 }, + { name: 'E038', rating: 3 }, + { name: 'E039', rating: 3 }, + { name: 'E040', rating: 3 }, + { name: 'E041', rating: 3 }, + { name: 'E042', rating: 3 }, + { name: 'E043', rating: 3 }, + { name: 'E044', rating: 3 }, + { name: 'E045', rating: 3 }, + { name: 'E046', rating: 3 }, + { name: 'E047', rating: 3 }, + { name: 'E048', rating: 3 }, + { name: 'E049', rating: 3 }, + { name: 'E050', rating: 3 }, + { name: 'E051', rating: 3 }, + { name: 'E052', rating: 3 }, + { name: 'E053', rating: 3 }, + { name: 'E054', rating: 3 }, + { name: 'E055', rating: 3 }, + { name: 'E056', rating: 3 }, + { name: 'E057', rating: 3 }, + { name: 'E058', rating: 3 }, + { name: 'E059', rating: 3 }, + { name: 'E060', rating: 3 }, + { name: 'E061', rating: 3 }, + { name: 'E062', rating: 3 }, + { name: 'E063', rating: 3 }, + { name: 'E064', rating: 3 }, + { name: 'E065', rating: 3 }, + { name: 'E066', rating: 3 }, + { name: 'E067', rating: 3 }, + { name: 'E068', rating: 3 }, + { name: 'E069', rating: 3 }, + { name: 'E070', rating: 3 }, + { name: 'E071', rating: 3 }, + { name: 'E072', rating: 3 }, + { name: 'E073', rating: 3 }, + { name: 'E074', rating: 3 }, + { name: 'E075', rating: 3 }, + { name: 'E076', rating: 3 }, + { name: 'E077', rating: 3 }, + { name: 'E078', rating: 3 }, + { name: 'E079', rating: 3 }, + { name: 'E080', rating: 3 }, + { name: 'E081', rating: 3 }, + { name: 'E082', rating: 3 }, + { name: 'E083', rating: 3 }, + { name: 'E084', rating: 3 }, + { name: 'E085', rating: 3 }, + { name: 'E086', rating: 3 }, + { name: 'E087', rating: 3 }, + { name: 'E088', rating: 3 }, + { name: 'E089', rating: 3 }, + { name: 'E090', rating: 3 }, + { name: 'E091', rating: 3 }, + { name: 'E092', rating: 3 }, + { name: 'E093', rating: 3 }, + { name: 'E094', rating: 3 }, + { name: 'E095', rating: 3 }, + { name: 'E096', rating: 3 }, + { name: 'E097', rating: 3 }, + { name: 'E098', rating: 3 }, + { name: 'E099', rating: 3 }, + { name: 'E100', rating: 3 }, + { name: 'E101', rating: 3 }, + { name: 'E102', rating: 3 }, + { name: 'E103', rating: 3 }, + { name: 'E104', rating: 3 }, + { name: 'E105', rating: 3 }, + { name: 'E106', rating: 3 }, + { name: 'E107', rating: 3 }, + { name: 'E108', rating: 3 }, + { name: 'E109', rating: 3 }, + { name: 'E110', rating: 3 }, + { name: 'E111', rating: 3 }, + { name: 'E112', rating: 3 }, + { name: 'E113', rating: 3 }, + { name: 'E114', rating: 3 }, + { name: 'E115', rating: 3 }, + { name: 'E116', rating: 3 }, + { name: 'E117', rating: 3 }, + { name: 'E118', rating: 3 }, + { name: 'E119', rating: 3 }, + { name: 'E120', rating: 3 }, + { name: 'E121', rating: 3 }, + { name: 'E122', rating: 3 }, + { name: 'E123', rating: 3 }, + { name: 'E124', rating: 3 }, + { name: 'E125', rating: 3 }, + { name: 'E126', rating: 3 }, + { name: 'E127', rating: 3 }, + { name: 'E128', rating: 3 }, + { name: 'E129', rating: 3 }, + { name: 'E130', rating: 3 }, + { name: 'E131', rating: 3 }, + { name: 'E132', rating: 3 }, + { name: 'E133', rating: 3 }, + { name: 'E134', rating: 3 }, + { name: 'E135', rating: 3 }, + { name: 'E136', rating: 3 }, + { name: 'E137', rating: 3 }, + { name: 'E138', rating: 3 }, + { name: 'E139', rating: 3 }, + { name: 'E140', rating: 3 }, + { name: 'E141', rating: 3 }, + { name: 'E142', rating: 3 }, + { name: 'E143', rating: 3 }, + { name: 'E144', rating: 3 }, + { name: 'E145', rating: 3 }, + { name: 'E146', rating: 3 }, + { name: 'E147', rating: 3 }, + { name: 'E148', rating: 3 }, + { name: 'E149', rating: 3 }, + { name: 'E150', rating: 3 }, + { name: 'E151', rating: 3 }, + { name: 'E152', rating: 3 }, + { name: 'E153', rating: 3 }, + { name: 'E154', rating: 3 }, + { name: 'E155', rating: 3 }, + { name: 'E156', rating: 3 }, + { name: 'E157', rating: 3 }, + { name: 'E158', rating: 3 }, + { name: 'E159', rating: 3 }, + { name: 'E160', rating: 3 }, + { name: 'E161', rating: 3 }, + { name: 'E162', rating: 3 }, + { name: 'E163', rating: 3 }, + { name: 'E164', rating: 3 }, + { name: 'E165', rating: 3 }, + { name: 'E166', rating: 3 }, + { name: 'E167', rating: 3 }, + { name: 'E168', rating: 3 }, + { name: 'E169', rating: 3 }, + { name: 'E170', rating: 3 }, + { name: 'E171', rating: 3 }, + { name: 'E172', rating: 3 }, + { name: 'E173', rating: 3 }, + { name: 'E174', rating: 3 }, + { name: 'E175', rating: 3 }, + { name: 'E176', rating: 3 }, + { name: 'E177', rating: 3 }, + { name: 'E178', rating: 3 }, + { name: 'E179', rating: 3 }, + { name: 'E180', rating: 3 }, + { name: 'E181', rating: 3 }, + { name: 'E182', rating: 3 }, + { name: 'E183', rating: 3 }, + { name: 'E184', rating: 3 }, + { name: 'E185', rating: 3 }, + { name: 'E186', rating: 3 }, + { name: 'F000', rating: 3 }, + { name: 'F001', rating: 3 }, + { name: 'F002', rating: 3 }, + { name: 'F003', rating: 3 }, + { name: 'F004', rating: 3 }, + { name: 'F005', rating: 3 }, + { name: 'F006', rating: 3 }, + { name: 'F007', rating: 3 }, + { name: 'F008', rating: 3 }, + { name: 'F009', rating: 3 }, + { name: 'F010', rating: 3 }, + { name: 'F011', rating: 3 }, + { name: 'F012', rating: 3 }, + { name: 'F013', rating: 3 }, + { name: 'F014', rating: 3 }, + { name: 'F015', rating: 3 }, + { name: 'F016', rating: 3 }, + { name: 'F017', rating: 3 }, + { name: 'F018', rating: 3 }, + { name: 'F019', rating: 3 }, + { name: 'F020', rating: 3 }, + { name: 'F021', rating: 3 }, + { name: 'F022', rating: 3 }, + { name: 'F023', rating: 3 }, + { name: 'F024', rating: 3 }, + { name: 'F025', rating: 3 }, + { name: 'F026', rating: 3 }, + { name: 'F027', rating: 3 }, + { name: 'F028', rating: 3 }, + { name: 'F029', rating: 3 }, + { name: 'F030', rating: 3 }, + { name: 'F031', rating: 3 }, + { name: 'F032', rating: 3 }, + { name: 'F033', rating: 3 }, + { name: 'F034', rating: 3 }, + { name: 'F035', rating: 3 }, + { name: 'F036', rating: 3 }, + { name: 'F037', rating: 3 }, + { name: 'F038', rating: 3 }, + { name: 'F039', rating: 3 }, + { name: 'F040', rating: 3 }, + { name: 'F041', rating: 3 }, + { name: 'F042', rating: 3 }, + { name: 'F043', rating: 3 }, + { name: 'F044', rating: 3 }, + { name: 'F045', rating: 3 }, + { name: 'F046', rating: 3 }, + { name: 'F047', rating: 3 }, + { name: 'F048', rating: 3 }, + { name: 'F049', rating: 3 }, + { name: 'F050', rating: 3 }, + { name: 'F051', rating: 3 }, + { name: 'F052', rating: 3 }, + { name: 'F053', rating: 3 }, + { name: 'F054', rating: 3 }, + { name: 'F055', rating: 3 }, + { name: 'F056', rating: 3 }, + { name: 'F057', rating: 3 }, + { name: 'F058', rating: 3 }, + { name: 'F059', rating: 3 }, + { name: 'F060', rating: 3 }, + { name: 'F061', rating: 3 }, + { name: 'F062', rating: 3 }, + { name: 'F063', rating: 3 }, + { name: 'F064', rating: 3 }, + { name: 'F065', rating: 3 }, + { name: 'F066', rating: 3 }, + { name: 'F067', rating: 3 }, + { name: 'F068', rating: 3 }, + { name: 'F069', rating: 3 }, + { name: 'F070', rating: 3 }, + { name: 'F071', rating: 3 }, + { name: 'F072', rating: 3 }, + { name: 'F073', rating: 3 }, + { name: 'F074', rating: 3 }, + { name: 'F075', rating: 3 }, + { name: 'F076', rating: 3 }, + { name: 'F077', rating: 3 }, + { name: 'F078', rating: 3 }, + { name: 'F079', rating: 3 }, + { name: 'F080', rating: 3 }, + { name: 'F081', rating: 3 }, + { name: 'F082', rating: 3 }, + { name: 'F083', rating: 3 }, + { name: 'F084', rating: 3 }, + { name: 'F085', rating: 3 }, + { name: 'F086', rating: 3 }, + { name: 'F087', rating: 3 }, + { name: 'F088', rating: 3 }, + { name: 'F089', rating: 3 }, + { name: 'F090', rating: 3 }, + { name: 'F091', rating: 3 }, + { name: 'F092', rating: 3 }, + { name: 'F093', rating: 3 }, + { name: 'F094', rating: 3 }, + { name: 'F095', rating: 3 }, + { name: 'F096', rating: 3 }, + { name: 'F097', rating: 3 }, + { name: 'F098', rating: 3 }, + { name: 'F099', rating: 3 }, + { name: 'F100', rating: 3 }, + { name: 'F101', rating: 3 }, + { name: 'F102', rating: 3 }, + { name: 'F103', rating: 3 }, + { name: 'F104', rating: 3 }, + { name: 'F105', rating: 3 }, + { name: 'F106', rating: 3 }, + { name: 'F107', rating: 3 }, + { name: 'F108', rating: 3 }, + { name: 'F109', rating: 3 }, + { name: 'F110', rating: 3 }, + { name: 'F111', rating: 3 }, + { name: 'F112', rating: 3 }, + { name: 'F113', rating: 3 }, + { name: 'F114', rating: 3 }, + { name: 'F115', rating: 3 }, + { name: 'F116', rating: 3 }, + { name: 'F117', rating: 3 }, + { name: 'F118', rating: 3 }, + { name: 'F119', rating: 3 }, + { name: 'F120', rating: 3 }, + { name: 'F121', rating: 3 }, + { name: 'F122', rating: 3 }, + { name: 'F123', rating: 3 }, + { name: 'F124', rating: 3 }, + { name: 'F125', rating: 3 }, + { name: 'F126', rating: 3 }, + { name: 'F127', rating: 3 }, + { name: 'F128', rating: 3 }, + { name: 'F129', rating: 3 }, + { name: 'F130', rating: 3 }, + { name: 'F131', rating: 3 }, + { name: 'F132', rating: 3 }, + { name: 'F133', rating: 3 }, + { name: 'F134', rating: 3 }, + { name: 'F135', rating: 3 }, + { name: 'F136', rating: 3 }, + { name: 'F137', rating: 3 }, + { name: 'F138', rating: 3 }, + { name: 'F139', rating: 3 }, + { name: 'F140', rating: 3 }, + { name: 'F141', rating: 3 }, + { name: 'F142', rating: 3 }, + { name: 'F143', rating: 3 }, + { name: 'F144', rating: 3 }, + { name: 'F145', rating: 3 }, + { name: 'F146', rating: 3 }, + { name: 'F147', rating: 3 }, + { name: 'F148', rating: 3 }, + { name: 'F149', rating: 3 }, + { name: 'F150', rating: 3 }, + { name: 'F151', rating: 3 }, + { name: 'F152', rating: 3 }, + { name: 'F153', rating: 3 }, + { name: 'F154', rating: 3 }, + { name: 'F155', rating: 3 }, + { name: 'F156', rating: 3 }, + { name: 'F157', rating: 3 }, + { name: 'F158', rating: 3 }, + { name: 'F159', rating: 3 }, + { name: 'F160', rating: 3 }, + { name: 'F161', rating: 3 }, + { name: 'F162', rating: 3 }, + { name: 'F163', rating: 3 }, + { name: 'F164', rating: 3 }, + { name: 'F165', rating: 3 }, + { name: 'F166', rating: 3 }, + { name: 'F167', rating: 3 }, + { name: 'F168', rating: 3 }, + { name: 'F169', rating: 3 }, + { name: 'F170', rating: 3 }, + { name: 'F171', rating: 3 }, + { name: 'F172', rating: 3 }, + { name: 'F173', rating: 3 }, + { name: 'F174', rating: 3 }, + { name: 'F175', rating: 3 }, + { name: 'F176', rating: 3 }, + { name: 'F177', rating: 3 }, + { name: 'F178', rating: 3 }, + { name: 'F179', rating: 3 }, + { name: 'F180', rating: 3 }, + { name: 'F181', rating: 3 }, + { name: 'F182', rating: 3 }, + { name: 'F183', rating: 3 }, + { name: 'F184', rating: 3 }, + { name: 'F185', rating: 3 }, + { name: 'F186', rating: 3 }, + { name: 'G000', rating: 4 }, + { name: 'G001', rating: 4 }, + { name: 'G002', rating: 4 }, + { name: 'G003', rating: 4 }, + { name: 'G004', rating: 4 }, + { name: 'G005', rating: 4 }, + { name: 'G006', rating: 4 }, + { name: 'G007', rating: 4 }, + { name: 'G008', rating: 4 }, + { name: 'G009', rating: 4 }, + { name: 'G010', rating: 4 }, + { name: 'G011', rating: 4 }, + { name: 'G012', rating: 4 }, + { name: 'G013', rating: 4 }, + { name: 'G014', rating: 4 }, + { name: 'G015', rating: 4 }, + { name: 'G016', rating: 4 }, + { name: 'G017', rating: 4 }, + { name: 'G018', rating: 4 }, + { name: 'G019', rating: 4 }, + { name: 'G020', rating: 4 }, + { name: 'G021', rating: 4 }, + { name: 'G022', rating: 4 }, + { name: 'G023', rating: 4 }, + { name: 'G024', rating: 4 }, + { name: 'G025', rating: 4 }, + { name: 'G026', rating: 4 }, + { name: 'G027', rating: 4 }, + { name: 'G028', rating: 4 }, + { name: 'G029', rating: 4 }, + { name: 'G030', rating: 4 }, + { name: 'G031', rating: 4 }, + { name: 'G032', rating: 4 }, + { name: 'G033', rating: 4 }, + { name: 'G034', rating: 4 }, + { name: 'G035', rating: 4 }, + { name: 'G036', rating: 4 }, + { name: 'G037', rating: 4 }, + { name: 'G038', rating: 4 }, + { name: 'G039', rating: 4 }, + { name: 'G040', rating: 4 }, + { name: 'G041', rating: 4 }, + { name: 'G042', rating: 4 }, + { name: 'G043', rating: 4 }, + { name: 'G044', rating: 4 }, + { name: 'G045', rating: 4 }, + { name: 'G046', rating: 4 }, + { name: 'G047', rating: 4 }, + { name: 'G048', rating: 4 }, + { name: 'G049', rating: 4 }, + { name: 'G050', rating: 4 }, + { name: 'G051', rating: 4 }, + { name: 'G052', rating: 4 }, + { name: 'G053', rating: 4 }, + { name: 'G054', rating: 4 }, + { name: 'G055', rating: 4 }, + { name: 'G056', rating: 4 }, + { name: 'G057', rating: 4 }, + { name: 'G058', rating: 4 }, + { name: 'G059', rating: 4 }, + { name: 'G060', rating: 4 }, + { name: 'G061', rating: 4 }, + { name: 'G062', rating: 4 }, + { name: 'G063', rating: 4 }, + { name: 'G064', rating: 4 }, + { name: 'G065', rating: 4 }, + { name: 'G066', rating: 4 }, + { name: 'G067', rating: 4 }, + { name: 'G068', rating: 4 }, + { name: 'G069', rating: 4 }, + { name: 'G070', rating: 4 }, + { name: 'G071', rating: 4 }, + { name: 'G072', rating: 4 }, + { name: 'G073', rating: 4 }, + { name: 'G074', rating: 4 }, + { name: 'G075', rating: 4 }, + { name: 'G076', rating: 4 }, + { name: 'G077', rating: 4 }, + { name: 'G078', rating: 4 }, + { name: 'G079', rating: 4 }, + { name: 'G080', rating: 4 }, + { name: 'G081', rating: 4 }, + { name: 'G082', rating: 4 }, + { name: 'G083', rating: 4 }, + { name: 'G084', rating: 4 }, + { name: 'G085', rating: 4 }, + { name: 'G086', rating: 4 }, + { name: 'G087', rating: 4 }, + { name: 'G088', rating: 4 }, + { name: 'G089', rating: 4 }, + { name: 'G090', rating: 4 }, + { name: 'G091', rating: 4 }, + { name: 'G092', rating: 4 }, + { name: 'G093', rating: 4 }, + { name: 'G094', rating: 4 }, + { name: 'G095', rating: 4 }, + { name: 'G096', rating: 4 }, + { name: 'G097', rating: 4 }, + { name: 'G098', rating: 4 }, + { name: 'G099', rating: 4 }, + { name: 'G100', rating: 4 }, + { name: 'G101', rating: 4 }, + { name: 'G102', rating: 4 }, + { name: 'G103', rating: 4 }, + { name: 'G104', rating: 4 }, + { name: 'G105', rating: 4 }, + { name: 'G106', rating: 4 }, + { name: 'G107', rating: 4 }, + { name: 'G108', rating: 4 }, + { name: 'G109', rating: 4 }, + { name: 'G110', rating: 4 }, + { name: 'G111', rating: 4 }, + { name: 'G112', rating: 4 }, + { name: 'G113', rating: 4 }, + { name: 'G114', rating: 4 }, + { name: 'G115', rating: 4 }, + { name: 'G116', rating: 4 }, + { name: 'G117', rating: 4 }, + { name: 'G118', rating: 4 }, + { name: 'G119', rating: 4 }, + { name: 'G120', rating: 4 }, + { name: 'G121', rating: 4 }, + { name: 'G122', rating: 4 }, + { name: 'G123', rating: 4 }, + { name: 'G124', rating: 4 }, + { name: 'G125', rating: 4 }, + { name: 'G126', rating: 4 }, + { name: 'G127', rating: 4 }, + { name: 'G128', rating: 4 }, + { name: 'G129', rating: 4 }, + { name: 'G130', rating: 4 }, + { name: 'G131', rating: 4 }, + { name: 'G132', rating: 4 }, + { name: 'G133', rating: 4 }, + { name: 'G134', rating: 4 }, + { name: 'G135', rating: 4 }, + { name: 'G136', rating: 4 }, + { name: 'G137', rating: 4 }, + { name: 'G138', rating: 4 }, + { name: 'G139', rating: 4 }, + { name: 'G140', rating: 4 }, + { name: 'G141', rating: 4 }, + { name: 'G142', rating: 4 }, + { name: 'G143', rating: 4 }, + { name: 'G144', rating: 4 }, + { name: 'G145', rating: 4 }, + { name: 'G146', rating: 4 }, + { name: 'G147', rating: 4 }, + { name: 'G148', rating: 4 }, + { name: 'G149', rating: 4 }, + { name: 'G150', rating: 4 }, + { name: 'G151', rating: 4 }, + { name: 'G152', rating: 4 }, + { name: 'G153', rating: 4 }, + { name: 'G154', rating: 4 }, + { name: 'G155', rating: 4 }, + { name: 'G156', rating: 4 }, + { name: 'G157', rating: 4 }, + { name: 'G158', rating: 4 }, + { name: 'G159', rating: 4 }, + { name: 'G160', rating: 4 }, + { name: 'G161', rating: 4 }, + { name: 'G162', rating: 4 }, + { name: 'G163', rating: 4 }, + { name: 'G164', rating: 4 }, + { name: 'G165', rating: 4 }, + { name: 'G166', rating: 4 }, + { name: 'G167', rating: 4 }, + { name: 'G168', rating: 4 }, + { name: 'G169', rating: 4 }, + { name: 'G170', rating: 4 }, + { name: 'G171', rating: 4 }, + { name: 'G172', rating: 4 }, + { name: 'G173', rating: 4 }, + { name: 'G174', rating: 4 }, + { name: 'G175', rating: 4 }, + { name: 'G176', rating: 4 }, + { name: 'G177', rating: 4 }, + { name: 'G178', rating: 4 }, + { name: 'G179', rating: 4 }, + { name: 'G180', rating: 4 }, + { name: 'G181', rating: 4 }, + { name: 'G182', rating: 4 }, + { name: 'G183', rating: 4 }, + { name: 'G184', rating: 4 }, + { name: 'G185', rating: 4 }, + { name: 'G186', rating: 4 }, + { name: 'H000', rating: 3 }, + { name: 'H001', rating: 3 }, + { name: 'H002', rating: 3 }, + { name: 'H003', rating: 3 }, + { name: 'H004', rating: 3 }, + { name: 'H005', rating: 3 }, + { name: 'H006', rating: 3 }, + { name: 'H007', rating: 3 }, + { name: 'H008', rating: 3 }, + { name: 'H009', rating: 3 }, + { name: 'H010', rating: 3 }, + { name: 'H011', rating: 3 }, + { name: 'H012', rating: 3 }, + { name: 'H013', rating: 3 }, + { name: 'H014', rating: 3 }, + { name: 'H015', rating: 3 }, + { name: 'H016', rating: 3 }, + { name: 'H017', rating: 3 }, + { name: 'H018', rating: 3 }, + { name: 'H019', rating: 3 }, + { name: 'H020', rating: 3 }, + { name: 'H021', rating: 3 }, + { name: 'H022', rating: 3 }, + { name: 'H023', rating: 3 }, + { name: 'H024', rating: 3 }, + { name: 'H025', rating: 3 }, + { name: 'H026', rating: 3 }, + { name: 'H027', rating: 3 }, + { name: 'H028', rating: 3 }, + { name: 'H029', rating: 3 }, + { name: 'H030', rating: 3 }, + { name: 'H031', rating: 3 }, + { name: 'H032', rating: 3 }, + { name: 'H033', rating: 3 }, + { name: 'H034', rating: 3 }, + { name: 'H035', rating: 3 }, + { name: 'H036', rating: 3 }, + { name: 'H037', rating: 3 }, + { name: 'H038', rating: 3 }, + { name: 'H039', rating: 3 }, + { name: 'H040', rating: 3 }, + { name: 'H041', rating: 3 }, + { name: 'H042', rating: 3 }, + { name: 'H043', rating: 3 }, + { name: 'H044', rating: 3 }, + { name: 'H045', rating: 3 }, + { name: 'H046', rating: 3 }, + { name: 'H047', rating: 3 }, + { name: 'H048', rating: 3 }, + { name: 'H049', rating: 3 }, + { name: 'H050', rating: 3 }, + { name: 'H051', rating: 3 }, + { name: 'H052', rating: 3 }, + { name: 'H053', rating: 3 }, + { name: 'H054', rating: 3 }, + { name: 'H055', rating: 3 }, + { name: 'H056', rating: 3 }, + { name: 'H057', rating: 3 }, + { name: 'H058', rating: 3 }, + { name: 'H059', rating: 3 }, + { name: 'H060', rating: 3 }, + { name: 'H061', rating: 3 }, + { name: 'H062', rating: 3 }, + { name: 'H063', rating: 3 }, + { name: 'H064', rating: 3 }, + { name: 'H065', rating: 3 }, + { name: 'H066', rating: 3 }, + { name: 'H067', rating: 3 }, + { name: 'H068', rating: 3 }, + { name: 'H069', rating: 3 }, + { name: 'H070', rating: 3 }, + { name: 'H071', rating: 3 }, + { name: 'H072', rating: 3 }, + { name: 'H073', rating: 3 }, + { name: 'H074', rating: 3 }, + { name: 'H075', rating: 3 }, + { name: 'H076', rating: 3 }, + { name: 'H077', rating: 3 }, + { name: 'H078', rating: 3 }, + { name: 'H079', rating: 3 }, + { name: 'H080', rating: 3 }, + { name: 'H081', rating: 3 }, + { name: 'H082', rating: 3 }, + { name: 'H083', rating: 3 }, + { name: 'H084', rating: 3 }, + { name: 'H085', rating: 3 }, + { name: 'H086', rating: 3 }, + { name: 'H087', rating: 3 }, + { name: 'H088', rating: 3 }, + { name: 'H089', rating: 3 }, + { name: 'H090', rating: 3 }, + { name: 'H091', rating: 3 }, + { name: 'H092', rating: 3 }, + { name: 'H093', rating: 3 }, + { name: 'H094', rating: 3 }, + { name: 'H095', rating: 3 }, + { name: 'H096', rating: 3 }, + { name: 'H097', rating: 3 }, + { name: 'H098', rating: 3 }, + { name: 'H099', rating: 3 }, + { name: 'H100', rating: 3 }, + { name: 'H101', rating: 3 }, + { name: 'H102', rating: 3 }, + { name: 'H103', rating: 3 }, + { name: 'H104', rating: 3 }, + { name: 'H105', rating: 3 }, + { name: 'H106', rating: 3 }, + { name: 'H107', rating: 3 }, + { name: 'H108', rating: 3 }, + { name: 'H109', rating: 3 }, + { name: 'H110', rating: 3 }, + { name: 'H111', rating: 3 }, + { name: 'H112', rating: 3 }, + { name: 'H113', rating: 3 }, + { name: 'H114', rating: 3 }, + { name: 'H115', rating: 3 }, + { name: 'H116', rating: 3 }, + { name: 'H117', rating: 3 }, + { name: 'H118', rating: 3 }, + { name: 'H119', rating: 3 }, + { name: 'H120', rating: 3 }, + { name: 'H121', rating: 3 }, + { name: 'H122', rating: 3 }, + { name: 'H123', rating: 3 }, + { name: 'H124', rating: 3 }, + { name: 'H125', rating: 3 }, + { name: 'H126', rating: 3 }, + { name: 'H127', rating: 3 }, + { name: 'H128', rating: 3 }, + { name: 'H129', rating: 3 }, + { name: 'H130', rating: 3 }, + { name: 'H131', rating: 3 }, + { name: 'H132', rating: 3 }, + { name: 'H133', rating: 3 }, + { name: 'H134', rating: 3 }, + { name: 'H135', rating: 3 }, + { name: 'H136', rating: 3 }, + { name: 'H137', rating: 3 }, + { name: 'H138', rating: 3 }, + { name: 'H139', rating: 3 }, + { name: 'H140', rating: 3 }, + { name: 'H141', rating: 3 }, + { name: 'H142', rating: 3 }, + { name: 'H143', rating: 3 }, + { name: 'H144', rating: 3 }, + { name: 'H145', rating: 3 }, + { name: 'H146', rating: 3 }, + { name: 'H147', rating: 3 }, + { name: 'H148', rating: 3 }, + { name: 'H149', rating: 3 }, + { name: 'H150', rating: 3 }, + { name: 'H151', rating: 3 }, + { name: 'H152', rating: 3 }, + { name: 'H153', rating: 3 }, + { name: 'H154', rating: 3 }, + { name: 'H155', rating: 3 }, + { name: 'H156', rating: 3 }, + { name: 'H157', rating: 3 }, + { name: 'H158', rating: 3 }, + { name: 'H159', rating: 3 }, + { name: 'H160', rating: 3 }, + { name: 'H161', rating: 3 }, + { name: 'H162', rating: 3 }, + { name: 'H163', rating: 3 }, + { name: 'H164', rating: 3 }, + { name: 'H165', rating: 3 }, + { name: 'H166', rating: 3 }, + { name: 'H167', rating: 3 }, + { name: 'H168', rating: 3 }, + { name: 'H169', rating: 3 }, + { name: 'H170', rating: 3 }, + { name: 'H171', rating: 3 }, + { name: 'H172', rating: 3 }, + { name: 'H173', rating: 3 }, + { name: 'H174', rating: 3 }, + { name: 'H175', rating: 3 }, + { name: 'H176', rating: 3 }, + { name: 'H177', rating: 3 }, + { name: 'H178', rating: 3 }, + { name: 'H179', rating: 3 }, + { name: 'H180', rating: 3 }, + { name: 'H181', rating: 3 }, + { name: 'H182', rating: 3 }, + { name: 'H183', rating: 3 }, + { name: 'H184', rating: 3 }, + { name: 'H185', rating: 3 }, + { name: 'H186', rating: 3 }, + { name: 'I000', rating: 2 }, + { name: 'I001', rating: 2 }, + { name: 'I002', rating: 2 }, + { name: 'I003', rating: 2 }, + { name: 'I004', rating: 2 }, + { name: 'I005', rating: 2 }, + { name: 'I006', rating: 2 }, + { name: 'I007', rating: 2 }, + { name: 'I008', rating: 2 }, + { name: 'I009', rating: 2 }, + { name: 'I010', rating: 2 }, + { name: 'I011', rating: 2 }, + { name: 'I012', rating: 2 }, + { name: 'I013', rating: 2 }, + { name: 'I014', rating: 2 }, + { name: 'I015', rating: 2 }, + { name: 'I016', rating: 2 }, + { name: 'I017', rating: 2 }, + { name: 'I018', rating: 2 }, + { name: 'I019', rating: 2 }, + { name: 'I020', rating: 2 }, + { name: 'I021', rating: 2 }, + { name: 'I022', rating: 2 }, + { name: 'I023', rating: 2 }, + { name: 'I024', rating: 2 }, + { name: 'I025', rating: 2 }, + { name: 'I026', rating: 2 }, + { name: 'I027', rating: 2 }, + { name: 'I028', rating: 2 }, + { name: 'I029', rating: 2 }, + { name: 'I030', rating: 2 }, + { name: 'I031', rating: 2 }, + { name: 'I032', rating: 2 }, + { name: 'I033', rating: 2 }, + { name: 'I034', rating: 2 }, + { name: 'I035', rating: 2 }, + { name: 'I036', rating: 2 }, + { name: 'I037', rating: 2 }, + { name: 'I038', rating: 2 }, + { name: 'I039', rating: 2 }, + { name: 'I040', rating: 2 }, + { name: 'I041', rating: 2 }, + { name: 'I042', rating: 2 }, + { name: 'I043', rating: 2 }, + { name: 'I044', rating: 2 }, + { name: 'I045', rating: 2 }, + { name: 'I046', rating: 2 }, + { name: 'I047', rating: 2 }, + { name: 'I048', rating: 2 }, + { name: 'I049', rating: 2 }, + { name: 'I050', rating: 2 }, + { name: 'I051', rating: 2 }, + { name: 'I052', rating: 2 }, + { name: 'I053', rating: 2 }, + { name: 'I054', rating: 2 }, + { name: 'I055', rating: 2 }, + { name: 'I056', rating: 2 }, + { name: 'I057', rating: 2 }, + { name: 'I058', rating: 2 }, + { name: 'I059', rating: 2 }, + { name: 'I060', rating: 2 }, + { name: 'I061', rating: 2 }, + { name: 'I062', rating: 2 }, + { name: 'I063', rating: 2 }, + { name: 'I064', rating: 2 }, + { name: 'I065', rating: 2 }, + { name: 'I066', rating: 2 }, + { name: 'I067', rating: 2 }, + { name: 'I068', rating: 2 }, + { name: 'I069', rating: 2 }, + { name: 'I070', rating: 2 }, + { name: 'I071', rating: 2 }, + { name: 'I072', rating: 2 }, + { name: 'I073', rating: 2 }, + { name: 'I074', rating: 2 }, + { name: 'I075', rating: 2 }, + { name: 'I076', rating: 2 }, + { name: 'I077', rating: 2 }, + { name: 'I078', rating: 2 }, + { name: 'I079', rating: 2 }, + { name: 'I080', rating: 2 }, + { name: 'I081', rating: 2 }, + { name: 'I082', rating: 2 }, + { name: 'I083', rating: 2 }, + { name: 'I084', rating: 2 }, + { name: 'I085', rating: 2 }, + { name: 'I086', rating: 2 }, + { name: 'I087', rating: 2 }, + { name: 'I088', rating: 2 }, + { name: 'I089', rating: 2 }, + { name: 'I090', rating: 2 }, + { name: 'I091', rating: 2 }, + { name: 'I092', rating: 2 }, + { name: 'I093', rating: 2 }, + { name: 'I094', rating: 2 }, + { name: 'I095', rating: 2 }, + { name: 'I096', rating: 2 }, + { name: 'I097', rating: 2 }, + { name: 'I098', rating: 2 }, + { name: 'I099', rating: 2 }, + { name: 'I100', rating: 2 }, + { name: 'I101', rating: 2 }, + { name: 'I102', rating: 2 }, + { name: 'I103', rating: 2 }, + { name: 'I104', rating: 2 }, + { name: 'I105', rating: 2 }, + { name: 'I106', rating: 2 }, + { name: 'I107', rating: 2 }, + { name: 'I108', rating: 2 }, + { name: 'I109', rating: 2 }, + { name: 'I110', rating: 2 }, + { name: 'I111', rating: 2 }, + { name: 'I112', rating: 2 }, + { name: 'I113', rating: 2 }, + { name: 'I114', rating: 2 }, + { name: 'I115', rating: 2 }, + { name: 'I116', rating: 2 }, + { name: 'I117', rating: 2 }, + { name: 'I118', rating: 2 }, + { name: 'I119', rating: 2 }, + { name: 'I120', rating: 2 }, + { name: 'I121', rating: 2 }, + { name: 'I122', rating: 2 }, + { name: 'I123', rating: 2 }, + { name: 'I124', rating: 2 }, + { name: 'I125', rating: 2 }, + { name: 'I126', rating: 2 }, + { name: 'I127', rating: 2 }, + { name: 'I128', rating: 2 }, + { name: 'I129', rating: 2 }, + { name: 'I130', rating: 2 }, + { name: 'I131', rating: 2 }, + { name: 'I132', rating: 2 }, + { name: 'I133', rating: 2 }, + { name: 'I134', rating: 2 }, + { name: 'I135', rating: 2 }, + { name: 'I136', rating: 2 }, + { name: 'I137', rating: 2 }, + { name: 'I138', rating: 2 }, + { name: 'I139', rating: 2 }, + { name: 'I140', rating: 2 }, + { name: 'I141', rating: 2 }, + { name: 'I142', rating: 2 }, + { name: 'I143', rating: 2 }, + { name: 'I144', rating: 2 }, + { name: 'I145', rating: 2 }, + { name: 'I146', rating: 2 }, + { name: 'I147', rating: 2 }, + { name: 'I148', rating: 2 }, + { name: 'I149', rating: 2 }, + { name: 'I150', rating: 2 }, + { name: 'I151', rating: 2 }, + { name: 'I152', rating: 2 }, + { name: 'I153', rating: 2 }, + { name: 'I154', rating: 2 }, + { name: 'I155', rating: 2 }, + { name: 'I156', rating: 2 }, + { name: 'I157', rating: 2 }, + { name: 'I158', rating: 2 }, + { name: 'I159', rating: 2 }, + { name: 'I160', rating: 2 }, + { name: 'I161', rating: 2 }, + { name: 'I162', rating: 2 }, + { name: 'I163', rating: 2 }, + { name: 'I164', rating: 2 }, + { name: 'I165', rating: 2 }, + { name: 'I166', rating: 2 }, + { name: 'I167', rating: 2 }, + { name: 'I168', rating: 2 }, + { name: 'I169', rating: 2 }, + { name: 'I170', rating: 2 }, + { name: 'I171', rating: 2 }, + { name: 'I172', rating: 2 }, + { name: 'I173', rating: 2 }, + { name: 'I174', rating: 2 }, + { name: 'I175', rating: 2 }, + { name: 'I176', rating: 2 }, + { name: 'I177', rating: 2 }, + { name: 'I178', rating: 2 }, + { name: 'I179', rating: 2 }, + { name: 'I180', rating: 2 }, + { name: 'I181', rating: 2 }, + { name: 'I182', rating: 2 }, + { name: 'I183', rating: 2 }, + { name: 'I184', rating: 2 }, + { name: 'I185', rating: 2 }, + { name: 'I186', rating: 2 }, + { name: 'J000', rating: 2 }, + { name: 'J001', rating: 2 }, + { name: 'J002', rating: 2 }, + { name: 'J003', rating: 2 }, + { name: 'J004', rating: 2 }, + { name: 'J005', rating: 2 }, + { name: 'J006', rating: 2 }, + { name: 'J007', rating: 2 }, + { name: 'J008', rating: 2 }, + { name: 'J009', rating: 2 }, + { name: 'J010', rating: 2 }, + { name: 'J011', rating: 2 }, + { name: 'J012', rating: 2 }, + { name: 'J013', rating: 2 }, + { name: 'J014', rating: 2 }, + { name: 'J015', rating: 2 }, + { name: 'J016', rating: 2 }, + { name: 'J017', rating: 2 }, + { name: 'J018', rating: 2 }, + { name: 'J019', rating: 2 }, + { name: 'J020', rating: 2 }, + { name: 'J021', rating: 2 }, + { name: 'J022', rating: 2 }, + { name: 'J023', rating: 2 }, + { name: 'J024', rating: 2 }, + { name: 'J025', rating: 2 }, + { name: 'J026', rating: 2 }, + { name: 'J027', rating: 2 }, + { name: 'J028', rating: 2 }, + { name: 'J029', rating: 2 }, + { name: 'J030', rating: 2 }, + { name: 'J031', rating: 2 }, + { name: 'J032', rating: 2 }, + { name: 'J033', rating: 2 }, + { name: 'J034', rating: 2 }, + { name: 'J035', rating: 2 }, + { name: 'J036', rating: 2 }, + { name: 'J037', rating: 2 }, + { name: 'J038', rating: 2 }, + { name: 'J039', rating: 2 }, + { name: 'J040', rating: 2 }, + { name: 'J041', rating: 2 }, + { name: 'J042', rating: 2 }, + { name: 'J043', rating: 2 }, + { name: 'J044', rating: 2 }, + { name: 'J045', rating: 2 }, + { name: 'J046', rating: 2 }, + { name: 'J047', rating: 2 }, + { name: 'J048', rating: 2 }, + { name: 'J049', rating: 2 }, + { name: 'J050', rating: 2 }, + { name: 'J051', rating: 2 }, + { name: 'J052', rating: 2 }, + { name: 'J053', rating: 2 }, + { name: 'J054', rating: 2 }, + { name: 'J055', rating: 2 }, + { name: 'J056', rating: 2 }, + { name: 'J057', rating: 2 }, + { name: 'J058', rating: 2 }, + { name: 'J059', rating: 2 }, + { name: 'J060', rating: 2 }, + { name: 'J061', rating: 2 }, + { name: 'J062', rating: 2 }, + { name: 'J063', rating: 2 }, + { name: 'J064', rating: 2 }, + { name: 'J065', rating: 2 }, + { name: 'J066', rating: 2 }, + { name: 'J067', rating: 2 }, + { name: 'J068', rating: 2 }, + { name: 'J069', rating: 2 }, + { name: 'J070', rating: 2 }, + { name: 'J071', rating: 2 }, + { name: 'J072', rating: 2 }, + { name: 'J073', rating: 2 }, + { name: 'J074', rating: 2 }, + { name: 'J075', rating: 2 }, + { name: 'J076', rating: 2 }, + { name: 'J077', rating: 2 }, + { name: 'J078', rating: 2 }, + { name: 'J079', rating: 2 }, + { name: 'J080', rating: 2 }, + { name: 'J081', rating: 2 }, + { name: 'J082', rating: 2 }, + { name: 'J083', rating: 2 }, + { name: 'J084', rating: 2 }, + { name: 'J085', rating: 2 }, + { name: 'J086', rating: 2 }, + { name: 'J087', rating: 2 }, + { name: 'J088', rating: 2 }, + { name: 'J089', rating: 2 }, + { name: 'J090', rating: 2 }, + { name: 'J091', rating: 2 }, + { name: 'J092', rating: 2 }, + { name: 'J093', rating: 2 }, + { name: 'J094', rating: 2 }, + { name: 'J095', rating: 2 }, + { name: 'J096', rating: 2 }, + { name: 'J097', rating: 2 }, + { name: 'J098', rating: 2 }, + { name: 'J099', rating: 2 }, + { name: 'J100', rating: 2 }, + { name: 'J101', rating: 2 }, + { name: 'J102', rating: 2 }, + { name: 'J103', rating: 2 }, + { name: 'J104', rating: 2 }, + { name: 'J105', rating: 2 }, + { name: 'J106', rating: 2 }, + { name: 'J107', rating: 2 }, + { name: 'J108', rating: 2 }, + { name: 'J109', rating: 2 }, + { name: 'J110', rating: 2 }, + { name: 'J111', rating: 2 }, + { name: 'J112', rating: 2 }, + { name: 'J113', rating: 2 }, + { name: 'J114', rating: 2 }, + { name: 'J115', rating: 2 }, + { name: 'J116', rating: 2 }, + { name: 'J117', rating: 2 }, + { name: 'J118', rating: 2 }, + { name: 'J119', rating: 2 }, + { name: 'J120', rating: 2 }, + { name: 'J121', rating: 2 }, + { name: 'J122', rating: 2 }, + { name: 'J123', rating: 2 }, + { name: 'J124', rating: 2 }, + { name: 'J125', rating: 2 }, + { name: 'J126', rating: 2 }, + { name: 'J127', rating: 2 }, + { name: 'J128', rating: 2 }, + { name: 'J129', rating: 2 }, + { name: 'J130', rating: 2 }, + { name: 'J131', rating: 2 }, + { name: 'J132', rating: 2 }, + { name: 'J133', rating: 2 }, + { name: 'J134', rating: 2 }, + { name: 'J135', rating: 2 }, + { name: 'J136', rating: 2 }, + { name: 'J137', rating: 2 }, + { name: 'J138', rating: 2 }, + { name: 'J139', rating: 2 }, + { name: 'J140', rating: 2 }, + { name: 'J141', rating: 2 }, + { name: 'J142', rating: 2 }, + { name: 'J143', rating: 2 }, + { name: 'J144', rating: 2 }, + { name: 'J145', rating: 2 }, + { name: 'J146', rating: 2 }, + { name: 'J147', rating: 2 }, + { name: 'J148', rating: 2 }, + { name: 'J149', rating: 2 }, + { name: 'J150', rating: 2 }, + { name: 'J151', rating: 2 }, + { name: 'J152', rating: 2 }, + { name: 'J153', rating: 2 }, + { name: 'J154', rating: 2 }, + { name: 'J155', rating: 2 }, + { name: 'J156', rating: 2 }, + { name: 'J157', rating: 2 }, + { name: 'J158', rating: 2 }, + { name: 'J159', rating: 2 }, + { name: 'J160', rating: 2 }, + { name: 'J161', rating: 2 }, + { name: 'J162', rating: 2 }, + { name: 'J163', rating: 2 }, + { name: 'J164', rating: 2 }, + { name: 'J165', rating: 2 }, + { name: 'J166', rating: 2 }, + { name: 'J167', rating: 2 }, + { name: 'J168', rating: 2 }, + { name: 'J169', rating: 2 }, + { name: 'J170', rating: 2 }, + { name: 'J171', rating: 2 }, + { name: 'J172', rating: 2 }, + { name: 'J173', rating: 2 }, + { name: 'J174', rating: 2 }, + { name: 'J175', rating: 2 }, + { name: 'J176', rating: 2 }, + { name: 'J177', rating: 2 }, + { name: 'J178', rating: 2 }, + { name: 'J179', rating: 2 }, + { name: 'J180', rating: 2 }, + { name: 'J181', rating: 2 }, + { name: 'J182', rating: 2 }, + { name: 'J183', rating: 2 }, + { name: 'J184', rating: 2 }, + { name: 'J185', rating: 2 }, + { name: 'J186', rating: 2 }, + { name: 'K000', rating: 2 }, + { name: 'K001', rating: 2 }, + { name: 'K002', rating: 2 }, + { name: 'K003', rating: 2 }, + { name: 'K004', rating: 2 }, + { name: 'K005', rating: 2 }, + { name: 'K006', rating: 2 }, + { name: 'K007', rating: 2 }, + { name: 'K008', rating: 2 }, + { name: 'K009', rating: 2 }, + { name: 'K010', rating: 2 }, + { name: 'K011', rating: 2 }, + { name: 'K012', rating: 2 }, + { name: 'K013', rating: 2 }, + { name: 'K014', rating: 2 }, + { name: 'K015', rating: 2 }, + { name: 'K016', rating: 2 }, + { name: 'K017', rating: 2 }, + { name: 'K018', rating: 2 }, + { name: 'K019', rating: 2 }, + { name: 'K020', rating: 2 }, + { name: 'K021', rating: 2 }, + { name: 'K022', rating: 2 }, + { name: 'K023', rating: 2 }, + { name: 'K024', rating: 2 }, + { name: 'K025', rating: 2 }, + { name: 'K026', rating: 2 }, + { name: 'K027', rating: 2 }, + { name: 'K028', rating: 2 }, + { name: 'K029', rating: 2 }, + { name: 'K030', rating: 2 }, + { name: 'K031', rating: 2 }, + { name: 'K032', rating: 2 }, + { name: 'K033', rating: 2 }, + { name: 'K034', rating: 2 }, + { name: 'K035', rating: 2 }, + { name: 'K036', rating: 2 }, + { name: 'K037', rating: 2 }, + { name: 'K038', rating: 2 }, + { name: 'K039', rating: 2 }, + { name: 'K040', rating: 2 }, + { name: 'K041', rating: 2 }, + { name: 'K042', rating: 2 }, + { name: 'K043', rating: 2 }, + { name: 'K044', rating: 2 }, + { name: 'K045', rating: 2 }, + { name: 'K046', rating: 2 }, + { name: 'K047', rating: 2 }, + { name: 'K048', rating: 2 }, + { name: 'K049', rating: 2 }, + { name: 'K050', rating: 2 }, + { name: 'K051', rating: 2 }, + { name: 'K052', rating: 2 }, + { name: 'K053', rating: 2 }, + { name: 'K054', rating: 2 }, + { name: 'K055', rating: 2 }, + { name: 'K056', rating: 2 }, + { name: 'K057', rating: 2 }, + { name: 'K058', rating: 2 }, + { name: 'K059', rating: 2 }, + { name: 'K060', rating: 2 }, + { name: 'K061', rating: 2 }, + { name: 'K062', rating: 2 }, + { name: 'K063', rating: 2 }, + { name: 'K064', rating: 2 }, + { name: 'K065', rating: 2 }, + { name: 'K066', rating: 2 }, + { name: 'K067', rating: 2 }, + { name: 'K068', rating: 2 }, + { name: 'K069', rating: 2 }, + { name: 'K070', rating: 2 }, + { name: 'K071', rating: 2 }, + { name: 'K072', rating: 2 }, + { name: 'K073', rating: 2 }, + { name: 'K074', rating: 2 }, + { name: 'K075', rating: 2 }, + { name: 'K076', rating: 2 }, + { name: 'K077', rating: 2 }, + { name: 'K078', rating: 2 }, + { name: 'K079', rating: 2 }, + { name: 'K080', rating: 2 }, + { name: 'K081', rating: 2 }, + { name: 'K082', rating: 2 }, + { name: 'K083', rating: 2 }, + { name: 'K084', rating: 2 }, + { name: 'K085', rating: 2 }, + { name: 'K086', rating: 2 }, + { name: 'K087', rating: 2 }, + { name: 'K088', rating: 2 }, + { name: 'K089', rating: 2 }, + { name: 'K090', rating: 2 }, + { name: 'K091', rating: 2 }, + { name: 'K092', rating: 2 }, + { name: 'K093', rating: 2 }, + { name: 'K094', rating: 2 }, + { name: 'K095', rating: 2 }, + { name: 'K096', rating: 2 }, + { name: 'K097', rating: 2 }, + { name: 'K098', rating: 2 }, + { name: 'K099', rating: 2 }, + { name: 'K100', rating: 2 }, + { name: 'K101', rating: 2 }, + { name: 'K102', rating: 2 }, + { name: 'K103', rating: 2 }, + { name: 'K104', rating: 2 }, + { name: 'K105', rating: 2 }, + { name: 'K106', rating: 2 }, + { name: 'K107', rating: 2 }, + { name: 'K108', rating: 2 }, + { name: 'K109', rating: 2 }, + { name: 'K110', rating: 2 }, + { name: 'K111', rating: 2 }, + { name: 'K112', rating: 2 }, + { name: 'K113', rating: 2 }, + { name: 'K114', rating: 2 }, + { name: 'K115', rating: 2 }, + { name: 'K116', rating: 2 }, + { name: 'K117', rating: 2 }, + { name: 'K118', rating: 2 }, + { name: 'K119', rating: 2 }, + { name: 'K120', rating: 2 }, + { name: 'K121', rating: 2 }, + { name: 'K122', rating: 2 }, + { name: 'K123', rating: 2 }, + { name: 'K124', rating: 2 }, + { name: 'K125', rating: 2 }, + { name: 'K126', rating: 2 }, + { name: 'K127', rating: 2 }, + { name: 'K128', rating: 2 }, + { name: 'K129', rating: 2 }, + { name: 'K130', rating: 2 }, + { name: 'K131', rating: 2 }, + { name: 'K132', rating: 2 }, + { name: 'K133', rating: 2 }, + { name: 'K134', rating: 2 }, + { name: 'K135', rating: 2 }, + { name: 'K136', rating: 2 }, + { name: 'K137', rating: 2 }, + { name: 'K138', rating: 2 }, + { name: 'K139', rating: 2 }, + { name: 'K140', rating: 2 }, + { name: 'K141', rating: 2 }, + { name: 'K142', rating: 2 }, + { name: 'K143', rating: 2 }, + { name: 'K144', rating: 2 }, + { name: 'K145', rating: 2 }, + { name: 'K146', rating: 2 }, + { name: 'K147', rating: 2 }, + { name: 'K148', rating: 2 }, + { name: 'K149', rating: 2 }, + { name: 'K150', rating: 2 }, + { name: 'K151', rating: 2 }, + { name: 'K152', rating: 2 }, + { name: 'K153', rating: 2 }, + { name: 'K154', rating: 2 }, + { name: 'K155', rating: 2 }, + { name: 'K156', rating: 2 }, + { name: 'K157', rating: 2 }, + { name: 'K158', rating: 2 }, + { name: 'K159', rating: 2 }, + { name: 'K160', rating: 2 }, + { name: 'K161', rating: 2 }, + { name: 'K162', rating: 2 }, + { name: 'K163', rating: 2 }, + { name: 'K164', rating: 2 }, + { name: 'K165', rating: 2 }, + { name: 'K166', rating: 2 }, + { name: 'K167', rating: 2 }, + { name: 'K168', rating: 2 }, + { name: 'K169', rating: 2 }, + { name: 'K170', rating: 2 }, + { name: 'K171', rating: 2 }, + { name: 'K172', rating: 2 }, + { name: 'K173', rating: 2 }, + { name: 'K174', rating: 2 }, + { name: 'K175', rating: 2 }, + { name: 'K176', rating: 2 }, + { name: 'K177', rating: 2 }, +]; +assert.sameValue(array.length, 2048); +// Sort the elements by `rating` in descending order. +// (This updates `array` in place.) +array.sort((a, b) => b.rating - a.rating); +const reduced = array.reduce((acc, element) => { + const letter = element.name.slice(0, 1); + const previousLetter = acc.slice(-1); + if (previousLetter === letter) { + return acc; + } + return acc + letter; +}, ''); +assert.sameValue(reduced, 'DGBEFHACIJK'); diff --git a/test/sendable/builtins/Array/prototype/sort/stability-5-elements.js b/test/sendable/builtins/Array/prototype/sort/stability-5-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..4d4c1624095e2d800891e78d412bf30951890b2a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/stability-5-elements.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Stability of Array.prototype.sort for an array with 5 elements. +info: | + The sort is required to be stable (that is, elements that compare equal + remain in their original order). +---*/ + +const array = [ + { name: 'A', rating: 2 }, + { name: 'B', rating: 3 }, + { name: 'C', rating: 2 }, + { name: 'D', rating: 3 }, + { name: 'E', rating: 3 }, +]; +assert.sameValue(array.length, 5); +// Sort the elements by `rating` in descending order. +// (This updates `array` in place.) +array.sort((a, b) => b.rating - a.rating); +const reduced = array.reduce((acc, element) => acc + element.name, ''); +assert.sameValue(reduced, 'BDEAC'); diff --git a/test/sendable/builtins/Array/prototype/sort/stability-513-elements.js b/test/sendable/builtins/Array/prototype/sort/stability-513-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..82267d1ac33439824be84a005d6f57888f9d60c2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/sort/stability-513-elements.js @@ -0,0 +1,555 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.sort +description: > + Stability of Array.prototype.sort for an array with 513 elements. +info: | + The sort is required to be stable (that is, elements that compare equal + remain in their original order). + The array length of 513 was chosen because until late 2018, Chakra + used to apply an unstable QuickSort for arrays with more than 512 + elements, although it used a stable insertion sort for anything else. + https://github.com/Microsoft/ChakraCore/pull/5724 +---*/ + +const array = [ + { name: 'A00', rating: 2 }, + { name: 'A01', rating: 2 }, + { name: 'A02', rating: 2 }, + { name: 'A03', rating: 2 }, + { name: 'A04', rating: 2 }, + { name: 'A05', rating: 2 }, + { name: 'A06', rating: 2 }, + { name: 'A07', rating: 2 }, + { name: 'A08', rating: 2 }, + { name: 'A09', rating: 2 }, + { name: 'A10', rating: 2 }, + { name: 'A11', rating: 2 }, + { name: 'A12', rating: 2 }, + { name: 'A13', rating: 2 }, + { name: 'A14', rating: 2 }, + { name: 'A15', rating: 2 }, + { name: 'A16', rating: 2 }, + { name: 'A17', rating: 2 }, + { name: 'A18', rating: 2 }, + { name: 'A19', rating: 2 }, + { name: 'A20', rating: 2 }, + { name: 'A21', rating: 2 }, + { name: 'A22', rating: 2 }, + { name: 'A23', rating: 2 }, + { name: 'A24', rating: 2 }, + { name: 'A25', rating: 2 }, + { name: 'A26', rating: 2 }, + { name: 'A27', rating: 2 }, + { name: 'A28', rating: 2 }, + { name: 'A29', rating: 2 }, + { name: 'A30', rating: 2 }, + { name: 'A31', rating: 2 }, + { name: 'A32', rating: 2 }, + { name: 'A33', rating: 2 }, + { name: 'A34', rating: 2 }, + { name: 'A35', rating: 2 }, + { name: 'A36', rating: 2 }, + { name: 'A37', rating: 2 }, + { name: 'A38', rating: 2 }, + { name: 'A39', rating: 2 }, + { name: 'A40', rating: 2 }, + { name: 'A41', rating: 2 }, + { name: 'A42', rating: 2 }, + { name: 'A43', rating: 2 }, + { name: 'A44', rating: 2 }, + { name: 'A45', rating: 2 }, + { name: 'A46', rating: 2 }, + { name: 'B00', rating: 3 }, + { name: 'B01', rating: 3 }, + { name: 'B02', rating: 3 }, + { name: 'B03', rating: 3 }, + { name: 'B04', rating: 3 }, + { name: 'B05', rating: 3 }, + { name: 'B06', rating: 3 }, + { name: 'B07', rating: 3 }, + { name: 'B08', rating: 3 }, + { name: 'B09', rating: 3 }, + { name: 'B10', rating: 3 }, + { name: 'B11', rating: 3 }, + { name: 'B12', rating: 3 }, + { name: 'B13', rating: 3 }, + { name: 'B14', rating: 3 }, + { name: 'B15', rating: 3 }, + { name: 'B16', rating: 3 }, + { name: 'B17', rating: 3 }, + { name: 'B18', rating: 3 }, + { name: 'B19', rating: 3 }, + { name: 'B20', rating: 3 }, + { name: 'B21', rating: 3 }, + { name: 'B22', rating: 3 }, + { name: 'B23', rating: 3 }, + { name: 'B24', rating: 3 }, + { name: 'B25', rating: 3 }, + { name: 'B26', rating: 3 }, + { name: 'B27', rating: 3 }, + { name: 'B28', rating: 3 }, + { name: 'B29', rating: 3 }, + { name: 'B30', rating: 3 }, + { name: 'B31', rating: 3 }, + { name: 'B32', rating: 3 }, + { name: 'B33', rating: 3 }, + { name: 'B34', rating: 3 }, + { name: 'B35', rating: 3 }, + { name: 'B36', rating: 3 }, + { name: 'B37', rating: 3 }, + { name: 'B38', rating: 3 }, + { name: 'B39', rating: 3 }, + { name: 'B40', rating: 3 }, + { name: 'B41', rating: 3 }, + { name: 'B42', rating: 3 }, + { name: 'B43', rating: 3 }, + { name: 'B44', rating: 3 }, + { name: 'B45', rating: 3 }, + { name: 'B46', rating: 3 }, + { name: 'C00', rating: 2 }, + { name: 'C01', rating: 2 }, + { name: 'C02', rating: 2 }, + { name: 'C03', rating: 2 }, + { name: 'C04', rating: 2 }, + { name: 'C05', rating: 2 }, + { name: 'C06', rating: 2 }, + { name: 'C07', rating: 2 }, + { name: 'C08', rating: 2 }, + { name: 'C09', rating: 2 }, + { name: 'C10', rating: 2 }, + { name: 'C11', rating: 2 }, + { name: 'C12', rating: 2 }, + { name: 'C13', rating: 2 }, + { name: 'C14', rating: 2 }, + { name: 'C15', rating: 2 }, + { name: 'C16', rating: 2 }, + { name: 'C17', rating: 2 }, + { name: 'C18', rating: 2 }, + { name: 'C19', rating: 2 }, + { name: 'C20', rating: 2 }, + { name: 'C21', rating: 2 }, + { name: 'C22', rating: 2 }, + { name: 'C23', rating: 2 }, + { name: 'C24', rating: 2 }, + { name: 'C25', rating: 2 }, + { name: 'C26', rating: 2 }, + { name: 'C27', rating: 2 }, + { name: 'C28', rating: 2 }, + { name: 'C29', rating: 2 }, + { name: 'C30', rating: 2 }, + { name: 'C31', rating: 2 }, + { name: 'C32', rating: 2 }, + { name: 'C33', rating: 2 }, + { name: 'C34', rating: 2 }, + { name: 'C35', rating: 2 }, + { name: 'C36', rating: 2 }, + { name: 'C37', rating: 2 }, + { name: 'C38', rating: 2 }, + { name: 'C39', rating: 2 }, + { name: 'C40', rating: 2 }, + { name: 'C41', rating: 2 }, + { name: 'C42', rating: 2 }, + { name: 'C43', rating: 2 }, + { name: 'C44', rating: 2 }, + { name: 'C45', rating: 2 }, + { name: 'C46', rating: 2 }, + { name: 'D00', rating: 4 }, + { name: 'D01', rating: 4 }, + { name: 'D02', rating: 4 }, + { name: 'D03', rating: 4 }, + { name: 'D04', rating: 4 }, + { name: 'D05', rating: 4 }, + { name: 'D06', rating: 4 }, + { name: 'D07', rating: 4 }, + { name: 'D08', rating: 4 }, + { name: 'D09', rating: 4 }, + { name: 'D10', rating: 4 }, + { name: 'D11', rating: 4 }, + { name: 'D12', rating: 4 }, + { name: 'D13', rating: 4 }, + { name: 'D14', rating: 4 }, + { name: 'D15', rating: 4 }, + { name: 'D16', rating: 4 }, + { name: 'D17', rating: 4 }, + { name: 'D18', rating: 4 }, + { name: 'D19', rating: 4 }, + { name: 'D20', rating: 4 }, + { name: 'D21', rating: 4 }, + { name: 'D22', rating: 4 }, + { name: 'D23', rating: 4 }, + { name: 'D24', rating: 4 }, + { name: 'D25', rating: 4 }, + { name: 'D26', rating: 4 }, + { name: 'D27', rating: 4 }, + { name: 'D28', rating: 4 }, + { name: 'D29', rating: 4 }, + { name: 'D30', rating: 4 }, + { name: 'D31', rating: 4 }, + { name: 'D32', rating: 4 }, + { name: 'D33', rating: 4 }, + { name: 'D34', rating: 4 }, + { name: 'D35', rating: 4 }, + { name: 'D36', rating: 4 }, + { name: 'D37', rating: 4 }, + { name: 'D38', rating: 4 }, + { name: 'D39', rating: 4 }, + { name: 'D40', rating: 4 }, + { name: 'D41', rating: 4 }, + { name: 'D42', rating: 4 }, + { name: 'D43', rating: 4 }, + { name: 'D44', rating: 4 }, + { name: 'D45', rating: 4 }, + { name: 'D46', rating: 4 }, + { name: 'E00', rating: 3 }, + { name: 'E01', rating: 3 }, + { name: 'E02', rating: 3 }, + { name: 'E03', rating: 3 }, + { name: 'E04', rating: 3 }, + { name: 'E05', rating: 3 }, + { name: 'E06', rating: 3 }, + { name: 'E07', rating: 3 }, + { name: 'E08', rating: 3 }, + { name: 'E09', rating: 3 }, + { name: 'E10', rating: 3 }, + { name: 'E11', rating: 3 }, + { name: 'E12', rating: 3 }, + { name: 'E13', rating: 3 }, + { name: 'E14', rating: 3 }, + { name: 'E15', rating: 3 }, + { name: 'E16', rating: 3 }, + { name: 'E17', rating: 3 }, + { name: 'E18', rating: 3 }, + { name: 'E19', rating: 3 }, + { name: 'E20', rating: 3 }, + { name: 'E21', rating: 3 }, + { name: 'E22', rating: 3 }, + { name: 'E23', rating: 3 }, + { name: 'E24', rating: 3 }, + { name: 'E25', rating: 3 }, + { name: 'E26', rating: 3 }, + { name: 'E27', rating: 3 }, + { name: 'E28', rating: 3 }, + { name: 'E29', rating: 3 }, + { name: 'E30', rating: 3 }, + { name: 'E31', rating: 3 }, + { name: 'E32', rating: 3 }, + { name: 'E33', rating: 3 }, + { name: 'E34', rating: 3 }, + { name: 'E35', rating: 3 }, + { name: 'E36', rating: 3 }, + { name: 'E37', rating: 3 }, + { name: 'E38', rating: 3 }, + { name: 'E39', rating: 3 }, + { name: 'E40', rating: 3 }, + { name: 'E41', rating: 3 }, + { name: 'E42', rating: 3 }, + { name: 'E43', rating: 3 }, + { name: 'E44', rating: 3 }, + { name: 'E45', rating: 3 }, + { name: 'E46', rating: 3 }, + { name: 'F00', rating: 3 }, + { name: 'F01', rating: 3 }, + { name: 'F02', rating: 3 }, + { name: 'F03', rating: 3 }, + { name: 'F04', rating: 3 }, + { name: 'F05', rating: 3 }, + { name: 'F06', rating: 3 }, + { name: 'F07', rating: 3 }, + { name: 'F08', rating: 3 }, + { name: 'F09', rating: 3 }, + { name: 'F10', rating: 3 }, + { name: 'F11', rating: 3 }, + { name: 'F12', rating: 3 }, + { name: 'F13', rating: 3 }, + { name: 'F14', rating: 3 }, + { name: 'F15', rating: 3 }, + { name: 'F16', rating: 3 }, + { name: 'F17', rating: 3 }, + { name: 'F18', rating: 3 }, + { name: 'F19', rating: 3 }, + { name: 'F20', rating: 3 }, + { name: 'F21', rating: 3 }, + { name: 'F22', rating: 3 }, + { name: 'F23', rating: 3 }, + { name: 'F24', rating: 3 }, + { name: 'F25', rating: 3 }, + { name: 'F26', rating: 3 }, + { name: 'F27', rating: 3 }, + { name: 'F28', rating: 3 }, + { name: 'F29', rating: 3 }, + { name: 'F30', rating: 3 }, + { name: 'F31', rating: 3 }, + { name: 'F32', rating: 3 }, + { name: 'F33', rating: 3 }, + { name: 'F34', rating: 3 }, + { name: 'F35', rating: 3 }, + { name: 'F36', rating: 3 }, + { name: 'F37', rating: 3 }, + { name: 'F38', rating: 3 }, + { name: 'F39', rating: 3 }, + { name: 'F40', rating: 3 }, + { name: 'F41', rating: 3 }, + { name: 'F42', rating: 3 }, + { name: 'F43', rating: 3 }, + { name: 'F44', rating: 3 }, + { name: 'F45', rating: 3 }, + { name: 'F46', rating: 3 }, + { name: 'G00', rating: 4 }, + { name: 'G01', rating: 4 }, + { name: 'G02', rating: 4 }, + { name: 'G03', rating: 4 }, + { name: 'G04', rating: 4 }, + { name: 'G05', rating: 4 }, + { name: 'G06', rating: 4 }, + { name: 'G07', rating: 4 }, + { name: 'G08', rating: 4 }, + { name: 'G09', rating: 4 }, + { name: 'G10', rating: 4 }, + { name: 'G11', rating: 4 }, + { name: 'G12', rating: 4 }, + { name: 'G13', rating: 4 }, + { name: 'G14', rating: 4 }, + { name: 'G15', rating: 4 }, + { name: 'G16', rating: 4 }, + { name: 'G17', rating: 4 }, + { name: 'G18', rating: 4 }, + { name: 'G19', rating: 4 }, + { name: 'G20', rating: 4 }, + { name: 'G21', rating: 4 }, + { name: 'G22', rating: 4 }, + { name: 'G23', rating: 4 }, + { name: 'G24', rating: 4 }, + { name: 'G25', rating: 4 }, + { name: 'G26', rating: 4 }, + { name: 'G27', rating: 4 }, + { name: 'G28', rating: 4 }, + { name: 'G29', rating: 4 }, + { name: 'G30', rating: 4 }, + { name: 'G31', rating: 4 }, + { name: 'G32', rating: 4 }, + { name: 'G33', rating: 4 }, + { name: 'G34', rating: 4 }, + { name: 'G35', rating: 4 }, + { name: 'G36', rating: 4 }, + { name: 'G37', rating: 4 }, + { name: 'G38', rating: 4 }, + { name: 'G39', rating: 4 }, + { name: 'G40', rating: 4 }, + { name: 'G41', rating: 4 }, + { name: 'G42', rating: 4 }, + { name: 'G43', rating: 4 }, + { name: 'G44', rating: 4 }, + { name: 'G45', rating: 4 }, + { name: 'G46', rating: 4 }, + { name: 'H00', rating: 3 }, + { name: 'H01', rating: 3 }, + { name: 'H02', rating: 3 }, + { name: 'H03', rating: 3 }, + { name: 'H04', rating: 3 }, + { name: 'H05', rating: 3 }, + { name: 'H06', rating: 3 }, + { name: 'H07', rating: 3 }, + { name: 'H08', rating: 3 }, + { name: 'H09', rating: 3 }, + { name: 'H10', rating: 3 }, + { name: 'H11', rating: 3 }, + { name: 'H12', rating: 3 }, + { name: 'H13', rating: 3 }, + { name: 'H14', rating: 3 }, + { name: 'H15', rating: 3 }, + { name: 'H16', rating: 3 }, + { name: 'H17', rating: 3 }, + { name: 'H18', rating: 3 }, + { name: 'H19', rating: 3 }, + { name: 'H20', rating: 3 }, + { name: 'H21', rating: 3 }, + { name: 'H22', rating: 3 }, + { name: 'H23', rating: 3 }, + { name: 'H24', rating: 3 }, + { name: 'H25', rating: 3 }, + { name: 'H26', rating: 3 }, + { name: 'H27', rating: 3 }, + { name: 'H28', rating: 3 }, + { name: 'H29', rating: 3 }, + { name: 'H30', rating: 3 }, + { name: 'H31', rating: 3 }, + { name: 'H32', rating: 3 }, + { name: 'H33', rating: 3 }, + { name: 'H34', rating: 3 }, + { name: 'H35', rating: 3 }, + { name: 'H36', rating: 3 }, + { name: 'H37', rating: 3 }, + { name: 'H38', rating: 3 }, + { name: 'H39', rating: 3 }, + { name: 'H40', rating: 3 }, + { name: 'H41', rating: 3 }, + { name: 'H42', rating: 3 }, + { name: 'H43', rating: 3 }, + { name: 'H44', rating: 3 }, + { name: 'H45', rating: 3 }, + { name: 'H46', rating: 3 }, + { name: 'I00', rating: 2 }, + { name: 'I01', rating: 2 }, + { name: 'I02', rating: 2 }, + { name: 'I03', rating: 2 }, + { name: 'I04', rating: 2 }, + { name: 'I05', rating: 2 }, + { name: 'I06', rating: 2 }, + { name: 'I07', rating: 2 }, + { name: 'I08', rating: 2 }, + { name: 'I09', rating: 2 }, + { name: 'I10', rating: 2 }, + { name: 'I11', rating: 2 }, + { name: 'I12', rating: 2 }, + { name: 'I13', rating: 2 }, + { name: 'I14', rating: 2 }, + { name: 'I15', rating: 2 }, + { name: 'I16', rating: 2 }, + { name: 'I17', rating: 2 }, + { name: 'I18', rating: 2 }, + { name: 'I19', rating: 2 }, + { name: 'I20', rating: 2 }, + { name: 'I21', rating: 2 }, + { name: 'I22', rating: 2 }, + { name: 'I23', rating: 2 }, + { name: 'I24', rating: 2 }, + { name: 'I25', rating: 2 }, + { name: 'I26', rating: 2 }, + { name: 'I27', rating: 2 }, + { name: 'I28', rating: 2 }, + { name: 'I29', rating: 2 }, + { name: 'I30', rating: 2 }, + { name: 'I31', rating: 2 }, + { name: 'I32', rating: 2 }, + { name: 'I33', rating: 2 }, + { name: 'I34', rating: 2 }, + { name: 'I35', rating: 2 }, + { name: 'I36', rating: 2 }, + { name: 'I37', rating: 2 }, + { name: 'I38', rating: 2 }, + { name: 'I39', rating: 2 }, + { name: 'I40', rating: 2 }, + { name: 'I41', rating: 2 }, + { name: 'I42', rating: 2 }, + { name: 'I43', rating: 2 }, + { name: 'I44', rating: 2 }, + { name: 'I45', rating: 2 }, + { name: 'I46', rating: 2 }, + { name: 'J00', rating: 2 }, + { name: 'J01', rating: 2 }, + { name: 'J02', rating: 2 }, + { name: 'J03', rating: 2 }, + { name: 'J04', rating: 2 }, + { name: 'J05', rating: 2 }, + { name: 'J06', rating: 2 }, + { name: 'J07', rating: 2 }, + { name: 'J08', rating: 2 }, + { name: 'J09', rating: 2 }, + { name: 'J10', rating: 2 }, + { name: 'J11', rating: 2 }, + { name: 'J12', rating: 2 }, + { name: 'J13', rating: 2 }, + { name: 'J14', rating: 2 }, + { name: 'J15', rating: 2 }, + { name: 'J16', rating: 2 }, + { name: 'J17', rating: 2 }, + { name: 'J18', rating: 2 }, + { name: 'J19', rating: 2 }, + { name: 'J20', rating: 2 }, + { name: 'J21', rating: 2 }, + { name: 'J22', rating: 2 }, + { name: 'J23', rating: 2 }, + { name: 'J24', rating: 2 }, + { name: 'J25', rating: 2 }, + { name: 'J26', rating: 2 }, + { name: 'J27', rating: 2 }, + { name: 'J28', rating: 2 }, + { name: 'J29', rating: 2 }, + { name: 'J30', rating: 2 }, + { name: 'J31', rating: 2 }, + { name: 'J32', rating: 2 }, + { name: 'J33', rating: 2 }, + { name: 'J34', rating: 2 }, + { name: 'J35', rating: 2 }, + { name: 'J36', rating: 2 }, + { name: 'J37', rating: 2 }, + { name: 'J38', rating: 2 }, + { name: 'J39', rating: 2 }, + { name: 'J40', rating: 2 }, + { name: 'J41', rating: 2 }, + { name: 'J42', rating: 2 }, + { name: 'J43', rating: 2 }, + { name: 'J44', rating: 2 }, + { name: 'J45', rating: 2 }, + { name: 'J46', rating: 2 }, + { name: 'K00', rating: 2 }, + { name: 'K01', rating: 2 }, + { name: 'K02', rating: 2 }, + { name: 'K03', rating: 2 }, + { name: 'K04', rating: 2 }, + { name: 'K05', rating: 2 }, + { name: 'K06', rating: 2 }, + { name: 'K07', rating: 2 }, + { name: 'K08', rating: 2 }, + { name: 'K09', rating: 2 }, + { name: 'K10', rating: 2 }, + { name: 'K11', rating: 2 }, + { name: 'K12', rating: 2 }, + { name: 'K13', rating: 2 }, + { name: 'K14', rating: 2 }, + { name: 'K15', rating: 2 }, + { name: 'K16', rating: 2 }, + { name: 'K17', rating: 2 }, + { name: 'K18', rating: 2 }, + { name: 'K19', rating: 2 }, + { name: 'K20', rating: 2 }, + { name: 'K21', rating: 2 }, + { name: 'K22', rating: 2 }, + { name: 'K23', rating: 2 }, + { name: 'K24', rating: 2 }, + { name: 'K25', rating: 2 }, + { name: 'K26', rating: 2 }, + { name: 'K27', rating: 2 }, + { name: 'K28', rating: 2 }, + { name: 'K29', rating: 2 }, + { name: 'K30', rating: 2 }, + { name: 'K31', rating: 2 }, + { name: 'K32', rating: 2 }, + { name: 'K33', rating: 2 }, + { name: 'K34', rating: 2 }, + { name: 'K35', rating: 2 }, + { name: 'K36', rating: 2 }, + { name: 'K37', rating: 2 }, + { name: 'K38', rating: 2 }, + { name: 'K39', rating: 2 }, + { name: 'K40', rating: 2 }, + { name: 'K41', rating: 2 }, + { name: 'K42', rating: 2 }, +]; +assert.sameValue(array.length, 513); +// Sort the elements by `rating` in descending order. +// (This updates `array` in place.) +array.sort((a, b) => b.rating - a.rating); +const reduced = array.reduce((acc, element) => { + const letter = element.name.slice(0, 1); + const previousLetter = acc.slice(-1); + if (previousLetter === letter) { + return acc; + } + return acc + letter; +}, ''); +assert.sameValue(reduced, 'DGBEFHACIJK'); diff --git a/test/sendable/builtins/Array/prototype/splice/15.4.4.12-9-a-1.js b/test/sendable/builtins/Array/prototype/splice/15.4.4.12-9-a-1.js new file mode 100644 index 0000000000000000000000000000000000000000..9b4d3faf62ef3f5eb950c9cc2969f8e6198bbf3b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/15.4.4.12-9-a-1.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + Array.prototype.splice - 'from' is the result of + ToString(actualStart+k) in an Array +---*/ + +var arrObj = [1, 2, 3]; +var newArrObj = arrObj.splice(-2, 1); +assert.sameValue(newArrObj.length, 1, 'newArrObj.length'); +assert.sameValue(newArrObj[0], 2, 'newArrObj[0]'); diff --git a/test/sendable/builtins/Array/prototype/splice/15.4.4.12-9-c-ii-1.js b/test/sendable/builtins/Array/prototype/splice/15.4.4.12-9-c-ii-1.js new file mode 100644 index 0000000000000000000000000000000000000000..d40f5353a5be6b41cb063e7239694250da910681 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/15.4.4.12-9-c-ii-1.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + Array.prototype.splice will splice an array even when + Array.prototype has index '0' set to read-only and 'fromPresent' + less than 'actualDeleteCount (Step 9.c.ii) +---*/ + +var arr = ["a", "b", "c"]; +SendableArray.prototype[0] = "test"; +var newArr = arr.splice(2, 1, "d"); +var verifyValue = false; +verifyValue = arr.length === 3 && arr[0] === "a" && arr[1] === "b" && arr[2] === "d" && + newArr[0] === "c" && newArr.length === 1; +var verifyEnumerable = false; +for (var p in newArr) { + if (newArr.hasOwnProperty("0") && p === "0") { + verifyEnumerable = true; + } +} +var verifyWritable = false; +newArr[0] = 12; +verifyWritable = newArr[0] === 12; +var verifyConfigurable = false; +delete newArr[0]; +verifyConfigurable = newArr.hasOwnProperty("0"); +assert(verifyValue, 'verifyValue !== true'); +assert.sameValue(verifyConfigurable, false, 'verifyConfigurable'); +assert(verifyEnumerable, 'verifyEnumerable !== true'); +assert(verifyWritable, 'verifyWritable !== true'); diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T1.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..d8d02696a2a4f2ee1fff29f752c9c60666a306e8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T1.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: length > deleteCount > start = 0, itemCount = 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(0, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(0,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(0,3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(0,3); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(0,3); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(0,3); arr[2] === 2. Actual: ' + (arr[2])); +} +if (x.length !== 1) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(0,3); x.length === 1. Actual: ' + (x.length)); +} +if (x[0] !== 3) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(0,3); x[0] === 3. Actual: ' + (x[0])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T2.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..d01fad6be7121910e3a855e03a64c57eb5a13fd7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T2.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: length > deleteCount > start = 0, itemCount > 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(0, 3, 4, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(0,3,4,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(0,3,4,5); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(0,3,4,5); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(0,3,4,5); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(0,3,4,5); arr[2] === 2. Actual: ' + (arr[2])); +} +if (x.length !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(0,3,4,5); x.length === 3. Actual: ' + (x.length)); +} +if (x[0] !== 4) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(0,3,4,5); x[0] === 4. Actual: ' + (x[0])); +} +if (x[1] !== 5) { + throw new Test262Error('#8: var x = [0,1,2,3]; var arr = x.splice(0,3,4,5); x[1] === 5. Actual: ' + (x[1])); +} +if (x[2] !== 3) { + throw new Test262Error('#9: var x = [0,1,2,3]; var arr = x.splice(0,3,4,5); x[2] === 3. Actual: ' + (x[2])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T3.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..7d4d45796d64c4b2a334bca54ac82fe6047509a2 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T3.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: length = deleteCount > start = 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(0, 4); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(0,4); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 4) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(0,4); arr.length === 4. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(0,4); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(0,4); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(0,4); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(0,4); arr[3] === 3. Actual: ' + (arr[3])); +} +if (x.length !== 0) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(0,4); x.length === 0. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T4.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..f288423e97e413774431f2d21b57135e1215565b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T4.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: length > deleteCount > start > 0, itemCount > 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(1, 3, 4, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(1,3,4,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(1,3,4,5); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 1) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(1,3,4,5); arr[0] === 1. Actual: ' + (arr[0])); +} +if (arr[1] !== 2) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(1,3,4,5); arr[1] === 2. Actual: ' + (arr[1])); +} +if (arr[2] !== 3) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(1,3,4,5); arr[2] === 3. Actual: ' + (arr[2])); +} +if (x.length !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(1,3,4,5); x.length === 3. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(1,3,4,5); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 4) { + throw new Test262Error('#8: var x = [0,1,2,3]; var arr = x.splice(1,3,4,5); x[1] === 4. Actual: ' + (x[1])); +} +if (x[2] !== 5) { + throw new Test262Error('#9: var x = [0,1,2,3]; var arr = x.splice(1,3,4,5); x[2] === 5. Actual: ' + (x[2])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T5.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..f12d55e90e3e4956d156e5330dbc06be7114287a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T5.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: deleteCount > length > start = 0, itemCount = 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(0, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(0,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 4) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(0,5); arr.length === 4. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(0,5); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(0,5); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(0,5); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(0,5); arr[3] === 3. Actual: ' + (arr[3])); +} +if (x.length !== 0) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(0,5); x.length === 0. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T6.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..c428a6191978572d31cd6f81032b6db5d22677b8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.1_T6.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: length = deleteCount > start > 0, itemCount > 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(1, 4, 4, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(1,4,4,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(1,4,4,5); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 1) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(1,4,4,5); arr[0] === 1. Actual: ' + (arr[0])); +} +if (arr[1] !== 2) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(1,4,4,5); arr[1] === 2. Actual: ' + (arr[1])); +} +if (arr[2] !== 3) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(1,4,4,5); arr[2] === 3. Actual: ' + (arr[2])); +} +if (x.length !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(1,4,4,5); x.length === 3. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(1,4,4,5); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 4) { + throw new Test262Error('#8: var x = [0,1,2,3]; var arr = x.splice(1,4,4,5); x[1] === 4. Actual: ' + (x[1])); +} +if (x[2] !== 5) { + throw new Test262Error('#9: var x = [0,1,2,3]; var arr = x.splice(1,4,4,5); x[2] === 5. Actual: ' + (x[2])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T1.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..a5f577c0b6478b316b479de97ba5d878d06eb40f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T1.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If deleteCount is negative, use 0 +esid: sec-array.prototype.splice +description: -length = start < deleteCount < 0, itemCount = 0 +---*/ + +var x = [0, 1]; +var arr = x.splice(-2, -1); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(-2,-1); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(-2,-1); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 2) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(-2,-1); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(-2,-1); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(-2,-1); x[1] === 1. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T2.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..b63c6e72dbea70a8e9f02aa11ebfc5a315529307 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T2.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If deleteCount is negative, use 0 +esid: sec-array.prototype.splice +description: -length < start = deleteCount < 0, itemCount = 0 +---*/ + +var x = [0, 1]; +var arr = x.splice(-1, -1); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(-1,-1); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(-1,-1); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 2) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(-1,-1); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(-1,-1); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(-1,-1); x[1] === 1. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T3.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..442a068d2d4c88ce0a03de5364fc8ba9d16f51f8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T3.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If deleteCount is negative, use 0 +esid: sec-array.prototype.splice +description: -length = start < deleteCount < 0, itemCount > 0 +---*/ + +var x = [0, 1]; +var arr = x.splice(-2, -1, 2, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(-2,-1,2,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(-2,-1,2,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 4) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(-2,-1,2,3); x.length === 4. Actual: ' + (x.length)); +} +if (x[0] !== 2) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(-2,-1,2,3); x[0] === 2. Actual: ' + (x[0])); +} +if (x[1] !== 3) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(-2,-1,2,3); x[1] === 3. Actual: ' + (x[1])); +} +if (x[2] !== 0) { + throw new Test262Error('#5: var x = [0,1]; var arr = x.splice(-2,-1,2,3); x[2] === 0. Actual: ' + (x[2])); +} +if (x[3] !== 1) { + throw new Test262Error('#6: var x = [0,1]; var arr = x.splice(-2,-1,2,3); x[3] === 1. Actual: ' + (x[3])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T4.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..11461eee38105e6e831ec85874b3290bec1a9c8a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T4.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If deleteCount is negative, use 0 +esid: sec-array.prototype.splice +description: -length < start = deleteCount < 0, itemCount > 0 +---*/ + +var x = [0, 1]; +var arr = x.splice(-1, -1, 2, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(-1,-1,2,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(-1,-1,2,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 4) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(-1,-1,2,3); x.length === 4. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(-1,-1,2,3); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 2) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(-1,-1,2,3); x[1] === 2. Actual: ' + (x[1])); +} +if (x[2] !== 3) { + throw new Test262Error('#5: var x = [0,1]; var arr = x.splice(-1,-1,2,3); x[2] === 3. Actual: ' + (x[2])); +} +if (x[3] !== 1) { + throw new Test262Error('#6: var x = [0,1]; var arr = x.splice(-1,-1,2,3); x[3] === 1. Actual: ' + (x[3])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T5.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..a68a5c119ff9cc857dc0f42d99070b6d17fbcae9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.2_T5.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If deleteCount is negative, use 0 +esid: sec-array.prototype.splice +description: start < -length < deleteCount < 0, itemCount > 0 +---*/ + +var x = [0, 1]; +var arr = x.splice(-3, -1, 2, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(-3,-1,2,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(-3,-1,2,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 4) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(-3,-1,2,3); x.length === 4. Actual: ' + (x.length)); +} +if (x[0] !== 2) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(-3,-1,2,3); x[0] === 2. Actual: ' + (x[0])); +} +if (x[1] !== 3) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(-3,-1,2,3); x[1] === 3. Actual: ' + (x[1])); +} +if (x[2] !== 0) { + throw new Test262Error('#5: var x = [0,1]; var arr = x.splice(-3,-1,2,3); x[2] === 0. Actual: ' + (x[2])); +} +if (x[3] !== 1) { + throw new Test262Error('#6: var x = [0,1]; var arr = x.splice(-3,-1,2,3); x[3] === 1. Actual: ' + (x[3])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T1.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..b56c626b73acf1ecc68b85fe5409623accef73cb --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T1.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If deleteCount is negative, use 0 +esid: sec-array.prototype.splice +description: -length < deleteCount < start = 0, itemCount = 0 +---*/ + +var x = [0, 1]; +var arr = x.splice(0, -1); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(0,-1); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(0,-1); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 2) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(0,-1); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(0,-1); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(0,-1); x[1] === 1. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T2.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..a27910b4437841111a3de43935ad570444a1d855 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T2.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If deleteCount is negative, use 0 +esid: sec-array.prototype.splice +description: -length = -start < deleteCount < 0, itemCount = 0 +---*/ + +var x = [0, 1]; +var arr = x.splice(2, -1); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(2,-1); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(2,-1); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 2) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(2,-1); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(2,-1); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(2,-1); x[1] === 1. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T3.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..96d4bb6b4bf68726a691e520c89ac900e3a57c8b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T3.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If deleteCount is negative, use 0 +esid: sec-array.prototype.splice +description: -length < deleteCount < start = 0, itemCount > 0 +---*/ + +var x = [0, 1]; +var arr = x.splice(0, -1, 2, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(0,-1,2,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(0,-1,2,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 4) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(0,-1,2,3); x.length === 4. Actual: ' + (x.length)); +} +if (x[0] !== 2) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(0,-1,2,3); x[0] === 2. Actual: ' + (x[0])); +} +if (x[1] !== 3) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(0,-1,2,3); x[1] === 3. Actual: ' + (x[1])); +} +if (x[2] !== 0) { + throw new Test262Error('#5: var x = [0,1]; var arr = x.splice(0,-1,2,3); x[2] === 0. Actual: ' + (x[2])); +} +if (x[3] !== 1) { + throw new Test262Error('#6: var x = [0,1]; var arr = x.splice(0,-1,2,3); x[3] === 1. Actual: ' + (x[3])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T4.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..a61cc2aa3a51d433fd61cb5bc7f8e66982113223 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T4.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If deleteCount is negative, use 0 +esid: sec-array.prototype.splice +description: -length = -start < deleteCount < 0, itemCount > 0 +---*/ + +var x = [0, 1]; +var arr = x.splice(2, -1, 2, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(2,-1,2,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(2,-1,2,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 4) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(2,-1,2,3); x.length === 4. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(2,-1,2,3); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(2,-1,2,3); x[1] === 1. Actual: ' + (x[1])); +} +if (x[2] !== 2) { + throw new Test262Error('#5: var x = [0,1]; var arr = x.splice(2,-1,2,3); x[2] === 2. Actual: ' + (x[2])); +} +if (x[3] !== 3) { + throw new Test262Error('#6: var x = [0,1]; var arr = x.splice(2,-1,2,3); x[3] === 3. Actual: ' + (x[3])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T5.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..24e602547e777b4187e6bd8483f965c34bfa2690 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.3_T5.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is positive, use min(start, length). + If deleteCount is negative, use 0 +esid: sec-array.prototype.splice +description: -start < -length < deleteCount < 0, itemCount > 0 +---*/ + +var x = [0, 1]; +var arr = x.splice(3, -1, 2, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(3,-1,2,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(3,-1,2,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 4) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(3,-1,2,3); x.length === 4. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(3,-1,2,3); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(3,-1,2,3); x[1] === 1. Actual: ' + (x[1])); +} +if (x[2] !== 2) { + throw new Test262Error('#5: var x = [0,1]; var arr = x.splice(3,-1,2,3); x[2] === 2. Actual: ' + (x[2])); +} +if (x[3] !== 3) { + throw new Test262Error('#6: var x = [0,1]; var arr = x.splice(3,-1,2,3); x[3] === 3. Actual: ' + (x[3])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T1.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..9d30278c2e01b95b43228a4cf15713ea5cd021c1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T1.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: length = -start > deleteCount > 0, itemCount = 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(-4, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(-4,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(-4,3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(-4,3); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(-4,3); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(-4,3); arr[2] === 2. Actual: ' + (arr[2])); +} +if (x.length !== 1) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(-4,3); x.length === 1. Actual: ' + (x.length)); +} +if (x[0] !== 3) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(-4,3); x[0] === 3. Actual: ' + (x[0])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T2.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..882da8ef1f92d2a359653be4611295c4e8859bc8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T2.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: length = -start > deleteCount > 0, itemCount > 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(-4, 3, 4, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(-4,3,4,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(-4,3,4,5); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(-4,3,4,5); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(-4,3,4,5); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(-4,3,4,5); arr[2] === 2. Actual: ' + (arr[2])); +} +if (x.length !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(-4,3,4,5); x.length === 3. Actual: ' + (x.length)); +} +if (x[0] !== 4) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(-4,3,4,5); x[0] === 4. Actual: ' + (x[0])); +} +if (x[1] !== 5) { + throw new Test262Error('#8: var x = [0,1,2,3]; var arr = x.splice(-4,3,4,5); x[1] === 5. Actual: ' + (x[1])); +} +if (x[2] !== 3) { + throw new Test262Error('#9: var x = [0,1,2,3]; var arr = x.splice(-4,3,4,5); x[2] === 3. Actual: ' + (x[2])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T3.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..b73e229c93f3af298597842dd294e2a073355d5c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T3.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: -start > length = deleteCount > 0, itemCount = 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(-5, 4); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(-5,4); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 4) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(-5,4); arr.length === 4. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(-5,4); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(-5,4); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(-5,4); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(-5,4); arr[3] === 3. Actual: ' + (arr[3])); +} +if (x.length !== 0) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(-5,4); x.length === 0. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T4.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..647c3798950cba888062b2147b829c146709cf35 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T4.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: length > -start = deleteCount > 0, itemCount > 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(-3, 3, 4, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(-3,3,4,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(-3,3,4,5); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 1) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(-3,3,4,5); arr[0] === 1. Actual: ' + (arr[0])); +} +if (arr[1] !== 2) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(-3,3,4,5); arr[1] === 2. Actual: ' + (arr[1])); +} +if (arr[2] !== 3) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(-3,3,4,5); arr[2] === 3. Actual: ' + (arr[2])); +} +if (x.length !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(-3,3,4,5); x.length === 3. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(-3,3,4,5); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 4) { + throw new Test262Error('#8: var x = [0,1,2,3]; var arr = x.splice(-3,3,4,5); x[1] === 4. Actual: ' + (x[1])); +} +if (x[2] !== 5) { + throw new Test262Error('#9: var x = [0,1,2,3]; var arr = x.splice(-3,3,4,5); x[2] === 5. Actual: ' + (x[2])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T5.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..38fa59c31003086c352144001279c04d4be304ec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T5.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: -start > deleteCount > length > 0, itemCount = 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(-9, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(-9,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 4) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(-9,5); arr.length === 4. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(-9,5); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(-9,5); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(-9,5); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(-9,5); arr[3] === 3. Actual: ' + (arr[3])); +} +if (x.length !== 0) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(-9,5); x.length === 0. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T6.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..75ffc42df3c58c1fd0a9d96b756b7f898c56741b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.4_T6.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + If start is negative, use max(start + length, 0). + If deleteCount is positive, use min(deleteCount, length - start) +esid: sec-array.prototype.splice +description: length = deleteCount > -start > 0, itemCount > 0 +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(-3, 4, 4, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(-3,4,4,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(-3,4,4,5); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 1) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(-3,4,4,5); arr[0] === 1. Actual: ' + (arr[0])); +} +if (arr[1] !== 2) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(-3,4,4,5); arr[1] === 2. Actual: ' + (arr[1])); +} +if (arr[2] !== 3) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(-3,4,4,5); arr[2] === 3. Actual: ' + (arr[2])); +} +if (x.length !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(-3,4,4,5); x.length === 3. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(-3,4,4,5); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 4) { + throw new Test262Error('#8: var x = [0,1,2,3]; var arr = x.splice(-3,4,4,5); x[1] === 4. Actual: ' + (x[1])); +} +if (x[2] !== 5) { + throw new Test262Error('#9: var x = [0,1,2,3]; var arr = x.splice(-3,4,4,5); x[2] === 5. Actual: ' + (x[2])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.5_T1.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.5_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..7f4778e6902950a27055849a4a59c25b0e2af9ab --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.5_T1.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Splice with undefined arguments +esid: sec-array.prototype.splice +description: start === undefined, end === undefined +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(undefined, undefined); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(undefined, undefined); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(undefined, undefined); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 4) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(undefined, undefined); x.length === 4. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(undefined, undefined); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(undefined, undefined); x[1] === 1. Actual: ' + (x[1])); +} +if (x[2] !== 2) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(undefined, undefined); x[2] === 2. Actual: ' + (x[2])); +} +if (x[3] !== 3) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(undefined, undefined); x[3] === 3. Actual: ' + (x[3])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.5_T2.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.5_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..9fe8fc521de03b57e16d92181fd9dd8539738c94 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A1.5_T2.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Splice with undefined arguments +esid: sec-array.prototype.splice +description: end === undefined +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(1, undefined); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(1,undefined); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(1,undefined); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 4) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(1,undefined); x.length === 4. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(1,undefined); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(1,undefined); x[1] === 1. Actual: ' + (x[1])); +} +if (x[2] !== 2) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(1,undefined); x[2] === 2. Actual: ' + (x[2])); +} +if (x[3] !== 3) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(1,undefined); x[3] === 3. Actual: ' + (x[3])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T1.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..d5bb2dc41eef9a25709853c66e6ae3f1779c60ea --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T1.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from start +esid: sec-array.prototype.splice +description: start is not integer +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(1.5, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(1.5,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(1.5,3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 1) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(1.5,3); arr[0] === 1. Actual: ' + (arr[0])); +} +if (arr[1] !== 2) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(1.5,3); arr[1] === 2. Actual: ' + (arr[1])); +} +if (arr[2] !== 3) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(1.5,3); arr[2] === 3. Actual: ' + (arr[2])); +} +if (x.length !== 1) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(1.5,3); x.length === 1. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(1.5,3); x[0] === 0. Actual: ' + (x[0])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T2.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..895463049f19f63a56d6d7527a2ce859ed817a1a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T2.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from start +esid: sec-array.prototype.splice +description: start = NaN +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(NaN, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(NaN,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(NaN,3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(NaN,3); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(NaN,3); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(NaN,3); arr[2] === 2. Actual: ' + (arr[2])); +} +if (x.length !== 1) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(NaN,3); x.length === 1. Actual: ' + (x.length)); +} +if (x[0] !== 3) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(NaN,3); x[0] === 3. Actual: ' + (x[0])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T3.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..f3176e81f0a1e079e0a903e486086acfadd16a08 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T3.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from start +esid: sec-array.prototype.splice +description: start = Infinity +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(Number.POSITIVE_INFINITY, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(Number.POSITIVE_INFINITY,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(Number.POSITIVE_INFINITY,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var x = x.splice(Number.POSITIVE_INFINITY,3); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var x = x.splice(Number.POSITIVE_INFINITY,3); x[1] === 1. Actual: ' + (x[1])); +} +if (x[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var x = x.splice(Number.POSITIVE_INFINITY,3); x[2] === 2. Actual: ' + (x[2])); +} +if (x[3] !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var x = x.splice(Number.POSITIVE_INFINITY,3); x[3] === 3. Actual: ' + (x[3])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T4.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..407bf7ed84f62681375d32f419315b6476c6da55 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T4.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from start +esid: sec-array.prototype.splice +description: start = -Infinity +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(Number.NEGATIVE_INFINITY, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(Number.NEGATIVE_INFINITY,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(Number.NEGATIVE_INFINITY,3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(Number.NEGATIVE_INFINITY,3); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(Number.NEGATIVE_INFINITY,3); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(Number.NEGATIVE_INFINITY,3); arr[2] === 2. Actual: ' + (arr[2])); +} +if (x.length !== 1) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(Number.NEGATIVE_INFINITY,3); x.length === 1. Actual: ' + (x.length)); +} +if (x[0] !== 3) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(Number.NEGATIVE_INFINITY,3); x[0] === 3. Actual: ' + (x[0])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T5.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..b8e5be100b5fe019f4248b974bd658323af3cfbc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.1_T5.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from start +esid: sec-array.prototype.splice +description: ToInteger use ToNumber +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice({ + valueOf: function() { + return 0 + }, + toString: function() { + return 3 + } +}, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice({valueOf: function() {return 0}, toString: function() {return 3}},3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice({valueOf: function() {return 0}, toString: function() {return 3}},3); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice({valueOf: function() {return 0}, toString: function() {return 3}},3); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice({valueOf: function() {return 0}, toString: function() {return 3}},3); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice({valueOf: function() {return 0}, toString: function() {return 3}},3); arr[2] === 2. Actual: ' + (arr[2])); +} +if (x.length !== 1) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice({valueOf: function() {return 0}, toString: function() {return 3}},3); x.length === 1. Actual: ' + (x.length)); +} +if (x[0] !== 3) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice({valueOf: function() {return 0}, toString: function() {return 3}},3); x[0] === 3. Actual: ' + (x[0])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T1.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..5749771bd2450e9897947e56e3c442399ccdaa31 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T1.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from deleteCount +esid: sec-array.prototype.splice +description: deleteCount is not integer +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(1, 3.5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(1,3.5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(1,3.5); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 1) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(1,3.5); arr[0] === 1. Actual: ' + (arr[0])); +} +if (arr[1] !== 2) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(1,3.5); arr[1] === 2. Actual: ' + (arr[1])); +} +if (arr[2] !== 3) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(1,3.5); arr[2] === 3. Actual: ' + (arr[2])); +} +if (x.length !== 1) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(1,3.5); x.length === 1. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(1,3.5); x[0] === 0. Actual: ' + (x[0])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T2.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..1e2545523f07274010917c5215850e83e611e1f4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T2.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from deleteCount +esid: sec-array.prototype.splice +description: deleteCount = NaN +---*/ + +var x = [0, 1]; +var arr = x.splice(0, NaN); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(0,NaN); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(0,NaN); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 2) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(0,NaN); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(0,NaN); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(0,NaN); x[1] === 1. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T3.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..c72c12c12ed3a744156af40e85d76889fcbd6165 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T3.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from deleteCount +esid: sec-array.prototype.splice +description: deleteCount = Infinity +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(0, Number.POSITIVE_INFINITY); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(0,Number.POSITIVE_INFINITY); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 4) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(0,Number.POSITIVE_INFINITY); arr.length === 4. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(0,Number.POSITIVE_INFINITY); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(0,Number.POSITIVE_INFINITY); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(0,Number.POSITIVE_INFINITY); arr[2] === 2. Actual: ' + (arr[2])); +} +if (arr[3] !== 3) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(0,Number.POSITIVE_INFINITY); arr[3] === 3. Actual: ' + (arr[3])); +} +if (x.length !== 0) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(0,Number.POSITIVE_INFINITY); x.length === 0. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T4.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..b0d9c0af2f9593fe86e05c26261a1252798740fe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T4.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from deleteCount +esid: sec-array.prototype.splice +description: deleteCount = -Infinity +---*/ + +var x = [0, 1]; +var arr = x.splice(0, Number.NEGATIVE_INFINITY); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#0: var x = [0,1]; var arr = x.splice(0,Number.NEGATIVE_INFINITY); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var x = [0,1]; var arr = x.splice(0,Number.NEGATIVE_INFINITY); arr.length === 0. Actual: ' + (arr.length)); +} +if (x.length !== 2) { + throw new Test262Error('#2: var x = [0,1]; var arr = x.splice(0,Number.NEGATIVE_INFINITY); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#3: var x = [0,1]; var arr = x.splice(0,Number.NEGATIVE_INFINITY); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#4: var x = [0,1]; var arr = x.splice(0,Number.NEGATIVE_INFINITY); x[1] === 1. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T5.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..a535879090e750f3fbd2b7271b0a4e0dcb6b4d96 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2.2_T5.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Operator use ToInteger from deleteCount +esid: sec-array.prototype.splice +description: ToInteger use ToNumber +---*/ + +var x = [0, 1, 2, 3]; +var arr = x.splice(0, { + valueOf: function() { + return 3 + }, + toString: function() { + return 0 + } +}); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "Array" + "]") { + throw new Test262Error('#1: var x = [0,1,2,3]; var arr = x.splice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var x = [0,1,2,3]; var arr = x.splice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var x = [0,1,2,3]; var arr = x.splice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var x = [0,1,2,3]; var arr = x.splice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var x = [0,1,2,3]; var arr = x.splice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); arr[2] === 2. Actual: ' + (arr[2])); +} +if (x.length !== 1) { + throw new Test262Error('#6: var x = [0,1,2,3]; var arr = x.splice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); x.length === 1. Actual: ' + (x.length)); +} +if (x[0] !== 3) { + throw new Test262Error('#7: var x = [0,1,2,3]; var arr = x.splice(0,{valueOf: function() {return 3}, toString: function() {return 0}}); x[0] === 3. Actual: ' + (x[0])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T1.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..c515fb81b5da11c81d966f2d3dc7fcd910164b89 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T1.js @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The splice function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.splice +description: > + If start is positive, use min(start, length). If deleteCount is + positive, use min(deleteCount, length - start) +---*/ + +var obj = { + 0: 0, + 1: 1, + 2: 2, + 3: 3 +}; +obj.length = 4; +obj.splice = SendableArray.prototype.splice; +var arr = obj.splice(0, 3, 4, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "SendableArray" + "]") { + throw new Test262Error('#1: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,3,4,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,3,4,5); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,3,4,5); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,3,4,5); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,3,4,5); arr[2] === 2. Actual: ' + (arr[2])); +} +if (obj.length !== 3) { + throw new Test262Error('#6: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,3,4,5); obj.length === 3. Actual: ' + (obj.length)); +} +if (obj[0] !== 4) { + throw new Test262Error('#7: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,3,4,5); obj[0] === 4. Actual: ' + (obj[0])); +} +if (obj[1] !== 5) { + throw new Test262Error('#8: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,3,4,5); obj[1] === 5. Actual: ' + (obj[1])); +} +if (obj[2] !== 3) { + throw new Test262Error('#9: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,3,4,5); obj[2] === 3. Actual: ' + (obj[2])); +} +if (obj[3] !== undefined) { + throw new Test262Error('#10: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,3,4,5); obj[3] === undefined. Actual: ' + (obj[3])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T2.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..620bf3e7974f4042846e25310747e9c779b1474e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T2.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The splice function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.splice +description: > + If start is negative, use max(start + length, 0). If deleteCount + is negative, use 0 +---*/ + +var obj = { + 0: 0, + 1: 1 +}; +obj.length = 2; +obj.splice = SendableArray.prototype.splice; +var arr = obj.splice(-2, -1, 2, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "SendableArray" + "]") { + throw new Test262Error('#0: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-2,-1,2,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-2,-1,2,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (obj.length !== 4) { + throw new Test262Error('#2: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-2,-1,2,3); obj.length === 4. Actual: ' + (obj.length)); +} +if (obj[0] !== 2) { + throw new Test262Error('#3: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-2,-1,2,3); obj[0] === 2. Actual: ' + (obj[0])); +} +if (obj[1] !== 3) { + throw new Test262Error('#4: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-2,-1,2,3); obj[1] === 3. Actual: ' + (obj[1])); +} +if (obj[2] !== 0) { + throw new Test262Error('#5: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-2,-1,2,3); obj[2] === 0. Actual: ' + (obj[2])); +} +if (obj[3] !== 1) { + throw new Test262Error('#6: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-2,-1,2,3); obj[3] === 1. Actual: ' + (obj[3])); +} +if (obj[4] !== undefined) { + throw new Test262Error('#7: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-2,-1,2,3); obj[4] === undefined. Actual: ' + (obj[4])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T3.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..f52b216ab21199e425c0c5e7aed61d6d0260ea9d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T3.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The splice function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.splice +description: > + If start is positive, use min(start, length). If deleteCount is + negative, use 0 +---*/ + +var obj = { + 0: 0, + 1: 1 +}; +obj.length = 2; +obj.splice = SendableArray.prototype.splice; +var arr = obj.splice(0, -1, 2, 3); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "SendableArray" + "]") { + throw new Test262Error('#0: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,-1,2,3); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 0) { + throw new Test262Error('#1: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,-1,2,3); arr.length === 0. Actual: ' + (arr.length)); +} +if (obj.length !== 4) { + throw new Test262Error('#2: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,-1,2,3); obj.length === 4. Actual: ' + (obj.length)); +} +if (obj[0] !== 2) { + throw new Test262Error('#3: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,-1,2,3); obj[0] === 2. Actual: ' + (obj[0])); +} +if (obj[1] !== 3) { + throw new Test262Error('#4: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,-1,2,3); obj[1] === 3. Actual: ' + (obj[1])); +} +if (obj[2] !== 0) { + throw new Test262Error('#5: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,-1,2,3); obj[2] === 0. Actual: ' + (obj[2])); +} +if (obj[3] !== 1) { + throw new Test262Error('#6: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,-1,2,3); obj[3] === 1. Actual: ' + (obj[3])); +} +if (obj[4] !== undefined) { + throw new Test262Error('#7: var obj = {0:0,1:1}; obj.length = 2; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(0,-1,2,3); obj[4] === undefined. Actual: ' + (obj[4])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T4.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..53a688a314e6b27441b0712ac64036759f02094f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A2_T4.js @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The splice function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.splice +description: > + If start is negative, use max(start + length, 0). If deleteCount + is positive, use min(deleteCount, length - start) +---*/ + +var obj = { + 0: 0, + 1: 1, + 2: 2, + 3: 3 +}; +obj.length = 4; +obj.splice = SendableArray.prototype.splice; +var arr = obj.splice(-4, 3, 4, 5); +arr.getClass = Object.prototype.toString; +if (arr.getClass() !== "[object " + "SendableArray" + "]") { + throw new Test262Error('#1: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-4,3,4,5); arr is Array object. Actual: ' + (arr.getClass())); +} +if (arr.length !== 3) { + throw new Test262Error('#2: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-4,3,4,5); arr.length === 3. Actual: ' + (arr.length)); +} +if (arr[0] !== 0) { + throw new Test262Error('#3: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-4,3,4,5); arr[0] === 0. Actual: ' + (arr[0])); +} +if (arr[1] !== 1) { + throw new Test262Error('#4: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-4,3,4,5); arr[1] === 1. Actual: ' + (arr[1])); +} +if (arr[2] !== 2) { + throw new Test262Error('#5: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-4,3,4,5); arr[2] === 2. Actual: ' + (arr[2])); +} +if (obj.length !== 3) { + throw new Test262Error('#6: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-4,3,4,5); obj.length === 3. Actual: ' + (obj.length)); +} +if (obj[0] !== 4) { + throw new Test262Error('#7: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-4,3,4,5); obj[0] === 4. Actual: ' + (obj[0])); +} +if (obj[1] !== 5) { + throw new Test262Error('#8: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-4,3,4,5); obj[1] === 5. Actual: ' + (obj[1])); +} +if (obj[2] !== 3) { + throw new Test262Error('#9: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-4,3,4,5); obj[2] === 3. Actual: ' + (obj[2])); +} +if (obj[3] !== undefined) { + throw new Test262Error('#10: var obj = {0:0,1:1,2:2,3:3}; obj.length = 4; obj.splice = SendableArray.prototype.splice; var arr = obj.splice(-4,3,4,5); obj[3] === undefined. Actual: ' + (obj[3])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A3_T1.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..18e9f4ae7a1ba0921f1f25a6527466e19eff94ca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A3_T1.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.splice +description: length is arbitrarily +---*/ + +var obj = {}; +obj.splice = SendableArray.prototype.splice; +obj[0] = "x"; +obj[4294967295] = "y"; +obj.length = 4294967296; +var arr = obj.splice(4294967295, 1); +if (arr.length !== 1) { + throw new Test262Error('#1: var obj = {}; obj.splice = SendableArray.prototype.splice; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; var arr = obj.splice(4294967295,1); arr.length === 1. Actual: ' + (arr.length)); +} +if (obj.length !== 4294967295) { + throw new Test262Error('#2: var obj = {}; obj.splice = SendableArray.prototype.splice; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; var arr = obj.splice(4294967295,1); obj.length === 4294967295. Actual: ' + (obj.length)); +} +if (obj[0] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.splice = SendableArray.prototype.splice; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; var arr = obj.splice(4294967295,1); obj[0] === "x". Actual: ' + (obj[0])); +} +if (obj[4294967295] !== undefined) { + throw new Test262Error('#4: var obj = {}; obj.splice = SendableArray.prototype.splice; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; var arr = obj.splice(4294967295,1); obj[4294967295] === undefined. Actual: ' + (obj[4294967295])); +} +if (arr[0] !== "y") { + throw new Test262Error('#5: var obj = {}; obj.splice = SendableArray.prototype.splice; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; var arr = obj.splice(4294967295,1); arr[0] === "y". Actual: ' + (arr[0])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A3_T3.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..77570cb40aec1e384559e30c009f87ea31e8fdc0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A3_T3.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.splice +description: length is arbitrarily +---*/ + +var obj = {}; +obj.splice = SendableArray.prototype.splice; +obj[4294967294] = "x"; +obj.length = -1; +var arr = obj.splice(4294967294, 1); +if (arr.length !== 0) { + throw new Test262Error('#1: var obj = {}; obj.splice = SendableArray.prototype.splice; obj[4294967294] = "x"; obj.length = -1; var arr = obj.splice(4294967294,1); arr.length === 0. Actual: ' + (arr.length)); +} +if (arr[0] !== undefined) { + throw new Test262Error('#2: var obj = {}; obj.splice = SendableArray.prototype.splice; obj[4294967294] = "x"; obj.length = 1; var arr = obj.splice(4294967294,1); arr[0] === undefined. Actual: ' + (arr[0])); +} +if (obj.length !== 0) { + throw new Test262Error('#3: var obj = {}; obj.splice = SendableArray.prototype.splice; obj[4294967294] = "x"; obj.length = 1; var arr = obj.splice(4294967294,1); obj.length === 0. Actual: ' + (obj.length)); +} +if (obj[4294967294] !== "x") { + throw new Test262Error('#4: var obj = {}; obj.splice = SendableArray.prototype.splice; obj[4294967294] = "x"; obj.length = 1; var arr = obj.splice(4294967294,1); obj[4294967294] === "x". Actual: ' + (obj[4294967294])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A4_T1.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A4_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..69dc7cee3b54f83cb36bd3d24331de50bc5453ba --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A4_T1.js @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]] from not an inherited property" +esid: sec-array.prototype.splice +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[1] = -1; +var x = [0, 1]; +var arr = x.splice(1, 1); +if (arr.length !== 1) { + throw new Test262Error('#1: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1); arr.length === 1. Actual: ' + (arr.length)); +} +if (arr[0] !== 1) { + throw new Test262Error('#2: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1); arr[0] === 1. Actual: ' + (arr[0])); +} +if (arr[1] !== -1) { + throw new Test262Error('#3: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1); arr[1] === -1. Actual: ' + (arr[1])); +} +if (x.length !== 1) { + throw new Test262Error('#4: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1); x.length === 1. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#5: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== -1) { + throw new Test262Error('#6: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1); x[1] === -1. Actual: ' + (x[1])); +} +Object.prototype[1] = -1; +Object.prototype.length = 2; +Object.prototype.splice = SendableArray.prototype.splice; +x = { + 0: 0, + 1: 1 +}; +var arr = x.splice(1, 1); +if (arr.length !== 1) { + throw new Test262Error('#7: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1); arr.length === 1. Actual: ' + (arr.length)); +} +if (arr[0] !== 1) { + throw new Test262Error('#8: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1); arr[0] === 1. Actual: ' + (arr[0])); +} +if (arr[1] !== -1) { + throw new Test262Error('#9: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1); arr[1] === -1. Actual: ' + (arr[1])); +} +if (x.length !== 1) { + throw new Test262Error('#10: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1); x.length === 1. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#11: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== -1) { + throw new Test262Error('#12: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1); x[1] === -1. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A4_T2.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A4_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..a5ea77c22e0e28ab1c270609ff8014273ea4ab44 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A4_T2.js @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]] from not an inherited property" +esid: sec-array.prototype.splice +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[1] = -1; +var x = [0, 1]; +var arr = x.splice(1, 1, 2); +if (arr.length !== 1) { + throw new Test262Error('#1: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1,2); arr.length === 1. Actual: ' + (arr.length)); +} +if (arr[0] !== 1) { + throw new Test262Error('#2: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1,2); arr[0] === 1. Actual: ' + (arr[0])); +} +if (arr[1] !== -1) { + throw new Test262Error('#3: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1,2); arr[1] === -1. Actual: ' + (arr[1])); +} +if (x.length !== 2) { + throw new Test262Error('#4: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1,2); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#5: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1,2); x[0] === 0. Actual: ' + (x[0])); +} + +if (x[1] !== 2) { + throw new Test262Error('#6: SendableArray.prototype[1] = -1; x = [0,1]; var arr = x.splice(1,1,2); x[1] === 2. Actual: ' + (x[1])); +} +Object.prototype[1] = -1; +Object.prototype.length = 2; +Object.prototype.splice = SendableArray.prototype.splice; +x = { + 0: 0, + 1: 1 +}; +var arr = x.splice(1, 1, 2); +if (arr.length !== 1) { + throw new Test262Error('#7: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1,2); arr.length === 1. Actual: ' + (arr.length)); +} +if (arr[0] !== 1) { + throw new Test262Error('#8: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1,2); arr[0] === 1. Actual: ' + (arr[0])); +} +if (arr[1] !== -1) { + throw new Test262Error('#9: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1,2); arr[1] === -1. Actual: ' + (arr[1])); +} +if (x.length !== 2) { + throw new Test262Error('#10: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1,2); x.length === 2. Actual: ' + (x.length)); +} +if (x[0] !== 0) { + throw new Test262Error('#11: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1,2); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 2) { + throw new Test262Error('#12: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.splice = SendableArray.prototype.splice; x = {0:0, 1:1}; var arr = x.splice(1,1,2); x[1] === 2. Actual: ' + (x[1])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A4_T3.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A4_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..1e4cd9e7079eb6c112a34c67efbf2278e2dc7d8f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A4_T3.js @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]] from not an inherited property" +esid: sec-array.prototype.splice +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[0] = -1; +var x = []; +x.length = 1; +var arr = x.splice(0, 1); +if (arr.length !== 1) { + throw new Test262Error('#1: SendableArray.prototype[0] = -1; x = []; x.length = 1; var arr = x.splice(0,1); arr.length === 1. Actual: ' + (arr.length)); +} +if (arr[0] !== -1) { + throw new Test262Error('#2: SendableArray.prototype[0] = -1; x = []; x.length = 1; var arr = x.splice(0,1); arr[0] === -1. Actual: ' + (arr[0])); +} +delete arr[0]; +if (arr[0] !== -1) { + throw new Test262Error('#3: SendableArray.prototype[0] = -1; x = []; x.length = 1; var arr = x.splice(0,1); delete arr[0]; arr[0] === -1. Actual: ' + (arr[0])); +} +if (x.length !== 0) { + throw new Test262Error('#4: SendableArray.prototype[0] = -1; x = []; x.length = 1; var arr = x.splice(0,1); x.length === 0. Actual: ' + (x.length)); +} +if (x[0] !== -1) { + throw new Test262Error('#5: SendableArray.prototype[0] = -1; x = []; x.length = 1; var arr = x.splice(0,1); x[0] === -1. Actual: ' + (x[0])); +} +Object.prototype[0] = -1; +Object.prototype.length = 1; +Object.prototype.splice = SendableArray.prototype.splice; +x = {}; +var arr = x.splice(0, 1); +if (arr.length !== 1) { + throw new Test262Error('#6: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.splice = SendableArray.prototype.splice; x = {}; var arr = x.splice(0,1); arr.length === 1. Actual: ' + (arr.length)); +} +if (arr[0] !== -1) { + throw new Test262Error('#7: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.splice = SendableArray.prototype.splice; x = {}; var arr = x.splice(0,1); arr[0] === -1. Actual: ' + (arr[0])); +} +delete arr[0]; +if (arr[0] !== -1) { + throw new Test262Error('#8: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.splice = SendableArray.prototype.splice; x = {}; var arr = x.splice(0,1); delete arr[0]; arr[0] === -1. Actual: ' + (arr[0])); +} +if (x.length !== 0) { + throw new Test262Error('#9: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.splice = SendableArray.prototype.splice; x = {}; var arr = x.splice(0,1); x.length === 0. Actual: ' + (x.length)); +} +if (x[0] !== -1) { + throw new Test262Error('#10: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.splice = SendableArray.prototype.splice; x = {}; var arr = x.splice(0,1); x[0] === -1. Actual: ' + (x[0])); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A6.1_T1.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A6.1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..dbc07ca540516c6b7e4c7564409c3dd2f3ffa006 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A6.1_T1.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Array.prototype.splice sets `length` on `this` +esid: sec-array.prototype.splice +description: Array.prototype.splice sets `length` on Array +---*/ + +var a = [0, 1, 2]; +a.splice(1, 2, 4); +if (a.length !== 2) { + throw new Test262Error("Expected a.length === 2, actually " + a.length); +} +if (a[0] !== 0) { + throw new Test262Error("Expected a[0] === 0, actually " + a[0]); +} +if (a[1] !== 4) { + throw new Test262Error("Expected a[1] === 4, actually " + a[1]); +} diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A6.1_T2.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A6.1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..7703083393bd75f166933fc0e162c70db4d977a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A6.1_T2.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Array.prototype.splice sets `length` on `this` +esid: sec-array.prototype.splice +description: Array.prototype.splice throws if `length` is read-only +---*/ + +var a = [0, 1, 2]; +Object.defineProperty(a, 'length', { + writable: false +}); +assert.throws(TypeError, function() { + a.splice(1, 2, 4); +}); diff --git a/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A6.1_T3.js b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A6.1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..3ddbcde1bf946bae0ef993b8dba0ce2b74a7a51a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/S15.4.4.12_A6.1_T3.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Array.prototype.splice sets `length` on `this` +esid: sec-array.prototype.splice +description: Array.prototype.splice throws if `length` is read-only +---*/ + +var a = { + get length() { + return 0; + }, + splice: SendableArray.prototype.splice +}; +try { + a.splice(1, 2, 4); + throw new Test262Error("Expected a TypeError"); +} catch (e) { + if (!(e instanceof TypeError)) { + throw e; + } +} diff --git a/test/sendable/builtins/Array/prototype/splice/call-with-boolean.js b/test/sendable/builtins/Array/prototype/splice/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..9b7e3bce321693677df2baf69a23db035342cea5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/call-with-boolean.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: Array.prototype.splice applied to boolean primitive +includes: [compareArray.js] +---*/ + +assert.compareArray(SendableArray.prototype.splice.call(true), [], 'SendableArray.prototype.splice.call(true) must return []'); +assert.compareArray(SendableArray.prototype.splice.call(false), [], 'SendableArray.prototype.splice.call(false) must return []'); diff --git a/test/sendable/builtins/Array/prototype/splice/called_with_one_argument.js b/test/sendable/builtins/Array/prototype/splice/called_with_one_argument.js new file mode 100644 index 0000000000000000000000000000000000000000..d1d41bcda19adc1181382ec941a68bc34af641f1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/called_with_one_argument.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Array.prototype.splice deletes length-start elements when called with one argument +info: | + 22.1.3.25 Array.prototype.splice (start, deleteCount , ...items ) + 9. Else if the number of actual arguments is 1, then + a. Let insertCount be 0. + b. Let actualDeleteCount be len – actualStart. +esid: sec-array.prototype.splice +---*/ + +var array = ["first", "second", "third"]; +var result = array.splice(1); +assert.sameValue(array.length, 1, "array length updated"); +assert.sameValue(array[0], "first", "array[0] unchanged"); +assert.sameValue(result.length, 2, "result array length correct"); +assert.sameValue(result[0], "second", "result[0] correct"); +assert.sameValue(result[1], "third", "result[1] correct"); diff --git a/test/sendable/builtins/Array/prototype/splice/clamps-length-to-integer-limit.js b/test/sendable/builtins/Array/prototype/splice/clamps-length-to-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..60db8f3fc9f1ef64f602afd5df0609dbab05e04b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/clamps-length-to-integer-limit.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + Length values exceeding 2^53-1 are clamped to 2^53-1. +features: [exponentiation] +---*/ + +var arrayLike = {}; +arrayLike.length = 2 ** 53 - 1; +SendableArray.prototype.splice.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53 - 1"); +arrayLike.length = 2 ** 53; +SendableArray.prototype.splice.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53"); +arrayLike.length = 2 ** 53 + 2; +SendableArray.prototype.splice.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53 + 2"); +arrayLike.length = Infinity; +SendableArray.prototype.splice.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is Infinity"); diff --git a/test/sendable/builtins/Array/prototype/splice/create-ctor-non-object.js b/test/sendable/builtins/Array/prototype/splice/create-ctor-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..cdc8725bac07ea49a0849635bec805fbb578aafd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-ctor-non-object.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + Behavior when `constructor` property is neither an Object nor undefined +---*/ + +var a = []; +a.constructor = null; +assert.throws(TypeError, function() { + a.splice(); +}, 'null value'); +a = []; +a.constructor = 1; +assert.throws(TypeError, function() { + a.splice(); +}, 'number value'); +a = []; +a.constructor = 'string'; +assert.throws(TypeError, function() { + a.splice(); +}, 'string value'); +a = []; +a.constructor = true; +assert.throws(TypeError, function() { + a.splice(); +}, 'boolean value'); diff --git a/test/sendable/builtins/Array/prototype/splice/create-ctor-poisoned.js b/test/sendable/builtins/Array/prototype/splice/create-ctor-poisoned.js new file mode 100644 index 0000000000000000000000000000000000000000..23f8fb0e133fee148cd520ddd5d33176b8677a82 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-ctor-poisoned.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: Abrupt completion from `constructor` property access +---*/ + +var a = []; +Object.defineProperty(a, 'constructor', { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + a.splice(); +}); diff --git a/test/sendable/builtins/Array/prototype/splice/create-non-array-invalid-len.js b/test/sendable/builtins/Array/prototype/splice/create-non-array-invalid-len.js new file mode 100644 index 0000000000000000000000000000000000000000..6c37e5058ade8e194e1669064d21136224647986 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-non-array-invalid-len.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: Abrupt completion from creating a new array +---*/ + +var callCount = 0; +var maxLength = Math.pow(2, 32); +var obj = Object.defineProperty({}, 'length', { + get: function() { + return maxLength; + }, + set: function() { + callCount += 1; + } +}); +assert.throws(RangeError, function() { + SendableArray.prototype.splice.call(obj, 0); +}); +assert.sameValue( + callCount, + 0, + 'RangeError thrown during array creation, not property modification' +); diff --git a/test/sendable/builtins/Array/prototype/splice/create-non-array.js b/test/sendable/builtins/Array/prototype/splice/create-non-array.js new file mode 100644 index 0000000000000000000000000000000000000000..69bde84ac5a26af11e45cb2be785fd63ca1f1e25 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-non-array.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: Constructor is ignored for non-Array values +---*/ + +var obj = { + length: 0 +}; +var callCount = 0; +var result; +Object.defineProperty(obj, 'constructor', { + get: function() { + callCount += 1; + } +}); +result = SendableArray.prototype.splice.call(obj); +assert.sameValue(callCount, 0, '`constructor` property not accessed'); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert(SendableArray.isArray(result), 'result is an SendableArray exotic object'); +assert.sameValue(result.length, 0, 'SendableArray created with appropriate length'); diff --git a/test/sendable/builtins/Array/prototype/splice/create-proto-from-ctor-realm-array.js b/test/sendable/builtins/Array/prototype/splice/create-proto-from-ctor-realm-array.js new file mode 100644 index 0000000000000000000000000000000000000000..6e112903e3a474503a14b8e7fa4df6cffa42f35f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-proto-from-ctor-realm-array.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: Prefer Array constructor of current realm record +---*/ + +var array = []; +var callCount = 0; +var OArray = $262.createRealm().global.SendableArray; +var speciesDesc = { + get: function() { + callCount += 1; + } +}; +var result; +array.constructor = OArray; +Object.defineProperty(SendableArray, Symbol.species, speciesDesc); +Object.defineProperty(OArray, Symbol.species, speciesDesc); +result = array.splice(); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert.sameValue(callCount, 0, 'Species constructor is not referenced'); diff --git a/test/sendable/builtins/Array/prototype/splice/create-proto-from-ctor-realm-non-array.js b/test/sendable/builtins/Array/prototype/splice/create-proto-from-ctor-realm-non-array.js new file mode 100644 index 0000000000000000000000000000000000000000..98b9db1ba384b95be1368c34bfbb7066ac119fc0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-proto-from-ctor-realm-non-array.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: Accept non-Array constructors from other realms +---*/ + +var array = []; +var callCount = 0; +var CustomCtor = function() {}; +var OObject = $262.createRealm().global.Object; +var speciesDesc = { + get: function() { + callCount += 1; + } +}; +var result; +array.constructor = OObject; +OObject[Symbol.species] = CustomCtor; +Object.defineProperty(SendableArray, Symbol.species, speciesDesc); +result = array.splice(); +assert.sameValue(Object.getPrototypeOf(result), CustomCtor.prototype); +assert.sameValue(callCount, 0, 'SendableArray species constructor is not referenced'); diff --git a/test/sendable/builtins/Array/prototype/splice/create-proxy.js b/test/sendable/builtins/Array/prototype/splice/create-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..239313a3fc9864bbc8dcebee717e631d30c475e3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-proxy.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: Species constructor of a Proxy object whose target is an array +---*/ + +var array = []; +var proxy = new Proxy(new Proxy(array, {}), {}); +var Ctor = function() {}; +var result; +array.constructor = function() {}; +array.constructor[Symbol.species] = Ctor; +result = SendableArray.prototype.splice.call(proxy); +assert.sameValue(Object.getPrototypeOf(result), Ctor.prototype); diff --git a/test/sendable/builtins/Array/prototype/splice/create-revoked-proxy.js b/test/sendable/builtins/Array/prototype/splice/create-revoked-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..cc87325ecaaf7a2ddd764f589d1f733953414be4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-revoked-proxy.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: Abrupt completion from constructor that is a revoked Proxy object +---*/ + +var o = Proxy.revocable([], {}); +var callCount = 0; +Object.defineProperty(o.proxy, 'constructor', { + get: function() { + callCount += 1; + } +}); +o.revoke(); +assert.throws(TypeError, function() { + SendableArray.prototype.splice.call(o.proxy); +}); +assert.sameValue(callCount, 0, '`constructor` property not accessed'); diff --git a/test/sendable/builtins/Array/prototype/splice/create-species-abrupt.js b/test/sendable/builtins/Array/prototype/splice/create-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..63388d2351db51e9da9e0fdf62468ab8b438d022 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-species-abrupt.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: Species constructor returns an abrupt completion +---*/ + +var Ctor = function() { + throw new Test262Error(); +}; +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; +assert.throws(Test262Error, function() { + a.splice(); +}); diff --git a/test/sendable/builtins/Array/prototype/splice/create-species-length-exceeding-integer-limit.js b/test/sendable/builtins/Array/prototype/splice/create-species-length-exceeding-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..11259d8d6b4ac77d64ee71b67c6d00e8dba53678 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-species-length-exceeding-integer-limit.js @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + Create species constructor with length exceeding integer limit and ensure MOP + operations are called in correct order. +includes: [compareArray.js, proxyTrapsHelper.js] +features: [Symbol.species, exponentiation] +---*/ + +function StopSplice() {} +var traps = []; +var targetLength; +var array = ["no-hole", /* hole */ , "stop"]; +array.constructor = { + [Symbol.species]: function(n) { + targetLength = n; + return target; + } +}; +var source = new Proxy(array, allowProxyTraps({ + get(t, pk, r) { + traps.push(`source.[[Get]]:${String(pk)}`); + // length property exceeding 2^53-1. + if (pk === "length") + return 2 ** 53 + 2; + return Reflect.get(t, pk, r); + }, + has(t, pk, r) { + traps.push(`source.[[Has]]:${String(pk)}`); + return Reflect.get(t, pk, r); + }, +})); +var target = new Proxy([], allowProxyTraps({ + defineProperty(t, pk, desc) { + traps.push(`target.[[DefineProperty]]:${String(pk)}`); + if (pk === "0" || pk === "1") + return Reflect.defineProperty(t, pk, desc); + throw new StopSplice(); + } +})); +assert.throws(StopSplice, function() { + // deleteCount argument exceeding 2^53-1. + SendableArray.prototype.splice.call(source, 0, 2 ** 53 + 4); +}, '// deleteCount argument exceeding 2^53-1. SendableArray.prototype.splice.call(source, 0, 2 ** 53 + 4) throws a StopSplice exception'); +assert.sameValue(targetLength, 2 ** 53 - 1, + 'The value of targetLength is expected to be 2 ** 53 - 1'); +assert.compareArray(traps, [ + "source.[[Get]]:length", + "source.[[Get]]:constructor", + "source.[[Has]]:0", + "source.[[Get]]:0", + "target.[[DefineProperty]]:0", + "source.[[Has]]:1", + "source.[[Has]]:2", + "source.[[Get]]:2", + "target.[[DefineProperty]]:2", +], 'The value of traps is expected to be [\n "source.[[Get]]:length",\n\n "source.[[Get]]:constructor",\n\n "source.[[Has]]:0",\n "source.[[Get]]:0",\n "target.[[DefineProperty]]:0",\n\n "source.[[Has]]:1",\n\n "source.[[Has]]:2",\n "source.[[Get]]:2",\n "target.[[DefineProperty]]:2",\n]'); diff --git a/test/sendable/builtins/Array/prototype/splice/create-species-neg-zero.js b/test/sendable/builtins/Array/prototype/splice/create-species-neg-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..fef347099cd1618dd9ef3e1b3cef5a35198cbfc5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-species-neg-zero.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: The value `-0` is converted to `0` +---*/ + +var args; +var Ctor = function() { + args = arguments; +}; +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; +a.splice(0, -0); +assert.sameValue(args.length, 1); +assert.sameValue(args[0], 0); diff --git a/test/sendable/builtins/Array/prototype/splice/create-species-non-ctor.js b/test/sendable/builtins/Array/prototype/splice/create-species-non-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..18dda71927f27546ef501c5e0e673177215ebd37 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-species-non-ctor.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + Behavior when the @@species attribute is a non-constructor object +includes: [isConstructor.js] +features: [Symbol.species, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(parseInt), + false, + 'precondition: isConstructor(parseInt) must return false' +); +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = parseInt; +assert.throws(TypeError, function() { + a.splice(); +}, 'a.splice() throws a TypeError exception'); diff --git a/test/sendable/builtins/Array/prototype/splice/create-species-null.js b/test/sendable/builtins/Array/prototype/splice/create-species-null.js new file mode 100644 index 0000000000000000000000000000000000000000..8dc29d81ff2300e9475cd2f6794cf1f4ec861cd4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-species-null.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + A null value for the @@species constructor is interpreted as `undefined` +features: [Symbol.species] +---*/ + +var a = []; +var result; +a.constructor = {}; +a.constructor[Symbol.species] = null; +result = a.splice(); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert(SendableArray.isArray(result), 'result is an SendableArray exotic object'); diff --git a/test/sendable/builtins/Array/prototype/splice/create-species-poisoned.js b/test/sendable/builtins/Array/prototype/splice/create-species-poisoned.js new file mode 100644 index 0000000000000000000000000000000000000000..1537394b5d0da4560106f21d4fcc4c7f354b9450 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-species-poisoned.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: Abrupt completion from `@@species` property access +features: [Symbol.species] +---*/ + +var a = []; +a.constructor = {}; +Object.defineProperty(a.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } +}); +assert.throws(Test262Error, function() { + a.splice(); +}); diff --git a/test/sendable/builtins/Array/prototype/splice/create-species-undef-invalid-len.js b/test/sendable/builtins/Array/prototype/splice/create-species-undef-invalid-len.js new file mode 100644 index 0000000000000000000000000000000000000000..9a8202ddf953614a55d091c5ebca1c4096e2a15d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-species-undef-invalid-len.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + An undefined value for the @@species constructor triggers the creation of + an Array exotic object +features: [Proxy] +---*/ + +var array = []; +var maxLength = Math.pow(2, 32); +var callCount = 0; +var proxy = new Proxy(array, { + get: function(_, name) { + if (name === 'length') { + return maxLength; + } + return array[name]; + }, + set: function() { + callCount += 1; + return true; + } +}); +assert.throws(RangeError, function() { + SendableArray.prototype.splice.call(proxy, 0); +}); +assert.sameValue( + callCount, + 0, + 'RangeError thrown during SendableArray creation, not property modification' +); diff --git a/test/sendable/builtins/Array/prototype/splice/create-species-undef.js b/test/sendable/builtins/Array/prototype/splice/create-species-undef.js new file mode 100644 index 0000000000000000000000000000000000000000..7fe6d840b429582deb887cfc3f4deef6da455ec6 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-species-undef.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + An undefined value for the @@species constructor triggers the creation of + an Array exotic object +features: [Symbol.species] +---*/ + +var a = []; +var result; +a.constructor = {}; +a.constructor[Symbol.species] = undefined; +result = a.splice(); +assert.sameValue(Object.getPrototypeOf(result), SendableArray.prototype); +assert(SendableArray.isArray(result), 'result is an SendableArray exotic object'); diff --git a/test/sendable/builtins/Array/prototype/splice/create-species.js b/test/sendable/builtins/Array/prototype/splice/create-species.js new file mode 100644 index 0000000000000000000000000000000000000000..f822ce17abfc71611fa8c32971ba44c25fe74085 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/create-species.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: Species constructor is used to create a new instance +features: [Symbol.species] +---*/ + +var thisValue, args, result; +var callCount = 0; +var instance = []; +var Ctor = function() { + callCount += 1; + thisValue = this; + args = arguments; + return instance; +}; +var a = [1, 2, 3, 4, 5]; +a.constructor = {}; +a.constructor[Symbol.species] = Ctor; +result = a.splice(2); +assert.sameValue(callCount, 1, 'Constructor invoked exactly once'); +assert.sameValue(Object.getPrototypeOf(thisValue), Ctor.prototype); +assert.sameValue(args.length, 1, 'Constructor invoked with a single argument'); +assert.sameValue(args[0], 3); +assert.sameValue(result, instance); diff --git a/test/sendable/builtins/Array/prototype/splice/length-and-deleteCount-exceeding-integer-limit.js b/test/sendable/builtins/Array/prototype/splice/length-and-deleteCount-exceeding-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..5803ba161567ceea81e91f1f65263a00321bb99c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/length-and-deleteCount-exceeding-integer-limit.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.splice +description: > + Length and deleteCount are both clamped to 2^53-1 when they exceed the integer limit. +includes: [compareArray.js] +features: [exponentiation] +---*/ + +var arrayLike = { + "9007199254740988": "9007199254740988", + "9007199254740989": "9007199254740989", + "9007199254740990": "9007199254740990", + "9007199254740991": "9007199254740991", + length: 2 ** 53 + 2, +}; +var result = SendableArray.prototype.splice.call(arrayLike, 9007199254740989, 2 ** 53 + 4); +assert.compareArray(result, ["9007199254740989", "9007199254740990"], + 'The value of result is expected to be ["9007199254740989", "9007199254740990"]'); +assert.sameValue(arrayLike.length, 2 ** 53 - 3, + 'The value of arrayLike.length is expected to be 2 ** 53 - 3'); +assert.sameValue(arrayLike["9007199254740988"], "9007199254740988", + 'The value of arrayLike["9007199254740988"] is expected to be "9007199254740988"'); +assert.sameValue("9007199254740989" in arrayLike, false, + 'The result of evaluating ("9007199254740989" in arrayLike) is expected to be false'); +assert.sameValue("9007199254740990" in arrayLike, false, + 'The result of evaluating ("9007199254740990" in arrayLike) is expected to be false'); +assert.sameValue(arrayLike["9007199254740991"], "9007199254740991", + 'The value of arrayLike["9007199254740991"] is expected to be "9007199254740991"'); diff --git a/test/sendable/builtins/Array/prototype/splice/length-exceeding-integer-limit-shrink-array.js b/test/sendable/builtins/Array/prototype/splice/length-exceeding-integer-limit-shrink-array.js new file mode 100644 index 0000000000000000000000000000000000000000..f5f67a4e66d3df9f0c581d24514f171e5550f0c7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/length-exceeding-integer-limit-shrink-array.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.splice +description: > + An element is removed from an array-like object whose length exceeds the integer limit. +includes: [compareArray.js] +features: [exponentiation] +---*/ + +var arrayLike = { + "9007199254740986": "9007199254740986", + "9007199254740987": "9007199254740987", + "9007199254740988": "9007199254740988", + /* "9007199254740989": hole */ + "9007199254740990": "9007199254740990", + "9007199254740991": "9007199254740991", + length: 2 ** 53 + 2, +}; +var result = SendableArray.prototype.splice.call(arrayLike, 9007199254740987, 1); +assert.compareArray(result, ["9007199254740987"], + 'The value of result is expected to be ["9007199254740987"]'); +assert.sameValue(arrayLike.length, 2 ** 53 - 2, + 'The value of arrayLike.length is expected to be 2 ** 53 - 2'); +assert.sameValue(arrayLike["9007199254740986"], "9007199254740986", + 'The value of arrayLike["9007199254740986"] is expected to be "9007199254740986"'); +assert.sameValue(arrayLike["9007199254740987"], "9007199254740988", + 'The value of arrayLike["9007199254740987"] is expected to be "9007199254740988"'); +assert.sameValue("9007199254740988" in arrayLike, false, + 'The result of evaluating ("9007199254740988" in arrayLike) is expected to be false'); +assert.sameValue(arrayLike["9007199254740989"], "9007199254740990", + 'The value of arrayLike["9007199254740989"] is expected to be "9007199254740990"'); +assert.sameValue("9007199254740990" in arrayLike, false, + 'The result of evaluating ("9007199254740990" in arrayLike) is expected to be false'); +assert.sameValue(arrayLike["9007199254740991"], "9007199254740991", + 'The value of arrayLike["9007199254740991"] is expected to be "9007199254740991"'); diff --git a/test/sendable/builtins/Array/prototype/splice/length-near-integer-limit-grow-array.js b/test/sendable/builtins/Array/prototype/splice/length-near-integer-limit-grow-array.js new file mode 100644 index 0000000000000000000000000000000000000000..1e19923cf3ee6439aa404d0703342faf4de6d734 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/length-near-integer-limit-grow-array.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-array.prototype.splice +description: > + A value is inserted in an array-like object whose length property is near the integer limit. +includes: [compareArray.js] +features: [exponentiation] +---*/ + +var arrayLike = { + "9007199254740985": "9007199254740985", + "9007199254740986": "9007199254740986", + "9007199254740987": "9007199254740987", + /* "9007199254740988": hole */ + "9007199254740989": "9007199254740989", + /* "9007199254740990": empty */ + "9007199254740991": "9007199254740991", + length: 2 ** 53 - 2, +}; +var result = SendableArray.prototype.splice.call(arrayLike, 9007199254740986, 0, "new-value"); +assert.compareArray(result, [], 'The value of result is expected to be []'); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, 'The value of arrayLike.length is expected to be 2 ** 53 - 1'); +assert.sameValue(arrayLike["9007199254740985"], "9007199254740985", + 'The value of arrayLike["9007199254740985"] is expected to be "9007199254740985"'); +assert.sameValue(arrayLike["9007199254740986"], "new-value", + 'The value of arrayLike["9007199254740986"] is expected to be "new-value"'); +assert.sameValue(arrayLike["9007199254740987"], "9007199254740986", + 'The value of arrayLike["9007199254740987"] is expected to be "9007199254740986"'); +assert.sameValue(arrayLike["9007199254740988"], "9007199254740987", + 'The value of arrayLike["9007199254740988"] is expected to be "9007199254740987"'); +assert.sameValue("9007199254740989" in arrayLike, false, + 'The result of evaluating ("9007199254740989" in arrayLike) is expected to be false'); +assert.sameValue(arrayLike["9007199254740990"], "9007199254740989", + 'The value of arrayLike["9007199254740990"] is expected to be "9007199254740989"'); +assert.sameValue(arrayLike["9007199254740991"], "9007199254740991", + 'The value of arrayLike["9007199254740991"] is expected to be "9007199254740991"'); diff --git a/test/sendable/builtins/Array/prototype/splice/length.js b/test/sendable/builtins/Array/prototype/splice/length.js new file mode 100644 index 0000000000000000000000000000000000000000..064bcd4f163635c4853cff47908a95d866cb52d7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/length.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + The "length" property of Array.prototype.splice +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.splice, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/splice/name.js b/test/sendable/builtins/Array/prototype/splice/name.js new file mode 100644 index 0000000000000000000000000000000000000000..a34abc1a5870debfba3cf5121e907797ca420b7d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + Array.prototype.splice.name is "splice". +info: | + Array.prototype.splice (start, deleteCount , ...items ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.splice, "name", { + value: "splice", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/splice/not-a-constructor.js b/test/sendable/builtins/Array/prototype/splice/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..8fce445d3ca368f751765f95079a930a21424b31 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.splice does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.splice), + false, + 'isConstructor(SendableArray.prototype.splice) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.splice(); +}); + diff --git a/test/sendable/builtins/Array/prototype/splice/prop-desc.js b/test/sendable/builtins/Array/prototype/splice/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..781eb26cf77daea55529b64191986466a57dafef --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + "splice" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.splice, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "splice", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/splice/property-traps-order-with-species.js b/test/sendable/builtins/Array/prototype/splice/property-traps-order-with-species.js new file mode 100644 index 0000000000000000000000000000000000000000..9f0f5cadbba4ae4a761ecf100429e40d8b79a1ac --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/property-traps-order-with-species.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + Ensure the correct property traps are called on the new array. +features: [Proxy, Symbol.species] +includes: [compareArray.js] +---*/ + +var log = []; +var a = [0, 1]; +a.constructor = {}; +a.constructor[Symbol.species] = function(len) { + return new Proxy(new SendableArray(len), new Proxy({}, { + get(t, pk, r) { + log.push(pk); + } + })); +}; +var r = a.splice(0); +assert.compareArray([ + // Step 11.c.ii: CreateDataPropertyOrThrow(A, ! ToString(k), fromValue). + "defineProperty", + // Step 11.c.ii: CreateDataPropertyOrThrow(A, ! ToString(k), fromValue). + "defineProperty", + // Step 12: Perform ? Set(A, "length", actualDeleteCount, true). + "set", + "getOwnPropertyDescriptor", + "defineProperty", +], log); diff --git a/test/sendable/builtins/Array/prototype/splice/set_length_no_args.js b/test/sendable/builtins/Array/prototype/splice/set_length_no_args.js new file mode 100644 index 0000000000000000000000000000000000000000..314c4d6c9ec758fe81993b61e54aaa56692061f5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/set_length_no_args.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: Array.prototype.splice sets length when called with no arguments +info: | + 22.1.3.25 Array.prototype.splice (start, deleteCount , ...items ) + + ... + 24. Let setStatus be Set(O, "length", len – actualDeleteCount + itemCount, true). + 25. ReturnIfAbrupt(setStatus). +esid: sec-array.prototype.splice +---*/ + +var getCallCount = 0, + setCallCount = 0; +var lengthValue; +var obj = { + get length() { + getCallCount += 1; + return "0"; + }, + set length(v) { + setCallCount += 1; + lengthValue = v; + } +}; +SendableArray.prototype.splice.call(obj); +assert.sameValue(getCallCount, 1, "Get('length') called exactly once"); +assert.sameValue(setCallCount, 1, "Set('length') called exactly once"); +assert.sameValue(lengthValue, 0, "Set('length') called with ToLength('0')"); diff --git a/test/sendable/builtins/Array/prototype/splice/target-array-non-extensible.js b/test/sendable/builtins/Array/prototype/splice/target-array-non-extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..9565e9b3014d3682a3e167e1a96a94753a613e37 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/target-array-non-extensible.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + TypeError is thrown if CreateDataProperty fails. + (result object is non-extensible) +---*/ + +var A = function(_length) { + this.length = 0; + Object.preventExtensions(this); +}; +var arr = [1]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.splice(0); +}); diff --git a/test/sendable/builtins/Array/prototype/splice/target-array-with-non-configurable-property.js b/test/sendable/builtins/Array/prototype/splice/target-array-with-non-configurable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..a883c5e88fcd12d6a673f7437792eadb92dbc229 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/target-array-with-non-configurable-property.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + TypeError is thrown if CreateDataProperty fails. + (result object's "0" is non-configurable) +---*/ + +var A = function(_length) { + Object.defineProperty(this, "0", { + writable: true, + configurable: false, + }); +}; +var arr = [1]; +arr.constructor = {}; +arr.constructor[Symbol.species] = A; +assert.throws(TypeError, function() { + arr.splice(0); +}); diff --git a/test/sendable/builtins/Array/prototype/splice/target-array-with-non-writable-property.js b/test/sendable/builtins/Array/prototype/splice/target-array-with-non-writable-property.js new file mode 100644 index 0000000000000000000000000000000000000000..ae081624abaffd0136f295f795e2f6c0d5ed498d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/target-array-with-non-writable-property.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + Non-writable properties are overwritten by CreateDataPropertyOrThrow. +features: [Symbol.species] +includes: [propertyHelper.js] +---*/ + +var a = [1]; +a.constructor = {}; +a.constructor[Symbol.species] = function(len) { + var q = new SendableArray(0); + Object.defineProperty(q, 0, { + value: 0, writable: false, configurable: true, enumerable: false, + }); + return q; +}; +var r = a.splice(0); +verifyProperty(r, 0, { + value: 1, writable: true, configurable: true, enumerable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/splice/throws-if-integer-limit-exceeded.js b/test/sendable/builtins/Array/prototype/splice/throws-if-integer-limit-exceeded.js new file mode 100644 index 0000000000000000000000000000000000000000..514387ab8b1b70b823bf3acc17b58c546393560c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/splice/throws-if-integer-limit-exceeded.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.splice +description: > + A TypeError is thrown if the new length exceeds 2^53-1. +info: | + 2. Let len be ? ToLength(? Get(O, "length")). + 7. Else, + a. Let insertCount be the number of actual arguments minus 2. + b. Let dc be ? ToInteger(deleteCount). + c. Let actualDeleteCount be min(max(dc, 0), len - actualStart). + 8. If len+insertCount-actualDeleteCount > 2^53-1, throw a TypeError exception. +features: [exponentiation] +---*/ + +var arrayLike = {}; +arrayLike.length = 2 ** 53 - 1; +assert.throws(TypeError, function() { + SendableArray.prototype.splice.call(arrayLike, 0, 0, null); +}, "Length is 2**53 - 1"); +arrayLike.length = 2 ** 53; +assert.throws(TypeError, function() { + SendableArray.prototype.splice.call(arrayLike, 0, 0, null); +}, "Length is 2**53"); +arrayLike.length = 2 ** 53 + 2; +assert.throws(TypeError, function() { + SendableArray.prototype.splice.call(arrayLike, 0, 0, null); +}, "Length is 2**53 + 2"); +arrayLike.length = Infinity; +assert.throws(TypeError, function() { + SendableArray.prototype.splice.call(arrayLike, 0, 0, null); +}, "Length is Infinity"); diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/S15.4.4.3_A1_T1.js b/test/sendable/builtins/Array/prototype/toLocaleString/S15.4.4.3_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..75f0cab377451f1ea77aa81f56064caaaed8dee3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/S15.4.4.3_A1_T1.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tolocalestring +info: | + The elements of the array are converted to strings using their + toLocaleString methods, and these strings are then concatenated, separated + by occurrences of a separator string that has been derived in an + implementation-defined locale-specific way +es5id: 15.4.4.3_A1_T1 +description: it is the function that should be invoked +---*/ + +var n = 0; +var obj = { + toLocaleString: function() { + n++ + } +}; +var arr = [undefined, obj, null, obj, obj]; +arr.toLocaleString(); +if (n !== 3) { + throw new Test262Error('#1: var n = 0; var obj = {toLocaleString: function() {n++}}; var arr = [undefined, obj, null, obj, obj]; arr.toLocaleString(); n === 3. Actual: ' + (n)); +} diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/S15.4.4.3_A3_T1.js b/test/sendable/builtins/Array/prototype/toLocaleString/S15.4.4.3_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..582dc4f1b6d33b84a382f40bbeee0ff273ea2689 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/S15.4.4.3_A3_T1.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tolocalestring +info: "[[Get]] from not an inherited property" +es5id: 15.4.4.3_A3_T1 +description: "[[Prototype]] of Array instance is Array.prototype" +---*/ + +var n = 0; +var obj = { + toLocaleString: function() { + n++ + } +}; +SendableArray.prototype[1] = obj; +var x = [obj]; +x.length = 2; +x.toLocaleString(); +if (n !== 2) { + throw new Test262Error('#1: var n = 0; var obj = {toLocaleString: function() {n++}}; Array.prototype[1] = obj; x = [obj]; x.length = 2; x.toLocaleString(); n === 2. Actual: ' + (n)); +} diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/invoke-element-tolocalestring.js b/test/sendable/builtins/Array/prototype/toLocaleString/invoke-element-tolocalestring.js new file mode 100644 index 0000000000000000000000000000000000000000..cba4ce33d4f12b429206ba14ab6722e22ceca5b9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/invoke-element-tolocalestring.js @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tolocalestring +description: > + The toLocaleString method of each non-undefined non-null element + must be called with no arguments. +includes: [compareArray.js] +---*/ + +const unique = { + toString() { + return ""; + } +}; +const testCases = [ + { label: "no arguments", args: [] }, + { label: "undefined locale", args: [undefined] }, + { label: "string locale", args: ["ar"] }, + { label: "object locale", args: [unique] }, + { label: "undefined locale and options", args: [undefined, unique] }, + { label: "string locale and options", args: ["zh", unique] }, + { label: "object locale and options", args: [unique, unique] }, + { label: "extra arguments", args: [unique, unique, unique] }, +]; +for (const { label, args } of testCases) { + assert.sameValue([undefined].toLocaleString(...args), "", + `must skip undefined elements when provided ${label}`); +} +for (const { label, args, expectedArgs } of testCases) { + assert.sameValue([null].toLocaleString(...args), "", + `must skip null elements when provided ${label}`); +} +if (typeof Intl !== "object") { + for (const { label, args } of testCases) { + const spy = { + toLocaleString(...receivedArgs) { + assert.compareArray(receivedArgs, [], + `must invoke element toLocaleString with no arguments when provided ${label}`); + return "ok"; + } + }; + assert.sameValue([spy].toLocaleString(...args), "ok"); + } +} diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/length.js b/test/sendable/builtins/Array/prototype/toLocaleString/length.js new file mode 100644 index 0000000000000000000000000000000000000000..ce2ccc66ba24a5bb0a0e4a1d861a43a76e96b982 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/length.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tolocalestring +description: > + The "length" property of Array.prototype.toLocaleString +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.toLocaleString, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/name.js b/test/sendable/builtins/Array/prototype/toLocaleString/name.js new file mode 100644 index 0000000000000000000000000000000000000000..278b290f1b050972afcda51e8bf68a5fcfd5455c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tolocalestring +description: > + Array.prototype.toLocaleString.name is "toLocaleString". +info: | + Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.toLocaleString, "name", { + value: "toLocaleString", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/not-a-constructor.js b/test/sendable/builtins/Array/prototype/toLocaleString/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..cd1a426f1158c554ec19554f16e0cf2fc471faf1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.toLocaleString does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.toLocaleString), + false, + 'isConstructor(SendableArray.prototype.toLocaleString) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.toLocaleString(); +}); + diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/primitive_this_value.js b/test/sendable/builtins/Array/prototype/toLocaleString/primitive_this_value.js new file mode 100644 index 0000000000000000000000000000000000000000..4bfadeb53fbaecba77634fb2e6a32bc6c980f1cf --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/primitive_this_value.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tolocalestring +description: Array.prototype.toLocaleString called with primitive element +info: | + 22.1.3.26 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + 10. Else + a. Let R be ToString(Invoke(firstElement, "toLocaleString")). + b. ReturnIfAbrupt(R). + 12. + e. Else + i. Let R be ToString(Invoke(nextElement, "toLocaleString")). + ii. ReturnIfAbrupt(R). +es6id: 22.1.3.26 +flags: [onlyStrict] +---*/ + +var listSeparator = ["", ""].toLocaleString(); +Boolean.prototype.toString = function() { + return typeof this; +}; +assert.sameValue([true, false].toLocaleString(), ("boolean" + listSeparator + "boolean")); diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/primitive_this_value_getter.js b/test/sendable/builtins/Array/prototype/toLocaleString/primitive_this_value_getter.js new file mode 100644 index 0000000000000000000000000000000000000000..a25ff67ad53e2afcd79c7323cd6922fc418dd28a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/primitive_this_value_getter.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tolocalestring +description: Array.prototype.toLocaleString called with primitive element in getter +info: | + 22.1.3.26 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + 10. Else + a. Let R be ToString(Invoke(firstElement, "toLocaleString")). + b. ReturnIfAbrupt(R). + 12. + e. Else + i. Let R be ToString(Invoke(nextElement, "toLocaleString")). + ii. ReturnIfAbrupt(R). +es6id: 22.1.3.26 +flags: [onlyStrict] +---*/ + +var listSeparator = ["", ""].toLocaleString(); +Object.defineProperty(Boolean.prototype, "toString", { + get: function() { + var v = typeof this; + return function() { + return v; + }; + } +}); +assert.sameValue([true, false].toLocaleString(), ("boolean" + listSeparator + "boolean")); diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/prop-desc.js b/test/sendable/builtins/Array/prototype/toLocaleString/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..3500037a813b12a5a45ef46c345a61f467872bd7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tolocalestring +description: > + "toLocaleString" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.toLocaleString, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "toLocaleString", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/resizable-buffer.js b/test/sendable/builtins/Array/prototype/toLocaleString/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..7eff242a15697c7f6697b0d22c7d84cb3853f167 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/resizable-buffer.js @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tolocalestring +description: > + Array.p.toLocaleString behaves correctly on TypedArrays backed by resizable + buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const taWrite = new ctor(rab); + // toLocaleString separator is implementation dependent. + function listToString(list) { + const comma = ['',''].toLocaleString(); + return list.join(comma); + } + // Write some data into the array. + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLength), listToString([0,2,4,6])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLengthWithOffset), listToString([4,6])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTracking), listToString([0,2,4,6])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTrackingWithOffset), listToString([4,6])); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLength), listToString([])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLengthWithOffset), listToString([])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTracking), listToString([0,2,4])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTrackingWithOffset), listToString([4])); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLength), listToString([])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLengthWithOffset), listToString([])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTrackingWithOffset), listToString([])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTracking), listToString([0])); + // Shrink to zero. + rab.resize(0); + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLength), listToString([])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLengthWithOffset), listToString([])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTrackingWithOffset), listToString([])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTracking), listToString([])); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLength), listToString([0,2,4,6])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLengthWithOffset), listToString([4,6])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTracking), listToString([0,2,4,6,8,10])); + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTrackingWithOffset), listToString([4,6,8,10])); +} diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/user-provided-tolocalestring-grow.js b/test/sendable/builtins/Array/prototype/toLocaleString/user-provided-tolocalestring-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..98c17d3ddc167a71baeca55bde401c307c211e74 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/user-provided-tolocalestring-grow.js @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tolocalestring +description: > + Array.p.toLocaleString behaves correctly when {Number,BigInt}.prototype.toLocaleString + is replaced with a user-provided function that grows the array. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const oldNumberPrototypeToLocaleString = Number.prototype.toLocaleString; +const oldBigIntPrototypeToLocaleString = BigInt.prototype.toLocaleString; +// toLocaleString separator is implementation dependent. +function listToString(list) { + const comma = ['',''].toLocaleString(); + const len = list.length; + let result = ''; + if (len > 1) { + for (let i=0; i < len - 1 ; i++) { + result += list[i] + comma; + } + } + if (len > 0) { + result += list[len-1]; + } + return result; +} +// Growing + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let resizeAfter = 2; + Number.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + } + return oldNumberPrototypeToLocaleString.call(this); + }; + BigInt.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + } + return oldBigIntPrototypeToLocaleString.call(this); + }; + // We iterate 4 elements since it was the starting length. Resizing doesn't + // affect the TA. + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLength), listToString([0,0,0,0])); +} +// Growing + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let resizeAfter = 2; + Number.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + } + return oldNumberPrototypeToLocaleString.call(this); + }; + BigInt.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + } + return oldBigIntPrototypeToLocaleString.call(this); + }; + + // We iterate 4 elements since it was the starting length. + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTracking), listToString([0,0,0,0])); +} +Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString; +BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString; diff --git a/test/sendable/builtins/Array/prototype/toLocaleString/user-provided-tolocalestring-shrink.js b/test/sendable/builtins/Array/prototype/toLocaleString/user-provided-tolocalestring-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..356a4ab42a8c1b678f3be340b4a5c8785683f918 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toLocaleString/user-provided-tolocalestring-shrink.js @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tolocalestring +description: > + Array.p.toLocaleString behaves correctly when {Number,BigInt}.prototype.toLocaleString + is replaced with a user-provided function that shrinks the array. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const oldNumberPrototypeToLocaleString = Number.prototype.toLocaleString; +const oldBigIntPrototypeToLocaleString = BigInt.prototype.toLocaleString; +// toLocaleString separator is implementation dependent. +function listToString(list) { + const comma = ['',''].toLocaleString(); + const len = list.length; + let result = ''; + if (len > 1) { + for (let i=0; i < len - 1 ; i++) { + result += list[i] + comma; + } + } + if (len > 0) { + result += list[len-1]; + } + return result; +} +// Shrinking + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let resizeAfter = 2; + Number.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + return oldNumberPrototypeToLocaleString.call(this); + }; + BigInt.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + return oldBigIntPrototypeToLocaleString.call(this); + }; + + // We iterate 4 elements, since it was the starting length. The TA goes + // OOB after 2 elements. + assert.sameValue(SendableArray.prototype.toLocaleString.call(fixedLength),listToString([0,0,'',''])); +} +// Shrinking + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let resizeAfter = 2; + Number.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + return oldNumberPrototypeToLocaleString.call(this); + }; + BigInt.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + return oldBigIntPrototypeToLocaleString.call(this); + }; + // We iterate 4 elements, since it was the starting length. Elements beyond + // the new length are converted to the empty string. + assert.sameValue(SendableArray.prototype.toLocaleString.call(lengthTracking),listToString([0,0,'',''])); +} +Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString; +BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString; diff --git a/test/sendable/builtins/Array/prototype/toReversed/frozen-this-value.js b/test/sendable/builtins/Array/prototype/toReversed/frozen-this-value.js new file mode 100644 index 0000000000000000000000000000000000000000..c4048bf6caf5518a5db9735c447a299196cc33ae --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/frozen-this-value.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed works on frozen objects +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = Object.freeze([0, 1, 2]); +var result = arr.toReversed(); +assert.compareArray(result, [2, 1, 0]); +var arrayLike = Object.freeze({ length: 3, 0: 0, 1: 1, 2: 2 }); +result = SendableArray.prototype.toReversed.call(arrayLike); +assert.compareArray(result, [2, 1, 0]); diff --git a/test/sendable/builtins/Array/prototype/toReversed/get-descending-order.js b/test/sendable/builtins/Array/prototype/toReversed/get-descending-order.js new file mode 100644 index 0000000000000000000000000000000000000000..bbc467464cd348926d46027a5249f1ab41e1884f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/get-descending-order.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed gets the array elements from the last one to the first one. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var order = []; +var arrayLike = { + length: 3, + get 0() { + order.push(0); + }, + get 1() { + order.push(1); + }, + get 2() { + order.push(2); + }, +}; +SendableArray.prototype.toReversed.call(arrayLike); +assert.compareArray(order, [2, 1, 0]); +order = []; +var arr = [0, 1, 2]; +Object.defineProperty(arr, 0, { get: function() { order.push(0); } }); +Object.defineProperty(arr, 1, { get: function() { order.push(1); } }); +Object.defineProperty(arr, 2, { get: function() { order.push(2); } }); +SendableArray.prototype.toReversed.call(arr); +assert.compareArray(order, [2, 1, 0]); diff --git a/test/sendable/builtins/Array/prototype/toReversed/holes-not-preserved.js b/test/sendable/builtins/Array/prototype/toReversed/holes-not-preserved.js new file mode 100644 index 0000000000000000000000000000000000000000..a34f321a163ddd87e0cde00ba6161052bcb4da16 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/holes-not-preserved.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed does not preserve holes in the array +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, /* hole */, 2, /* hole */, 4]; +SendableArray.prototype[3] = 3; +var reversed = arr.toReversed(); +assert.compareArray(reversed, [4, 3, 2, undefined, 0]); +assert(reversed.hasOwnProperty(3)); diff --git a/test/sendable/builtins/Array/prototype/toReversed/ignores-species.js b/test/sendable/builtins/Array/prototype/toReversed/ignores-species.js new file mode 100644 index 0000000000000000000000000000000000000000..78a359233850cb55f597f554428aa27e97fab550 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/ignores-species.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed ignores @@species +---*/ + +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = function () {} +assert.sameValue(Object.getPrototypeOf(a.toReversed()), SendableArray.prototype); +var b = []; +Object.defineProperty(b, "constructor", { + get() { + throw new Test262Error("Should not get .constructor"); + } +}); +b.toReversed(); diff --git a/test/sendable/builtins/Array/prototype/toReversed/immutable.js b/test/sendable/builtins/Array/prototype/toReversed/immutable.js new file mode 100644 index 0000000000000000000000000000000000000000..423ec07666a8bbc65f2b23ee57acb671ff034a62 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/immutable.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed does not mutate its this value +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2]; +arr.toReversed(); +assert.compareArray(arr, [0, 1, 2]); +assert.notSameValue(arr.toReversed(), arr); diff --git a/test/sendable/builtins/Array/prototype/toReversed/length-casted-to-zero.js b/test/sendable/builtins/Array/prototype/toReversed/length-casted-to-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..4749e17be4b8d74dec641cae21406654393b5a50 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/length-casted-to-zero.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed creates an empty array if the this value .length is not a positive integer. +info: | + Array.prototype.toReversed ( ) + 2. Let len be ? LengthOfArrayLike(O). +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(SendableArray.prototype.toReversed.call({ length: -2 }), []); +assert.compareArray(SendableArray.prototype.toReversed.call({ length: "dog" }), []); +assert.compareArray(SendableArray.prototype.toReversed.call({ length: NaN }), []); diff --git a/test/sendable/builtins/Array/prototype/toReversed/length-decreased-while-iterating.js b/test/sendable/builtins/Array/prototype/toReversed/length-decreased-while-iterating.js new file mode 100644 index 0000000000000000000000000000000000000000..24829881701baa1a16b2cee86feb99ff9613c5a7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/length-decreased-while-iterating.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed caches the length getting the array elements. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2, 3, 4]; +SendableArray.prototype[1] = 5; +Object.defineProperty(arr, "3", { + get() { + arr.length = 1; + return 3; + } +}); +assert.compareArray(arr.toReversed(), [4, 3, undefined, 5, 0]); diff --git a/test/sendable/builtins/Array/prototype/toReversed/length-exceeding-array-length-limit.js b/test/sendable/builtins/Array/prototype/toReversed/length-exceeding-array-length-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..e6e4d5e4cee8d9ff1bdb436daa3d52171bab6089 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/length-exceeding-array-length-limit.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed limits the length to 2 ** 32 - 1 +info: | + Array.prototype.toReversed ( ) +features: [change-array-by-copy, exponentiation] +---*/ + +// Object with large "length" property +var arrayLike = { + get "0"() { + throw new Test262Error("Get 0"); + }, + get "4294967295" () { // 2 ** 32 - 1 + throw new Test262Error("Get 2147483648"); + }, + get "4294967296" () { // 2 ** 32 + throw new Test262Error("Get 2147483648"); + }, + length: 2 ** 32 +}; +assert.throws(RangeError, function() { + SendableArray.prototype.toReversed.call(arrayLike); +}); diff --git a/test/sendable/builtins/Array/prototype/toReversed/length-increased-while-iterating.js b/test/sendable/builtins/Array/prototype/toReversed/length-increased-while-iterating.js new file mode 100644 index 0000000000000000000000000000000000000000..681d16819ca187ec2361408847d9619e1d0199e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/length-increased-while-iterating.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed caches the length getting the array elements. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2]; +Object.defineProperty(arr, "0", { + get() { + arr.push(4); + return 0; + } +}); +assert.compareArray(arr.toReversed(), [2, 1, 0]); diff --git a/test/sendable/builtins/Array/prototype/toReversed/length-tolength.js b/test/sendable/builtins/Array/prototype/toReversed/length-tolength.js new file mode 100644 index 0000000000000000000000000000000000000000..8b9c0c386e6a32f4b86a204914574664bda8ccd1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/length-tolength.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed converts the this value length to a number. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(SendableArray.prototype.toReversed.call({ length: "2", 0: 1, 1: 2, 2: 3 }), [2, 1]); +var arrayLike = { + length: { + valueOf: () => 2 + }, + 0: 1, + 1: 2, + 2: 3, +}; +assert.compareArray(SendableArray.prototype.toReversed.call(arrayLike), [2, 1]); diff --git a/test/sendable/builtins/Array/prototype/toReversed/length.js b/test/sendable/builtins/Array/prototype/toReversed/length.js new file mode 100644 index 0000000000000000000000000000000000000000..8c847691b8c091b8a37fa8ce380f52fe1a248d67 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/length.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + The "length" property of Array.prototype.toReversed +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +verifyProperty(SendableArray.prototype.toReversed, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/toReversed/name.js b/test/sendable/builtins/Array/prototype/toReversed/name.js new file mode 100644 index 0000000000000000000000000000000000000000..b7804ad9e88e0557c7e6247a581088adf3ca5ea3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/name.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed.name is "toReversed". +info: | + Array.prototype.toReversed ( ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +verifyProperty(SendableArray.prototype.toReversed, "name", { + value: "toReversed", + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/toReversed/not-a-constructor.js b/test/sendable/builtins/Array/prototype/toReversed/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..a04f729b54ff307f805cdd11d9157c1922d91db0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/not-a-constructor.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.toReversed does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [change-array-by-copy, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.toReversed), + false, + 'isConstructor(SendableArray.prototype.toReversed) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.toReversed(); +}); + diff --git a/test/sendable/builtins/Array/prototype/toReversed/property-descriptor.js b/test/sendable/builtins/Array/prototype/toReversed/property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..e6e128a49f7ebd4d4d899af0c7431bd4690a4734 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/property-descriptor.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + "toReversed" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +assert.sameValue(typeof SendableArray.prototype.toReversed, "function", "typeof"); +verifyProperty(SendableArray.prototype, "toReversed", { + value: SendableArray.prototype.toReversed, + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/toReversed/this-value-boolean.js b/test/sendable/builtins/Array/prototype/toReversed/this-value-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..68ec6c0787c12ce5c0dae42cf7e2d70ea1286d02 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/this-value-boolean.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed converts booleans to objects +info: | + Array.prototype.toReversed ( ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? LengthOfArrayLike(O). + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(SendableArray.prototype.toReversed.call(true), []); +assert.compareArray(SendableArray.prototype.toReversed.call(false), []); +/* Add length and indexed properties to `Boolean.prototype` */ +Boolean.prototype.length = 3; +assert.compareArray(SendableArray.prototype.toReversed.call(true), [undefined, undefined, undefined]); +assert.compareArray(SendableArray.prototype.toReversed.call(false), [undefined, undefined, undefined]); +delete Boolean.prototype.length; +Boolean.prototype[0] = "monkeys"; +Boolean.prototype[2] = "bogus"; +assert.compareArray(SendableArray.prototype.toReversed.call(true), []); +assert.compareArray(SendableArray.prototype.toReversed.call(false), []); diff --git a/test/sendable/builtins/Array/prototype/toReversed/this-value-nullish.js b/test/sendable/builtins/Array/prototype/toReversed/this-value-nullish.js new file mode 100644 index 0000000000000000000000000000000000000000..a1526df47b5e4a0276ec7987903e429b612bf837 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/this-value-nullish.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed throws if the receiver is null or undefined +features: [change-array-by-copy] +---*/ + +assert.throws(TypeError, () => { + SendableArray.prototype.toReversed.call(null); +}); +assert.throws(TypeError, () => { + SendableArray.prototype.toReversed.call(undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/toReversed/zero-or-one-element.js b/test/sendable/builtins/Array/prototype/toReversed/zero-or-one-element.js new file mode 100644 index 0000000000000000000000000000000000000000..c4724a647966a011095472ab4abe99d03a0c15dc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toReversed/zero-or-one-element.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toReversed +description: > + Array.prototype.toReversed returns a new array even if it has zero or one elements +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var zero = []; +var zeroReversed = zero.toReversed(); +assert.notSameValue(zero, zeroReversed); +assert.compareArray(zero, zeroReversed); +var one = [1]; +var oneReversed = one.toReversed(); +assert.notSameValue(one, oneReversed); +assert.compareArray(one, oneReversed); diff --git a/test/sendable/builtins/Array/prototype/toSorted/comparefn-called-after-get-elements.js b/test/sendable/builtins/Array/prototype/toSorted/comparefn-called-after-get-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..dccd9abb54cdaa3ade61a5b577071c78279916a9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/comparefn-called-after-get-elements.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted reads all the array elements before calling compareFn +info: | + SortIndexedProperties ( obj, len, SortCompare, skipHoles ) + 3. Repeat, while k < len, + a. Let Pk be ! ToString(𝔽(k)). + i. Let kValue be ? Get(O, Pk). + 4. Sort items using an implementation-defined sequence of + calls to SortCompare. If any such call returns an abrupt + completion, stop before performing any further calls to + SortCompare or steps in this algorithm and return that + Completion Record. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var getCalls = []; +var arrayLike = { + length: 3, + get 0() { getCalls.push(0); return 2; }, + get 1() { getCalls.push(1); return 1; }, + get 2() { getCalls.push(2); return 3; }, +} +assert.throws(Test262Error, function() { + SendableArray.prototype.toSorted.call(arrayLike, () => { + throw new Test262Error(); + }); +}); +assert.compareArray(getCalls, [0, 1, 2]); diff --git a/test/sendable/builtins/Array/prototype/toSorted/comparefn-not-a-function.js b/test/sendable/builtins/Array/prototype/toSorted/comparefn-not-a-function.js new file mode 100644 index 0000000000000000000000000000000000000000..9e9afe2291819abc8c4519c1855d332f7df9ae88 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/comparefn-not-a-function.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted verifies that the comparator is callable before reading the length. +info: | + Array.prototype.toSorted ( compareFn ) + 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception. + 2. ... + 3. Let len be ? LengthOfArrayLike(O). +features: [change-array-by-copy] +---*/ + +var getLengthThrow = { + get length() { + throw new Test262Error("IsCallable(comparefn) should be observed before this.length"); + } +}; +var invalidComparators = [null, true, false, "", /a/g, 42, 42n, [], {}, Symbol()]; +for (var i = 0; i < invalidComparators.length; i++) { + assert.throws(TypeError, function() { + [1].toSorted(invalidComparators[i]); + }, String(invalidComparators[i]) + " on an array"); + assert.throws(TypeError, function() { + SendableArray.prototype.toSorted.call(getLengthThrow, invalidComparators[i]); + }, String(invalidComparators[i]) + " on an object whose 'length' throws"); +} diff --git a/test/sendable/builtins/Array/prototype/toSorted/comparefn-stop-after-error.js b/test/sendable/builtins/Array/prototype/toSorted/comparefn-stop-after-error.js new file mode 100644 index 0000000000000000000000000000000000000000..e098e3083054207e4cef7a6011798422fba5cac7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/comparefn-stop-after-error.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted doesn't call compareFn if there is an error +info: | + Array.prototype.toSorted ( compareFn ) + 7. Sort items using an implementation-defined sequence of + calls to SortCompare. If any such call returns an abrupt + completion, stop before performing any further calls to + SortCompare or steps in this algorithm and return that completion. +features: [change-array-by-copy] +---*/ + +var arrayLike = { + length: 1, + get 0() { throw new Test262Error(); }, +}; +var called = false; +assert.throws(Test262Error, function() { + SendableArray.prototype.toSorted.call(arrayLike, () => { + called = true; + }); +}); +assert.sameValue(called, false); +called = 0; +assert.throws(Test262Error, function() { + [1, 2, 3].toSorted(() => { + ++called; + if (called === 1) { + throw new Test262Error(); + } + }); +}); +assert.sameValue(called, 1); diff --git a/test/sendable/builtins/Array/prototype/toSorted/frozen-this-value.js b/test/sendable/builtins/Array/prototype/toSorted/frozen-this-value.js new file mode 100644 index 0000000000000000000000000000000000000000..7ea93595afb19dc0c7fc243e6b0347edf6a3566b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/frozen-this-value.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted works on frozen objects +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = Object.freeze([2, 0, 1]); +var result = arr.toSorted(); +assert.compareArray(result, [0, 1, 2]); +var arrayLike = Object.freeze({ length: 3, 0: 2, 1: 0, 2: 1 }); +result = SendableArray.prototype.toSorted.call(arrayLike); +assert.compareArray(result, [0, 1, 2]); diff --git a/test/sendable/builtins/Array/prototype/toSorted/holes-not-preserved.js b/test/sendable/builtins/Array/prototype/toSorted/holes-not-preserved.js new file mode 100644 index 0000000000000000000000000000000000000000..39362c712c9f23ac3fb3cce05378dc9818bfbc8f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/holes-not-preserved.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted does not preserve holes in the array +info: | + Array.prototype.toSorted ( compareFn ) + 8. Repeat, while j < len, + a. Perform ! CreateDataPropertyOrThrow(A, ! ToString(𝔽(j)), sortedList[j]). + b. Set j to j + 1. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [3, /* hole */, 4, /* hole */, 1]; +SendableArray.prototype[3] = 2; +var sorted = arr.toSorted(); +assert.compareArray(sorted, [1, 2, 3, 4, undefined]); +assert(sorted.hasOwnProperty(4)); diff --git a/test/sendable/builtins/Array/prototype/toSorted/ignores-species.js b/test/sendable/builtins/Array/prototype/toSorted/ignores-species.js new file mode 100644 index 0000000000000000000000000000000000000000..42d9147b009c59e4ac931c589cc1c5498bafc4b3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/ignores-species.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted ignores @@species +info: | + Array.prototype.toSorted ( compareFn ) + 8. Let A be ? ArrayCreate(𝔽(len)). +features: [change-array-by-copy] +---*/ + +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = function () {} +assert.sameValue(Object.getPrototypeOf(a.toSorted()), SendableArray.prototype); +var b = []; +Object.defineProperty(b, "constructor", { + get() { + throw new Test262Error("Should not get .constructor"); + } +}); +b.toSorted(); diff --git a/test/sendable/builtins/Array/prototype/toSorted/immutable.js b/test/sendable/builtins/Array/prototype/toSorted/immutable.js new file mode 100644 index 0000000000000000000000000000000000000000..19418ed536bba50d599340b7b846561ff39f9d06 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/immutable.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted does not mutate its this value +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [2, 0, 1]; +arr.toSorted(); +assert.compareArray(arr, [2, 0, 1]); +assert.notSameValue(arr.toSorted(), arr); diff --git a/test/sendable/builtins/Array/prototype/toSorted/length-casted-to-zero.js b/test/sendable/builtins/Array/prototype/toSorted/length-casted-to-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..e2533f9492cfa5d22867abfd9a28ed71e826103d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/length-casted-to-zero.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted creates an empty array if the this value .length is not a positive integer. +info: | + Array.prototype.toSorted ( compareFn ) + 3. Let len be ? LengthOfArrayLike(O). +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(SendableArray.prototype.toSorted.call({ length: -2 }), []); +assert.compareArray(SendableArray.prototype.toSorted.call({ length: "dog" }), []); +assert.compareArray(SendableArray.prototype.toSorted.call({ length: NaN }), []); diff --git a/test/sendable/builtins/Array/prototype/toSorted/length-decreased-while-iterating.js b/test/sendable/builtins/Array/prototype/toSorted/length-decreased-while-iterating.js new file mode 100644 index 0000000000000000000000000000000000000000..8b59dc68563535dbab2a7422b3a4c67b4b8160fc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/length-decreased-while-iterating.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted caches the length getting the array elements. +info: | + Array.prototype.toSorted ( compareFn ) + 3. Let len be ? LengthOfArrayLike(O). + 6. Let sortedList be ? SortIndexedProperties(obj, len, SortCompare, false). +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [5, 1, 4, 6, 3]; +SendableArray.prototype[3] = 2; +Object.defineProperty(arr, "2", { + get() { + arr.length = 1; + return 4; + } +}); +assert.compareArray(arr.toSorted(), [1, 2, 4, 5, undefined]); diff --git a/test/sendable/builtins/Array/prototype/toSorted/length-exceeding-array-length-limit.js b/test/sendable/builtins/Array/prototype/toSorted/length-exceeding-array-length-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..48601b3b55ffc1af89343889a1bc319dd375df3f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/length-exceeding-array-length-limit.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted limits the length to 2 ** 32 - 1 +---*/ + +// Object with large "length" property +var arrayLike = { + get "0"() { + throw new Test262Error("Get 0"); + }, + get "4294967295" () { // 2 ** 32 - 1 + throw new Test262Error("Get 2147483648"); + }, + get "4294967296" () { // 2 ** 32 + throw new Test262Error("Get 2147483648"); + }, + length: 2 ** 32 +}; +assert.throws(RangeError, function() { + SendableArray.prototype.toSorted.call(arrayLike); +}); diff --git a/test/sendable/builtins/Array/prototype/toSorted/length-increased-while-iterating.js b/test/sendable/builtins/Array/prototype/toSorted/length-increased-while-iterating.js new file mode 100644 index 0000000000000000000000000000000000000000..418d20fef2ce0407b9ecc37cea16d3adc40a97bc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/length-increased-while-iterating.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted caches the length getting the array elements. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [5, 0, 3]; +Object.defineProperty(arr, "0", { + get() { + arr.push(1); + return 5; + } +}); +assert.compareArray(arr.toSorted(), [0, 3, 5]); diff --git a/test/sendable/builtins/Array/prototype/toSorted/length-tolength.js b/test/sendable/builtins/Array/prototype/toSorted/length-tolength.js new file mode 100644 index 0000000000000000000000000000000000000000..6ffbe2d1c15dd9e963f5cab04b07ea701d6f22c9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/length-tolength.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted converts the this value length to a number. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(SendableArray.prototype.toSorted.call({ length: "2", 0: 4, 1: 0, 2: 1 }), [0, 4]); +var arrayLike = { + length: { + valueOf: () => 2 + }, + 0: 4, + 1: 0, + 2: 1, +}; +assert.compareArray(SendableArray.prototype.toSorted.call(arrayLike), [0, 4]); diff --git a/test/sendable/builtins/Array/prototype/toSorted/length.js b/test/sendable/builtins/Array/prototype/toSorted/length.js new file mode 100644 index 0000000000000000000000000000000000000000..a426c65909eec72112b739c7b2f9c88228769859 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/length.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + The "length" property of Array.prototype.toSorted +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +verifyProperty(SendableArray.prototype.toSorted, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/toSorted/name.js b/test/sendable/builtins/Array/prototype/toSorted/name.js new file mode 100644 index 0000000000000000000000000000000000000000..ad602cd09cf7486772219e9b035dc6496eb45f55 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/name.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted.name is "toSorted". +info: | + Array.prototype.toSorted ( compareFn ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +verifyProperty(SendableArray.prototype.toSorted, "name", { + value: "toSorted", + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/toSorted/not-a-constructor.js b/test/sendable/builtins/Array/prototype/toSorted/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..57f7953afdfd24751f23c4210008acaa58db8144 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.toSorted does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [change-array-by-copy, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.toSorted), + false, + 'isConstructor(SendableArray.prototype.toSorted) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.toSorted(); +}); + diff --git a/test/sendable/builtins/Array/prototype/toSorted/property-descriptor.js b/test/sendable/builtins/Array/prototype/toSorted/property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..15b1523687e403b0ecbf3186de2bad122126640d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/property-descriptor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + "toSorted" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +assert.sameValue(typeof SendableArray.prototype.toSorted, "function", "typeof"); +verifyProperty(SendableArray.prototype, "toSorted", { + value: SendableArray.prototype.toSorted, + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/toSorted/this-value-boolean.js b/test/sendable/builtins/Array/prototype/toSorted/this-value-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..6d0bb6d2c7b9ead9688ac3d9011d4ac8729e182f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/this-value-boolean.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted converts booleans to objects +info: | + Array.prototype.toSorted ( compareFn ) + 1. Let O be ? ToObject(this value). + 2. Let len be ? LengthOfArrayLike(O). +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(SendableArray.prototype.toSorted.call(true), []); +assert.compareArray(SendableArray.prototype.toSorted.call(false), []); +/* Add length and indexed properties to `Boolean.prototype` */ +Boolean.prototype.length = 3; +assert.compareArray(SendableArray.prototype.toSorted.call(true), [undefined, undefined, undefined]); +assert.compareArray(SendableArray.prototype.toSorted.call(false), [undefined, undefined, undefined]); +delete Boolean.prototype.length; +Boolean.prototype[0] = "monkeys"; +Boolean.prototype[2] = "bogus"; +assert.compareArray(SendableArray.prototype.toSorted.call(true), []); +assert.compareArray(SendableArray.prototype.toSorted.call(false), []); diff --git a/test/sendable/builtins/Array/prototype/toSorted/this-value-nullish.js b/test/sendable/builtins/Array/prototype/toSorted/this-value-nullish.js new file mode 100644 index 0000000000000000000000000000000000000000..84c922c7cc65dd4a05f6522466c191be770eaeb1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/this-value-nullish.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted throws if the receiver is null or undefined +info: | + Array.prototype.toSorted ( compareFn ) + 1. Let O be ? ToObject(this value). +features: [change-array-by-copy] +---*/ + +assert.throws(TypeError, () => { + SendableArray.prototype.toSorted.call(null); +}); +assert.throws(TypeError, () => { + SendableArray.prototype.toSorted.call(undefined); +}); diff --git a/test/sendable/builtins/Array/prototype/toSorted/zero-or-one-element.js b/test/sendable/builtins/Array/prototype/toSorted/zero-or-one-element.js new file mode 100644 index 0000000000000000000000000000000000000000..9c3784d1789f8d6af5dbc1f431f4cea6d7600bf1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSorted/zero-or-one-element.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSorted +description: > + Array.prototype.toSorted returns a new array even if it has zero or one elements +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var zero = []; +var zeroReversed = zero.toSorted(); +assert.notSameValue(zero, zeroReversed); +assert.compareArray(zero, zeroReversed); +var one = [1]; +var oneReversed = one.toSorted(); +assert.notSameValue(one, oneReversed); +assert.compareArray(one, oneReversed); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/deleteCount-clamped-between-zero-and-remaining-count.js b/test/sendable/builtins/Array/prototype/toSpliced/deleteCount-clamped-between-zero-and-remaining-count.js new file mode 100644 index 0000000000000000000000000000000000000000..c106ed4ac02d1b06f8cd0aaf22c156625aec716a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/deleteCount-clamped-between-zero-and-remaining-count.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: deleteCount is clamped between zero and len - actualStart +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + 10. Else, + a. Let dc be ? ToIntegerOrInfinity(deleteCount). + b. Let actualDeleteCount be the result of clamping dc between 0 and len - actualStart. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3, 4, 5].toSpliced(2, -1), + [0, 1, 2, 3, 4, 5] +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].toSpliced(-4, -1), + [0, 1, 2, 3, 4, 5] +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].toSpliced(2, 6), + [0, 1] +); +assert.compareArray( + [0, 1, 2, 3, 4, 5].toSpliced(-4, 6), + [0, 1] +); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/deleteCount-missing.js b/test/sendable/builtins/Array/prototype/toSpliced/deleteCount-missing.js new file mode 100644 index 0000000000000000000000000000000000000000..b3d0a33b5e325c1bed8636fe8e2121027287a8bd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/deleteCount-missing.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced deletes the elements after start when called with one argument +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + 9. Else if deleteCount is not present, then + a. Let actualDeleteCount be len - actualStart. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = ["first", "second", "third"].toSpliced(1); +assert.compareArray(result, ["first"]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/deleteCount-undefined.js b/test/sendable/builtins/Array/prototype/toSpliced/deleteCount-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..449cf24c4a6cf25fb4a0c0de1672c6bb6a8ab376 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/deleteCount-undefined.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced(number, undefined) returns a copy of the original array +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 6. Else, let actualStart be min(relativeStart, len). + 8. If start is not present, then + a. Let actualDeleteCount be 0. + 9. Else if deleteCount is not present, then + a. Let actualDeleteCount be len - actualStart. + 10. Else, + a. Let dc be ? ToIntegerOrInfinity(deleteCount). + b. Let actualDeleteCount be the result of clamping dc between 0 and len - actualStart. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = ["first", "second", "third"].toSpliced(1, undefined); +assert.compareArray(result, ["first", "second", "third"]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/discarded-element-not-read.js b/test/sendable/builtins/Array/prototype/toSpliced/discarded-element-not-read.js new file mode 100644 index 0000000000000000000000000000000000000000..6963f706249188869f7960e1e85128c634547876 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/discarded-element-not-read.js @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced does not Get the discarded elements in the original array +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 6. Else, let actualStart be min(relativeStart, len). + 8. If start is not present, then + a. Let actualDeleteCount be 0. + 9. Else if deleteCount is not present, then + a. Let actualDeleteCount be len - actualStart. + 10. Else, + a. Let dc be ? ToIntegerOrInfinity(deleteCount). + b. Let actualDeleteCount be the result of clamping dc between 0 and len - actualStart. + 11. Let newLen be len + insertCount - actualDeleteCount. + 15. Let r be actualStart + actualDeleteCount. + 18. Repeat, while i < newLen, + a. Let Pi be ! ToString(𝔽(i)). + b. Let from be ! ToString(𝔽(r)). + c. Let fromValue be ? Get(O, from). + d. Perform ! CreateDataPropertyOrThrow(A, Pi, fromValue). + e. Set i to i + 1. + f. Set r to r + 1. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arrayLike = { + 0: "a", + 1: "b", + get 2() { throw new Test262Error(); }, + 3: "c", + length: 4, +}; +/* + * In this example, just before step 18, i == 2 and r == 3. + * So A[2] is set to arrayLike[3] and arrayLike[2] is never read + * (since i and r both increase monotonically). + */ +var result = SendableArray.prototype.toSpliced.call(arrayLike, 2, 1); +assert.compareArray(result, ["a", "b", "c"]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/elements-read-in-order.js b/test/sendable/builtins/Array/prototype/toSpliced/elements-read-in-order.js new file mode 100644 index 0000000000000000000000000000000000000000..46b5b210a0662a23d32c45983ee3c6babd1ec7e5 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/elements-read-in-order.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced reads the items of the original array in order +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + 14. Let i be 0. + 15. Let r be actualStart + actualDeleteCount. + 16. Repeat, while i < actualStart, + a. Let Pi be ! ToString(𝔽(i)). + b. Let iValue be ? Get(O, Pi). + c. Perform ! CreateDataPropertyOrThrow(A, Pi, iValue). + d. Set i to i + 1. + 17. For each element E of items, do + a. Let Pi be ! ToString(𝔽(i)). + b. Perform ! CreateDataPropertyOrThrow(A, Pi, E). + c. Set i to i + 1. + 18. Repeat, while i < newLen, + a. Let Pi be ! ToString(𝔽(i)). + b. Let from be ! ToString(𝔽(r)). + c. Let fromValue be ? Get(O, from). + d. Perform ! CreateDataPropertyOrThrow(A, Pi, fromValue). + e. Set i to i + 1. + f. Set r to r + 1. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var order = []; +var arrayLike = { + get 0() { order.push(0); return "a" }, + get 1() { order.push(1); return "b" }, + 2: "none", + get 3() { order.push(3); return "c" }, + length: 4, +}; +var result = SendableArray.prototype.toSpliced.call(arrayLike, 2, 1); +assert.compareArray(result, ["a", "b", "c"]); +assert.compareArray(order, [0, 1, 3]); +order = []; +var arr = [0, 1, "none", 3]; +Object.defineProperty(arr, 0, { get: function() { order.push(0); return "a" } }); +Object.defineProperty(arr, 1, { get: function() { order.push(1); return "b" } }); +Object.defineProperty(arr, 3, { get: function() { order.push(3); return "c" } }); +result = SendableArray.prototype.toSpliced.call(arr, 2, 1); +assert.compareArray(result, ["a", "b", "c"]); +assert.compareArray(order, [0, 1, 3]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/frozen-this-value.js b/test/sendable/builtins/Array/prototype/toSpliced/frozen-this-value.js new file mode 100644 index 0000000000000000000000000000000000000000..88f40cc55168b13ae36118872107804cf7d4eeca --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/frozen-this-value.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced works on frozen objects +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = Object.freeze([2, 0, 1]); +var result = arr.toSpliced(); +assert.compareArray(result, [2, 0, 1]); +var arrayLike = Object.freeze({ length: 3, 0: 0, 1: 1, 2: 2 }); +assert.compareArray(SendableArray.prototype.toSpliced.call(arrayLike, 1, 1, 4, 5), [0, 4, 5, 2]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/holes-not-preserved.js b/test/sendable/builtins/Array/prototype/toSpliced/holes-not-preserved.js new file mode 100644 index 0000000000000000000000000000000000000000..6619767d00621eb14c44c2bed977cd84ab9d07db --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/holes-not-preserved.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced does not preserve holes in the array +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + 13. Let k be 0. + 14. Repeat, while k < actualStart, + a. Let Pk be ! ToString(𝔽(k)). + b. Let kValue be ? Get(O, Pk). + c. Perform ? CreateDataPropertyOrThrow(A, Pk, kValue). + d. Set k to k + 1. + 16. Repeat, while k < newLen, + a. Let Pk be ! ToString(𝔽(k)). + b. Let from be ! ToString(𝔽(k + actualDeleteCount - insertCount)). + c. Let fromValue be ? Get(O, from). + d. Perform ? CreateDataPropertyOrThrow(A, Pk, fromValue). + e. Set k to k + 1. +includes: [compareArray.js] +features: [change-array-by-copy] +---*/ + +var arr = [0, /* hole */, 2, /* hole */, 4]; +SendableArray.prototype[3] = 3; +var spliced = arr.toSpliced(0, 0); +assert.compareArray(spliced, [0, undefined, 2, 3, 4]); +assert(spliced.hasOwnProperty(1)); +assert(spliced.hasOwnProperty(3)); +spliced = arr.toSpliced(0, 0, -1); +assert.compareArray(spliced, [-1, 0, undefined, 2, 3, 4]); +assert(spliced.hasOwnProperty(1)); +assert(spliced.hasOwnProperty(3)); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/ignores-species.js b/test/sendable/builtins/Array/prototype/toSpliced/ignores-species.js new file mode 100644 index 0000000000000000000000000000000000000000..f4943e04405efba63298326a9d1118091344d035 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/ignores-species.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced ignores @@species +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + 12. Let A be ? ArrayCreate(𝔽(newLen)). +features: [change-array-by-copy] +---*/ + +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = function () {} +assert.sameValue(Object.getPrototypeOf(a.toSpliced(0, 0)), SendableArray.prototype); +var b = []; +Object.defineProperty(b, "constructor", { + get() { + throw new Test262Error("Should not get .constructor"); + } +}); +b.toSpliced(0, 0); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/immutable.js b/test/sendable/builtins/Array/prototype/toSpliced/immutable.js new file mode 100644 index 0000000000000000000000000000000000000000..0be967b4010073f8a2e980bbecbc81a2791fd052 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/immutable.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced does not mutate its this value +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [2, 0, 1]; +arr.toSpliced(0, 0, -1); +assert.compareArray(arr, [2, 0, 1]); +assert.notSameValue(arr.toSpliced(0, 0, -1), arr); +assert.notSameValue(arr.toSpliced(0, 1, -1), arr); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/length-casted-to-zero.js b/test/sendable/builtins/Array/prototype/toSpliced/length-casted-to-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..86a2140dee6c7f89922e87aed881d269fe694031 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/length-casted-to-zero.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced treats its `this` value's `length` property as zero if the + property's value is not a positive integer. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + 2. Let len be ? LengthOfArrayLike(O). +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(SendableArray.prototype.toSpliced.call({ length: -2 }, 0, 0, 2, 3), [2, 3]); +assert.compareArray(SendableArray.prototype.toSpliced.call({ length: "dog" }, 0, 0, 2, 3), [2, 3]); +assert.compareArray(SendableArray.prototype.toSpliced.call({ length: NaN }, 0, 0, 2, 3), [2, 3]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/length-clamped-to-2pow53minus1.js b/test/sendable/builtins/Array/prototype/toSpliced/length-clamped-to-2pow53minus1.js new file mode 100644 index 0000000000000000000000000000000000000000..eb4008307f95f5ed4e6c7cf1ac0209695bc010ce --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/length-clamped-to-2pow53minus1.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Length is clamped to 2^53-1 when they exceed the integer limit. +features: [change-array-by-copy, exponentiation] +includes: [compareArray.js] +---*/ + +var arrayLike = { + "9007199254740989": 2 ** 53 - 3, + "9007199254740990": 2 ** 53 - 2, + "9007199254740991": 2 ** 53 - 1, + "9007199254740992": 2 ** 53, + "9007199254740994": 2 ** 53 + 2, // NOTE: 2 ** 53 + 1 is 2 ** 53 + length: 2 ** 53 + 20, +}; +var result = SendableArray.prototype.toSpliced.call(arrayLike, 0, 2 ** 53 - 3); +assert.sameValue(result.length, 2); +assert.compareArray(result, [2 ** 53 - 3, 2 ** 53 - 2]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/length-decreased-while-iterating.js b/test/sendable/builtins/Array/prototype/toSpliced/length-decreased-while-iterating.js new file mode 100644 index 0000000000000000000000000000000000000000..acfe2a4d4a27dfd9722aa845bcdbe5bfa498710c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/length-decreased-while-iterating.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced caches the length getting the array elements. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2, 3, 4, 5]; +SendableArray.prototype[3] = 6; +Object.defineProperty(arr, "2", { + get() { + arr.length = 1; + return 2; + } +}); +assert.compareArray(arr.toSpliced(0, 0), [0, 1, 2, 6, undefined, undefined]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/length-exceeding-array-length-limit.js b/test/sendable/builtins/Array/prototype/toSpliced/length-exceeding-array-length-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..3374a41205aca30f001cd06112d565d359bcb2dc --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/length-exceeding-array-length-limit.js @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced limits the length to 2 ** 32 - 1 +features: [change-array-by-copy, exponentiation] +---*/ + +// Object with large "length" property +var arrayLike = { + get "0"() { + throw new Test262Error("Get 0"); + }, + get "4294967295" () { // 2 ** 32 - 1 + throw new Test262Error("Get 4294967295"); + }, + get "4294967296" () { // 2 ** 32 + throw new Test262Error("Get 4294967296"); + }, + length: 2 ** 32 +}; +assert.throws(RangeError, function() { + SendableArray.prototype.toSpliced.call(arrayLike, 0, 0); +}); +arrayLike.length = 2 ** 32 - 1; +assert.throws(RangeError, function() { + SendableArray.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); +arrayLike.length = 2 ** 32; +assert.throws(RangeError, function() { + SendableArray.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); +arrayLike.length = 2 ** 32 + 1; +assert.throws(RangeError, function() { + SendableArray.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); +arrayLike.length = 2 ** 52 - 2; +assert.throws(RangeError, function() { + SendableArray.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); +arrayLike.length = 2 ** 53 - 1; +assert.throws(TypeError, function() { + SendableArray.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); +arrayLike.length = 2 ** 53; +assert.throws(TypeError, function() { + SendableArray.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); +arrayLike.length = 2 ** 53 + 1; +assert.throws(TypeError, function() { + SendableArray.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/length-increased-while-iterating.js b/test/sendable/builtins/Array/prototype/toSpliced/length-increased-while-iterating.js new file mode 100644 index 0000000000000000000000000000000000000000..2f0d84b9a5a6c1c75bafc71fa41c8a7cc3275136 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/length-increased-while-iterating.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced caches the length getting the array elements. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2]; +Object.defineProperty(arr, "0", { + get() { + arr.push(10); + return 0; + } +}); +Object.defineProperty(arr, "2", { + get() { + arr.push(11); + return 2; + } +}); +assert.compareArray(arr.toSpliced(1, 0, 0.5), [0, 0.5, 1, 2]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/length-tolength.js b/test/sendable/builtins/Array/prototype/toSpliced/length-tolength.js new file mode 100644 index 0000000000000000000000000000000000000000..955624e0373910b5a344610f66abc301c385389a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/length-tolength.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced converts the this value length to a number. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(SendableArray.prototype.toSpliced.call({ length: "2", 0: 0, 1: 1, 2: 2 }, 0, 0), [0, 1]); +var arrayLike = { + length: { + valueOf: () => 2 + }, + 0: 0, + 1: 1, + 2: 2, +}; +assert.compareArray(SendableArray.prototype.toSpliced.call(arrayLike, 0, 0), [0, 1]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/length.js b/test/sendable/builtins/Array/prototype/toSpliced/length.js new file mode 100644 index 0000000000000000000000000000000000000000..df82e6d2266f7b4d4a10c3e58565ca3e7490095b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/length.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + The "length" property of Array.prototype.toSpliced +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +verifyProperty(SendableArray.prototype.toSpliced, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/mutate-while-iterating.js b/test/sendable/builtins/Array/prototype/toSpliced/mutate-while-iterating.js new file mode 100644 index 0000000000000000000000000000000000000000..90ffd8c584417898dd93ca71780a411defb1364b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/mutate-while-iterating.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced gets array elements one at a time. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2, 3]; +var zerothElementStorage = arr[0]; +Object.defineProperty(arr, "0", { + get() { + arr[1] = 42; + return zerothElementStorage; + }, + set(v) { + zerothElementStorage = v; + } +}); +Object.defineProperty(arr, "2", { + get() { + arr[0] = 17; + arr[3] = 37; + return 2; + } +}); +assert.compareArray(arr.toSpliced(1, 0, 0.5), [0, 0.5, 42, 2, 37]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/name.js b/test/sendable/builtins/Array/prototype/toSpliced/name.js new file mode 100644 index 0000000000000000000000000000000000000000..d6e37dc26948a1f48db0729f0d7df9e9bcff5f82 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/name.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced.name is "toSpliced". +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +verifyProperty(SendableArray.prototype.toSpliced, "name", { + value: "toSpliced", + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/not-a-constructor.js b/test/sendable/builtins/Array/prototype/toSpliced/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..28b67085b0d5b591fc618be019421f4caa0ecbc1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/not-a-constructor.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.toSpliced does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [change-array-by-copy, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.toSpliced), + false, + 'isConstructor(SendableArray.prototype.toSpliced) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.toSpliced(); +}); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/property-descriptor.js b/test/sendable/builtins/Array/prototype/toSpliced/property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..0c922dca1e0ba67b75db35cd462eae368b0b904a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/property-descriptor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + "toSpliced" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +assert.sameValue(typeof SendableArray.prototype.toSpliced, "function", "typeof"); +verifyProperty(SendableArray.prototype, "toSpliced", { + value: SendableArray.prototype.toSpliced, + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/start-and-deleteCount-missing.js b/test/sendable/builtins/Array/prototype/toSpliced/start-and-deleteCount-missing.js new file mode 100644 index 0000000000000000000000000000000000000000..302670361c6491e8ce51a0fafb91925bb7b861a9 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/start-and-deleteCount-missing.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced returns a copy of the array if called with zero arguments +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 6. Else, let actualStart be min(relativeStart, len). + 8. If start is not present, then + a. Let actualDeleteCount be 0. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +let arr = ["first", "second", "third"]; +let result = arr.toSpliced(); +assert.compareArray(result, arr); +assert.notSameValue(result, arr); + diff --git a/test/sendable/builtins/Array/prototype/toSpliced/start-and-deleteCount-undefineds.js b/test/sendable/builtins/Array/prototype/toSpliced/start-and-deleteCount-undefineds.js new file mode 100644 index 0000000000000000000000000000000000000000..ad5abd1677335d08c757202056237f7a9b55c07d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/start-and-deleteCount-undefineds.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced(undefined, undefined) returns a copy of the original array +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +let arr = ["first", "second", "third"]; +let result = arr.toSpliced(undefined, undefined); +assert.compareArray(result, arr); +assert.notSameValue(result, arr); + diff --git a/test/sendable/builtins/Array/prototype/toSpliced/start-bigger-than-length.js b/test/sendable/builtins/Array/prototype/toSpliced/start-bigger-than-length.js new file mode 100644 index 0000000000000000000000000000000000000000..e99efb24210fdfd2d4692bd20fde8f21e3ea1b57 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/start-bigger-than-length.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced clamps the start argument to the this value length. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 4. If relativeStart is -∞, let actualStart be 0. + 5. Else if relativeStart < 0, let actualStart be max(len + relativeStart, 0). + 6. Else, let actualStart be min(relativeStart, len). +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = [0, 1, 2, 3, 4].toSpliced(10, 1, 5, 6); +assert.compareArray(result, [0, 1, 2, 3, 4, 5, 6]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/start-neg-infinity-is-zero.js b/test/sendable/builtins/Array/prototype/toSpliced/start-neg-infinity-is-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..16a9c31e1741701c7c2e60eba1c539fa83260962 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/start-neg-infinity-is-zero.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced treats negative Infinity as zero for start. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 4. If relativeStart is -∞, let actualStart be 0. + 5. Else if relativeStart < 0, let actualStart be max(len + relativeStart, 0). +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = [0, 1, 2, 3, 4].toSpliced(-Infinity, 2); +assert.compareArray(result, [2, 3, 4]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/start-neg-less-than-minus-length-is-zero.js b/test/sendable/builtins/Array/prototype/toSpliced/start-neg-less-than-minus-length-is-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..bde832bdd26b83ae254462707629addfb2aa937c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/start-neg-less-than-minus-length-is-zero.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced treats a value smaller than -length as zero for start. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 4. If relativeStart is -∞, let actualStart be 0. + 5. Else if relativeStart < 0, let actualStart be max(len + relativeStart, 0). +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = [0, 1, 2, 3, 4].toSpliced(-20, 2); +assert.compareArray(result, [2, 3, 4]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/start-neg-subtracted-from-length.js b/test/sendable/builtins/Array/prototype/toSpliced/start-neg-subtracted-from-length.js new file mode 100644 index 0000000000000000000000000000000000000000..48a716f8941046939d84c501cb0817cb3844f103 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/start-neg-subtracted-from-length.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced treats a negative start as relative to the end. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 4. If relativeStart is -∞, let actualStart be 0. + 5. Else if relativeStart < 0, let actualStart be max(len + relativeStart, 0). +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = [0, 1, 2, 3, 4].toSpliced(-3, 2); +assert.compareArray(result, [0, 1, 4]); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/start-undefined-and-deleteCount-missing.js b/test/sendable/builtins/Array/prototype/toSpliced/start-undefined-and-deleteCount-missing.js new file mode 100644 index 0000000000000000000000000000000000000000..11a7bff6138ac07ff5c7382e007b9d5194dbaf19 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/start-undefined-and-deleteCount-missing.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced(undefined) returns an empty array +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 6. Else, let actualStart be min(relativeStart, len). + 8. If start is not present, then + a. Let actualDeleteCount be 0. + 8. Else if deleteCount is not present, then + a. Let actualDeleteCount be len - actualStart. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = ["first", "second", "third"].toSpliced(undefined); +assert.compareArray(result, []); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/this-value-boolean.js b/test/sendable/builtins/Array/prototype/toSpliced/this-value-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..52033f2df42f77960429c5138f4ef1c9951769a8 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/this-value-boolean.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced converts booleans to objects +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + 1. Let O be ? ToObject(this value). + 2. Let len be ? LengthOfArrayLike(O). +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(SendableArray.prototype.toSpliced.call(true, 0, 0), []); +assert.compareArray(SendableArray.prototype.toSpliced.call(false, 0, 0), []); +/* Add length and indexed properties to `Boolean.prototype` */ +Boolean.prototype.length = 3; +assert.compareArray(SendableArray.prototype.toSpliced.call(true, 0, 0), [undefined, undefined, undefined]); +assert.compareArray(SendableArray.prototype.toSpliced.call(false, 0, 0), [undefined, undefined, undefined]); +delete Boolean.prototype.length; +Boolean.prototype[0] = "monkeys"; +Boolean.prototype[2] = "bogus"; +assert.compareArray(SendableArray.prototype.toSpliced.call(true, 0, 0), []); +assert.compareArray(SendableArray.prototype.toSpliced.call(false, 0, 0), []); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/this-value-nullish.js b/test/sendable/builtins/Array/prototype/toSpliced/this-value-nullish.js new file mode 100644 index 0000000000000000000000000000000000000000..60700f3396d22b14b63f8e20bc6bd97171bac03b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/this-value-nullish.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced throws if the receiver is null or undefined +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + 1. Let O be ? ToObject(this value). +features: [change-array-by-copy] +---*/ + +assert.throws(TypeError, () => { + SendableArray.prototype.toSpliced.call(null, 0, 0); +}, '`SendableArray.prototype.toSpliced.call(null)` throws TypeError'); +assert.throws(TypeError, () => { + SendableArray.prototype.toSpliced.call(undefined, 0, 0); +}, '`SendableArray.prototype.toSpliced.call(undefined)` throws TypeError'); diff --git a/test/sendable/builtins/Array/prototype/toSpliced/unmodified.js b/test/sendable/builtins/Array/prototype/toSpliced/unmodified.js new file mode 100644 index 0000000000000000000000000000000000000000..7c8f9c5cc88fbe7dde916a14c0ceba87be9176a1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toSpliced/unmodified.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced returns a new array even if it the result is equal to the original array +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [1, 2, 3]; +var spliced = arr.toSpliced(1, 0); +assert.notSameValue(arr, spliced); +assert.compareArray(arr, spliced); diff --git a/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T1.js b/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..eaf0d968ba09c9a9a24ea565c073c9169a19853e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T1.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tostring +info: | + The result of calling this function is the same as if + the built-in join method were invoked for this object with no argument +es5id: 15.4.4.2_A1_T1 +description: If Result(2) is zero, return the empty string +---*/ + +var x = new SendableArray(); +if (x.toString() !== x.join()) { + throw new Test262Error('#1.1: x = new SendableArray(); x.toString() === x.join(). Actual: ' + (x.toString())); +} else { + if (x.toString() !== "") { + throw new Test262Error('#1.2: x = new SendableArray(); x.toString() === "". Actual: ' + (x.toString())); + } +} +x = []; +x[0] = 1; +x.length = 0; +if (x.toString() !== x.join()) { + throw new Test262Error('#2.1: x = []; x[0] = 1; x.length = 0; x.toString() === x.join(). Actual: ' + (x.toString())); +} else { + if (x.toString() !== "") { + throw new Test262Error('#2.2: x = []; x[0] = 1; x.length = 0; x.toString() === "". Actual: ' + (x.toString())); + } +} diff --git a/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T2.js b/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..ccf1dc690434054f708483534d01dc6cb0f5415e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T2.js @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tostring +info: | + The result of calling this function is the same as if + the built-in join method were invoked for this object with no argument +es5id: 15.4.4.2_A1_T2 +description: > + The elements of the array are converted to strings, and these + strings are then concatenated, separated by occurrences of the + separator. If no separator is provided, a single comma is used as + the separator +---*/ + +var x = new SendableArray(0, 1, 2, 3); +if (x.toString() !== x.join()) { + throw new Test262Error('#1.1: x = new SendableArray(0,1,2,3); x.toString() === x.join(). Actual: ' + (x.toString())); +} else { + if (x.toString() !== "0,1,2,3") { + throw new Test262Error('#1.2: x = new SendableArray(0,1,2,3); x.toString() === "0,1,2,3". Actual: ' + (x.toString())); + } +} +x = []; +x[0] = 0; +x[3] = 3; +if (x.toString() !== x.join()) { + throw new Test262Error('#2.1: x = []; x[0] = 0; x[3] = 3; x.toString() === x.join(). Actual: ' + (x.toString())); +} else { + if (x.toString() !== "0,,,3") { + throw new Test262Error('#2.2: x = []; x[0] = 0; x[3] = 3; x.toString() === "0,,,3". Actual: ' + (x.toString())); + } +} +x = new SendableArray(undefined, 1, null, 3); +if (x.toString() !== x.join()) { + throw new Test262Error('#3.1: x = SendableArray(undefined,1,null,3); x.toString() === x.join(). Actual: ' + (x.toString())); +} else { + if (x.toString() !== ",1,,3") { + throw new Test262Error('#3.2: x = SendableArray(undefined,1,null,3); x.toString() === ",1,,3". Actual: ' + (x.toString())); + } +} +x = []; +x[0] = 0; +if (x.toString() !== x.join()) { + throw new Test262Error('#4.1: x = []; x[0] = 0; x.toString() === x.join(). Actual: ' + (x.toString())); +} else { + if (x.toString() !== "0") { + throw new Test262Error('#4.2: x = []; x[0] = 0; x.toString() === "0". Actual: ' + (x.toString())); + } +} diff --git a/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T3.js b/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..03c50f0b3fc3baa797367182b3b9ce8cd6c59ec3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T3.js @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tostring +info: | + The result of calling this function is the same as if + the built-in join method were invoked for this object with no argument +es5id: 15.4.4.2_A1_T3 +description: Operator use ToString from array arguments +---*/ + +var x = new SendableArray("", "", ""); +if (x.toString() !== x.join()) { + throw new Test262Error('#0.1: var x = new SendableArray("","",""); x.toString() === x.join(). Actual: ' + (x.toString())); +} else { + if (x.toString() !== ",,") { + throw new Test262Error('#0.2: var x = new SendableArray("","",""); x.toString() === ",,". Actual: ' + (x.toString())); + } +} +var x = new SendableArray("\\", "\\", "\\"); +if (x.toString() !== x.join()) { + throw new Test262Error('#1.1: var x = new SendableArray("\\","\\","\\"); x.toString() === x.join(). Actual: ' + (x.toString())); +} else { + if (x.toString() !== "\\,\\,\\") { + throw new Test262Error('#1.2: var x = new SendableArray("\\","\\","\\"); x.toString() === "\\,\\,\\". Actual: ' + (x.toString())); + } +} +var x = new SendableArray("&", "&", "&"); +if (x.toString() !== x.join()) { + throw new Test262Error('#2.1: var x = new SendableArray("&", "&", "&"); x.toString() === x.join(). Actual: ' + (x.toString())); +} else { + if (x.toString() !== "&,&,&") { + throw new Test262Error('#2.2: var x = new SendableArray("&", "&", "&"); x.toString() === "&,&,&". Actual: ' + (x.toString())); + } +} +var x = new SendableArray(true, true, true); +if (x.toString() !== x.join()) { + throw new Test262Error('#3.1: var x = new SendableArray(true,true,true); x.toString(true,true,true) === x.join(). Actual: ' + (x.toString(true, true, true))); +} else { + if (x.toString() !== "true,true,true") { + throw new Test262Error('#3.2: var x = new SendableArray(true,true,true); x.toString(true,true,true) === "true,true,true". Actual: ' + (x.toString(true, true, true))); + } +} +var x = new SendableArray(null, null, null); +if (x.toString() !== x.join()) { + throw new Test262Error('#4.1: var x = new SendableArray(null,null,null); x.toString(null,null,null) === x.join(). Actual: ' + (x.toString(null, null, null))); +} else { + if (x.toString() !== ",,") { + throw new Test262Error('#4.2: var x = new SendableArray(null,null,null); x.toString(null,null,null) === ",,". Actual: ' + (x.toString(null, null, null))); + } +} +var x = new SendableArray(undefined, undefined, undefined); +if (x.toString() !== x.join()) { + throw new Test262Error('#5.1: var x = new SendableArray(undefined,undefined,undefined); x.toString(undefined,undefined,undefined) === x.join(). Actual: ' + (x.toString(undefined, undefined, undefined))); +} else { + if (x.toString() !== ",,") { + throw new Test262Error('#5.2: var x = new SendableArray(undefined,undefined,undefined); x.toString(undefined,undefined,undefined) === ",,". Actual: ' + (x.toString(undefined, undefined, undefined))); + } +} +var x = new SendableArray(Infinity, Infinity, Infinity); +if (x.toString() !== x.join()) { + throw new Test262Error('#6.1: var x = new SendableArray(Infinity,Infinity,Infinity); x.toString(Infinity,Infinity,Infinity) === x.join(). Actual: ' + (x.toString(Infinity, Infinity, Infinity))); +} else { + if (x.toString() !== "Infinity,Infinity,Infinity") { + throw new Test262Error('#6.2: var x = new SendableArray(Infinity,Infinity,Infinity); x.toString(Infinity,Infinity,Infinity) === "Infinity,Infinity,Infinity". Actual: ' + (x.toString(Infinity, Infinity, Infinity))); + } +} +var x = new SendableArray(NaN, NaN, NaN); +if (x.toString() !== x.join()) { + throw new Test262Error('#7.1: var x = new SendableArray(NaN,NaN,NaN); x.toString(NaN,NaN,NaN) === x.join(). Actual: ' + (x.toString(NaN, NaN, NaN))); +} else { + if (x.toString() !== "NaN,NaN,NaN") { + throw new Test262Error('#7.2: var x = new SendableArray(NaN,NaN,NaN); x.toString(NaN,NaN,NaN) === "NaN,NaN,NaN". Actual: ' + (x.toString(NaN, NaN, NaN))); + } +} diff --git a/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T4.js b/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..c60e7e0e115108d7430d641f152919c35a88f14b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A1_T4.js @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tostring +info: | + The result of calling this function is the same as if + the built-in join method were invoked for this object with no argument +es5id: 15.4.4.2_A1_T4 +description: If Type(value) is Object, evaluate ToPrimitive(value, String) +---*/ + +var object = { + valueOf() { + return "+" + } +}; +var x = new SendableArray(object); +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); +var object = { + valueOf() { + return "+" + }, + toString() { + return "*" + } +}; +var x = new SendableArray(object); +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); +var object = { + valueOf() { + return "+" + }, + toString() { + return {} + } +}; +var x = new SendableArray(object); +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); +var object = { + valueOf() { + throw "error" + }, + toString() { + return "*" + } +}; +var x = new SendableArray(object); +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); +var object = { + toString() { + return "*" + } +}; +var x = new SendableArray(object); +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); +var object = { + valueOf() { + return {} + }, + toString() { + return "*" + } +} +var x = new SendableArray(object); +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); +assert.throws(Test262Error, () => { + var object = { + valueOf() { + return "+" + }, + toString() { + throw new Test262Error(); + } + }; + var x = new SendableArray(object); + x.toString(); +}); +assert.throws(TypeError, () => { + var object = { + valueOf() { + return {} + }, + toString() { + return {} + } + }; + var x = new SendableArray(object); + x.toString(); +}); diff --git a/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A3_T1.js b/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..39235ffa72c7b53946d176b5c54083946a1aee2f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toString/S15.4.4.2_A3_T1.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tostring +info: "[[Get]] from not an inherited property" +es5id: 15.4.4.2_A3_T1 +description: "[[Prototype]] of Array instance is Array.prototype" +---*/ + +SendableArray.prototype[1] = 1; +var x = [0]; +x.length = 2; +if (x.toString() !== "0,1") { + throw new Test262Error('#1: SendableArray.prototype[1] = 1; x = [0]; x.length = 2; x.toString() === "0,1". Actual: ' + (x.toString())); +} diff --git a/test/sendable/builtins/Array/prototype/toString/call-with-boolean.js b/test/sendable/builtins/Array/prototype/toString/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..fe80670a8e8532c43b8c14d7d7f3d6714b79041b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toString/call-with-boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.toString +description: Array.prototype.toString applied to boolean primitive +---*/ + +assert.sameValue( + SendableArray.prototype.toString.call(true), + "[object Boolean]", + 'SendableArray.prototype.toString.call(true) must return "[object Boolean]"' +); +assert.sameValue( + SendableArray.prototype.toString.call(false), + "[object Boolean]", + 'SendableArray.prototype.toString.call(false) must return "[object Boolean]"' +); diff --git a/test/sendable/builtins/Array/prototype/toString/length.js b/test/sendable/builtins/Array/prototype/toString/length.js new file mode 100644 index 0000000000000000000000000000000000000000..26820784981ff0213db90bb9c09703a58e2d5c96 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toString/length.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tostring +description: > + Array.prototype.toString.length is 0. +info: | + Array.prototype.toString ( ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.toString, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/toString/name.js b/test/sendable/builtins/Array/prototype/toString/name.js new file mode 100644 index 0000000000000000000000000000000000000000..806c369d313ad7232a2a51ac920e416fb4bd5cd7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toString/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tostring +description: > + Array.prototype.toString.name is "toString". +info: | + Array.prototype.toString ( ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.toString, "name", { + value: "toString", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/toString/non-callable-join-string-tag.js b/test/sendable/builtins/Array/prototype/toString/non-callable-join-string-tag.js new file mode 100644 index 0000000000000000000000000000000000000000..d272653d0065ccd1804027104562a4ede81811ff --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toString/non-callable-join-string-tag.js @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tostring +description: > + If "join" value is non-callable, Object.prototype.toString intrinsic is called. +info: | + Array.prototype.toString ( ) + 2. Let func be ? Get(array, "join"). + 3. If IsCallable(func) is false, set func to the intrinsic function %Object.prototype.toString%. + 4. Return ? Call(func, array). +features: [Symbol.toStringTag, Proxy, Reflect, BigInt] +---*/ + +assert(delete Object.prototype.toString); +assert.sameValue(SendableArray.prototype.toString.call({ join: null }), "[object Object]"); +assert.sameValue(SendableArray.prototype.toString.call({ join: true }), "[object Object]"); +assert.sameValue(SendableArray.prototype.toString.call({ join: 0 }), "[object Object]"); +assert.sameValue(SendableArray.prototype.toString.call({ join: "join" }), "[object Object]"); +assert.sameValue(SendableArray.prototype.toString.call({ join: Symbol() }), "[object Object]"); +assert.sameValue(SendableArray.prototype.toString.call({ join: 0n }), "[object Object]"); +assert.sameValue(SendableArray.prototype.toString.call({ join: {} }), "[object Object]"); +let revokeOnGet = false; +const proxyTarget = []; +var proxyObj = Proxy.revocable(proxyTarget, { + get: (target, key, receiver) => { + if (revokeOnGet) + revoke(); + return Reflect.get(target, key, receiver); + }, +}); +var proxy = proxyObj.proxy; +var revoke = proxyObj.revoke; +proxyTarget.join = undefined; +assert.sameValue(SendableArray.prototype.toString.call(proxy), "[object SendableArray]"); +revokeOnGet = true; +assert.throws(TypeError, () => { SendableArray.prototype.toString.call(proxy); }); +assert.sameValue(SendableArray.prototype.toString.call((function() { return arguments; })()), "[object Arguments]"); +assert.sameValue(SendableArray.prototype.toString.call(new Error), "[object Error]"); +assert.sameValue(SendableArray.prototype.toString.call(new Boolean), "[object Boolean]"); +assert.sameValue(SendableArray.prototype.toString.call(new Number), "[object Number]"); +assert.sameValue(SendableArray.prototype.toString.call(new String), "[object String]"); +assert.sameValue(SendableArray.prototype.toString.call(new Date), "[object Date]"); +assert.sameValue(SendableArray.prototype.toString.call(new RegExp), "[object RegExp]"); +assert.sameValue(SendableArray.prototype.toString.call(new Proxy(() => {}, {})), "[object Function]"); +assert.sameValue(SendableArray.prototype.toString.call(new Proxy(new Date, {})), "[object Object]"); +assert.sameValue(SendableArray.prototype.toString.call({ [Symbol.toStringTag]: "Foo" }), "[object Foo]"); +assert.sameValue(SendableArray.prototype.toString.call(new Map), "[object Map]"); +RegExp.prototype[Symbol.toStringTag] = "Foo"; +assert.sameValue(SendableArray.prototype.toString.call(new RegExp), "[object Foo]"); +Number.prototype[Symbol.toStringTag] = Object("Foo"); // ignored +assert.sameValue(SendableArray.prototype.toString.call(new Number), "[object Number]"); +Object.defineProperty(JSON, Symbol.toStringTag, { value: "Foo" }); +assert.sameValue(SendableArray.prototype.toString.call(JSON), "[object Foo]"); +assert(delete Set.prototype[Symbol.toStringTag]); +assert.sameValue(SendableArray.prototype.toString.call(new Set), "[object Object]"); +Object.defineProperty(Object.prototype, Symbol.toStringTag, { get: () => { throw new Test262Error(); } }); +assert.throws(Test262Error, () => { SendableArray.prototype.toString.call({}); }); diff --git a/test/sendable/builtins/Array/prototype/toString/not-a-constructor.js b/test/sendable/builtins/Array/prototype/toString/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..4b0f3c74bb01cae835efb5d2efecbc5495ced297 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toString/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.toString does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.toString), + false, + 'isConstructor(SendableArray.prototype.toString) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.toString(); +}); + diff --git a/test/sendable/builtins/Array/prototype/toString/prop-desc.js b/test/sendable/builtins/Array/prototype/toString/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..d9e93323caec46b2ac5bf12ec191ff51afc3dc8d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/toString/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.tostring +description: > + "toString" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.toString, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "toString", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A1_T1.js b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..910b395b95e4943c82d402a02599d37ba14c7f6a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A1_T1.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The arguments are prepended to the start of the array, such that + their order within the array is the same as the order in which they appear in + the argument list +esid: sec-array.prototype.unshift +description: Checking case when unsift is given no arguments or one argument +---*/ + +var x = new SendableArray(); +var unshift = x.unshift(1); +if (unshift !== 1) { + throw new Test262Error('#1: x = new SendableArray(); x.unshift(1) === 1. Actual: ' + (unshift)); +} +if (x[0] !== 1) { + throw new Test262Error('#2: x = new SendableArray(); x.unshift(1); x[0] === 1. Actual: ' + (x[0])); +} +var unshift = x.unshift(); +if (unshift !== 1) { + throw new Test262Error('#3: x = new SendableArray(); x.unshift(1); x.unshift() === 1. Actual: ' + (unshift)); +} +if (x[1] !== undefined) { + throw new Test262Error('#4: x = new SendableArray(); x.unshift(1); x.unshift(); x[1] === unedfined. Actual: ' + (x[1])); +} +var unshift = x.unshift(-1); +if (unshift !== 2) { + throw new Test262Error('#5: x = new SendableArray(); x.unshift(1); x.unshift(); x.unshift(-1) === 2. Actual: ' + (unshift)); +} +if (x[0] !== -1) { + throw new Test262Error('#6: x = new SendableArray(); x.unshift(1); x.unshift(-1); x[0] === -1. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#7: x = new SendableArray(); x.unshift(1); x.unshift(-1); x[1] === 1. Actual: ' + (x[1])); +} +if (x.length !== 2) { + throw new Test262Error('#8: x = new SendableArray(); x.unshift(1); x.unshift(); x.unshift(-1); x.length === 2. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A1_T2.js b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..86c1ad5b171c47f62ba935339fef9c1ae47b197f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A1_T2.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The arguments are prepended to the start of the array, such that + their order within the array is the same as the order in which they appear in + the argument list +esid: sec-array.prototype.unshift +description: Checking case when unsift is given many arguments +---*/ + +var x = []; +if (x.length !== 0) { + throw new Test262Error('#1: x = []; x.length === 0. Actual: ' + (x.length)); +} +x[0] = 0; +var unshift = x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); +if (unshift !== 6) { + throw new Test262Error('#2: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1) === 6. Actual: ' + (unshift)); +} +if (x[5] !== 0) { + throw new Test262Error('#3: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[5] === 0. Actual: ' + (x[5])); +} +if (x[0] !== true) { + throw new Test262Error('#4: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[0] === true. Actual: ' + (x[0])); +} +if (x[1] !== Number.POSITIVE_INFINITY) { + throw new Test262Error('#5: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[1] === Number.POSITIVE_INFINITY. Actual: ' + (x[1])); +} +if (x[2] !== "NaN") { + throw new Test262Error('#6: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[2] === "NaN". Actual: ' + (x[2])); +} +if (x[3] !== "1") { + throw new Test262Error('#7: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[3] === "1". Actual: ' + (x[3])); +} +if (x[4] !== -1) { + throw new Test262Error('#8: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[4] === -1. Actual: ' + (x[4])); +} +if (x.length !== 6) { + throw new Test262Error('#9: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x.length === 6. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A2_T1.js b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..9d50717b343dc6d12e36f509eeeec925efde9b38 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A2_T1.js @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The unshift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.unshift +description: > + The arguments are prepended to the start of the array, such that + their order within the array is the same as the order in which + they appear in the argument list +---*/ + +var obj = {}; +obj.unshift = SendableArray.prototype.unshift; +if (obj.length !== undefined) { + throw new Test262Error('#0: var obj = {}; obj.length === undefined. Actual: ' + (obj.length)); +} else { + var unshift = obj.unshift(-1); + if (unshift !== 1) { + throw new Test262Error('#1: var obj = {}; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-1) === 1. Actual: ' + (unshift)); + } + if (obj.length !== 1) { + throw new Test262Error('#2: var obj = {}; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-1); obj.length === 1. Actual: ' + (obj.length)); + } + if (obj["0"] !== -1) { + throw new Test262Error('#3: var obj = {}; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-1); obj["0"] === -1. Actual: ' + (obj["0"])); + } +} +obj.length = undefined; +var unshift = obj.unshift(-4); +if (unshift !== 1) { + throw new Test262Error('#4: var obj = {}; obj.length = undefined; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-4) === 1. Actual: ' + (unshift)); +} +if (obj.length !== 1) { + throw new Test262Error('#5: var obj = {}; obj.length = undefined; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-4); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -4) { + throw new Test262Error('#6: var obj = {}; obj.length = undefined; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-4); obj["0"] === -4. Actual: ' + (obj["0"])); +} +obj.length = null +var unshift = obj.unshift(-7); +if (unshift !== 1) { + throw new Test262Error('#7: var obj = {}; obj.length = null; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-7) === 1. Actual: ' + (unshift)); +} +if (obj.length !== 1) { + throw new Test262Error('#8: var obj = {}; obj.length = null; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-7); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -7) { + throw new Test262Error('#9: var obj = {}; obj.length = null; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-7); obj["0"] === -7. Actual: ' + (obj["0"])); +} diff --git a/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A2_T2.js b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..1d1f4ec55774a174380eb0c9bf5122ece0b408c3 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A2_T2.js @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The unshift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.unshift +description: > + The arguments are prepended to the start of the array, such that + their order within the array is the same as the order in which + they appear in the argument list +---*/ + +var obj = {}; +obj.unshift = SendableArray.prototype.unshift; +obj.length = NaN; +var unshift = obj.unshift(-1); +if (unshift !== 1) { + throw new Test262Error('#1: var obj = {}; obj.length = NaN; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-1) === 1. Actual: ' + (unshift)); +} +if (obj.length !== 1) { + throw new Test262Error('#2: var obj = {}; obj.length = NaN; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-1); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -1) { + throw new Test262Error('#3: var obj = {}; obj.length = NaN; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-1); obj["0"] === -1. Actual: ' + (obj["0"])); +} +obj.length = Number.NEGATIVE_INFINITY; +var unshift = obj.unshift(-7); +if (unshift !== 1) { + throw new Test262Error('#7: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-7) === 1. Actual: ' + (unshift)); +} +if (obj.length !== 1) { + throw new Test262Error('#8: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-7); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -7) { + throw new Test262Error('#9: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-7); obj["0"] === -7. Actual: ' + (obj["0"])); +} +obj.length = 0.5; +var unshift = obj.unshift(-10); +if (unshift !== 1) { + throw new Test262Error('#10: var obj = {}; obj.length = 0.5; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-10) === 1. Actual: ' + (unshift)); +} +if (obj.length !== 1) { + throw new Test262Error('#11: var obj = {}; obj.length = 0.5; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-10); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -10) { + throw new Test262Error('#12: var obj = {}; obj.length = 0.5; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-10); obj["0"] === -10. Actual: ' + (obj["0"])); +} +obj.length = 1.5; +var unshift = obj.unshift(-13); +if (unshift !== 2) { + throw new Test262Error('#13: var obj = {}; obj.length = 1.5; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-13) === 2. Actual: ' + (unshift)); +} +if (obj.length !== 2) { + throw new Test262Error('#14: var obj = {}; obj.length = 1.5; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-13); obj.length === 2. Actual: ' + (obj.length)); +} +if (obj["0"] !== -13) { + throw new Test262Error('#15: var obj = {}; obj.length = 1.5; obj.unshift = SendableArray.prototype.unshift; obj.unshift(-13); obj["0"] === -13. Actual: ' + (obj["0"])); +} +obj.length = new Number(0); +var unshift = obj.unshift(-16); +if (unshift !== 1) { + throw new Test262Error('#16: var obj = {}; obj.length = new Number(0); obj.unshift = SendableArray.prototype.unshift; obj.unshift(-16) === 1. Actual: ' + (unshift)); +} +if (obj.length !== 1) { + throw new Test262Error('#17: var obj = {}; obj.length = new Number(0); obj.unshift = SendableArray.prototype.unshift; obj.unshift(-16); obj.length === 1. Actual: ' + (obj.length)); +} +if (obj["0"] !== -16) { + throw new Test262Error('#18: var obj = {}; obj.length = new Number(0); obj.unshift = SendableArray.prototype.unshift; obj.unshift(-16); obj["0"] === -16. Actual: ' + (obj["0"])); +} diff --git a/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A2_T3.js b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..7f38988e8bf376fbb08e43d1f39fb90231a134de --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A2_T3.js @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: | + The unshift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.unshift +description: > + Operator use ToNumber from length. If Type(value) is Object, + evaluate ToPrimitive(value, Number) +---*/ + +var obj = {}; +obj.unshift = SendableArray.prototype.unshift; +obj.length = { + valueOf() { + return 3 + } +}; +var unshift = obj.unshift(); +assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); +obj.length = { + valueOf() { + return 3 + }, + toString() { + return 1 + } +}; +var unshift = obj.unshift(); +assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); +obj.length = { + valueOf() { + return 3 + }, + toString() { + return {} + } +}; +var unshift = obj.unshift(); +assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); +try { + obj.length = { + valueOf() { + return 3 + }, + toString() { + throw "error" + } + }; + var unshift = obj.unshift(); + assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); +} +catch (e) { + assert.notSameValue(e, "error", 'The value of e is not "error"'); +} +obj.length = { + toString() { + return 1 + } +}; +var unshift = obj.unshift(); +assert.sameValue(unshift, 1, 'The value of unshift is expected to be 1'); +obj.length = { + valueOf() { + return {} + }, + toString() { + return 1 + } +} +var unshift = obj.unshift(); +assert.sameValue(unshift, 1, 'The value of unshift is expected to be 1'); +try { + + obj.length = { + valueOf() { + throw "error" + }, + toString() { + return 1 + } + }; + var unshift = obj.unshift(); + throw new Test262Error('#7.1: obj.length = {valueOf() {throw "error"}, toString() {return 1}}; obj.unshift() throw "error". Actual: ' + (unshift)); +} +catch (e) { + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); +} +try { + + obj.length = { + valueOf() { + return {} + }, + toString() { + return {} + } + }; + var unshift = obj.unshift(); + throw new Test262Error('#8.1: obj.length = {valueOf() {return {}}, toString() {return {}}} obj.unshift() throw TypeError. Actual: ' + (unshift)); +} +catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A3_T2.js b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..36886c5232ff90ab737d68baa77c4e7656e02505 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A3_T2.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.unshift +description: length = -4294967295 +---*/ + +var obj = {}; +obj.unshift = SendableArray.prototype.unshift; +obj[0] = ""; +obj.length = -4294967295; +var unshift = obj.unshift("x", "y", "z"); +if (unshift !== 3) { + throw new Test262Error('#1: var obj = {}; obj.unshift = SendableArray.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z") === 3. Actual: ' + (unshift)); +} +if (obj.length !== 3) { + throw new Test262Error('#2: var obj = {}; obj.unshift = SendableArray.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z"); obj.length === 3. Actual: ' + (obj.length)); +} +if (obj[0] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.unshift = SendableArray.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z"); obj[0] === "x". Actual: ' + (obj[0])); +} +if (obj[1] !== "y") { + throw new Test262Error('#4: var obj = {}; obj.unshift = SendableArray.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z"); obj[1] === "y". Actual: ' + (obj[1])); +} +if (obj[2] !== "z") { + throw new Test262Error('#5: var obj = {}; obj.unshift = SendableArray.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z"); obj[2] === "z". Actual: ' + (obj[2])); +} +if (obj[3] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.unshift = SendableArray.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z"); obj[3] === undefined. Actual: ' + (obj[3])); +} diff --git a/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A4_T1.js b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A4_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..92ec2748bb4f524474159b907867932e2691312a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A4_T1.js @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]], [[Delete]] from not an inherited property" +esid: sec-array.prototype.unshift +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[0] = -1; +var x = [1]; +x.length = 1; +var unshift = x.unshift(0); +if (unshift !== 2) { + throw new Test262Error('#1: SendableArray.prototype[0] = -1; x = [1]; x.length = 1; x.unshift(0) === 2. Actual: ' + (unshift)); +} +if (x[0] !== 0) { + throw new Test262Error('#2: SendableArray.prototype[0] = -1; x = [1]; x.length = 1; x.unshift(0); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#3: SendableArray.prototype[0] = -1; x = [1]; x.length = 1; x.unshift(0); x[1] === 1. Actual: ' + (x[1])); +} +delete x[0]; +if (x[0] !== -1) { + throw new Test262Error('#4: SendableArray.prototype[0] = -1; x = [1]; x.length = 1; x.unshift(0); delete x[0]; x[0] === -1. Actual: ' + (x[0])); +} +Object.prototype[0] = -1; +Object.prototype.length = 1; +Object.prototype.unshift = SendableArray.prototype.unshift; +x = { + 0: 1 +}; +var unshift = x.unshift(0); +if (unshift !== 2) { + throw new Test262Error('#5: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {0:0}; x.unshift(0) === 2. Actual: ' + (unshift)); +} +if (x[0] !== 0) { + throw new Test262Error('#6: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {0:0}; x.unshift(0); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#7: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {0:0}; x.unshift(0); x[1] === 1. Actual: ' + (x[1])); +} +delete x[0]; +if (x[0] !== -1) { + throw new Test262Error('#8: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {0:0}; x.unshift(0); delete x[0]; x[0] === -1. Actual: ' + (x[0])); +} +if (x.length !== 2) { + throw new Test262Error('#9: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {0:0}; x.unshift(0); x.length === 1. Actual: ' + (x.length)); +} +delete x.length; +if (x.length !== 1) { + throw new Test262Error('#10: Object.prototype[1] = -1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {0:0}; x.unshift(0); delete x; x.length === 1. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A4_T2.js b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A4_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..c09d900eb7501e1f8d90589763f25e182c08b15e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/S15.4.4.13_A4_T2.js @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +info: "[[Get]], [[Delete]] from not an inherited property" +esid: sec-array.prototype.unshift +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +SendableArray.prototype[0] = 1; +var x = []; +x.length = 1; +var unshift = x.unshift(0); +if (unshift !== 2) { + throw new Test262Error('#1: SendableArray.prototype[0] = 1; x = []; x.length = 1; x.unshift(0) === 2. Actual: ' + (unshift)); +} +if (x[0] !== 0) { + throw new Test262Error('#2: SendableArray.prototype[0] = 1; x = []; x.length = 1; x.unshift(0); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#3: SendableArray.prototype[0] = 1; x = []; x.length = 1; x.unshift(0); x[1] === 1. Actual: ' + (x[1])); +} +delete x[0]; +if (x[0] !== 1) { + throw new Test262Error('#4: SendableArray.prototype[0] = 1; x = [1]; x.length = 1; x.unshift(0); delete x[0]; x[0] === 1. Actual: ' + (x[0])); +} +Object.prototype[0] = 1; +Object.prototype.length = 1; +Object.prototype.unshift = SendableArray.prototype.unshift; +x = {}; +var unshift = x.unshift(0); +if (unshift !== 2) { + throw new Test262Error('#5: Object.prototype[0] = 1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {}; x.unshift(0) === 2. Actual: ' + (unshift)); +} +if (x[0] !== 0) { + throw new Test262Error('#6: Object.prototype[0] = 1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {}; x.unshift(0); x[0] === 0. Actual: ' + (x[0])); +} +if (x[1] !== 1) { + throw new Test262Error('#7: Object.prototype[0] = 1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {}; x.unshift(0); x[1] === 1. Actual: ' + (x[1])); +} +delete x[0]; +if (x[0] !== 1) { + throw new Test262Error('#8: Object.prototype[0] = 1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {}; x.unshift(0); delete x[0]; x[0] === 1. Actual: ' + (x[0])); +} +if (x.length !== 2) { + throw new Test262Error('#9: Object.prototype[0] = 1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {}; x.unshift(0); x.length === 1. Actual: ' + (x.length)); +} +delete x.length; +if (x.length !== 1) { + throw new Test262Error('#10: Object.prototype[1] = 1; Object.prototype.length = 1; Object.prototype.unshift = SendableArray.prototype.unshift; x = {}; x.unshift(0); delete x; x.length === 1. Actual: ' + (x.length)); +} diff --git a/test/sendable/builtins/Array/prototype/unshift/call-with-boolean.js b/test/sendable/builtins/Array/prototype/unshift/call-with-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..7e91802f5175130283236bef9086b3489bbd7485 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/call-with-boolean.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: Array.prototype.unshift applied to boolean primitive +---*/ + +assert.sameValue(SendableArray.prototype.unshift.call(true), 0, 'SendableArray.prototype.unshift.call(true) must return 0'); +assert.sameValue(SendableArray.prototype.unshift.call(false), 0, 'SendableArray.prototype.unshift.call(false) must return 0'); diff --git a/test/sendable/builtins/Array/prototype/unshift/clamps-to-integer-limit.js b/test/sendable/builtins/Array/prototype/unshift/clamps-to-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..c19523684519c4de129f79075b2785a2012e198a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/clamps-to-integer-limit.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: > + Length values exceeding 2^53-1 are clamped to 2^53-1. +info: | + 1. ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. Let argCount be the number of actual arguments. + 4. If argCount > 0, then ... + 5. Perform ? Set(O, "length", len+argCount, true). +features: [exponentiation] +---*/ + +var arrayLike = {}; +arrayLike.length = 2 ** 53 - 1; +SendableArray.prototype.unshift.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53 - 1"); +arrayLike.length = 2 ** 53; +SendableArray.prototype.unshift.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53"); +arrayLike.length = 2 ** 53 + 2; +SendableArray.prototype.unshift.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53 + 2"); +arrayLike.length = Infinity; +SendableArray.prototype.unshift.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is Infinity"); diff --git a/test/sendable/builtins/Array/prototype/unshift/length-near-integer-limit.js b/test/sendable/builtins/Array/prototype/unshift/length-near-integer-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..469a2a20029a53bc70106a74ab2705f60e57b66e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/length-near-integer-limit.js @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: > + Test properties are correctly accessed when length property is near 2^53-1. +info: | + 2. Let len be ? ToLength(? Get(O, "length")). + 3. Let argCount be the number of actual arguments. + 4. If argCount > 0, then + ... + b. Let k be len. + c. Repeat, while k > 0, + i. Let from be ! ToString(k-1). + ii. Let to be ! ToString(k+argCount-1). + iii. Let fromPresent be ? HasProperty(O, from). + iv. If fromPresent is true, then + 1. Let fromValue be ? Get(O, from). + 2. Perform ? Set(O, to, fromValue, true). + v. Else fromPresent is false, + 1. Perform ? DeletePropertyOrThrow(O, to). + vi. Decrease k by 1. +features: [exponentiation] +---*/ + +function StopUnshift() {} +var arrayLike = { + get "9007199254740986" () { + throw new StopUnshift(); + }, + "9007199254740987": "9007199254740987", + /* "9007199254740988": hole */ + "9007199254740989": "9007199254740989", + /* "9007199254740990": empty */ + "9007199254740991": "9007199254740991", + length: 2 ** 53 - 2 +}; +assert.throws(StopUnshift, function() { + SendableArray.prototype.unshift.call(arrayLike, null); +}); +assert.sameValue(arrayLike.length, 2 ** 53 - 2, + "arrayLike.length is unchanged"); +assert.sameValue(arrayLike["9007199254740987"], "9007199254740987", + "arrayLike['9007199254740987'] is unchanged"); +assert.sameValue(arrayLike["9007199254740988"], "9007199254740987", + "arrayLike['9007199254740988'] is replaced with arrayLike['9007199254740987']"); +assert.sameValue("9007199254740989" in arrayLike, false, + "arrayLike['9007199254740989'] is removed"); +assert.sameValue(arrayLike["9007199254740990"], "9007199254740989", + "arrayLike['9007199254740990'] is replaced with arrayLike['9007199254740989']"); +assert.sameValue(arrayLike["9007199254740991"], "9007199254740991", + "arrayLike['9007199254740991'] is unchanged"); diff --git a/test/sendable/builtins/Array/prototype/unshift/length.js b/test/sendable/builtins/Array/prototype/unshift/length.js new file mode 100644 index 0000000000000000000000000000000000000000..a5468abe6b33d481b3fafedd634b41e34d059b4d --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/length.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: > + The "length" property of Array.prototype.unshift +info: | + 22.1.3.29 Array.prototype.unshift ( ...items ) + The length property of the unshift method is 1. + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.unshift, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/unshift/name.js b/test/sendable/builtins/Array/prototype/unshift/name.js new file mode 100644 index 0000000000000000000000000000000000000000..e7615895cb9344e1a6cbdf0b4f82717b25f2e53c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: > + Array.prototype.unshift.name is "unshift". +info: | + Array.prototype.unshift ( ...items ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.unshift, "name", { + value: "unshift", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/unshift/not-a-constructor.js b/test/sendable/builtins/Array/prototype/unshift/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..81515667ff9003588369a3039ca2861d593aae80 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.unshift does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.unshift), + false, + 'isConstructor(SendableArray.prototype.unshift) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.unshift(); +}); + diff --git a/test/sendable/builtins/Array/prototype/unshift/prop-desc.js b/test/sendable/builtins/Array/prototype/unshift/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..31afc9a3c7c02b68431391a1a5ab4082a7ba2780 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/prop-desc.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: > + "unshift" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.unshift, 'function', 'typeof'); +verifyProperty(SendableArray.prototype, "unshift", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/unshift/set-length-array-is-frozen.js b/test/sendable/builtins/Array/prototype/unshift/set-length-array-is-frozen.js new file mode 100644 index 0000000000000000000000000000000000000000..a734cf73ca52e7d6691bef7d16afa5e96085227c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/set-length-array-is-frozen.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: > + A TypeError is thrown when "length" is [[Set]] on a frozen array. +---*/ + +var array = []; +var arrayPrototypeSet0Calls = 0; +Object.defineProperty(SendableArray.prototype, "0", { + set(_val) { + Object.freeze(array); + arrayPrototypeSet0Calls++; + }, +}); +assert.throws(TypeError, function() { + array.unshift(1); +}); +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); +assert.sameValue(arrayPrototypeSet0Calls, 1); diff --git a/test/sendable/builtins/Array/prototype/unshift/set-length-array-length-is-non-writable.js b/test/sendable/builtins/Array/prototype/unshift/set-length-array-length-is-non-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..ecdad69157fd09e267ee86f1ef16c58295008a1b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/set-length-array-length-is-non-writable.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: > + A TypeError is thrown when "length" is [[Set]] on an array with non-writable "length". +---*/ + +var array = []; +var arrayPrototypeSet0Calls = 0; +Object.defineProperty(SendableArray.prototype, "0", { + set(_val) { + Object.defineProperty(array, "length", { writable: false }); + arrayPrototypeSet0Calls++; + }, +}); +assert.throws(TypeError, function() { + array.unshift(1); +}); +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); +assert.sameValue(arrayPrototypeSet0Calls, 1); diff --git a/test/sendable/builtins/Array/prototype/unshift/set-length-zero-array-is-frozen.js b/test/sendable/builtins/Array/prototype/unshift/set-length-zero-array-is-frozen.js new file mode 100644 index 0000000000000000000000000000000000000000..d82faf54411fdff94d04a7150c664ccb9553b7b1 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/set-length-zero-array-is-frozen.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: > + A TypeError is thrown when "length" is [[Set]] on an empty frozen array. +---*/ + +var array = []; +Object.freeze(array); +assert.throws(TypeError, function() { + array.unshift(); +}); +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); diff --git a/test/sendable/builtins/Array/prototype/unshift/set-length-zero-array-length-is-non-writable.js b/test/sendable/builtins/Array/prototype/unshift/set-length-zero-array-length-is-non-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..992d0eedddbf1ba87c9d8fdc5fb96d4858e29eec --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/set-length-zero-array-length-is-non-writable.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: > + A TypeError is thrown when "length" is [[Set]] on an empty array with non-writable "length". +---*/ + +var array = []; +Object.defineProperty(array, "length", { writable: false }); +assert.throws(TypeError, function() { + array.unshift(); +}); +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); diff --git a/test/sendable/builtins/Array/prototype/unshift/throws-if-integer-limit-exceeded.js b/test/sendable/builtins/Array/prototype/unshift/throws-if-integer-limit-exceeded.js new file mode 100644 index 0000000000000000000000000000000000000000..6228d92ae4a8711d61d1b7664849213f94fd0f06 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/throws-if-integer-limit-exceeded.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: > + A TypeError is thrown if the new length exceeds 2^53-1. +info: | + 2. Let len be ? ToLength(? Get(O, "length")). + 3. Let argCount be the number of actual arguments. + 4. If argCount > 0, then + a. If len+argCount > 2^53-1, throw a TypeError exception. + b. ... +features: [exponentiation] +---*/ + +var arrayLike = {}; +arrayLike.length = 2 ** 53 - 1; +assert.throws(TypeError, function() { + SendableArray.prototype.unshift.call(arrayLike, null); +}, "Length is 2**53 - 1"); +arrayLike.length = 2 ** 53; +assert.throws(TypeError, function() { + SendableArray.prototype.unshift.call(arrayLike, null); +}, "Length is 2**53"); +arrayLike.length = 2 ** 53 + 2; +assert.throws(TypeError, function() { + SendableArray.prototype.unshift.call(arrayLike, null); +}, "Length is 2**53 + 2"); +arrayLike.length = Infinity; +assert.throws(TypeError, function() { + SendableArray.prototype.unshift.call(arrayLike, null); +}, "Length is Infinity"); diff --git a/test/sendable/builtins/Array/prototype/unshift/throws-with-string-receiver.js b/test/sendable/builtins/Array/prototype/unshift/throws-with-string-receiver.js new file mode 100644 index 0000000000000000000000000000000000000000..547d1b737b1519c39230c41126b59dec6618309f --- /dev/null +++ b/test/sendable/builtins/Array/prototype/unshift/throws-with-string-receiver.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.unshift +description: > + Array#unshift throws TypeError upon attempting to modify a string +---*/ + +assert.throws(TypeError, () => { + SendableArray.prototype.unshift.call(''); +}, "SendableArray.prototype.unshift.call('')"); +assert.throws(TypeError, () => { + SendableArray.prototype.unshift.call('', 1); +}, "SendableArray.prototype.unshift.call('', 1)"); +assert.throws(TypeError, () => { + SendableArray.prototype.unshift.call('abc'); +}, "SendableArray.prototype.unshift.call('abc')"); +assert.throws(TypeError, () => { + SendableArray.prototype.unshift.call('abc', 1); +}, "SendableArray.prototype.unshift.call('abc', 1)"); diff --git a/test/sendable/builtins/Array/prototype/values/iteration-mutable.js b/test/sendable/builtins/Array/prototype/values/iteration-mutable.js new file mode 100644 index 0000000000000000000000000000000000000000..ce1ceffea5fa737f1ee33570fc5feba242a47fda --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/iteration-mutable.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.values +description: > + New items in the array are accessible via iteration until iterator is "done". +info: | + When an item is added to the array after the iterator is created but + before the iterator is "done" (as defined by 22.1.5.2.1), the new item's + value should be accessible via iteration. When an item is added to the + array after the iterator is "done", the new item should not be + accessible via iteration. +---*/ + +var array = []; +var iterator = array.values(); +var result; +array.push('a'); +result = iterator.next(); +assert.sameValue(result.done, false, 'First result `done` flag'); +assert.sameValue(result.value, 'a', 'First result `value`'); +result = iterator.next(); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +array.push('b'); +result = iterator.next(); +assert.sameValue( + result.done, true, + 'Exhausted result `done` flag (after push)' +); +assert.sameValue( + result.value, undefined, + 'Exhausted result `value` (after push)' +); diff --git a/test/sendable/builtins/Array/prototype/values/iteration.js b/test/sendable/builtins/Array/prototype/values/iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..79fd21771a04aa61729e96af0476efc36e0fcb1b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/iteration.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.values +description: > + The return is a valid iterator with the array's numeric properties. +info: | + 22.1.3.29 Array.prototype.values ( ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "value"). +---*/ + +var array = ['a', 'b', 'c']; +var iterator = array.values(); +var result; +result = iterator.next(); +assert.sameValue(result.value, 'a', 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); +result = iterator.next(); +assert.sameValue(result.value, 'b', 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); +result = iterator.next(); +assert.sameValue(result.value, 'c', 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); diff --git a/test/sendable/builtins/Array/prototype/values/length.js b/test/sendable/builtins/Array/prototype/values/length.js new file mode 100644 index 0000000000000000000000000000000000000000..8fa8f8d1423990f365fd30d65dfdf50e03f24137 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/length.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.values +description: Array.prototype.values `length` property +info: | + ES6 Section 17: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.values, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/values/name.js b/test/sendable/builtins/Array/prototype/values/name.js new file mode 100644 index 0000000000000000000000000000000000000000..7677a8285ea6fe9b9f025f61af13844ce1bbea40 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/name.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.values +description: Array.prototype.values `name` property +info: | + ES6 Section 17: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. Unless otherwise specified, this value is the name that is given to + the function in this specification. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArray.prototype.values, "name", { + value: "values", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/values/not-a-constructor.js b/test/sendable/builtins/Array/prototype/values/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..c93152300bacd3198ae38e67a89325ca2149a43b --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/not-a-constructor.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.values does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [Reflect.construct, Array.prototype.values, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.values), + false, + 'isConstructor(SendableArray.prototype.values) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.values(); +}); + diff --git a/test/sendable/builtins/Array/prototype/values/prop-desc.js b/test/sendable/builtins/Array/prototype/values/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..7cafe9fb5061b42b8237233fb6c560fab989169e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/prop-desc.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.values +description: Array.prototype.values property descriptor +info: | + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArray.prototype.values, 'function'); +verifyProperty(SendableArray.prototype, "values", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Array/prototype/values/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/Array/prototype/values/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..12c47983a639ad77c91f1cc04e1012f871a4ef1c --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.values +description: > + Array.p.values behaves correctly on TypedArrays backed by resizable buffers and + resized mid-iteration. +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + // The fixed length array is not affected by resizing. + TestIterationAndResize(SendableArray.prototype.values.call(fixedLength), [ + 0, + 2, + 4, + 6 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + // The fixed length array is not affected by resizing. + TestIterationAndResize(SendableArray.prototype.values.call(fixedLengthWithOffset), [ + 4, + 6 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(SendableArray.prototype.values.call(lengthTracking), [ + 0, + 2, + 4, + 6, + 0, + 0 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + TestIterationAndResize(SendableArray.prototype.values.call(lengthTrackingWithOffset), [ + 4, + 6, + 0, + 0 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/Array/prototype/values/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/Array/prototype/values/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..8c54e2e66d3227684ada2e144314e061a2689901 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.values +description: > + Array.p.values behaves correctly on TypedArrays backed by resizable buffers + that are shrunk mid-iteration. +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + + // The fixed length array goes out of bounds when the RAB is resized. + assert.throws(TypeError, () => { + TestIterationAndResize(SendableArray.prototype.values.call(fixedLength), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + assert.throws(TypeError, () => { + TestIterationAndResize(SendableArray.prototype.values.call(fixedLengthWithOffset), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(SendableArray.prototype.values.call(lengthTracking), [ + 0, + 2, + 4 + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // The fixed length array goes out of bounds when the RAB is resized. + TestIterationAndResize(SendableArray.prototype.values.call(lengthTrackingWithOffset), [ + 4, + 6 + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/Array/prototype/values/resizable-buffer.js b/test/sendable/builtins/Array/prototype/values/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..c602c9675f3ea67d31ab600560d8f9c7647f6cfd --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/resizable-buffer.js @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.values +description: > + Array.p.values behaves correctly on TypedArrays backed by resizable buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function IteratorToNumbers(iterator) { + const result = []; + for (let value of iterator) { + result.push(Number(value)); + } + return result; +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(fixedLength)), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(fixedLengthWithOffset)), [ + 4, + 6 + ]); + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(lengthTracking)), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(lengthTrackingWithOffset)), [ + 4, + 6 + ]); + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + // TypedArray.prototype.{entries, keys, values} throw right away when + // called. Array.prototype.{entries, keys, values} don't throw, but when + // we try to iterate the returned ArrayIterator, that throws. + SendableArray.prototype.values.call(fixedLength); + SendableArray.prototype.values.call(fixedLengthWithOffset); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.values.call(fixedLength)); + }); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.values.call(fixedLengthWithOffset)); + }); + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(lengthTracking)), [ + 0, + 2, + 4 + ]); + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(lengthTrackingWithOffset)), [4]); + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + SendableArray.prototype.values.call(fixedLength); + SendableArray.prototype.values.call(fixedLengthWithOffset); + SendableArray.prototype.values.call(lengthTrackingWithOffset); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.values.call(fixedLength)); + }); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.values.call(fixedLengthWithOffset)); + }); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.values.call(lengthTrackingWithOffset)); + }); + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(lengthTracking)), [0]); + // Shrink to zero. + rab.resize(0); + SendableArray.prototype.values.call(fixedLength); + SendableArray.prototype.values.call(fixedLengthWithOffset); + SendableArray.prototype.values.call(lengthTrackingWithOffset); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.values.call(fixedLength)); + }); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.values.call(fixedLengthWithOffset)); + }); + assert.throws(TypeError, () => { + SendableArray.from(SendableArray.prototype.values.call(lengthTrackingWithOffset)); + }); + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(lengthTracking)), []); + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(fixedLength)), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(fixedLengthWithOffset)), [ + 4, + 6 + ]); + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(lengthTracking)), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(IteratorToNumbers(SendableArray.prototype.values.call(lengthTrackingWithOffset)), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/Array/prototype/values/returns-iterator-from-object.js b/test/sendable/builtins/Array/prototype/values/returns-iterator-from-object.js new file mode 100644 index 0000000000000000000000000000000000000000..7316356a200a08d796494565f13978ca86ce8248 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/returns-iterator-from-object.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.values +description: > + Creates an iterator from a custom object. +info: | + 22.1.3.29 Array.prototype.values ( ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "value"). +features: [Symbol.iterator] +---*/ + +var obj = { + length: 2 +}; +var iter = SendableArray.prototype.values.call(obj); +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].values() is %ArrayIteratorPrototype%' +); diff --git a/test/sendable/builtins/Array/prototype/values/returns-iterator.js b/test/sendable/builtins/Array/prototype/values/returns-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..ab06ab6976d34f5f62e92e5bbb406873fd1d2e5e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/returns-iterator.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.values +description: > + The method should return an Iterator instance. +info: | + 22.1.3.29 Array.prototype.values ( ) + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). + 3. Return CreateArrayIterator(O, "value"). + 22.1.5.1 CreateArrayIterator Abstract Operation + 2. Let iterator be ObjectCreate(%ArrayIteratorPrototype%, «‍[[IteratedObject]], + [[ArrayIteratorNextIndex]], [[ArrayIterationKind]]»). + 6. Return iterator. +features: [Symbol.iterator] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); +var iter = [].values(); +assert.sameValue( + Object.getPrototypeOf(iter), ArrayIteratorProto, + 'The prototype of [].values() is %ArrayIteratorPrototype%' +); diff --git a/test/sendable/builtins/Array/prototype/values/this-val-non-obj-coercible.js b/test/sendable/builtins/Array/prototype/values/this-val-non-obj-coercible.js new file mode 100644 index 0000000000000000000000000000000000000000..4ee963fb15f3dab645a318fae3f85ca552d02948 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/values/this-val-non-obj-coercible.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.values +description: > + `this` value not object coercible +info: | + 1. Let O be ToObject(this value). + 2. ReturnIfAbrupt(O). +---*/ + +assert.throws(TypeError, function() { + SendableArray.prototype.values.call(undefined); +}); +assert.throws(TypeError, function() { + SendableArray.prototype.values.call(null); +}); diff --git a/test/sendable/builtins/Array/prototype/with/frozen-this-value.js b/test/sendable/builtins/Array/prototype/with/frozen-this-value.js new file mode 100644 index 0000000000000000000000000000000000000000..7a2a79c8e9df8f3c454a23f190bfd364e6fb0eb7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/frozen-this-value.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with works on frozen objects +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = Object.freeze([0, 1, 2]); +var result = arr.with(1, 3); +assert.compareArray(result, [0, 3, 2]); +var arrayLike = Object.freeze({ length: 3, 0: 0, 1: 1, 2: 2 }); +var result2 = SendableArray.prototype.with.call(arrayLike, 1, 3); +assert.compareArray(result2, [0, 3, 2]); diff --git a/test/sendable/builtins/Array/prototype/with/holes-not-preserved.js b/test/sendable/builtins/Array/prototype/with/holes-not-preserved.js new file mode 100644 index 0000000000000000000000000000000000000000..7072eeb64816159148f7d8bfd1e869d7e2eb57c4 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/holes-not-preserved.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with does not preserve holes in the array +info: | + Array.prototype.with ( ) + 2. Let len be ? LengthOfArrayLike(O). + 5. Repeat, while k < len + a. Let Pk be ! ToString(𝔽(k)). + b. If k is actualIndex, let fromValue be value. + c. Else, let fromValue be ? Get(O, Pk). + d. Perform ? CreateDataPropertyOrThrow(A, Pk, fromValue). + e. Set k to k + 1. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, /* hole */, 2, /* hole */, 4]; +SendableArray.prototype[3] = 3; +var result = arr.with(2, 6); +assert.compareArray(result, [0, undefined, 6, 3, 4]); +assert(result.hasOwnProperty(1)); +assert(result.hasOwnProperty(3)); diff --git a/test/sendable/builtins/Array/prototype/with/ignores-species.js b/test/sendable/builtins/Array/prototype/with/ignores-species.js new file mode 100644 index 0000000000000000000000000000000000000000..11ee50d95c42cd12ef7b30f0f0b4d21739d58077 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/ignores-species.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with ignores @@species +---*/ + +var a = [1, 2, 3]; +a.constructor = {}; +a.constructor[Symbol.species] = function () {} +assert.sameValue(Object.getPrototypeOf(a.with(0, 0)), SendableArray.prototype); +var b = [1, 2, 3]; +Object.defineProperty(b, "constructor", { + get() { + throw new Test262Error("Should not get .constructor"); + } +}); +b.with(0, 0); diff --git a/test/sendable/builtins/Array/prototype/with/immutable.js b/test/sendable/builtins/Array/prototype/with/immutable.js new file mode 100644 index 0000000000000000000000000000000000000000..3b69acb2e707a982c3fad7dfcc9fcd8f96a613be --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/immutable.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with does not mutate its this value +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2]; +arr.with(1, 3); +assert.compareArray(arr, [0, 1, 2]); +assert.notSameValue(arr.with(1, 3), arr); +assert.notSameValue(arr.with(1, 1), arr); diff --git a/test/sendable/builtins/Array/prototype/with/index-bigger-or-eq-than-length.js b/test/sendable/builtins/Array/prototype/with/index-bigger-or-eq-than-length.js new file mode 100644 index 0000000000000000000000000000000000000000..6b6f5f9ec037c4c8dd622b25d3059e07630a7966 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/index-bigger-or-eq-than-length.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with throws if the index is bigger than or equal to the array length. +info: | + Array.prototype.with ( index, value ) + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + 6. If actualIndex >= len or actualIndex < 0, throw a *RangeError* exception. +features: [change-array-by-copy, exponentiation] +---*/ + +assert.throws(RangeError, function() { + [0, 1, 2].with(3, 7); +}); +assert.throws(RangeError, function() { + [0, 1, 2].with(10, 7); +}); +assert.throws(RangeError, function() { + [0, 1, 2].with(2 ** 53 + 2, 7); +}); +assert.throws(RangeError, function() { + [0, 1, 2].with(Infinity, 7); +}); diff --git a/test/sendable/builtins/Array/prototype/with/index-casted-to-number.js b/test/sendable/builtins/Array/prototype/with/index-casted-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..702f9e7ba7cbe07f486d6c322c126ff3921d3974 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/index-casted-to-number.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with casts the index to an integer. +info: | + Array.prototype.with ( index, value ) + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 4, 16]; +assert.compareArray(arr.with(1.2, 7), [0, 7, 16]); +assert.compareArray(arr.with("1", 3), [0, 3, 16]); +assert.compareArray(arr.with("-1", 5), [0, 4, 5]); +assert.compareArray(arr.with(NaN, 2), [2, 4, 16]); +assert.compareArray(arr.with("dog", "cat"), ["cat", 4, 16]); diff --git a/test/sendable/builtins/Array/prototype/with/index-negative.js b/test/sendable/builtins/Array/prototype/with/index-negative.js new file mode 100644 index 0000000000000000000000000000000000000000..aee5fe36e0fe32a0974fbf42575f374d256d7555 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/index-negative.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with adds length to index if it's negative. +info: | + Array.prototype.with ( index, value ) + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2]; +assert.compareArray(arr.with(-1, 4), [0, 1, 4]); +assert.compareArray(arr.with(-3, 4), [4, 1, 2]); +// -0 is not < 0 +assert.compareArray(arr.with(-0, 4), [4, 1, 2]); diff --git a/test/sendable/builtins/Array/prototype/with/index-smaller-than-minus-length.js b/test/sendable/builtins/Array/prototype/with/index-smaller-than-minus-length.js new file mode 100644 index 0000000000000000000000000000000000000000..03f875cf4c9747dd81be414dcd25a1b92d5826a0 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/index-smaller-than-minus-length.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with throws if the (negative) index is smaller than -length. +info: | + Array.prototype.with ( index, value ) + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + 6. If actualIndex >= len or actualIndex < 0, throw a *RangeError* exception. +features: [change-array-by-copy, exponentiation] +---*/ + +[0, 1, 2].with(-3, 7); +assert.throws(RangeError, function() { + [0, 1, 2].with(-4, 7); +}); +assert.throws(RangeError, function() { + [0, 1, 2].with(-10, 7); +}); +assert.throws(RangeError, function() { + [0, 1, 2].with(-(2 ** 53) - 2, 7); +}); +assert.throws(RangeError, function() { + [0, 1, 2].with(-Infinity, 7); +}); diff --git a/test/sendable/builtins/Array/prototype/with/length-decreased-while-iterating.js b/test/sendable/builtins/Array/prototype/with/length-decreased-while-iterating.js new file mode 100644 index 0000000000000000000000000000000000000000..0d83a65da3884a92eae2d15127dca46e14f9f111 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/length-decreased-while-iterating.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with caches the length getting the array elements. +info: | + Array.prototype.with ( index, value ) + 2. Let len be ? LengthOfArrayLike(O). + 5. Repeat, while k < len + a. Let Pk be ! ToString(𝔽(k)). + b. If k is actualIndex, let fromValue be value. + c. Else, let fromValue be ? Get(O, Pk). + d. Perform ? CreateDataPropertyOrThrow(A, Pk, fromValue). + e. Set k to k + 1. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +SendableArray.prototype[4] = 5; +var arr = Object.defineProperty([0, 1, 2, 3, 4], "1", { + get() { + arr.length = 1; + return 1; + } +}); +assert.compareArray(arr.with(2, 7), [0, 1, 7, undefined, 5]); +arr = Object.defineProperty([0, 1, 2, 3, 4], "1", { + get() { + arr.length = 1; + return 1; + } +}); +assert.compareArray(arr.with(0, 7), [7, 1, undefined, undefined, 5]); diff --git a/test/sendable/builtins/Array/prototype/with/length-exceeding-array-length-limit.js b/test/sendable/builtins/Array/prototype/with/length-exceeding-array-length-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..4e60f1dd07e8d60cd9256b507cdd48df10ca0533 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/length-exceeding-array-length-limit.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with limits the length to 2 ** 32 - 1 +---*/ + +// Object with large "length" property +var arrayLike = { + get "0"() { + throw new Test262Error("Get 0"); + }, + get "4294967295" () { // 2 ** 32 - 1 + throw new Test262Error("Get 4294967295"); + }, + get "4294967296" () { // 2 ** 32 + throw new Test262Error("Get 4294967296"); + }, + length: 2 ** 32 +}; +assert.throws(RangeError, function() { + SendableArray.prototype.with.call(arrayLike, 0, 0); +}); diff --git a/test/sendable/builtins/Array/prototype/with/length-increased-while-iterating.js b/test/sendable/builtins/Array/prototype/with/length-increased-while-iterating.js new file mode 100644 index 0000000000000000000000000000000000000000..72963dc4cccdad0d4df016724be3dbcd0998b287 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/length-increased-while-iterating.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with caches the length getting the array elements. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2]; +Object.defineProperty(arr, "0", { + get() { + arr.push(4); + return 0; + } +}); +assert.compareArray(arr.with(1, 4), [0, 4, 2]); diff --git a/test/sendable/builtins/Array/prototype/with/length-tolength.js b/test/sendable/builtins/Array/prototype/with/length-tolength.js new file mode 100644 index 0000000000000000000000000000000000000000..394719aec931e5d02197dc99e8cc7b7b273cc1fe --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/length-tolength.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with converts the this value length to a number. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arrayLike = { length: "2", 0: 1, 1: 2, 2: 3 }; +assert.compareArray(SendableArray.prototype.with.call(arrayLike, 0, 4), [4, 2]); +var arrayLike = { + length: { + valueOf: () => 2 + }, + 0: 1, + 1: 2, + 2: 3, +}; +assert.compareArray(SendableArray.prototype.with.call(arrayLike, 0, 4), [4, 2]); diff --git a/test/sendable/builtins/Array/prototype/with/length.js b/test/sendable/builtins/Array/prototype/with/length.js new file mode 100644 index 0000000000000000000000000000000000000000..c17c99a33c92eb6a25d76c9ebf04277b4daf0ff7 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/length.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + The "length" property of Array.prototype.with +info: | + 17 ECMAScript Standard Built-in Objects + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +verifyProperty(SendableArray.prototype.with, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/with/name.js b/test/sendable/builtins/Array/prototype/with/name.js new file mode 100644 index 0000000000000000000000000000000000000000..36e0e57acb9cca117ec71753263f2868dfb7076a --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/name.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with.name is "with". +info: | + Array.prototype.with ( index, value ) + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +verifyProperty(SendableArray.prototype.with, "name", { + value: "with", + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/with/no-get-replaced-index.js b/test/sendable/builtins/Array/prototype/with/no-get-replaced-index.js new file mode 100644 index 0000000000000000000000000000000000000000..7b1951738960be2dae7b3f6f61c70cdb06199903 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/no-get-replaced-index.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with does not [[Get]] the value in the replaced position +info: | + Array.prototype.with ( ) + 5. Repeat, while k < len + a. Let Pk be ! ToString(𝔽(k)). + b. If k is actualIndex, let fromValue be value. + c. Else, let fromValue be ? Get(O, Pk). + d. Perform ? CreateDataPropertyOrThrow(A, Pk, fromValue). + e. Set k to k + 1. +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2, 3]; +Object.defineProperty(arr, "2", { + get() { + throw new Test262Error("Should not get '2'"); + } +}); +var result = arr.with(2, 6); +assert.compareArray(result, [0, 1, 6, 3]); diff --git a/test/sendable/builtins/Array/prototype/with/not-a-constructor.js b/test/sendable/builtins/Array/prototype/with/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..651e49ecba600afab6113ba9378b53f8cc60399e --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/not-a-constructor.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.with does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + sec-evaluatenew + 7. If IsConstructor(constructor) is false, throw a TypeError exception. +includes: [isConstructor.js] +features: [change-array-by-copy, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(SendableArray.prototype.with), + false, + 'isConstructor(SendableArray.prototype.with) must return false' +); +assert.throws(TypeError, () => { + new SendableArray.prototype.with(); +}); + diff --git a/test/sendable/builtins/Array/prototype/with/property-descriptor.js b/test/sendable/builtins/Array/prototype/with/property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..d72c585d1238c5f14495353a5b532317b437ecde --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/property-descriptor.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + "with" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [change-array-by-copy] +---*/ + +assert.sameValue(typeof SendableArray.prototype.with, "function", "typeof"); +verifyProperty(SendableArray.prototype, "with", { + value: SendableArray.prototype.with, + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Array/prototype/with/this-value-boolean.js b/test/sendable/builtins/Array/prototype/with/this-value-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..fe5fdf823f1f51369c1802d950781815377f2772 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/this-value-boolean.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with casts primitive receivers to objects +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +Boolean.prototype.length = 2; +Boolean.prototype[0] = 0; +Boolean.prototype[1] = 1; +assert.compareArray(SendableArray.prototype.with.call(true, 0, 2), [2, 1]); +assert.compareArray(SendableArray.prototype.with.call(false, 0, 2), [2, 1]); +/* Add length and indexed properties to `Boolean.prototype` */ +Boolean.prototype.length = 3; +delete Boolean.prototype[0]; +delete Boolean.prototype[1]; +assert.compareArray(SendableArray.prototype.with.call(true, 0, 2), [2, undefined, undefined]); +assert.compareArray(SendableArray.prototype.with.call(false, 0, 2), [2, undefined, undefined]); +delete Boolean.prototype.length; +Boolean.prototype[0] = "monkeys"; +Boolean.prototype[2] = "bogus"; +assert.throws(RangeError, + () => compareArray(SendableArray.prototype.with.call(true, 0, 2)), + "SendableArray.prototype.with on object with undefined length"); +assert.throws(RangeError, + () => compareArray(SendableArray.prototype.with.call(false, 0, 2)), + "SendableArray.prototype.with on object with undefined length"); diff --git a/test/sendable/builtins/Array/prototype/with/this-value-nullish.js b/test/sendable/builtins/Array/prototype/with/this-value-nullish.js new file mode 100644 index 0000000000000000000000000000000000000000..9c82910df561a2bd9ebcaf7be676c0ca01f29102 --- /dev/null +++ b/test/sendable/builtins/Array/prototype/with/this-value-nullish.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +esid: sec-array.prototype.with +description: > + Array.prototype.with throws if the receiver is null or undefined +features: [change-array-by-copy] +---*/ + +assert.throws(TypeError, () => { + SendableArray.prototype.with.call(null, 0, 0); +}); +assert.throws(TypeError, () => { + SendableArray.prototype.with.call(undefined, 0, 0); +}); diff --git a/test/sendable/builtins/ArrayBuffer/Symbol.species/length.js b/test/sendable/builtins/ArrayBuffer/Symbol.species/length.js new file mode 100644 index 0000000000000000000000000000000000000000..7dbaea4cf9515e10e79e10be55a8fe2801c2875f --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/Symbol.species/length.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-get-sendableArrayBuffer-@@species +description: > + get SendableArrayBuffer [ @@species ].length is 0. +info: | + get SendableArrayBuffer [ @@species ] + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.species] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer, Symbol.species); + +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/Symbol.species/return-value.js b/test/sendable/builtins/ArrayBuffer/Symbol.species/return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..849e8ade94079f729f8b19215d0a4f00ac373b29 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/Symbol.species/return-value.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-get-sendableArrayBuffer-@@species +description: Return value of @@species accessor method +info: | + 1. Return the this value. +features: [Symbol.species] +---*/ + +var thisVal = {}; +var accessor = Object.getOwnPropertyDescriptor(SendableArrayBuffer, Symbol.species).get; + +assert.sameValue(accessor.call(thisVal), thisVal); diff --git a/test/sendable/builtins/ArrayBuffer/Symbol.species/symbol-species-name.js b/test/sendable/builtins/ArrayBuffer/Symbol.species/symbol-species-name.js new file mode 100644 index 0000000000000000000000000000000000000000..384337f98e109616af0e69d3218a990d6f4438b8 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/Symbol.species/symbol-species-name.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-get-sendableArrayBuffer-@@species +description: > + SendableArrayBuffer[Symbol.species] accessor property get name +info: | + 24.1.3.3 get SendableArrayBuffer [ @@species ] + + ... + The value of the name property of this function is "get [Symbol.species]". +features: [Symbol.species] +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableArrayBuffer, Symbol.species); + +verifyProperty(descriptor.get, "name", { + value: "get [Symbol.species]", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/Symbol.species/symbol-species.js b/test/sendable/builtins/ArrayBuffer/Symbol.species/symbol-species.js new file mode 100644 index 0000000000000000000000000000000000000000..1b86666f8d355ab5bb119dee5a87da98c360a4cb --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/Symbol.species/symbol-species.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +info: | + SendableArrayBuffer has a property at `Symbol.species` +esid: sec-get-sendableArrayBuffer-@@species +author: Sam Mikes +description: SendableArrayBuffer[Symbol.species] exists per spec +features: [SendableArrayBuffer, Symbol.species] +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer, Symbol.species); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +verifyNotWritable(SendableArrayBuffer, Symbol.species, Symbol.species); +verifyNotEnumerable(SendableArrayBuffer, Symbol.species); +verifyConfigurable(SendableArrayBuffer, Symbol.species); diff --git a/test/sendable/builtins/ArrayBuffer/allocation-limit.js b/test/sendable/builtins/ArrayBuffer/allocation-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..cc37c2c63d43b4c227a730e3e73f63fded86b8f3 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/allocation-limit.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + Throws a RangeError if requested Data Block is too large. +info: | + SendableArrayBuffer( length ) + + ... + 6. Return AllocateSendableArrayBuffer(NewTarget, byteLength). + + 6.2.6.1 CreateByteDataBlock(size) + ... + 2. Let db be a new Data Block value consisting of size bytes. If it is + impossible to create such a Data Block, throw a RangeError exception. + ... +---*/ + +assert.throws(RangeError, function() { + // Allocating 7 PiB should fail with a RangeError. + // Math.pow(1024, 5) = 1125899906842624 + new SendableArrayBuffer(7 * 1125899906842624); +}, "`length` parameter is 7 PiB"); + +assert.throws(RangeError, function() { + // Allocating almost 8 PiB should fail with a RangeError. + // Math.pow(2, 53) = 9007199254740992 + new SendableArrayBuffer(9007199254740992 - 1); +}, "`length` parameter is Math.pow(2, 53) - 1"); diff --git a/test/sendable/builtins/ArrayBuffer/data-allocation-after-object-creation.js b/test/sendable/builtins/ArrayBuffer/data-allocation-after-object-creation.js new file mode 100644 index 0000000000000000000000000000000000000000..750689dd768c092957b4513d7e95492b2f37ffa6 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/data-allocation-after-object-creation.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + The new SendableArrayBuffer instance is created prior to allocating the Data Block. +info: | + SendableArrayBuffer( length ) + + ... + 6. Return AllocateSendableArrayBuffer(NewTarget, byteLength). + + AllocateSendableArrayBuffer( constructor, byteLength ) + 1. Let obj be OrdinaryCreateFromConstructor(constructor, "%SendableArrayBufferPrototype%", + «[[SendableArrayBufferData]], [[SendableArrayBufferByteLength]]» ). + 2. ReturnIfAbrupt(obj). + ... + 4. Let block be CreateByteDataBlock(byteLength). + 5. ReturnIfAbrupt(block). + ... +features: [Reflect.construct] +---*/ + +function DummyError() {} + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get: function() { + throw new DummyError(); + } +}); + +assert.throws(DummyError, function() { + // Allocating 7 PiB should fail with a RangeError. + // Math.pow(1024, 5) = 1125899906842624 + Reflect.construct(SendableArrayBuffer, [7 * 1125899906842624], newTarget); +}); diff --git a/test/sendable/builtins/ArrayBuffer/init-zero.js b/test/sendable/builtins/ArrayBuffer/init-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..b438ee281b44a9a38ca3f4613a2dda1d328783b2 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/init-zero.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: All bytes are initialized to zero +info: | + [...] + 5. Return ? AllocateSendableArrayBuffer(NewTarget, byteLength). + + 24.1.1.1 AllocateSendableArrayBuffer + + 3. Let block be ? CreateByteDataBlock(byteLength). + + 6.2.6.1 CreateByteDataBlock + + 1. Assert: size≥0. + 2. Let db be a new Data Block value consisting of size bytes. If it is + impossible to create such a Data Block, throw a RangeError exception. + 3. Set all of the bytes of db to 0. + 4. Return db. +features: [DataView] +---*/ + +var view = new DataView(new SendableArrayBuffer(9)); + +assert.sameValue(view.getUint8(0), 0, 'index 0'); +assert.sameValue(view.getUint8(1), 0, 'index 1'); +assert.sameValue(view.getUint8(2), 0, 'index 2'); +assert.sameValue(view.getUint8(3), 0, 'index 3'); +assert.sameValue(view.getUint8(4), 0, 'index 4'); +assert.sameValue(view.getUint8(5), 0, 'index 5'); +assert.sameValue(view.getUint8(6), 0, 'index 6'); +assert.sameValue(view.getUint8(7), 0, 'index 7'); +assert.sameValue(view.getUint8(8), 0, 'index 8'); diff --git a/test/sendable/builtins/ArrayBuffer/is-a-constructor.js b/test/sendable/builtins/ArrayBuffer/is-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..54e581681787dec30c4108367adbe8bb1cbd5a60 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/is-a-constructor.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The SendableArrayBuffer constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, SendableArrayBuffer] +---*/ + +assert.sameValue(isConstructor(SendableArrayBuffer), true, 'isConstructor(SendableArrayBuffer) must return true'); +new SendableArrayBuffer(); + diff --git a/test/sendable/builtins/ArrayBuffer/isView/arg-has-no-viewedarraybuffer.js b/test/sendable/builtins/ArrayBuffer/isView/arg-has-no-viewedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..e8c9701fde8b965c8ba05b165ca6aa41b130ae97 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/arg-has-no-viewedarraybuffer.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return false if arg has no [[ViewedSendableArrayBuffer]] internal slot. +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedSendableArrayBuffer]] internal slot, return true. + 3. Return false. +---*/ + +assert.sameValue(SendableArrayBuffer.isView({}), false, "ordinary object"); +assert.sameValue(SendableArrayBuffer.isView([]), false, "Array"); diff --git a/test/sendable/builtins/ArrayBuffer/isView/arg-is-arraybuffer.js b/test/sendable/builtins/ArrayBuffer/isView/arg-is-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..50364c13232ff7885027703b42fec80d42bbc3e2 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/arg-is-arraybuffer.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return false from an instance of SendableArrayBuffer +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedSendableArrayBuffer]] internal slot, return true. + 3. Return false. +---*/ + +var sample = new SendableArrayBuffer(1); + +assert.sameValue(SendableArrayBuffer.isView(sample), false); diff --git a/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview-buffer.js b/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..67c2dfc3f188f0190a445102081897c1cf31d1cb --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview-buffer.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return false from DataView's instance `.buffer` +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedSendableArrayBuffer]] internal slot, return true. + 3. Return false. +features: [DataView] +---*/ + +var sample = new DataView(new SendableArrayBuffer(1), 0, 0).buffer; + +assert.sameValue(SendableArrayBuffer.isView(sample), false); diff --git a/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview-constructor.js b/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..5da2f888205702fee0d491b02f8d0a3b216733a5 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview-constructor.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return false if arg is the DataView constructor +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedSendableArrayBuffer]] internal slot, return true. + 3. Return false. +features: [DataView] +---*/ + +assert.sameValue(SendableArrayBuffer.isView(DataView), false, "DataView"); diff --git a/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview-subclass-instance.js b/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview-subclass-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..a53fa6340f2b4e2eb55a5fd2b5dbae1b7308bace --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview-subclass-instance.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return true if arg is an instance from a subclass of DataView +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedSendableArrayBuffer]] internal slot, return true. + 3. Return false. +features: [class, DataView] +---*/ + +class DV extends DataView {} + +var sample = new DV(new SendableArrayBuffer(1), 0, 0); + +assert(SendableArrayBuffer.isView(sample)); diff --git a/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview.js b/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview.js new file mode 100644 index 0000000000000000000000000000000000000000..8973f949cddaa9361b1ac6e406bcd275b2b0614e --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/arg-is-dataview.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return true if is an instance of DataView +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedSendableArrayBuffer]] internal slot, return true. + 3. Return false. +features: [DataView] +---*/ + +var sample = new DataView(new SendableArrayBuffer(1), 0, 0); + +assert.sameValue(SendableArrayBuffer.isView(sample), true); diff --git a/test/sendable/builtins/ArrayBuffer/isView/arg-is-not-object.js b/test/sendable/builtins/ArrayBuffer/isView/arg-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..bfd59a067919f9f07530703ed7ced929bc078a3f --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/arg-is-not-object.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return false if arg is not Object +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + ... +---*/ + +assert.sameValue(SendableArrayBuffer.isView(null), false, "null"); +assert.sameValue(SendableArrayBuffer.isView(undefined), false, "undefined"); +assert.sameValue(SendableArrayBuffer.isView(1), false, "number"); +assert.sameValue(SendableArrayBuffer.isView(""), false, "string"); diff --git a/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray-buffer.js b/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..10cb5633daf6f08c38d0d2a5818a15ed7b7d7f2b --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray-buffer.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return false from TypedArray's instance `.buffer` +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedSendableArrayBuffer]] internal slot, return true. + 3. Return false. +features: [TypedArray] +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(ctor) { + var sample = new ctor().buffer; + + assert.sameValue(SendableArrayBuffer.isView(sample), false); +}); diff --git a/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray-constructor.js b/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..4bdcc737abf920c03972e9e8d815eb750931a3fa --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray-constructor.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return false if arg is a TypedArray constructor +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedSendableArrayBuffer]] internal slot, return true. + 3. Return false. +features: [TypedArray] +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(ctor) { + assert.sameValue(SendableArrayBuffer.isView(ctor), false); +}); diff --git a/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray-subclass-instance.js b/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray-subclass-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..67e9b19bae20359389fc2340db0f439a8e68ec54 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray-subclass-instance.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return true if arg is an instance from a subclass of TypedArray +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedSendableArrayBuffer]] internal slot, return true. + 3. Return false. +features: [class, TypedArray] +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(ctor) { + class TA extends ctor {} + + var sample = new TA(); + + assert(SendableArrayBuffer.isView(sample)); +}); diff --git a/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray.js b/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray.js new file mode 100644 index 0000000000000000000000000000000000000000..16818663e8166e5bea6ca67e8b0fba03775012f5 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/arg-is-typedarray.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return true if arg is an instance of TypedArray +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedSendableArrayBuffer]] internal slot, return true. + 3. Return false. +features: [TypedArray] +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(ctor) { + var sample = new ctor(); + + assert.sameValue(SendableArrayBuffer.isView(sample), true); +}); diff --git a/test/sendable/builtins/ArrayBuffer/isView/invoked-as-a-fn.js b/test/sendable/builtins/ArrayBuffer/isView/invoked-as-a-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..110bad9f2c2a00a95e4ec1d2be16155de6fc7afd --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/invoked-as-a-fn.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + `isView` can be invoked as a function +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedSendableArrayBuffer]] internal slot, return true. + 3. Return false. +features: [TypedArray, DataView] +includes: [testTypedArray.js] +---*/ + +var isView = SendableArrayBuffer.isView; + +testWithTypedArrayConstructors(function(ctor) { + var sample = new ctor(); + assert.sameValue(isView(sample), true, "instance of TypedArray"); +}); + +var dv = new DataView(new SendableArrayBuffer(1), 0, 0); +assert.sameValue(isView(dv), true, "instance of DataView"); + +assert.sameValue(isView(), false, "undefined arg"); +assert.sameValue(isView({}), false, "ordinary object"); diff --git a/test/sendable/builtins/ArrayBuffer/isView/length.js b/test/sendable/builtins/ArrayBuffer/isView/length.js new file mode 100644 index 0000000000000000000000000000000000000000..84efc9d78910927baa1d642e1d404bda165673ee --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/length.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + SendableArrayBuffer.isView.length is 1. +info: | + SendableArrayBuffer.isView ( arg ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArrayBuffer.isView, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/isView/name.js b/test/sendable/builtins/ArrayBuffer/isView/name.js new file mode 100644 index 0000000000000000000000000000000000000000..32076c558154a95fdfb9ab26bedfcb9926b8e5da --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/name.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + SendableArrayBuffer.isView.name is "isView". +info: | + SendableArrayBuffer.isView ( arg ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArrayBuffer.isView, "name", { + value: "isView", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/isView/no-arg.js b/test/sendable/builtins/ArrayBuffer/isView/no-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..71f6604cca437d57353b6c49b010577331f47cd8 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/no-arg.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + Return false if isView is called with no arg +info: | + 24.1.3.1 SendableArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + ... +---*/ + +assert.sameValue(SendableArrayBuffer.isView(), false); diff --git a/test/sendable/builtins/ArrayBuffer/isView/not-a-constructor.js b/test/sendable/builtins/ArrayBuffer/isView/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..fbec420fedf9350808d41ffe7fc077f04570a03a --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/not-a-constructor.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableArrayBuffer.isView does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableArrayBuffer, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableArrayBuffer.isView), false, 'isConstructor(SendableArrayBuffer.isView) must return false'); + +assert.throws(TypeError, () => { + new SendableArrayBuffer.isView(); +}); + diff --git a/test/sendable/builtins/ArrayBuffer/isView/prop-desc.js b/test/sendable/builtins/ArrayBuffer/isView/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..047326978843fa981b7716c6646ba1dba67fecb1 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/isView/prop-desc.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + + +/*--- +esid: sec-sendableArrayBuffer.isview +description: > + "isView" property of SendableArrayBuffer +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArrayBuffer, "isView", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/length-is-absent.js b/test/sendable/builtins/ArrayBuffer/length-is-absent.js new file mode 100644 index 0000000000000000000000000000000000000000..0ea1c6250dd62a5454253a73c41a27416b9add8d --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/length-is-absent.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + Returns an empty instance if length is absent +info: | + SendableArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + 3. Return ? AllocateSendableArrayBuffer(NewTarget, byteLength). +---*/ + +var buffer = new SendableArrayBuffer(); + +assert.sameValue(buffer.byteLength, 0); diff --git a/test/sendable/builtins/ArrayBuffer/length-is-too-large-throws.js b/test/sendable/builtins/ArrayBuffer/length-is-too-large-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..06015f94846308efc5d8fb8041a3be8bb0757503 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/length-is-too-large-throws.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + Throws a RangeError if length >= 2 ** 53 +info: | + SendableArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +---*/ + +assert.throws(RangeError, function() { + // Math.pow(2, 53) = 9007199254740992 + new SendableArrayBuffer(9007199254740992); +}, "`length` parameter is too large"); + +assert.throws(RangeError, function() { + new SendableArrayBuffer(Infinity); +}, "`length` parameter is positive Infinity"); diff --git a/test/sendable/builtins/ArrayBuffer/length.js b/test/sendable/builtins/ArrayBuffer/length.js new file mode 100644 index 0000000000000000000000000000000000000000..14013edd06d5b48f0ef0a9d8c7808db7f5711417 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/length.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-constructor +description: > + SendableArrayBuffer.length is 1. +info: | + SendableArrayBuffer ( length ) + + ECMAScript Standard Built-in Objects: + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [SendableArrayBuffer] +---*/ + +verifyProperty(SendableArrayBuffer, "length", { + value: 1, + enumerable: false, + writable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/ArrayBuffer/name.js b/test/sendable/builtins/ArrayBuffer/name.js new file mode 100644 index 0000000000000000000000000000000000000000..ec0aa54d5fac675e1b25e4781c52f84004ded96e --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/name.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-constructor +description: > + SendableArrayBuffer.name is "SendableArrayBuffer". +info: | + 17 ECMAScript Standard Built-in Objects: + + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. + + Unless otherwise specified, the name property of a built-in Function object, + if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. + +includes: [propertyHelper.js] +---*/ + +assert.sameValue(SendableArrayBuffer.name, "SendableArrayBuffer"); + +verifyProperty(SendableArrayBuffer, "name", { + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/ArrayBuffer/negative-length-throws.js b/test/sendable/builtins/ArrayBuffer/negative-length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..f95674c1a844593730aa6f256057811a57a708c2 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/negative-length-throws.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + Throws a Range Error if length represents an integer < 0 +info: | + SendableArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +---*/ + +assert.throws(RangeError, function() { + new SendableArrayBuffer(-1); +}); + +assert.throws(RangeError, function() { + new SendableArrayBuffer(-1.1); +}); + +assert.throws(RangeError, function() { + new SendableArrayBuffer(-Infinity); +}); diff --git a/test/sendable/builtins/ArrayBuffer/newtarget-prototype-is-not-object.js b/test/sendable/builtins/ArrayBuffer/newtarget-prototype-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..d9e99b3c6925305dd68fa4b5da614aed965d950e --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/newtarget-prototype-is-not-object.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + [[Prototype]] defaults to %SendableArrayBufferPrototype% if NewTarget.prototype is not an object. +info: | + SendableArrayBuffer( length ) + + SendableArrayBuffer called with argument length performs the following steps: + + ... + 6. Return AllocateSendableArrayBuffer(NewTarget, byteLength). + + AllocateSendableArrayBuffer( constructor, byteLength ) + 1. Let obj be OrdinaryCreateFromConstructor(constructor, "%SendableArrayBufferPrototype%", + «[[SendableArrayBufferData]], [[SendableArrayBufferByteLength]]» ). + 2. ReturnIfAbrupt(obj). + ... +features: [Reflect.construct, Symbol] +---*/ + +function newTarget() {} + +newTarget.prototype = undefined; +var SendableArrayBuffer = Reflect.construct(SendableArrayBuffer, [1], newTarget); +assert.sameValue(Object.getPrototypeOf(SendableArrayBuffer), SendableArrayBuffer.prototype, "newTarget.prototype is undefined"); + +newTarget.prototype = null; +var SendableArrayBuffer = Reflect.construct(SendableArrayBuffer, [2], newTarget); +assert.sameValue(Object.getPrototypeOf(SendableArrayBuffer), SendableArrayBuffer.prototype, "newTarget.prototype is null"); + +newTarget.prototype = true; +var SendableArrayBuffer = Reflect.construct(SendableArrayBuffer, [3], newTarget); +assert.sameValue(Object.getPrototypeOf(SendableArrayBuffer), SendableArrayBuffer.prototype, "newTarget.prototype is a Boolean"); + +newTarget.prototype = ""; +var SendableArrayBuffer = Reflect.construct(SendableArrayBuffer, [4], newTarget); +assert.sameValue(Object.getPrototypeOf(SendableArrayBuffer), SendableArrayBuffer.prototype, "newTarget.prototype is a String"); + +newTarget.prototype = Symbol(); +var SendableArrayBuffer = Reflect.construct(SendableArrayBuffer, [5], newTarget); +assert.sameValue(Object.getPrototypeOf(SendableArrayBuffer), SendableArrayBuffer.prototype, "newTarget.prototype is a Symbol"); + +newTarget.prototype = 1; +var SendableArrayBuffer = Reflect.construct(SendableArrayBuffer, [6], newTarget); +assert.sameValue(Object.getPrototypeOf(SendableArrayBuffer), SendableArrayBuffer.prototype, "newTarget.prototype is a Number"); diff --git a/test/sendable/builtins/ArrayBuffer/options-maxbytelength-allocation-limit.js b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-allocation-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..4e7460ab00f71f64e63bc497f65b381e4cd554d3 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-allocation-limit.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + Throws a RangeError if the requested Data Block is too large. +info: | + SendableArrayBuffer ( length [ , options ] ) + + ... + 4. Return ? AllocateSendableArrayBuffer(NewTarget, byteLength, requestedMaxByteLength). + + AllocateSendableArrayBuffer ( constructor, byteLength [ , maxByteLength ] ) + + ... + 5. Let block be ? CreateByteDataBlock(byteLength). + ... + + CreateByteDataBlock ( size ) + + ... + 2. Let db be a new Data Block value consisting of size bytes. If it is + impossible to create such a Data Block, throw a RangeError exception. + ... + +features: [resizable-SendableArrayBuffer] +---*/ + +assert.throws(RangeError, function() { + // Allocating 7 PiB should fail with a RangeError. + // Math.pow(1024, 5) = 1125899906842624 + new SendableArrayBuffer(0, {maxByteLength: 7 * 1125899906842624}); +}, "`maxByteLength` option is 7 PiB"); + +assert.throws(RangeError, function() { + // Allocating almost 8 PiB should fail with a RangeError. + // Math.pow(2, 53) = 9007199254740992 + new SendableArrayBuffer(0, {maxByteLength: 9007199254740992 - 1}); +}, "`maxByteLength` option is Math.pow(2, 53) - 1"); diff --git a/test/sendable/builtins/ArrayBuffer/options-maxbytelength-compared-before-object-creation.js b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-compared-before-object-creation.js new file mode 100644 index 0000000000000000000000000000000000000000..84889969cd97cafc02234f3a130e2a36929b4a5b --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-compared-before-object-creation.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + The byteLength argument is validated before OrdinaryCreateFromConstructor. +info: | + SendableArrayBuffer ( length [ , options ] ) + + ... + 4. Return ? AllocateSendableArrayBuffer(NewTarget, byteLength, requestedMaxByteLength). + + AllocateSendableArrayBuffer ( constructor, byteLength [ , maxByteLength ] ) + + ... + 3. If allocatingResizableBuffer is true, then + a. If byteLength > maxByteLength, throw a RangeError exception. + ... + 4. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%SendableArrayBuffer.prototype%", slots). + ... + +features: [resizable-SendableArrayBuffer, Reflect.construct] +---*/ + +let newTarget = Object.defineProperty(function(){}.bind(null), "prototype", { + get() { + throw new Test262Error(); + } +}); + +assert.throws(RangeError, function() { + let byteLength = 10; + let options = { + maxByteLength: 0, + }; + + // Throws a RangeError, because `byteLength` is larger than `options.maxByteLength`. + Reflect.construct(SendableArrayBuffer, [byteLength, options], newTarget); +}); diff --git a/test/sendable/builtins/ArrayBuffer/options-maxbytelength-data-allocation-after-object-creation.js b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-data-allocation-after-object-creation.js new file mode 100644 index 0000000000000000000000000000000000000000..07f9079a9264fdd3fe664b66d68843fa0b901930 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-data-allocation-after-object-creation.js @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + The new SendableArrayBuffer instance is created prior to allocating the Data Block. +info: | + SendableArrayBuffer ( length [ , options ] ) + + ... + 4. Return ? AllocateSendableArrayBuffer(NewTarget, byteLength, requestedMaxByteLength). + + AllocateSendableArrayBuffer ( constructor, byteLength [ , maxByteLength ] ) + + ... + 4. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%SendableArrayBuffer.prototype%", slots). + 5. Let block be ? CreateByteDataBlock(byteLength). + ... + +features: [resizable-SendableArrayBuffer, Reflect.construct] +---*/ + +function DummyError() {} + +let newTarget = Object.defineProperty(function(){}.bind(null), "prototype", { + get() { + throw new DummyError(); + } +}); + +assert.throws(DummyError, function() { + let byteLength = 0; + let options = { + maxByteLength: 7 * 1125899906842624 + }; + + // Allocating 7 PiB should fail with a RangeError. + // Math.pow(1024, 5) = 1125899906842624 + Reflect.construct(SendableArrayBuffer, [], newTarget); +}); diff --git a/test/sendable/builtins/ArrayBuffer/options-maxbytelength-diminuitive.js b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-diminuitive.js new file mode 100644 index 0000000000000000000000000000000000000000..f6bbc7b1643307008a4a41d4f307f8122d19f873 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-diminuitive.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-constructor +description: | + Invoked with an options object whose `maxByteLength` property is less than + the length. +info: | + SendableArrayBuffer( length [ , options ] ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + 3. Let requestedMaxByteLength be ? GetSendableArrayBufferMaxByteLengthOption(options). + 4. If requestedMaxByteLength is empty, then + a. [...] + 5. If byteLength > requestedMaxByteLength, throw a RangeError exception. +features: [resizable-SendableArrayBuffer] +---*/ + +assert.throws(RangeError, function() { + new SendableArrayBuffer(1, {maxByteLength: 0}); +}); diff --git a/test/sendable/builtins/ArrayBuffer/options-maxbytelength-excessive.js b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-excessive.js new file mode 100644 index 0000000000000000000000000000000000000000..5f1a78c3610acb124b4a5aba07781d1a007b8301 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-excessive.js @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-constructor +description: | + Invoked with an options object whose `maxByteLength` property exceeds the + maximum length value +info: | + SendableArrayBuffer( length [ , options ] ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + 3. Let requestedMaxByteLength be ? GetSendableArrayBufferMaxByteLengthOption(options). + [...] + + 1.1.5 GetSendableArrayBufferMaxByteLengthOption ( options ) + + 1. If Type(options) is not Object, return empty. + 2. Let maxByteLength be ? Get(options, "maxByteLength"). + 3. If maxByteLength is undefined, return empty. + 4. Return ? ToIndex(maxByteLength). +features: [resizable-SendableArrayBuffer] +---*/ + +assert.throws(RangeError, function() { + // Math.pow(2, 53) = 9007199254740992 + new SendableArrayBuffer(0, { maxByteLength: 9007199254740992 }); +}); diff --git a/test/sendable/builtins/ArrayBuffer/options-maxbytelength-negative.js b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-negative.js new file mode 100644 index 0000000000000000000000000000000000000000..df8ced5c944a470d5e1fc9c5573e192231be3f7c --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-negative.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-constructor +description: Invoked with an options object whose `maxByteLength` property is negative +info: | + SendableArrayBuffer( length [ , options ] ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + 3. Let requestedMaxByteLength be ? GetSendableArrayBufferMaxByteLengthOption(options). + [...] + + 1.1.5 GetSendableArrayBufferMaxByteLengthOption ( options ) + + 1. If Type(options) is not Object, return empty. + 2. Let maxByteLength be ? Get(options, "maxByteLength"). + 3. If maxByteLength is undefined, return empty. + 4. Return ? ToIndex(maxByteLength). +features: [resizable-SendableArrayBuffer] +---*/ + +assert.throws(RangeError, function() { + new SendableArrayBuffer(0, { maxByteLength: -1 }); +}); diff --git a/test/sendable/builtins/ArrayBuffer/options-maxbytelength-object.js b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-object.js new file mode 100644 index 0000000000000000000000000000000000000000..3ea4da2f8135d6d7ce75a1d02b4c8e279c0d077a --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-object.js @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-constructor +description: | + Invoked with an options object whose `maxByteLength` property cannot be + coerced to a primitive value +info: | + SendableArrayBuffer( length [ , options ] ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + 3. Let requestedMaxByteLength be ? GetSendableArrayBufferMaxByteLengthOption(options). + [...] + + 1.1.5 GetSendableArrayBufferMaxByteLengthOption ( options ) + + 1. If Type(options) is not Object, return empty. + 2. Let maxByteLength be ? Get(options, "maxByteLength"). + 3. If maxByteLength is undefined, return empty. + 4. Return ? ToIndex(maxByteLength). +features: [resizable-SendableArrayBuffer] +---*/ + +var log = []; +var options = { + maxByteLength: { + toString: function() { + log.push('toString'); + return {}; + }, + valueOf: function() { + log.push('valueOf'); + return {}; + } + } +}; + +assert.throws(TypeError, function() { + new SendableArrayBuffer(0, options); +}); + +assert.sameValue(log.length, 2); +assert.sameValue(log[0], 'valueOf'); +assert.sameValue(log[1], 'toString'); diff --git a/test/sendable/builtins/ArrayBuffer/options-maxbytelength-poisoned.js b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-poisoned.js new file mode 100644 index 0000000000000000000000000000000000000000..89a553bbbf5dabb056ff663753c4175717728e35 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-poisoned.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-constructor +description: Invoked with an options object whose `maxByteLength` property throws +info: | + SendableArrayBuffer( length [ , options ] ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + 3. Let requestedMaxByteLength be ? GetSendableArrayBufferMaxByteLengthOption(options). + [...] + + 1.1.5 GetSendableArrayBufferMaxByteLengthOption ( options ) + + 1. If Type(options) is not Object, return empty. + 2. Let maxByteLength be ? Get(options, "maxByteLength"). +features: [resizable-SendableArrayBuffer] +---*/ + +var options = { + get maxByteLength() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + new SendableArrayBuffer(0, options); +}); diff --git a/test/sendable/builtins/ArrayBuffer/options-maxbytelength-undefined.js b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..4168ec6689114465a893f4bb55eba4ca6ba995b4 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/options-maxbytelength-undefined.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-constructor +description: Invoked with an options object whose `maxByteLength` property is undefined +info: | + SendableArrayBuffer( length [ , options ] ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + 3. Let requestedMaxByteLength be ? GetSendableArrayBufferMaxByteLengthOption(options). + 4. If requestedMaxByteLength is empty, then + a. Return ? AllocateSendableArrayBuffer(NewTarget, byteLength). + + 1.1.5 GetSendableArrayBufferMaxByteLengthOption ( options ) + + 1. If Type(options) is not Object, return empty. + 2. Let maxByteLength be ? Get(options, "maxByteLength"). + 3. If maxByteLength is undefined, return empty. +features: [resizable-SendableArrayBuffer] +---*/ + +assert.sameValue(new SendableArrayBuffer(0, {}).resizable, false); +assert.sameValue(new SendableArrayBuffer(0, {maxByteLength: undefined}).resizable, false); diff --git a/test/sendable/builtins/ArrayBuffer/options-non-object.js b/test/sendable/builtins/ArrayBuffer/options-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..d7fb596bf9f08ae6f2371c839a955db73025ba44 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/options-non-object.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-constructor +description: Invoked with a non-object value for options +info: | + SendableArrayBuffer( length [ , options ] ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + 3. Let requestedMaxByteLength be ? GetSendableArrayBufferMaxByteLengthOption(options). + 4. If requestedMaxByteLength is empty, then + a. Return ? AllocateSendableArrayBuffer(NewTarget, byteLength). + + 1.1.5 GetSendableArrayBufferMaxByteLengthOption ( options ) + + 1. If Type(options) is not Object, return empty. +features: [resizable-SendableArrayBuffer] +---*/ + +assert.sameValue(new SendableArrayBuffer(0, null).resizable, false, 'null'); +assert.sameValue(new SendableArrayBuffer(0, true).resizable, false, 'boolean'); +assert.sameValue(new SendableArrayBuffer(0, Symbol(3)).resizable, false, 'symbol'); +assert.sameValue(new SendableArrayBuffer(0, 1n).resizable, false, 'bigint'); +assert.sameValue(new SendableArrayBuffer(0, 'string').resizable, false, 'string'); +assert.sameValue(new SendableArrayBuffer(0, 9).resizable, false, 'number'); +assert.sameValue(new SendableArrayBuffer(0, undefined).resizable, false, 'undefined'); diff --git a/test/sendable/builtins/ArrayBuffer/prop-desc.js b/test/sendable/builtins/ArrayBuffer/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..732d929ee3d0809486a01d239e6601f9b3dee775 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prop-desc.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-constructor +description: > + Property descriptor of SendableArrayBuffer +info: | + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SendableArrayBuffer, "function", "`typeof SendableArrayBuffer` is `'function'`"); + +verifyProperty(this, "SendableArrayBuffer", { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/ArrayBuffer/proto-from-ctor-realm.js b/test/sendable/builtins/ArrayBuffer/proto-from-ctor-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..3e6bc798e80dbac0beaed9f45b43c9b5047da92c --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/proto-from-ctor-realm.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 5. Return ? AllocateSendableArrayBuffer(NewTarget, byteLength). + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [cross-realm, Reflect] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +var o = Reflect.construct(SendableArrayBuffer, [], C); + +assert.sameValue(Object.getPrototypeOf(o), other.SendableArrayBuffer.prototype); diff --git a/test/sendable/builtins/ArrayBuffer/prototype-from-newtarget.js b/test/sendable/builtins/ArrayBuffer/prototype-from-newtarget.js new file mode 100644 index 0000000000000000000000000000000000000000..8aea514f186f3fcdea7d713e2ea7f34cb877e509 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype-from-newtarget.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + The [[Prototype]] internal slot is computed from NewTarget. +info: | + SendableArrayBuffer( length ) + + SendableArrayBuffer called with argument length performs the following steps: + + ... + 6. Return AllocateSendableArrayBuffer(NewTarget, byteLength). + + AllocateSendableArrayBuffer( constructor, byteLength ) + 1. Let obj be OrdinaryCreateFromConstructor(constructor, "%SendableArrayBufferPrototype%", + «[[SendableArrayBufferData]], [[SendableArrayBufferByteLength]]» ). + 2. ReturnIfAbrupt(obj). + ... +features: [Reflect.construct] +---*/ + +var SendableArrayBuffer = Reflect.construct(SendableArrayBuffer, [8], Object); +assert.sameValue(Object.getPrototypeOf(SendableArrayBuffer), Object.prototype, "NewTarget is built-in Object constructor"); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get: function() { + return Array.prototype; + } +}); +var SendableArrayBuffer = Reflect.construct(SendableArrayBuffer, [16], newTarget); +assert.sameValue(Object.getPrototypeOf(SendableArrayBuffer), Array.prototype, "NewTarget is BoundFunction with accessor"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/Symbol.toStringTag.js b/test/sendable/builtins/ArrayBuffer/prototype/Symbol.toStringTag.js new file mode 100644 index 0000000000000000000000000000000000000000..0bd961069d96b419c202d4ca5b1241a4b784ee99 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/Symbol.toStringTag.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype-@@tostringtag +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "SendableArrayBuffer". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.toStringTag] +---*/ + +assert.sameValue(SendableArrayBuffer.prototype[Symbol.toStringTag], 'SendableArrayBuffer'); + +verifyProperty(SendableArrayBuffer.prototype, Symbol.toStringTag, { + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/byteLength/detached-buffer.js b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..ff4589294d606b80cc49b3a33ed632d9677d5841 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/detached-buffer.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.bytelength +description: Returns 0 if the buffer is detached +info: | + get SendableArrayBuffer.prototype.byteLength + ... + If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality] +---*/ + +var ab = new SendableArrayBuffer(1); + +$DETACHBUFFER(ab); + +assert.sameValue(ab.byteLength, 0, 'The value of ab.byteLength is 0'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/byteLength/invoked-as-accessor.js b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/invoked-as-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..242b4d1fb23f13fce797ca3a426f048db53efe36 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/invoked-as-accessor.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.bytelength +description: Requires this value to have a [[SendableArrayBufferData]] internal slot +info: | + 24.1.4.1 get SendableArrayBuffer.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have an [[SendableArrayBufferData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.byteLength; +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/byteLength/invoked-as-func.js b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..d5d725c765ec9ed9b3fe9113c4e4a58c2d30b7ce --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/invoked-as-func.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.bytelength +description: Throws a TypeError exception when invoked as a function +info: | + 24.1.4.1 get SendableArrayBuffer.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have an [[SendableArrayBufferData]] internal slot, throw a TypeError + exception. + ... +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/byteLength/length.js b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/length.js new file mode 100644 index 0000000000000000000000000000000000000000..7171ba3b550450727f87adeb24e8dc162eaab522 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/length.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.bytelength +description: > + get SendableArrayBuffer.prototype.byteLength.length is 0. +info: | + get SendableArrayBuffer.prototype.byteLength + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer.prototype, "byteLength"); + +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/byteLength/name.js b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/name.js new file mode 100644 index 0000000000000000000000000000000000000000..78ca53f19c903ff063cbc05f0d20026bbf5a0c41 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/name.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.bytelength +description: > + get SendableArrayBuffer.prototype.byteLength + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, 'byteLength' +); + +verifyProperty(descriptor.get, "name", { + value: "get byteLength", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/byteLength/prop-desc.js b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..9f46f11a904b6389959d1963ccf6d4967c0212ec --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/prop-desc.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.bytelength +description: > + "byteLength" property of SendableArrayBuffer.prototype +info: | + SendableArrayBuffer.prototype.byteLength is an accessor property whose set accessor + function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer.prototype, "byteLength"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(SendableArrayBuffer.prototype, "byteLength"); +verifyConfigurable(SendableArrayBuffer.prototype, "byteLength"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/byteLength/return-bytelength.js b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/return-bytelength.js new file mode 100644 index 0000000000000000000000000000000000000000..9b89bd13e14b4378527e285f48d8bd28112f2f1e --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/return-bytelength.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.bytelength +description: Return value from [[ByteLength]] internal slot +info: | + 24.1.4.1 get SendableArrayBuffer.prototype.byteLength + + ... + 5. Let length be the value of O's [[SendableArrayBufferByteLength]] internal slot. + 6. Return length. +---*/ + +var ab1 = new SendableArrayBuffer(0); +assert.sameValue(ab1.byteLength, 0); + +var ab2 = new SendableArrayBuffer(42); +assert.sameValue(ab2.byteLength, 42); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/byteLength/this-has-no-typedarrayname-internal.js b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/this-has-no-typedarrayname-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..a8569b0fc6703ee5d6812abf27d3065849aabed0 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/this-has-no-typedarrayname-internal.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.bytelength +description: > + Throws a TypeError exception when `this` does not have a [[SendableArrayBufferData]] + internal slot +info: | + 24.1.4.1 get SendableArrayBuffer.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have an [[SendableArrayBufferData]] internal slot, throw a TypeError + exception. + ... +features: [DataView, Int8Array] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ta = new Int8Array(8); +assert.throws(TypeError, function() { + getter.call(ta); +}); + +var dv = new DataView(new SendableArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/byteLength/this-is-not-object.js b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..c5f85b04ba86f5ed6cc474afebc7c881be681658 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/this-is-not-object.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.bytelength +description: Throws a TypeError exception when `this` is not Object +info: | + 24.1.4.1 get SendableArrayBuffer.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/byteLength/this-is-sharedarraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..22a5422b9d52b736545a4f44f88b1eb4ad7977cb --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/byteLength/this-is-sharedarraybuffer.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.bytelength +description: Throws a TypeError exception when `this` is a SharedArrayBuffer +features: [align-detached-buffer-semantics-with-web-reality, SharedArrayBuffer] +---*/ + +var byteLength = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "byteLength" +); + +var getter = byteLength.get; +var sab = new SharedArrayBuffer(4); + +assert.throws(TypeError, function() { + getter.call(sab); +}, "`this` cannot be a SharedArrayBuffer"); + +assert.throws(TypeError, function() { + Object.defineProperties(sab, { byteLength }); + sab.byteLength; +}, "`this` cannot be a SharedArrayBuffer"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/constructor.js b/test/sendable/builtins/ArrayBuffer/prototype/constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..8509330a7d56156d0a4bcf60e068f3cc7acefdc9 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/constructor.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.constructor +description: > + The `SendableArrayBuffer.prototype.constructor` property descriptor. +info: | + The initial value of SendableArrayBuffer.prototype.constructor is the intrinsic + object %SendableArrayBuffer%. + + 17 ECMAScript Standard Built-in Objects: + Every other data property described in clauses 18 through 26 and in + Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(SendableArrayBuffer.prototype.constructor, SendableArrayBuffer); + +verifyProperty(SendableArrayBuffer.prototype, "constructor", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/detached/detached-buffer-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/detached/detached-buffer-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..9b48ac93c82b0c39590ac09dc668d2357c3ba1ed --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/detached/detached-buffer-resizable.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.detached +description: Return a boolean indicating if the SendableArrayBuffer is detached +info: | + get SendableArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. Return IsDetachedBuffer(O). +includes: [detachArrayBuffer.js] +features: [SendableArrayBuffer, arraybuffer-transfer, resizable-arraybuffer] +---*/ + +var ab1 = new SendableArrayBuffer(0, { maxByteLength: 0 }); +assert.sameValue(ab1.detached, false, 'Resizable SendableArrayBuffer with maxByteLength of 0 is not detached'); + +$DETACHBUFFER(ab1); + +assert.sameValue(ab1.detached, true, 'Resizable SendableArrayBuffer with maxByteLength of 0 is now detached'); + +var ab2 = new SendableArrayBuffer(0, { maxByteLength: 23 }); +assert.sameValue(ab2.detached, false, 'Resizable SendableArrayBuffer with maxByteLength of 23 is not detached'); + +$DETACHBUFFER(ab2); + +assert.sameValue(ab2.detached, true, 'Resizable SendableArrayBuffer with maxByteLength of 23 is now detached'); + +var ab3 = new SendableArrayBuffer(42, { maxByteLength: 42 }); +assert.sameValue(ab3.detached, false, 'Resizable SendableArrayBuffer with maxByteLength of 42 is not detached'); + +$DETACHBUFFER(ab3); + +assert.sameValue(ab3.detached, true, 'Resizable SendableArrayBuffer with maxByteLength of 42 is now detached'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/detached/detached-buffer.js b/test/sendable/builtins/ArrayBuffer/prototype/detached/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..e341d27c2171a070ef6c75f00f73d085ac60f2f6 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/detached/detached-buffer.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.detached +description: Returns true if the buffer is detached, else false +info: | + get SendableArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. Return IsDetachedBuffer(O). + +includes: [detachArrayBuffer.js] +features: [SendableArrayBuffer, arraybuffer-transfer] +---*/ + +var ab = new SendableArrayBuffer(1); + +assert.sameValue(ab.detached, false); + +$DETACHBUFFER(ab); + +assert.sameValue(ab.detached, true); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/detached/invoked-as-accessor.js b/test/sendable/builtins/ArrayBuffer/prototype/detached/invoked-as-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..41dbb5e837ee45191f03131a706cb95449ef902e --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/detached/invoked-as-accessor.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.detached +description: Returns true if the buffer is detached, else false +info: | + get SendableArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. Return IsDetachedBuffer(O). + +features: [SendableArrayBuffer, arraybuffer-transfer] +---*/ + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.detached; +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/detached/invoked-as-func.js b/test/sendable/builtins/ArrayBuffer/prototype/detached/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..58be7ffcfc9f439f35290c125a2e7103f732beca --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/detached/invoked-as-func.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.detached +description: Returns true if the buffer is detached, else false +info: | + get SendableArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] + +features: [SendableArrayBuffer, arraybuffer-transfer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, 'detached' +).get; + +assert.sameValue(typeof getter, 'function'); + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/detached/length.js b/test/sendable/builtins/ArrayBuffer/prototype/detached/length.js new file mode 100644 index 0000000000000000000000000000000000000000..a506c5680a2b85446c96e30f10a16a95f988c20b --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/detached/length.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.detached +description: > + get SendableArrayBuffer.prototype.detached.length is 0. +info: | + get SendableArrayBuffer.prototype.detached + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. + +includes: [propertyHelper.js] +features: [SendableArrayBuffer, arraybuffer-transfer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer.prototype, 'detached'); + +verifyProperty(desc.get, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/detached/name.js b/test/sendable/builtins/ArrayBuffer/prototype/detached/name.js new file mode 100644 index 0000000000000000000000000000000000000000..a9f7718e222045607398399e7cff01137dc4275a --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/detached/name.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.detached +description: > + get SendableArrayBuffer.prototype.detached + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +features: [SendableArrayBuffer, arraybuffer-transfer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer.prototype, 'detached'); + +verifyProperty(desc.get, 'name', { + value: 'get detached', + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/detached/prop-desc.js b/test/sendable/builtins/ArrayBuffer/prototype/detached/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..41e63462f3ac1c03f44bfb229810474be6d08f14 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/detached/prop-desc.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.detached +description: > + "detached" property of SendableArrayBuffer.prototype +info: | + SendableArrayBuffer.prototype.detached is an accessor property whose set + accessor function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js] +features: [SendableArrayBuffer, arraybuffer-transfer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer.prototype, 'detached'); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +verifyProperty(SendableArrayBuffer.prototype, 'detached', { + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/detached/this-has-no-arraybufferdata-internal.js b/test/sendable/builtins/ArrayBuffer/prototype/detached/this-has-no-arraybufferdata-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..6dc067f22c96610740fc62fd8e8ab5f3a0d4cf32 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/detached/this-has-no-arraybufferdata-internal.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.detached +description: > + Throws a TypeError exception when `this` does not have a [[SendableArrayBufferData]] + internal slot +info: | + get SendableArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [DataView, Int8Array, SendableArrayBuffer, arraybuffer-transfer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "detached" +).get; + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ta = new Int8Array(8); +assert.throws(TypeError, function() { + getter.call(ta); +}); + +var dv = new DataView(new SendableArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/detached/this-is-not-object.js b/test/sendable/builtins/ArrayBuffer/prototype/detached/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..a2383a08aa9a708b054a0a0f8a6cdfa2d8dff415 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/detached/this-is-not-object.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.detached +description: Throws a TypeError exception when `this` is not Object +info: | + get SendableArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [Symbol, SendableArrayBuffer, arraybuffer-transfer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "detached" +).get; + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..265f890bebd040f5f277d60ff516464b95bdb37a --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer-resizable.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.detached +description: Throws a TypeError exception when `this` is a resizable SharedArrayBuffer +info: | + get SendableArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + [...] +features: [SharedArrayBuffer, SendableArrayBuffer, arraybuffer-transfer] +---*/ + +var detached = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "detached" +); + +var getter = detached.get; +var sab = new SharedArrayBuffer(4); + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call(sab); +}, "`this` cannot be a SharedArrayBuffer"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..2efa28853d88bb2cd02ca858b89741c91c695161 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/detached/this-is-sharedarraybuffer.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.detached +description: Throws a TypeError exception when `this` is a SharedArrayBuffer +info: | + get SendableArrayBuffer.prototype.detached + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + [...] +features: [SharedArrayBuffer, SendableArrayBuffer, arraybuffer-transfer] +---*/ + +var detached = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "detached" +); + +var getter = detached.get; +var sab = new SharedArrayBuffer(4); + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call(sab); +}, "`this` cannot be a SharedArrayBuffer"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/detached-buffer.js b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..80bf7bfd706ff9f2f87dac2c292931f435986c27 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/detached-buffer.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.maxbytelength +description: Returns 0 if the buffer is detached +info: | + get SendableArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, return +0𝔽. + [...] +includes: [detachArrayBuffer.js] +features: [resizable-arraybuffer] +---*/ + +var ab = new SendableArrayBuffer(1); + +$DETACHBUFFER(ab); + +assert.sameValue(ab.maxByteLength, 0); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/invoked-as-accessor.js b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/invoked-as-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..260f603d2b9869fc6fce3f1d247e94ac0aca27ee --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/invoked-as-accessor.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.maxbytelength +description: Requires this value to have a [[SendableArrayBufferData]] internal slot +info: | + get SendableArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [resizable-arraybuffer] +---*/ + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.maxByteLength; +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/invoked-as-func.js b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..629b4231b367edaed80a9390139dc42e9d5e9d43 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/invoked-as-func.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.maxbytelength +description: Throws a TypeError exception when invoked as a function +info: | + get SendableArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, 'maxByteLength' +).get; + +assert.sameValue(typeof getter, 'function'); + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/length.js b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/length.js new file mode 100644 index 0000000000000000000000000000000000000000..ade931bf570c6f2f9398550e39523ef6bd6d759b --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.maxbytelength +description: > + get SendableArrayBuffer.prototype.maxByteLength.length is 0. +info: | + get SendableArrayBuffer.prototype.maxByteLength + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer.prototype, 'maxByteLength'); + +verifyProperty(desc.get, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/name.js b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/name.js new file mode 100644 index 0000000000000000000000000000000000000000..3b4439b5f0fd6d6e3ca20a2cf5673ad3aca63f16 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/name.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.maxbytelength +description: > + get SendableArrayBuffer.prototype.maxByteLength + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +features: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer.prototype, 'maxByteLength'); + +verifyProperty(desc.get, 'name', { + value: 'get maxByteLength', + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/prop-desc.js b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..fd8f03bab080e94d6442283e5bb474725b8fb288 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/prop-desc.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.maxbytelength +description: > + "maxByteLength" property of SendableArrayBuffer.prototype +info: | + SendableArrayBuffer.prototype.maxByteLength is an accessor property whose set + accessor function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js] +features: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer.prototype, 'maxByteLength'); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +verifyProperty(SendableArrayBuffer.prototype, 'maxByteLength', { + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-non-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-non-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..e7deeb0fc137b2246d82049a707e765fecec5221 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-non-resizable.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.maxbytelength +description: Return value from [[SendableArrayBufferByteLength]] internal slot +info: | + 24.1.4.1 get SendableArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, return +0𝔽. + 5. If IsResizableSendableArrayBuffer(O) is true, then + [...] + 6. Else, + a. Let length be O.[[SendableArrayBufferByteLength]]. + 7. Return 𝔽(length). +features: [resizable-arraybuffer] +---*/ + +var ab1 = new SendableArrayBuffer(0); +assert.sameValue(ab1.maxByteLength, 0); + +var ab2 = new SendableArrayBuffer(42); +assert.sameValue(ab2.maxByteLength, 42); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..3529ea80547dff9e6b17b62b8520b36b85a130e2 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/return-maxbytelength-resizable.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.maxbytelength +description: Return value from [[SendableArrayBufferMaxByteLength]] internal slot +info: | + 24.1.4.1 get SendableArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, return +0𝔽. + 5. If IsResizableSendableArrayBuffer(O) is true, then + a. Let length be O.[[SendableArrayBufferMaxByteLength]]. + 6. Else, + [...] + 7. Return 𝔽(length). +features: [resizable-arraybuffer] +---*/ + +var ab1 = new SendableArrayBuffer(0, { maxByteLength: 0 }); +assert.sameValue(ab1.maxByteLength, 0); + +var ab2 = new SendableArrayBuffer(0, { maxByteLength: 23 }); +assert.sameValue(ab2.maxByteLength, 23); + +var ab3 = new SendableArrayBuffer(42, { maxByteLength: 42 }); +assert.sameValue(ab3.maxByteLength, 42); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/this-has-no-arraybufferdata-internal.js b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/this-has-no-arraybufferdata-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..2c649fc6a564602bff2fb30a2f6dcdcfedd3a39d --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/this-has-no-arraybufferdata-internal.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.maxbytelength +description: > + Throws a TypeError exception when `this` does not have a [[SendableArrayBufferData]] + internal slot +info: | + get SendableArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [DataView, Int8Array, resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "maxByteLength" +).get; + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ta = new Int8Array(8); +assert.throws(TypeError, function() { + getter.call(ta); +}); + +var dv = new DataView(new SendableArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/this-is-not-object.js b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..d74989e49e282e4f1d493f956ec80096e02fb6d2 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/this-is-not-object.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.maxbytelength +description: Throws a TypeError exception when `this` is not Object +info: | + get SendableArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [Symbol, resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "maxByteLength" +).get; + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/this-is-sharedarraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..885b589e94d4798c6472e0dd6cef579c5df76950 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/maxByteLength/this-is-sharedarraybuffer.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.maxbytelength +description: Throws a TypeError exception when `this` is a SharedArrayBuffer +info: | + get SendableArrayBuffer.prototype.maxByteLength + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + [...] +features: [SharedArrayBuffer, resizable-arraybuffer] +---*/ + +var maxByteLength = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "maxByteLength" +); + +var getter = maxByteLength.get; +var sab = new SharedArrayBuffer(4); + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call(sab); +}, "`this` cannot be a SharedArrayBuffer"); + +Object.defineProperties(sab, { maxByteLength: maxByteLength }); + +assert.throws(TypeError, function() { + sab.maxByteLength; +}, "`this` cannot be a SharedArrayBuffer"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resizable/detached-buffer.js b/test/sendable/builtins/ArrayBuffer/prototype/resizable/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..805bbd8e8665963776ac89106e5ec7345a401758 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resizable/detached-buffer.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.resizable +description: Unaffected by buffer's attachedness +info: | + get SendableArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. Return IsResizableSendableArrayBuffer(O). + + IsResizableSendableArrayBuffer ( arrayBuffer ) + + 1. Assert: Type(arrayBuffer) is Object and arrayBuffer has an + [[SendableArrayBufferData]] internal slot. + 2. If buffer has an [[SendableArrayBufferMaxByteLength]] internal slot, return true. + 3. Return false. +includes: [detachArrayBuffer.js] +features: [resizable-arraybuffer] +---*/ + +var ab1 = new SendableArrayBuffer(1); + +$DETACHBUFFER(ab1); + +assert.sameValue(ab1.resizable, false); + +var ab2 = new SendableArrayBuffer(1, {maxByteLength: 1}); + +$DETACHBUFFER(ab2); + +assert.sameValue(ab2.resizable, true); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resizable/invoked-as-accessor.js b/test/sendable/builtins/ArrayBuffer/prototype/resizable/invoked-as-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..6c5e04d71fe627ce2bfe6e57fdf3b02bb1793423 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resizable/invoked-as-accessor.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.resizable +description: Requires this value to have a [[SendableArrayBufferData]] internal slot +info: | + get SendableArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [resizable-arraybuffer] +---*/ + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resizable; +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resizable/invoked-as-func.js b/test/sendable/builtins/ArrayBuffer/prototype/resizable/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..593565b59590d92b8c3f56a8b44b40452ee688e7 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resizable/invoked-as-func.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.resizable +description: Throws a TypeError exception when invoked as a function +info: | + get SendableArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, 'resizable' +).get; + +assert.sameValue(typeof getter, 'function'); + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resizable/length.js b/test/sendable/builtins/ArrayBuffer/prototype/resizable/length.js new file mode 100644 index 0000000000000000000000000000000000000000..e830502082c7d08002a31c171680ad82a12235de --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resizable/length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.resizable +description: > + get SendableArrayBuffer.prototype.resizable.length is 0. +info: | + get SendableArrayBuffer.prototype.resizeable + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer.prototype, 'resizable'); + +verifyProperty(desc.get, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resizable/name.js b/test/sendable/builtins/ArrayBuffer/prototype/resizable/name.js new file mode 100644 index 0000000000000000000000000000000000000000..87dc79d2573d2e5e460fc6199a4f92c1ff63739a --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resizable/name.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.resizable +description: > + get SendableArrayBuffer.prototype.resizable + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +features: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer.prototype, 'resizable'); + +verifyProperty(desc.get, 'name', { + value: 'get resizable', + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resizable/prop-desc.js b/test/sendable/builtins/ArrayBuffer/prototype/resizable/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..6880d704e29baf770b28e030b5187d8cb5eacd4b --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resizable/prop-desc.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.resizable +description: > + "resizable" property of SendableArrayBuffer.prototype +info: | + SendableArrayBuffer.prototype.resizable is an accessor property whose set accessor + function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js] +features: [resizable-arraybuffer] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableArrayBuffer.prototype, 'resizable'); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +verifyProperty(SendableArrayBuffer.prototype, 'resizable', { + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resizable/return-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/resizable/return-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..eb78ff9d3c4c6e65b7797a2d40bd92a342a43af0 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resizable/return-resizable.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.resizable +description: Return value according to [[SendableArrayBufferMaxByteLength]] internal slot +info: | + get SendableArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. Return IsResizableSendableArrayBuffer(O). + + IsResizableSendableArrayBuffer ( arrayBuffer ) + + 1. Assert: Type(arrayBuffer) is Object and arrayBuffer has an + [[SendableArrayBufferData]] internal slot. + 2. If buffer has an [[SendableArrayBufferMaxByteLength]] internal slot, return true. + 3. Return false. +features: [resizable-arraybuffer] +---*/ + +var ab1 = new SendableArrayBuffer(1); + +assert.sameValue(ab1.resizable, false); + +var ab2 = new SendableArrayBuffer(1, {maxByteLength: 1}); + +assert.sameValue(ab2.resizable, true); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resizable/this-has-no-arraybufferdata-internal.js b/test/sendable/builtins/ArrayBuffer/prototype/resizable/this-has-no-arraybufferdata-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..826aed1ce89b436438195ab1adb73f11fcebc881 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resizable/this-has-no-arraybufferdata-internal.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.resizable +description: > + Throws a TypeError exception when `this` does not have a [[SendableArrayBufferData]] + internal slot +info: | + get SendableArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [DataView, Int8Array, resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "resizable" +).get; + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ta = new Int8Array(8); +assert.throws(TypeError, function() { + getter.call(ta); +}); + +var dv = new DataView(new SendableArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resizable/this-is-not-object.js b/test/sendable/builtins/ArrayBuffer/prototype/resizable/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..4d91334441c5200dcbec97c59a2e03e60556f052 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resizable/this-is-not-object.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.resizable +description: Throws a TypeError exception when `this` is not Object +info: | + get SendableArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [Symbol, resizable-arraybuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "resizable" +).get; + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resizable/this-is-sharedarraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/resizable/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..87b0088eaed9fffe73d11b6f476a86f66a169902 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resizable/this-is-sharedarraybuffer.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-sendableArraybuffer.prototype.resizable +description: Throws a TypeError exception when `this` is a SharedArrayBuffer +info: | + get SendableArrayBuffer.prototype.resizable + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + [...] +features: [SharedArrayBuffer, resizable-arraybuffer] +---*/ + +var resizable = Object.getOwnPropertyDescriptor( + SendableArrayBuffer.prototype, "resizable" +); + +var getter = resizable.get; +var sab = new SharedArrayBuffer(4); + +assert.sameValue(typeof getter, "function"); + +assert.throws(TypeError, function() { + getter.call(sab); +}, "`this` cannot be a SharedArrayBuffer"); + +Object.defineProperties(sab, { resizable: resizable }); + +assert.throws(TypeError, function() { + sab.resizable; +}, "`this` cannot be a SharedArrayBuffer"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/coerced-new-length-detach.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/coerced-new-length-detach.js new file mode 100644 index 0000000000000000000000000000000000000000..fafaf3b47a25c7537673b68db5c2dd840b8a6886 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/coerced-new-length-detach.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + SendableArrayBuffer.p.resize has one detach check after argument coercion +includes: [detachArrayBuffer.js] +features: [resizable-arraybuffer] +---*/ + +{ + const rab = new SendableArrayBuffer(64, { maxByteLength: 1024 }); + let called = false; + assert.throws(TypeError, () => rab.resize({ valueOf() { + $DETACHBUFFER(rab); + called = true; + }})); + assert(called); +} + +{ + const rab = new SendableArrayBuffer(64, { maxByteLength: 1024 }); + $DETACHBUFFER(rab); + let called = false; + assert.throws(TypeError, () => rab.resize({ valueOf() { + called = true; + }})); + assert(called); +} diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/descriptor.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..d2bce47a7177602b58b659773d82c45c62bcc0d3 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/descriptor.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + SendableArrayBuffer.prototype.resize has default data property attributes. +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 17 ECMAScript Standard Built-in Objects: + Every other data property described in clauses 18 through 26 and in + Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [resizable-arraybuffer] +---*/ + +verifyProperty(SendableArrayBuffer.prototype, 'resize', { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/extensible.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..c1457716f9db28443a6e99f14296f8b3f832e9b7 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/extensible.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: SendableArrayBuffer.prototype.resize is extensible. +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 17 ECMAScript Standard Built-in Objects: + Unless specified otherwise, the [[Extensible]] internal slot + of a built-in object initially has the value true. +features: [resizable-arraybuffer] +---*/ + +assert(Object.isExtensible(SendableArrayBuffer.prototype.resize)); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/length.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/length.js new file mode 100644 index 0000000000000000000000000000000000000000..4cee0f096dac55034207bac4422b5eb6163b26b9 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + SendableArrayBuffer.prototype.resize.length is 1. +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [resizable-arraybuffer] +---*/ + +verifyProperty(SendableArrayBuffer.prototype.resize, 'length', { + value: 1, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/name.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/name.js new file mode 100644 index 0000000000000000000000000000000000000000..370aa2f29760bd08de1e0d4abac07fd6c65b51d4 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + SendableArrayBuffer.prototype.resize.name is "resize". +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +features: [resizable-arraybuffer] +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArrayBuffer.prototype.resize, 'name', { + value: 'resize', + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/new-length-excessive.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/new-length-excessive.js new file mode 100644 index 0000000000000000000000000000000000000000..d6043b55bc4e378899ba128dfdb0d32fc8deb4cc --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/new-length-excessive.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + Throws a RangeError the newLength value is larger than the max byte length +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. Let newByteLength be ? ToIntegerOrInfinity(newLength). + 6. If newByteLength < 0 or newByteLength > O.[[SendableArrayBufferMaxByteLength]], + throw a RangeError exception. + [...] +features: [resizable-arraybuffer] +---*/ + +var ab = new SendableArrayBuffer(4, {maxByteLength: 4}); + +assert.throws(RangeError, function() { + ab.resize(5); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/new-length-negative.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/new-length-negative.js new file mode 100644 index 0000000000000000000000000000000000000000..be51dbc967ec41668f54dd9642a8e8ccb686361d --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/new-length-negative.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + Throws a RangeError the newLength value is less than zero +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. Let newByteLength be ? ToIntegerOrInfinity(newLength). + 6. If newByteLength < 0 or newByteLength > O.[[SendableArrayBufferMaxByteLength]], + throw a RangeError exception. + [...] +features: [resizable-arraybuffer] +---*/ + +var ab = new SendableArrayBuffer(4, {maxByteLength: 4}); + +assert.throws(RangeError, function() { + ab.resize(-1); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/new-length-non-number.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/new-length-non-number.js new file mode 100644 index 0000000000000000000000000000000000000000..745a6282fcb4110830f0e75086a2ae9e1bde4397 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/new-length-non-number.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: Throws a TypeError if provided length cannot be coerced to a number +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. Let newByteLength be ? ToIntegerOrInfinity(newLength). + [...] +features: [resizable-arraybuffer] +---*/ + +var log = []; +var newLength = { + toString: function() { + log.push('toString'); + return {}; + }, + valueOf: function() { + log.push('valueOf'); + return {}; + } +}; +var ab = new SendableArrayBuffer(0, {maxByteLength: 4}); + +assert.throws(TypeError, function() { + ab.resize(newLength); +}); + +assert.sameValue(log.length, 2); +assert.sameValue(log[0], 'valueOf'); +assert.sameValue(log[1], 'toString'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/nonconstructor.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/nonconstructor.js new file mode 100644 index 0000000000000000000000000000000000000000..f841179db233567cccd269f626dceb4125172c89 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/nonconstructor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + SendableArrayBuffer.prototype.resize is not a constructor function. +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 17 ECMAScript Standard Built-in Objects: + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified + in the description of a particular function. +includes: [isConstructor.js] +features: [resizable-arraybuffer, Reflect.construct] +---*/ + +assert(!isConstructor(SendableArrayBuffer.prototype.resize), "SendableArrayBuffer.prototype.resize is not a constructor"); + +var arrayBuffer = new SendableArrayBuffer(8); +assert.throws(TypeError, function() { + new arrayBuffer.resize(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-grow.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..96a336a507405d540a9d302dd3c01c17b29cc790 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-grow.js @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: Behavior when attempting to grow a resizable array buffer +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. Let newByteLength be ? ToIntegerOrInfinity(newLength). + 6. If newByteLength < 0 or newByteLength > O.[[SendableArrayBufferMaxByteLength]], + throw a RangeError exception. + 7. Let hostHandled be ? HostResizeSendableArrayBuffer(O, newByteLength). + [...] + + HostResizeSendableArrayBuffer ( buffer, newByteLength ) + + The implementation of HostResizeSendableArrayBuffer must conform to the following + requirements: + + - The abstract operation does not detach buffer. + - The abstract operation may complete normally or abruptly. + - If the abstract operation completes normally with handled, + buffer.[[SendableArrayBufferByteLength]] is newByteLength. + - The return value is either handled or unhandled. +features: [resizable-arraybuffer] +---*/ + +var ab = new SendableArrayBuffer(4, {maxByteLength: 5}); +var caught = false; +var result; + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `SendableArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ab.resize, 'function'); + +try { + result = ab.resize(5); +} catch (_) { + caught = true; +} + +try { + ab.slice(); +} catch (_) { + throw new Test262Error('The SendableArrayBuffer under test was detached'); +} + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation and conforms to the +// invarient regarding [[SendableArrayBufferByteLength]] +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method updates [[SendableArrayBufferByteLength]] +// +// The final two conditions are indistinguishable. +assert(caught || ab.byteLength === 5, 'byteLength'); + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation, and the `resize` +// method returns early +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method executes its final steps +// +// All three conditions have the same effect on the value of `result`. +assert.sameValue(result, undefined, 'normal completion value'); + +// The contents of the SendableArrayBuffer are not guaranteed by the host-defined +// abstract operation, so they are not asserted in this test. diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-same-size-zero-explicit.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-same-size-zero-explicit.js new file mode 100644 index 0000000000000000000000000000000000000000..fafd0a5c7ab19df9bbbd6fd300150c662fb2cc12 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-same-size-zero-explicit.js @@ -0,0 +1,91 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + Behavior when attempting to reset the size of a resizable array buffer to zero explicitly +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. Let newByteLength be ? ToIntegerOrInfinity(newLength). + 6. If newByteLength < 0 or newByteLength > O.[[SendableArrayBufferMaxByteLength]], + throw a RangeError exception. + 7. Let hostHandled be ? HostResizeSendableArrayBuffer(O, newByteLength). + [...] + + HostResizeSendableArrayBuffer ( buffer, newByteLength ) + + The implementation of HostResizeSendableArrayBuffer must conform to the following + requirements: + + - The abstract operation does not detach buffer. + - The abstract operation may complete normally or abruptly. + - If the abstract operation completes normally with handled, + buffer.[[SendableArrayBufferByteLength]] is newByteLength. + - The return value is either handled or unhandled. +features: [resizable-arraybuffer] +---*/ + +var ab = new SendableArrayBuffer(0, {maxByteLength: 0}); +var caught = false; +var result; + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `SendableArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ab.resize, 'function'); + +try { + result = ab.resize(0); +} catch (_) { + caught = true; +} + +try { + ab.slice(); +} catch (_) { + throw new Test262Error('The SendableArrayBuffer under test was detached'); +} + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation and conforms to the +// invarient regarding [[SendableArrayBufferByteLength]] +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method updates [[SendableArrayBufferByteLength]] +// +// The final two conditions are indistinguishable. +assert(caught || ab.byteLength === 0, 'byteLength'); + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation, and the `resize` +// method returns early +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method executes its final steps +// +// All three conditions have the same effect on the value of `result`. +assert.sameValue(result, undefined, 'normal completion value'); + +// The contents of the SendableArrayBuffer are not guaranteed by the host-defined +// abstract operation, so they are not asserted in this test. diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js new file mode 100644 index 0000000000000000000000000000000000000000..6636e700540f18401a964c42ab8b45df1b7c59b9 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-same-size-zero-implicit.js @@ -0,0 +1,91 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + Behavior when attempting to reset the size of a resizable array buffer to zero explicitly +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. Let newByteLength be ? ToIntegerOrInfinity(newLength). + 6. If newByteLength < 0 or newByteLength > O.[[SendableArrayBufferMaxByteLength]], + throw a RangeError exception. + 7. Let hostHandled be ? HostResizeSendableArrayBuffer(O, newByteLength). + [...] + + HostResizeSendableArrayBuffer ( buffer, newByteLength ) + + The implementation of HostResizeSendableArrayBuffer must conform to the following + requirements: + + - The abstract operation does not detach buffer. + - The abstract operation may complete normally or abruptly. + - If the abstract operation completes normally with handled, + buffer.[[SendableArrayBufferByteLength]] is newByteLength. + - The return value is either handled or unhandled. +features: [resizable-arraybuffer] +---*/ + +var ab = new SendableArrayBuffer(0, {maxByteLength: 0}); +var caught = false; +var result; + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `SendableArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ab.resize, 'function'); + +try { + result = ab.resize(); +} catch (_) { + caught = true; +} + +try { + ab.slice(); +} catch (_) { + throw new Test262Error('The SendableArrayBuffer under test was detached'); +} + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation and conforms to the +// invarient regarding [[SendableArrayBufferByteLength]] +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method updates [[SendableArrayBufferByteLength]] +// +// The final two conditions are indistinguishable. +assert(caught || ab.byteLength === 0, 'byteLength'); + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation, and the `resize` +// method returns early +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method executes its final steps +// +// All three conditions have the same effect on the value of `result`. +assert.sameValue(result, undefined, 'normal completion value'); + +// The contents of the SendableArrayBuffer are not guaranteed by the host-defined +// abstract operation, so they are not asserted in this test. diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-same-size.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-same-size.js new file mode 100644 index 0000000000000000000000000000000000000000..a8705402c6f0259f6da3a397b7dcc8b189373e27 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-same-size.js @@ -0,0 +1,91 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + Behavior when attempting to reset the size of a resizable array buffer +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. Let newByteLength be ? ToIntegerOrInfinity(newLength). + 6. If newByteLength < 0 or newByteLength > O.[[SendableArrayBufferMaxByteLength]], + throw a RangeError exception. + 7. Let hostHandled be ? HostResizeSendableArrayBuffer(O, newByteLength). + [...] + + HostResizeSendableArrayBuffer ( buffer, newByteLength ) + + The implementation of HostResizeSendableArrayBuffer must conform to the following + requirements: + + - The abstract operation does not detach buffer. + - The abstract operation may complete normally or abruptly. + - If the abstract operation completes normally with handled, + buffer.[[SendableArrayBufferByteLength]] is newByteLength. + - The return value is either handled or unhandled. +features: [resizable-arraybuffer] +---*/ + +var ab = new SendableArrayBuffer(4, {maxByteLength: 4}); +var caught = false; +var result; + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `SendableArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ab.resize, 'function'); + +try { + result = ab.resize(4); +} catch (_) { + caught = true; +} + +try { + ab.slice(); +} catch (_) { + throw new Test262Error('The SendableArrayBuffer under test was detached'); +} + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation and conforms to the +// invarient regarding [[SendableArrayBufferByteLength]] +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method updates [[SendableArrayBufferByteLength]] +// +// The final two conditions are indistinguishable. +assert(caught || ab.byteLength === 4, 'byteLength'); + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation, and the `resize` +// method returns early +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method executes its final steps +// +// All three conditions have the same effect on the value of `result`. +assert.sameValue(result, undefined, 'normal completion value'); + +// The contents of the SendableArrayBuffer are not guaranteed by the host-defined +// abstract operation, so they are not asserted in this test. diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-shrink-zero-explicit.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-shrink-zero-explicit.js new file mode 100644 index 0000000000000000000000000000000000000000..44be46a894555f9e956d42e1ba8bd96a394ae290 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-shrink-zero-explicit.js @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: Behavior when attempting to shrink a resizable array buffer to zero explicitly +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. Let newByteLength be ? ToIntegerOrInfinity(newLength). + 6. If newByteLength < 0 or newByteLength > O.[[SendableArrayBufferMaxByteLength]], + throw a RangeError exception. + 7. Let hostHandled be ? HostResizeSendableArrayBuffer(O, newByteLength). + [...] + + HostResizeSendableArrayBuffer ( buffer, newByteLength ) + + The implementation of HostResizeSendableArrayBuffer must conform to the following + requirements: + + - The abstract operation does not detach buffer. + - The abstract operation may complete normally or abruptly. + - If the abstract operation completes normally with handled, + buffer.[[SendableArrayBufferByteLength]] is newByteLength. + - The return value is either handled or unhandled. +features: [resizable-arraybuffer] +---*/ + +var ab = new SendableArrayBuffer(4, {maxByteLength: 4}); +var caught = false; +var result; + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `SendableArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ab.resize, 'function'); + +try { + result = ab.resize(0); +} catch (_) { + caught = true; +} + +try { + ab.slice(); +} catch (_) { + throw new Test262Error('The SendableArrayBuffer under test was detached'); +} + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation and conforms to the +// invarient regarding [[SendableArrayBufferByteLength]] +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method updates [[SendableArrayBufferByteLength]] +// +// The final two conditions are indistinguishable. +assert(caught || ab.byteLength === 0, 'byteLength'); + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation, and the `resize` +// method returns early +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method executes its final steps +// +// All three conditions have the same effect on the value of `result`. +assert.sameValue(result, undefined, 'normal completion value'); + +// The contents of the SendableArrayBuffer are not guaranteed by the host-defined +// abstract operation, so they are not asserted in this test. diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-shrink-zero-implicit.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-shrink-zero-implicit.js new file mode 100644 index 0000000000000000000000000000000000000000..91aa1718f6fbce727c98fee713591c3f9b911d49 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-shrink-zero-implicit.js @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: Behavior when attempting to shrink a resizable array buffer to zero implicitly +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. Let newByteLength be ? ToIntegerOrInfinity(newLength). + 6. If newByteLength < 0 or newByteLength > O.[[SendableArrayBufferMaxByteLength]], + throw a RangeError exception. + 7. Let hostHandled be ? HostResizeSendableArrayBuffer(O, newByteLength). + [...] + + HostResizeSendableArrayBuffer ( buffer, newByteLength ) + + The implementation of HostResizeSendableArrayBuffer must conform to the following + requirements: + + - The abstract operation does not detach buffer. + - The abstract operation may complete normally or abruptly. + - If the abstract operation completes normally with handled, + buffer.[[SendableArrayBufferByteLength]] is newByteLength. + - The return value is either handled or unhandled. +features: [resizable-arraybuffer] +---*/ + +var ab = new SendableArrayBuffer(4, {maxByteLength: 4}); +var caught = false; +var result; + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `SendableArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ab.resize, 'function'); + +try { + result = ab.resize(); +} catch (_) { + caught = true; +} + +try { + ab.slice(); +} catch (_) { + throw new Test262Error('The SendableArrayBuffer under test was detached'); +} + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation and conforms to the +// invarient regarding [[SendableArrayBufferByteLength]] +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method updates [[SendableArrayBufferByteLength]] +// +// The final two conditions are indistinguishable. +assert(caught || ab.byteLength === 0, 'byteLength'); + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation, and the `resize` +// method returns early +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method executes its final steps +// +// All three conditions have the same effect on the value of `result`. +assert.sameValue(result, undefined, 'normal completion value'); + +// The contents of the SendableArrayBuffer are not guaranteed by the host-defined +// abstract operation, so they are not asserted in this test. diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-shrink.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..1ccab5add6394bf0607feeea7282bec03c0cc232 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/resize-shrink.js @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: Behavior when attempting to shrink a resizable array buffer +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. Let newByteLength be ? ToIntegerOrInfinity(newLength). + 6. If newByteLength < 0 or newByteLength > O.[[SendableArrayBufferMaxByteLength]], + throw a RangeError exception. + 7. Let hostHandled be ? HostResizeSendableArrayBuffer(O, newByteLength). + [...] + + HostResizeSendableArrayBuffer ( buffer, newByteLength ) + + The implementation of HostResizeSendableArrayBuffer must conform to the following + requirements: + + - The abstract operation does not detach buffer. + - The abstract operation may complete normally or abruptly. + - If the abstract operation completes normally with handled, + buffer.[[SendableArrayBufferByteLength]] is newByteLength. + - The return value is either handled or unhandled. +features: [resizable-arraybuffer] +---*/ + +var ab = new SendableArrayBuffer(4, {maxByteLength: 4}); +var caught = false; +var result; + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `SendableArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ab.resize, 'function'); + +try { + result = ab.resize(3); +} catch (_) { + caught = true; +} + +try { + ab.slice(); +} catch (_) { + throw new Test262Error('The SendableArrayBuffer under test was detached'); +} + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation and conforms to the +// invarient regarding [[SendableArrayBufferByteLength]] +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method updates [[SendableArrayBufferByteLength]] +// +// The final two conditions are indistinguishable. +assert(caught || ab.byteLength === 3, 'byteLength'); + +// One of the following three conditions must be met: +// +// - HostResizeSendableArrayBuffer returns an abrupt completion +// - HostResizeSendableArrayBuffer handles the resize operation, and the `resize` +// method returns early +// - HostResizeSendableArrayBuffer does not handle the resize operation, and the +// `resize` method executes its final steps +// +// All three conditions have the same effect on the value of `result`. +assert.sameValue(result, undefined, 'normal completion value'); + +// The contents of the SendableArrayBuffer are not guaranteed by the host-defined +// abstract operation, so they are not asserted in this test. diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-detached.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-detached.js new file mode 100644 index 0000000000000000000000000000000000000000..29b07f73c3d84c85febbb6e7d5d97ce0e0766d63 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-detached.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + Throws a TypeError if `this` does not have an [[SendableArrayBufferData]] internal slot. +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + [...] +includes: [detachArrayBuffer.js] +features: [resizable-arraybuffer] +---*/ + +assert.sameValue(typeof SendableArrayBuffer.prototype.resize, 'function'); + +var ab = new SendableArrayBuffer(1); + +$DETACHBUFFER(ab); + +assert.throws(TypeError, function() { + ab.resize(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-not-arraybuffer-object.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-not-arraybuffer-object.js new file mode 100644 index 0000000000000000000000000000000000000000..8de2c17c5550a7af2bf86d3cb4bb19f8f96ca9e4 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-not-arraybuffer-object.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + Throws a TypeError if `this` does not have an [[SendableArrayBufferData]] internal slot. +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + [...] +features: [resizable-arraybuffer] +---*/ + +assert.sameValue(typeof SendableArrayBuffer.prototype.resize, 'function'); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resize(); +}, '`this` value is the SendableArrayBuffer prototype'); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resize.call({}); +}, '`this` value is an object'); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resize.call([]); +}, '`this` value is an array'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-not-object.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..3f8db1d1878fa200a2e68ab0799395bdc7bc3c0a --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-not-object.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: Throws a TypeError if `this` valueis not an object. +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + [...] +features: [resizable-arraybuffer, Symbol, BigInt] +---*/ + +assert.sameValue(typeof SendableArrayBuffer.prototype.resize, "function"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resize.call(undefined); +}, "`this` value is undefined"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resize.call(null); +}, "`this` value is null"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resize.call(true); +}, "`this` value is Boolean"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resize.call(""); +}, "`this` value is String"); + +var symbol = Symbol(); +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resize.call(symbol); +}, "`this` value is Symbol"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resize.call(1); +}, "`this` value is Number"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resize.call(1n); +}, "`this` value is bigint"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-not-resizable-arraybuffer-object.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-not-resizable-arraybuffer-object.js new file mode 100644 index 0000000000000000000000000000000000000000..971bc3ddd83a616b1f3b4a5b141f26c7c91a15a4 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-not-resizable-arraybuffer-object.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: > + Throws a TypeError if `this` does not have an [[SendableArrayBufferMaxByteLength]] internal slot. +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + [...] +features: [resizable-arraybuffer] +---*/ + +var ab; + +assert.sameValue(typeof SendableArrayBuffer.prototype.resize, 'function'); + +ab = new SendableArrayBuffer(4); +assert.throws(TypeError, function() { + ab.resize(0); +}, 'zero byte length'); + +ab = new SendableArrayBuffer(4); +assert.throws(TypeError, function() { + ab.resize(3); +}, 'smaller byte length'); + +ab = new SendableArrayBuffer(4); +assert.throws(TypeError, function() { + ab.resize(4); +}, 'same byte length'); + +ab = new SendableArrayBuffer(4); +assert.throws(TypeError, function() { + ab.resize(5); +}, 'larger byte length'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-sharedarraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..3276d772cd5aacdbb1052fe2227820dca8b6d40d --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/resize/this-is-sharedarraybuffer.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.resize +description: Throws a TypeError if `this` value is a SharedArrayBuffer +info: | + SendableArrayBuffer.prototype.resize ( newLength ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferMaxByteLength]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + [...] +features: [SharedArrayBuffer, resizable-arraybuffer] +---*/ + +var sab = new SharedArrayBuffer(0); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.resize.call(sab); +}, '`this` value cannot be a SharedArrayBuffer'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/context-is-not-arraybuffer-object.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/context-is-not-arraybuffer-object.js new file mode 100644 index 0000000000000000000000000000000000000000..8388897d53d0cfcf7ad3f194b1b2d83233a956b6 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/context-is-not-arraybuffer-object.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Throws a TypeError if `this` does not have an [[SendableArrayBufferData]] internal slot. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have an [[SendableArrayBufferData]] internal slot, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.slice.call({}); +}, "`this` value is Object"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.slice.call([]); +}, "`this` value is Array"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/context-is-not-object.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/context-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..785152d04799ec609926c26b46e3eda12b490754 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/context-is-not-object.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Throws a TypeError if `this` is not an Object. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.slice.call(undefined); +}, "`this` value is undefined"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.slice.call(null); +}, "`this` value is null"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.slice.call(true); +}, "`this` value is Boolean"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.slice.call(""); +}, "`this` value is String"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.slice.call(Symbol()); +}, "`this` value is Symbol"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.slice.call(1); +}, "`this` value is Number"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/descriptor.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..756ab71310b4cd6f6dc8043a33fc303c97d71da4 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/descriptor.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + SendableArrayBuffer.prototype.slice has default data property attributes. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Every other data property described in clauses 18 through 26 and in + Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArrayBuffer.prototype, "slice", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/end-default-if-absent.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/end-default-if-absent.js new file mode 100644 index 0000000000000000000000000000000000000000..ad5e4f73a8a412388936ac54c0bbd675f107e215 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/end-default-if-absent.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + The `end` index defaults to [[SendableArrayBufferByteLength]] if absent. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 9. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). + 10. ReturnIfAbrupt(relativeEnd). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var start = 6; +var result = arrayBuffer.slice(start); +assert.sameValue(result.byteLength, 2); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/end-default-if-undefined.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/end-default-if-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..8d011d7400e7c46943d579f5b9e7058f08452033 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/end-default-if-undefined.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + The `end` index defaults to [[SendableArrayBufferByteLength]] if undefined. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 9. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). + 10. ReturnIfAbrupt(relativeEnd). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var start = 6, + end = undefined; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 2); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/end-exceeds-length.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/end-exceeds-length.js new file mode 100644 index 0000000000000000000000000000000000000000..eb230e8c572bfdb0c73128257abba3ef327e482f --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/end-exceeds-length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Large `end` index is clamped to [[SendableArrayBufferByteLength]]. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 8. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var start = 1, + end = 12; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 7, "slice(1, 12)"); + +var start = 2, + end = 0x100000000; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6, "slice(2, 0x100000000)"); + +var start = 3, + end = +Infinity; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 5, "slice(3, Infinity)"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/extensible.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..2b878ab3ccee693ea645d0f2aa907f207fe7b406 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/extensible.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + SendableArrayBuffer.prototype.slice is extensible. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Unless specified otherwise, the [[Extensible]] internal slot + of a built-in object initially has the value true. +---*/ + +assert(Object.isExtensible(SendableArrayBuffer.prototype.slice)); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/length.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/length.js new file mode 100644 index 0000000000000000000000000000000000000000..d506009c9a6cb68fbd438e4720c37f8c5f287e42 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/length.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + SendableArrayBuffer.prototype.slice.length is 2. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArrayBuffer.prototype.slice, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/name.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/name.js new file mode 100644 index 0000000000000000000000000000000000000000..8f9e6dd12468746000c3a34c3fd8e77b249822a6 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/name.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + SendableArrayBuffer.prototype.slice.name is "slice". +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArrayBuffer.prototype.slice, "name", { + value: "slice", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/negative-end.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/negative-end.js new file mode 100644 index 0000000000000000000000000000000000000000..d15f68af65f9151515edeecfbbed6c3ab53699f2 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/negative-end.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Negative `end` index is relative to [[SendableArrayBufferByteLength]]. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 8. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var start = 2, + end = -4; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 2, "slice(2, -4)"); + +var start = 2, + end = -10; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(2, -10)"); + +var start = 2, + end = -Infinity; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(2, -Infinity)"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/negative-start.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/negative-start.js new file mode 100644 index 0000000000000000000000000000000000000000..dfa8b4881c799c408778128a9ed85d2f21f6d528 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/negative-start.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Negative `start` index is relative to [[SendableArrayBufferByteLength]]. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 8. If relativeStart < 0, let first be max((len + relativeStart),0); else let first be min(relativeStart, len). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var start = -5, + end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 3, "slice(-5, 6)"); + +var start = -12, + end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6, "slice(-12, 6)"); + +var start = -Infinity, + end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6, "slice(-Infinity, 6)"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/nonconstructor.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/nonconstructor.js new file mode 100644 index 0000000000000000000000000000000000000000..867e41e8b2648658c54d9afe132fcef7e7449820 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/nonconstructor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + SendableArrayBuffer.prototype.slice is not a constructor function. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified + in the description of a particular function. +includes: [isConstructor.js] +features: [Reflect.construct] +---*/ + +assert(!isConstructor(SendableArrayBuffer.prototype.slice), "SendableArrayBuffer.prototype.slice is not a constructor"); + +var arrayBuffer = new SendableArrayBuffer(8); +assert.throws(TypeError, function() { + new arrayBuffer.slice(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/not-a-constructor.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..4773d4a2899301e02ba725a4f71a9263ce6dff5b --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableArrayBuffer.prototype.slice does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableArrayBuffer, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableArrayBuffer.prototype.slice), + false, + 'isConstructor(SendableArrayBuffer.prototype.slice) must return false' +); + +assert.throws(TypeError, () => { + let ab = new SendableArrayBuffer(); new ab.slice(); +}); + diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/number-conversion.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/number-conversion.js new file mode 100644 index 0000000000000000000000000000000000000000..c9c3acfc52953f4966b9746091f49bcf1f847b11 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/number-conversion.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + ToInteger(start) is called before ToInteger(end). +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 6. Let relativeStart be ToInteger(start). + 7. ReturnIfAbrupt(relativeStart). + ... + 9. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). + 10. ReturnIfAbrupt(relativeEnd). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var log = ""; +var start = { + valueOf: function() { + log += "start-"; + return 0; + } +}; +var end = { + valueOf: function() { + log += "end"; + return 8; + } +}; + +arrayBuffer.slice(start, end); +assert.sameValue(log, "start-end"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/species-constructor-is-not-object.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-constructor-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..8e0d475d0e8d59534713363b2b73673f2c779f0a --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-constructor-is-not-object.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Throws TypeError if `constructor` property is not an object. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %SendableArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). + 4. If C is undefined, return defaultConstructor. + 5. If Type(C) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +function callSlice() { + arrayBuffer.slice(); +} + +arrayBuffer.constructor = null; +assert.throws(TypeError, callSlice, "`constructor` value is null"); + +arrayBuffer.constructor = true; +assert.throws(TypeError, callSlice, "`constructor` value is Boolean"); + +arrayBuffer.constructor = ""; +assert.throws(TypeError, callSlice, "`constructor` value is String"); + +arrayBuffer.constructor = Symbol(); +assert.throws(TypeError, callSlice, "`constructor` value is Symbol"); + +arrayBuffer.constructor = 1; +assert.throws(TypeError, callSlice, "`constructor` value is Number"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/species-constructor-is-undefined.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-constructor-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..ade4cbed528b263a6f5f3749c55018cf45769594 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-constructor-is-undefined.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Uses default constructor is `constructor` property is undefined. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %SendableArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). + 4. If C is undefined, return defaultConstructor. + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); +arrayBuffer.constructor = undefined; + +var result = arrayBuffer.slice(); +assert.sameValue(Object.getPrototypeOf(result), SendableArrayBuffer.prototype); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-not-constructor.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-not-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..78868af1966deb3ccb126427c4452d751b144cf7 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-not-constructor.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Throws a TypeError if species constructor is not a constructor function. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %SendableArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + ... + 9. If IsConstructor(S) is true, return S. + 10. Throw a TypeError exception. +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; + +var arrayBuffer = new SendableArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +function callSlice() { + arrayBuffer.slice(); +} + +speciesConstructor[Symbol.species] = {}; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Object"); + +speciesConstructor[Symbol.species] = Function.prototype; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Function.prototype"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-not-object.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..61049abdb6b9036a457b8380da35fa76d60a0c89 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-not-object.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Throws a TypeError if species constructor is not an object. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %SendableArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + 8. If S is either undefined or null, return defaultConstructor. + 9. If IsConstructor(S) is true, return S. + 10. Throw a TypeError exception. +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; + +var arrayBuffer = new SendableArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +function callSlice() { + arrayBuffer.slice(); +} + +speciesConstructor[Symbol.species] = true; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Boolean"); + +speciesConstructor[Symbol.species] = ""; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is String"); + +speciesConstructor[Symbol.species] = Symbol(); +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Symbol"); + +speciesConstructor[Symbol.species] = 1; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Number"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-null.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-null.js new file mode 100644 index 0000000000000000000000000000000000000000..01dc5b04bb765c61eb89fe92889c7438248aa5f5 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-null.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Uses default constructor is species constructor is null. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %SendableArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + 8. If S is either undefined or null, return defaultConstructor. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = null; + +var arrayBuffer = new SendableArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(Object.getPrototypeOf(result), SendableArrayBuffer.prototype); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-undefined.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..8aced78431656955b7f4c06387fa5070ef6e7a6d --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-is-undefined.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Uses default constructor is species constructor is undefined. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %SendableArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + 8. If S is either undefined or null, return defaultConstructor. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = undefined; + +var arrayBuffer = new SendableArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(Object.getPrototypeOf(result), SendableArrayBuffer.prototype); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-larger-arraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-larger-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..4d047e1f307649b14e0a8b55115b2b3d8e4737d1 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-larger-arraybuffer.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Does not throw TypeError if new SendableArrayBuffer is too large. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %SendableArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + 15. Let new be Construct(ctor, «newLen»). + 16. ReturnIfAbrupt(new). + ... + 20. If the value of new’s [[SendableArrayBufferByteLength]] internal slot < newLen, throw a TypeError exception. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return new SendableArrayBuffer(10); +}; + +var arrayBuffer = new SendableArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(result.byteLength, 10); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-not-arraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-not-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9ef26803eba3451298b696c6806d86f3f1d68f93 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-not-arraybuffer.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Throws a TypeError if new object is not an SendableArrayBuffer instance. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %SendableArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + 15. Let new be Construct(ctor, «newLen»). + 16. ReturnIfAbrupt(new). + 17. If new does not have an [[SendableArrayBufferData]] internal slot, throw a TypeError exception. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return {}; +}; + +var arrayBuffer = new SendableArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +assert.throws(TypeError, function() { + arrayBuffer.slice(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-same-arraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-same-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..6a2ce72115bbf6d58004905cb4faffbc9c9092b0 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-same-arraybuffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Throws a TypeError if species constructor returns `this` value. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + 1. Let O be the this value. + ... + 13. Let ctor be SpeciesConstructor(O, %SendableArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + 15. Let new be Construct(ctor, «newLen»). + 16. ReturnIfAbrupt(new). + ... + 19. If SameValue(new, O) is true, throw a TypeError exception. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return arrayBuffer; +}; + +var arrayBuffer = new SendableArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +assert.throws(TypeError, function() { + arrayBuffer.slice(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-smaller-arraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-smaller-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..83c944260bfa2616a906f29bc605ab8165a44c8a --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/species-returns-smaller-arraybuffer.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Throws a TypeError if new SendableArrayBuffer is too small. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %SendableArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + 15. Let new be Construct(ctor, «newLen»). + 16. ReturnIfAbrupt(new). + ... + 20. If the value of new’s [[SendableArrayBufferByteLength]] internal slot < newLen, throw a TypeError exception. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return new SendableArrayBuffer(4); +}; + +var arrayBuffer = new SendableArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +assert.throws(TypeError, function() { + arrayBuffer.slice(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/species.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/species.js new file mode 100644 index 0000000000000000000000000000000000000000..e7c06f12417a51e9cba9356e78a69a893ab4d5fc --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/species.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + New SendableArrayBuffer instance is created from SpeciesConstructor. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %SendableArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + 15. Let new be Construct(ctor, «newLen»). + 16. ReturnIfAbrupt(new). + ... + 26. Return new. +features: [Symbol.species] +---*/ + +var resultBuffer; + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return resultBuffer = new SendableArrayBuffer(length); +}; + +var arrayBuffer = new SendableArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(result, resultBuffer); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/start-default-if-absent.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/start-default-if-absent.js new file mode 100644 index 0000000000000000000000000000000000000000..d5d359fde62e22d91bd52d0fb74c10e31d4fdceb --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/start-default-if-absent.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + The `start` index defaults to 0 if absent. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 6. Let relativeStart be ToInteger(start). + 7. ReturnIfAbrupt(relativeStart). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var result = arrayBuffer.slice(); +assert.sameValue(result.byteLength, 8); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/start-default-if-undefined.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/start-default-if-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..45ce01746f98307aef95208fb1c2938901124ce4 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/start-default-if-undefined.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + The `start` index defaults to 0 if undefined. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 6. Let relativeStart be ToInteger(start). + 7. ReturnIfAbrupt(relativeStart). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var start = undefined, + end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/start-exceeds-end.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/start-exceeds-end.js new file mode 100644 index 0000000000000000000000000000000000000000..3e5ec86011f458e4ace26887dfe459a18e512d85 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/start-exceeds-end.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Returns zero-length buffer if `start` index exceeds `end` index. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 12. Let newLen be max(final-first,0). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var start = 5, + end = 4; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/start-exceeds-length.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/start-exceeds-length.js new file mode 100644 index 0000000000000000000000000000000000000000..42ca6c7544fb91ef2819e4a8a8077eeaf63667d5 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/start-exceeds-length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Large `start` index is clamped to [[SendableArrayBufferByteLength]]. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 8. If relativeStart < 0, let first be max((len + relativeStart),0); else let first be min(relativeStart, len). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var start = 10, + end = 8; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(10, 8)"); + +var start = 0x100000000, + end = 7; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(0x100000000, 7)"); + +var start = +Infinity, + end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(+Infinity, 6)"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/this-is-sharedarraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..b3da19c3d69194961d74f3153f24ccbddd0114f7 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/this-is-sharedarraybuffer.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + Throws a TypeError if `this` is a SharedArrayBuffer +features: [SharedArrayBuffer] +---*/ + +assert.throws(TypeError, function() { + var sab = new SharedArrayBuffer(0); + SendableArrayBuffer.prototype.slice.call(sab); +}, "`this` value cannot be a SharedArrayBuffer"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/tointeger-conversion-end.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/tointeger-conversion-end.js new file mode 100644 index 0000000000000000000000000000000000000000..832d6eba7d335749377ff6d90ccac242395358b0 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/tointeger-conversion-end.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + The `end` index parameter is converted to an integral numeric value. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 9. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). + 10. ReturnIfAbrupt(relativeEnd). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var start = 0, + end = 4.5; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 4, "slice(0, 4.5)"); + +var start = 0, + end = NaN; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(0, NaN)"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/slice/tointeger-conversion-start.js b/test/sendable/builtins/ArrayBuffer/prototype/slice/tointeger-conversion-start.js new file mode 100644 index 0000000000000000000000000000000000000000..526febd541ee7abecb1112abe73989f3aa677514 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/slice/tointeger-conversion-start.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.slice +description: > + The `start` index parameter is converted to an integral numeric value. +info: | + SendableArrayBuffer.prototype.slice ( start, end ) + + ... + 6. Let relativeStart be ToInteger(start). + 7. ReturnIfAbrupt(relativeStart). + ... +---*/ + +var arrayBuffer = new SendableArrayBuffer(8); + +var start = 4.5, + end = 8; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 4, "slice(4.5, 8)"); + +var start = NaN, + end = 8; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 8, "slice(NaN, 8)"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/descriptor.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..c859fabd06caf57ad64caf43314adba5ef5f33fa --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/descriptor.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: > + SendableArrayBuffer.prototype.transfer has default data property attributes. +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Every other data property described in clauses 18 through 26 and in + Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [arraybuffer-transfer] +---*/ + +verifyProperty(SendableArrayBuffer.prototype, 'transfer', { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/extensible.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..414fd4924f0bde8f8c4f9345a460881b93c04118 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/extensible.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: SendableArrayBuffer.prototype.transfer is extensible. +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Unless specified otherwise, the [[Extensible]] internal slot + of a built-in object initially has the value true. +features: [arraybuffer-transfer] +---*/ + +assert(Object.isExtensible(SendableArrayBuffer.prototype.transfer)); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-larger-no-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-larger-no-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..dbefae9e4adac254f73b6e984e716fc2b13ea88c --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-larger-no-resizable.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Transfering from a fixed-size SendableArrayBuffer into a larger SendableArrayBuffer +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [arraybuffer-transfer] +---*/ + +// NOTE: This file is a copy of "from-fixed-to-larger.js" with the resizable +// SendableArrayBuffer parts removed, so it can run in implementations which don't yet +// support the "resizable-arraybuffer" feature. + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(5); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.byteLength, 5, 'dest.byteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); +assert.sameValue(destArray[4], 0, 'destArray[4]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-larger.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-larger.js new file mode 100644 index 0000000000000000000000000000000000000000..bc3e8b0e8f963c690867e3183c25a5d5d6981de3 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-larger.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Transfering from a fixed-size SendableArrayBuffer into a larger SendableArrayBuffer +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(5); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 5, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 5, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); +assert.sameValue(destArray[4], 0, 'destArray[4]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-same-no-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-same-no-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..ecb14cfe896610f03ce704a447a96bc3d0962856 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-same-no-resizable.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: | + Transfering from a fixed-size SendableArrayBuffer into an SendableArrayBuffer with the same + byte length +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [arraybuffer-transfer] +---*/ + +// NOTE: This file is a copy of "from-fixed-to-same.js" with the resizable +// SendableArrayBuffer parts removed, so it can run in implementations which don't yet +// support the "resizable-arraybuffer" feature. + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.byteLength, 4, 'dest.byteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-same.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-same.js new file mode 100644 index 0000000000000000000000000000000000000000..8b3a30970bf3f71284d242b9a174d23c7a73b7f9 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-same.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: | + Transfering from a fixed-size SendableArrayBuffer into an SendableArrayBuffer with the same + byte length +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 4, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 4, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller-no-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller-no-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..950bd368955831b70624d48542b6b1e0cc1fc78a --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller-no-resizable.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Transfering from a fixed-size SendableArrayBuffer into a smaller SendableArrayBuffer +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [arraybuffer-transfer] +---*/ + +// NOTE: This file is a copy of "from-fixed-to-smaller.js" with the resizable +// SendableArrayBuffer parts removed, so it can run in implementations which don't yet +// support the "resizable-arraybuffer" feature. + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(3); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.byteLength, 3, 'dest.byteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller.js new file mode 100644 index 0000000000000000000000000000000000000000..42e8fc5270ac933b82efbe904532bc44fa212077 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-smaller.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Transfering from a fixed-size SendableArrayBuffer into a smaller SendableArrayBuffer +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(3); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 3, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 3, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-zero-no-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-zero-no-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..1d8c9379976f6cd65d8901ebfa19b41b7ea42b8f --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-zero-no-resizable.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Transfering from a fixed-size SendableArrayBuffer into a zero-length SendableArrayBuffer +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [arraybuffer-transfer] +---*/ + +// NOTE: This file is a copy of "from-fixed-to-zero.js" with the resizable +// SendableArrayBuffer parts removed, so it can run in implementations which don't yet +// support the "resizable-arraybuffer" feature. + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(0); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.byteLength, 0, 'dest.byteLength'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-zero.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..f09826436ad5f20411ac3bdd39af1e0927bcd15c --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-fixed-to-zero.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Transfering from a fixed-size SendableArrayBuffer into a zero-length SendableArrayBuffer +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(0); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 0, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 0, 'dest.maxByteLength'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-larger.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-larger.js new file mode 100644 index 0000000000000000000000000000000000000000..8b96d05156b35534df708b67b84b439a00220ac4 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-larger.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Transfering from a resizable SendableArrayBuffer into a larger SendableArrayBuffer +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(5); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, true, 'dest.resizable'); +assert.sameValue(dest.byteLength, 5, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 8, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); +assert.sameValue(destArray[4], 0, 'destArray[4]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-same.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-same.js new file mode 100644 index 0000000000000000000000000000000000000000..4278d15b326ea645e11ba6b75c77bf77b2e4d21b --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-same.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: | + Transfering from a resizable SendableArrayBuffer into an SendableArrayBuffer with the same + byte length +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, true, 'dest.resizable'); +assert.sameValue(dest.byteLength, 4, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 8, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-smaller.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-smaller.js new file mode 100644 index 0000000000000000000000000000000000000000..0941b941855874d5febf9c094fa46bcd2e6eff5e --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-smaller.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Transfering from a resizable SendableArrayBuffer into a smaller SendableArrayBuffer +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(3); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, true, 'dest.resizable'); +assert.sameValue(dest.byteLength, 3, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 8, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-zero.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..92db62b4dc64c5dec32fd0325995725af4ac1970 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/from-resizable-to-zero.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Transfering from a resizable SendableArrayBuffer into a zero-length SendableArrayBuffer +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + 7. Let new be ? Construct(%SendableArrayBuffer%, « 𝔽(newByteLength) »). + 8. NOTE: This method returns a fixed-length SendableArrayBuffer. + 9. Let copyLength be min(newByteLength, O.[[SendableArrayBufferByteLength]]). + 10. Let fromBlock be O.[[SendableArrayBufferData]]. + 11. Let toBlock be new.[[SendableArrayBufferData]]. + 12. Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength). + 13. NOTE: Neither creation of the new Data Block nor copying from the old + Data Block are observable. Implementations reserve the right to implement + this method as a zero-copy move or a realloc. + 14. Perform ! DetachSendableArrayBuffer(O). + 15. Return new. +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transfer(0); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, true, 'dest.resizable'); +assert.sameValue(dest.byteLength, 0, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 8, 'dest.maxByteLength'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/length.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/length.js new file mode 100644 index 0000000000000000000000000000000000000000..206aa0f37914a165cb815539d3e7230d71dec98e --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: > + SendableArrayBuffer.prototype.transfer.length is 0. +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [arraybuffer-transfer] +---*/ + +verifyProperty(SendableArrayBuffer.prototype.transfer, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/name.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/name.js new file mode 100644 index 0000000000000000000000000000000000000000..0f866e09cef817ace36fe19dcc12564d3e6720de --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: > + SendableArrayBuffer.prototype.transfer.name is "transfer". +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +features: [arraybuffer-transfer] +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArrayBuffer.prototype.transfer, 'name', { + value: 'transfer', + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/new-length-excessive.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/new-length-excessive.js new file mode 100644 index 0000000000000000000000000000000000000000..5cc279b3291f9b466181ffe7dfa53c575ed8209a --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/new-length-excessive.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: > + Throws a RangeError if the newLength is larger than 2^53 - 1 due to clamping + in ToIndex. +features: [arraybuffer-transfer] +---*/ + +var ab = new SendableArrayBuffer(0); + +assert.throws(RangeError, function() { + // Math.pow(2, 53) = 9007199254740992 + ab.transfer(9007199254740992); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/new-length-non-number.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/new-length-non-number.js new file mode 100644 index 0000000000000000000000000000000000000000..19b1c0247efeb4659fce6670f0717d73c4cb6275 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/new-length-non-number.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Throws a TypeError if provided length cannot be coerced to a number +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + [...] +features: [arraybuffer-transfer] +---*/ + +var log = []; +var newLength = { + toString: function() { + log.push('toString'); + return {}; + }, + valueOf: function() { + log.push('valueOf'); + return {}; + } +}; +var ab = new SendableArrayBuffer(0); + +assert.throws(TypeError, function() { + ab.transfer(newLength); +}); + +assert.sameValue(log.length, 2); +assert.sameValue(log[0], 'valueOf'); +assert.sameValue(log[1], 'toString'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/nonconstructor.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/nonconstructor.js new file mode 100644 index 0000000000000000000000000000000000000000..2a364cf9b4395fd5600c2762c162da8185212210 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/nonconstructor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: > + SendableArrayBuffer.prototype.transfer is not a constructor function. +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified + in the description of a particular function. +includes: [isConstructor.js] +features: [arraybuffer-transfer, Reflect.construct] +---*/ + +assert(!isConstructor(SendableArrayBuffer.prototype.transfer), "SendableArrayBuffer.prototype.transfer is not a constructor"); + +var arrayBuffer = new SendableArrayBuffer(8); +assert.throws(TypeError, function() { + new arrayBuffer.transfer(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-detached.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-detached.js new file mode 100644 index 0000000000000000000000000000000000000000..896b1a387cbadc8f61d16e8b2baa3c10dcbf887d --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-detached.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: > + Throws a TypeError if `this` does not have an [[SendableArrayBufferData]] internal slot. +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + [...] +includes: [detachArrayBuffer.js] +features: [arraybuffer-transfer] +---*/ + +assert.sameValue(typeof SendableArrayBuffer.prototype.transfer, 'function'); + +var ab = new SendableArrayBuffer(1); + +$DETACHBUFFER(ab); + +assert.throws(TypeError, function() { + ab.transfer(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-not-arraybuffer-object.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-not-arraybuffer-object.js new file mode 100644 index 0000000000000000000000000000000000000000..d6931265133046aa17353e229d8db442763493c5 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-not-arraybuffer-object.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: > + Throws a TypeError if `this` does not have an [[SendableArrayBufferData]] internal slot. +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [arraybuffer-transfer] +---*/ + +assert.sameValue(typeof SendableArrayBuffer.prototype.transfer, 'function'); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transfer(); +}, '`this` value is the SendableArrayBuffer prototype'); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transfer.call({}); +}, '`this` value is an object'); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transfer.call([]); +}, '`this` value is an array'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-not-object.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..79ccb4951c99125c59b46f98209bd53e50672d59 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-not-object.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Throws a TypeError if `this` valueis not an object. +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [arraybuffer-transfer, Symbol, BigInt] +---*/ + +assert.sameValue(typeof SendableArrayBuffer.prototype.transfer, "function"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transfer.call(undefined); +}, "`this` value is undefined"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transfer.call(null); +}, "`this` value is null"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transfer.call(true); +}, "`this` value is Boolean"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transfer.call(""); +}, "`this` value is String"); + +var symbol = Symbol(); +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transfer.call(symbol); +}, "`this` value is Symbol"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transfer.call(1); +}, "`this` value is Number"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transfer.call(1n); +}, "`this` value is bigint"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-sharedarraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..fa2e4220c26b1cb115892f7721227898242408ae --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transfer/this-is-sharedarraybuffer.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfer +description: Throws a TypeError if `this` value is a SharedArrayBuffer +info: | + SendableArrayBuffer.prototype.transfer ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + [...] +features: [SharedArrayBuffer, arraybuffer-transfer] +---*/ + +var sab = new SharedArrayBuffer(0); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transfer.call(sab); +}, '`this` value cannot be a SharedArrayBuffer'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/descriptor.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..c1d94bd3bceb2b408a0904b939d4baf974c817cc --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/descriptor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: > + SendableArrayBuffer.prototype.transferToFixedLength has default data property + attributes. +info: | + SendableArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Every other data property described in clauses 18 through 26 and in + Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [arraybuffer-transfer] +---*/ + +verifyProperty(SendableArrayBuffer.prototype, 'transferToFixedLength', { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/extensible.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/extensible.js new file mode 100644 index 0000000000000000000000000000000000000000..286635ea02bc544f1f35365cb50da131427e0854 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/extensible.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: SendableArrayBuffer.prototype.transferToFixedLength is extensible. +info: | + SendableArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Unless specified otherwise, the [[Extensible]] internal slot + of a built-in object initially has the value true. +features: [arraybuffer-transfer] +---*/ + +assert(Object.isExtensible(SendableArrayBuffer.prototype.transferToFixedLength)); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-larger-no-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-larger-no-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..683b1ed52b1caf5316fcc09265af505a2f7a4749 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-larger-no-resizable.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Transfering from a fixed-size SendableArrayBuffer into a larger SendableArrayBuffer +features: [arraybuffer-transfer] +---*/ + +// NOTE: This file is a copy of "from-fixed-to-larger.js" with the resizable +// SendableArrayBuffer parts removed, so it can run in implementations which don't yet +// support the "resizable-arraybuffer" feature. + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(5); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.byteLength, 5, 'dest.byteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); +assert.sameValue(destArray[4], 0, 'destArray[4]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-larger.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-larger.js new file mode 100644 index 0000000000000000000000000000000000000000..6f1ecc80bd89fcaaff8876222c21296fdcd086b0 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-larger.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Transfering from a fixed-size SendableArrayBuffer into a larger SendableArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(5); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 5, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 5, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); +assert.sameValue(destArray[4], 0, 'destArray[4]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-same-no-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-same-no-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..46059bb568df6f6c95a92b4e807373165176a336 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-same-no-resizable.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: | + Transfering from a fixed-size SendableArrayBuffer into an SendableArrayBuffer with the same + byte length +features: [arraybuffer-transfer] +---*/ + +// NOTE: This file is a copy of "from-fixed-to-same.js" with the resizable +// SendableArrayBuffer parts removed, so it can run in implementations which don't yet +// support the "resizable-arraybuffer" feature. + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.byteLength, 4, 'dest.byteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-same.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-same.js new file mode 100644 index 0000000000000000000000000000000000000000..e354a800d9fa330391b2762e91b820df0fb3c1d7 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-same.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: | + Transfering from a fixed-size SendableArrayBuffer into an SendableArrayBuffer with the same + byte length +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 4, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 4, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-smaller-no-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-smaller-no-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..15d1babc796cee4de90e406fbe9ec9842b8e77de --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-smaller-no-resizable.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Transfering from a fixed-size SendableArrayBuffer into a smaller SendableArrayBuffer +features: [arraybuffer-transfer] +---*/ + +// NOTE: This file is a copy of "from-fixed-to-samller.js" with the resizable +// SendableArrayBuffer parts removed, so it can run in implementations which don't yet +// support the "resizable-arraybuffer" feature. + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(3); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.byteLength, 3, 'dest.byteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-smaller.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-smaller.js new file mode 100644 index 0000000000000000000000000000000000000000..079ecc0eb70be682abd2773fc0a8b47510d2b2e6 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-smaller.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Transfering from a fixed-size SendableArrayBuffer into a smaller SendableArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(3); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 3, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 3, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-zero-no-resizable.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-zero-no-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..422445cc86e4785772587e5a05bbe5cfb019d6c5 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-zero-no-resizable.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Transfering from a fixed-size SendableArrayBuffer into a zero-length SendableArrayBuffer +features: [arraybuffer-transfer] +---*/ + +// NOTE: This file is a copy of "from-fixed-to-zero.js" with the resizable +// SendableArrayBuffer parts removed, so it can run in implementations which don't yet +// support the "resizable-arraybuffer" feature. + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(0); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.byteLength, 0, 'dest.byteLength'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-zero.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..6b6974d42d2db231ed916264b2f662d89dceca93 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-fixed-to-zero.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Transfering from a fixed-size SendableArrayBuffer into a zero-length SendableArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(0); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 0, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 0, 'dest.maxByteLength'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-larger.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-larger.js new file mode 100644 index 0000000000000000000000000000000000000000..e9cd06fee945534d6dbe4cc7e7977636f3fb08a1 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-larger.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Transfering from a resizable SendableArrayBuffer into a larger SendableArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(5); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 5, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 5, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); +assert.sameValue(destArray[4], 0, 'destArray[4]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-same.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-same.js new file mode 100644 index 0000000000000000000000000000000000000000..5efeb5d5e0a4a930bbcfe8366d969b90b94afcb5 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-same.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: | + Transfering from a resizable SendableArrayBuffer into an SendableArrayBuffer with the same + byte length +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 4, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 4, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); +assert.sameValue(destArray[3], 4, 'destArray[3]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-smaller.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-smaller.js new file mode 100644 index 0000000000000000000000000000000000000000..5192f7ea0973f3f7fe6099244e693c1023716f0e --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-smaller.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Transfering from a resizable SendableArrayBuffer into a smaller SendableArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(3); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 3, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 3, 'dest.maxByteLength'); + +var destArray = new Uint8Array(dest); + +assert.sameValue(destArray[0], 1, 'destArray[0]'); +assert.sameValue(destArray[1], 2, 'destArray[1]'); +assert.sameValue(destArray[2], 3, 'destArray[2]'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-zero.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..43f4c96bd400f21645be6b1e27468be058e7e574 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/from-resizable-to-zero.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Transfering from a resizable SendableArrayBuffer into a zero-length SendableArrayBuffer +features: [resizable-arraybuffer, arraybuffer-transfer] +---*/ + +var source = new SendableArrayBuffer(4, { maxByteLength: 8 }); + +var sourceArray = new Uint8Array(source); +sourceArray[0] = 1; +sourceArray[1] = 2; +sourceArray[2] = 3; +sourceArray[3] = 4; + +var dest = source.transferToFixedLength(0); + +assert.sameValue(source.byteLength, 0, 'source.byteLength'); +assert.throws(TypeError, function() { + source.slice(); +}); + +assert.sameValue(dest.resizable, false, 'dest.resizable'); +assert.sameValue(dest.byteLength, 0, 'dest.byteLength'); +assert.sameValue(dest.maxByteLength, 0, 'dest.maxByteLength'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/length.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/length.js new file mode 100644 index 0000000000000000000000000000000000000000..21ac516269dc7be8935aa598e5039d7ee1079458 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: > + SendableArrayBuffer.prototype.transferToFixedLength.length is 0. +info: | + SendableArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [arraybuffer-transfer] +---*/ + +verifyProperty(SendableArrayBuffer.prototype.transferToFixedLength, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/name.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/name.js new file mode 100644 index 0000000000000000000000000000000000000000..ec77e4d22ca6f65d4e8a0664387171cd4119bdeb --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: > + SendableArrayBuffer.prototype.transferToFixedLength.name is "transfer". +info: | + SendableArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +features: [arraybuffer-transfer] +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableArrayBuffer.prototype.transferToFixedLength, 'name', { + value: 'transferToFixedLength', + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/new-length-excessive.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/new-length-excessive.js new file mode 100644 index 0000000000000000000000000000000000000000..153658517836074ce23514d12a908d46fd2b938e --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/new-length-excessive.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: > + Throws a RangeError if the newLength is larger than 2^53 - 1 due to clamping + in ToIndex. +features: [arraybuffer-transfer] +---*/ + +var ab = new SendableArrayBuffer(0); + +assert.throws(RangeError, function() { + // Math.pow(2, 53) = 9007199254740992 + ab.transferToFixedLength(9007199254740992); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/new-length-non-number.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/new-length-non-number.js new file mode 100644 index 0000000000000000000000000000000000000000..c73bf0095201867237cb6010cfdea7ae0e435548 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/new-length-non-number.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Throws a TypeError if provided length cannot be coerced to a number +info: | + SendableArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + 5. If newLength is undefined, let newByteLength be + O.[[SendableArrayBufferByteLength]]. + 6. Else, let newByteLength be ? ToIntegerOrInfinity(newLength). + [...] +features: [arraybuffer-transfer] +---*/ + +var log = []; +var newLength = { + toString: function() { + log.push('toString'); + return {}; + }, + valueOf: function() { + log.push('valueOf'); + return {}; + } +}; +var ab = new SendableArrayBuffer(0); + +assert.throws(TypeError, function() { + ab.transferToFixedLength(newLength); +}); + +assert.sameValue(log.length, 2); +assert.sameValue(log[0], 'valueOf'); +assert.sameValue(log[1], 'toString'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/nonconstructor.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/nonconstructor.js new file mode 100644 index 0000000000000000000000000000000000000000..97bb42a0ed5e5ec0c4cb93a1c010165645bf1b93 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/nonconstructor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: > + SendableArrayBuffer.prototype.transferToFixedLength is not a constructor function. +info: | + SendableArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 17 ECMAScript Standard Built-in Objects: + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified + in the description of a particular function. +includes: [isConstructor.js] +features: [arraybuffer-transfer, Reflect.construct] +---*/ + +assert(!isConstructor(SendableArrayBuffer.prototype.transferToFixedLength), "SendableArrayBuffer.prototype.transferToFixedLength is not a constructor"); + +var arrayBuffer = new SendableArrayBuffer(8); +assert.throws(TypeError, function() { + new arrayBuffer.transfer(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-detached.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-detached.js new file mode 100644 index 0000000000000000000000000000000000000000..149dc9f33ad3b625ce2cca5f83b3563969f02929 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-detached.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: > + Throws a TypeError if `this` does not have an [[SendableArrayBufferData]] internal slot. +info: | + SendableArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. + [...] +includes: [detachArrayBuffer.js] +features: [arraybuffer-transfer] +---*/ + +assert.sameValue(typeof SendableArrayBuffer.prototype.transferToFixedLength, 'function'); + +var ab = new SendableArrayBuffer(1); + +$DETACHBUFFER(ab); + +assert.throws(TypeError, function() { + ab.transferToFixedLength(); +}); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-arraybuffer-object.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-arraybuffer-object.js new file mode 100644 index 0000000000000000000000000000000000000000..c8ca0a6345f39ce923cfa097901b9407aae05f87 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-arraybuffer-object.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: > + Throws a TypeError if `this` does not have an [[SendableArrayBufferData]] internal slot. +info: | + SendableArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [arraybuffer-transfer] +---*/ + +assert.sameValue(typeof SendableArrayBuffer.prototype.transferToFixedLength, 'function'); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transferToFixedLength(); +}, '`this` value is the SendableArrayBuffer prototype'); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transferToFixedLength.call({}); +}, '`this` value is an object'); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transferToFixedLength.call([]); +}, '`this` value is an array'); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-object.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..06d57cffc3f98cc97cd07d37bfb1c639a2eb83d7 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-not-object.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Throws a TypeError if `this` valueis not an object. +info: | + SendableArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + [...] +features: [arraybuffer-transfer, Symbol, BigInt] +---*/ + +assert.sameValue(typeof SendableArrayBuffer.prototype.transferToFixedLength, "function"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transferToFixedLength.call(undefined); +}, "`this` value is undefined"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transferToFixedLength.call(null); +}, "`this` value is null"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transferToFixedLength.call(true); +}, "`this` value is Boolean"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transferToFixedLength.call(""); +}, "`this` value is String"); + +var symbol = Symbol(); +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transferToFixedLength.call(symbol); +}, "`this` value is Symbol"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transferToFixedLength.call(1); +}, "`this` value is Number"); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transferToFixedLength.call(1n); +}, "`this` value is bigint"); diff --git a/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-sharedarraybuffer.js b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..8545c16eeb87fb09dcf4728852bd3588174ac3b4 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/prototype/transferToFixedLength/this-is-sharedarraybuffer.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-sendableArraybuffer.prototype.transfertofixedlength +description: Throws a TypeError if `this` value is a SharedArrayBuffer +info: | + SendableArrayBuffer.prototype.transferToFixedLength ( [ newLength ] ) + + 1. Let O be the this value. + 2. Perform ? RequireInternalSlot(O, [[SendableArrayBufferData]]). + 3. If IsSharedArrayBuffer(O) is true, throw a TypeError exception. + [...] +features: [SharedArrayBuffer, arraybuffer-transfer] +---*/ + +var sab = new SharedArrayBuffer(0); + +assert.throws(TypeError, function() { + SendableArrayBuffer.prototype.transferToFixedLength.call(sab); +}, '`this` value cannot be a SharedArrayBuffer'); diff --git a/test/sendable/builtins/ArrayBuffer/return-abrupt-from-length-symbol.js b/test/sendable/builtins/ArrayBuffer/return-abrupt-from-length-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..8bdf5a44a06ca44bdc45e664c8e44f3b29d98664 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/return-abrupt-from-length-symbol.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + Throws a TypeError if length is a symbol +info: | + SendableArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + ... +features: [Symbol] +---*/ + +var s = Symbol(); + +assert.throws(TypeError, function() { + new SendableArrayBuffer(s); +}, "`length` parameter is a Symbol"); diff --git a/test/sendable/builtins/ArrayBuffer/return-abrupt-from-length.js b/test/sendable/builtins/ArrayBuffer/return-abrupt-from-length.js new file mode 100644 index 0000000000000000000000000000000000000000..90a215c02681f79dbc3dbdf9357fbcebfbe2f05d --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/return-abrupt-from-length.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + Return abrupt from ToIndex(length) +info: | + SendableArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + ... +---*/ + +var len = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + new SendableArrayBuffer(len); +}); diff --git a/test/sendable/builtins/ArrayBuffer/toindex-length.js b/test/sendable/builtins/ArrayBuffer/toindex-length.js new file mode 100644 index 0000000000000000000000000000000000000000..49d8e5a705b4a443406b5c0cea01e6d36a3ef1e2 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/toindex-length.js @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + The `length` parameter is converted to a value numeric index value. +info: | + SendableArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + 3. Return ? AllocateSendableArrayBuffer(NewTarget, byteLength). + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + c. Let index be ! ToLength(integerIndex). + d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception. + 3. Return index. +---*/ + +var obj1 = { + valueOf: function() { + return 42; + } +}; + +var obj2 = { + toString: function() { + return 42; + } +}; + +var buffer; + +buffer = new SendableArrayBuffer(obj1); +assert.sameValue(buffer.byteLength, 42, "object's valueOf"); + +buffer = new SendableArrayBuffer(obj2); +assert.sameValue(buffer.byteLength, 42, "object's toString"); + +buffer = new SendableArrayBuffer(""); +assert.sameValue(buffer.byteLength, 0, "the Empty string"); + +buffer = new SendableArrayBuffer("0"); +assert.sameValue(buffer.byteLength, 0, "string '0'"); + +buffer = new SendableArrayBuffer("1"); +assert.sameValue(buffer.byteLength, 1, "string '1'"); + +buffer = new SendableArrayBuffer(true); +assert.sameValue(buffer.byteLength, 1, "true"); + +buffer = new SendableArrayBuffer(false); +assert.sameValue(buffer.byteLength, 0, "false"); + +buffer = new SendableArrayBuffer(NaN); +assert.sameValue(buffer.byteLength, 0, "NaN"); + +buffer = new SendableArrayBuffer(null); +assert.sameValue(buffer.byteLength, 0, "null"); + +buffer = new SendableArrayBuffer(undefined); +assert.sameValue(buffer.byteLength, 0, "undefined"); + +buffer = new SendableArrayBuffer(0.1); +assert.sameValue(buffer.byteLength, 0, "0.1"); + +buffer = new SendableArrayBuffer(0.9); +assert.sameValue(buffer.byteLength, 0, "0.9"); + +buffer = new SendableArrayBuffer(1.1); +assert.sameValue(buffer.byteLength, 1, "1.1"); + +buffer = new SendableArrayBuffer(1.9); +assert.sameValue(buffer.byteLength, 1, "1.9"); + +buffer = new SendableArrayBuffer(-0.1); +assert.sameValue(buffer.byteLength, 0, "-0.1"); + +buffer = new SendableArrayBuffer(-0.99999); +assert.sameValue(buffer.byteLength, 0, "-0.99999"); diff --git a/test/sendable/builtins/ArrayBuffer/undefined-newtarget-throws.js b/test/sendable/builtins/ArrayBuffer/undefined-newtarget-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9a05e998901085c1e0e49e46a249274bfa333faf --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/undefined-newtarget-throws.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + Throws a TypeError if SendableArrayBuffer is called as a function. +info: | + SendableArrayBuffer( length ) + + SendableArrayBuffer called with argument length performs the following steps: + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableArrayBuffer(); +}); + +assert.throws(TypeError, function() { + SendableArrayBuffer(10); +}); diff --git a/test/sendable/builtins/ArrayBuffer/zero-length.js b/test/sendable/builtins/ArrayBuffer/zero-length.js new file mode 100644 index 0000000000000000000000000000000000000000..093bdc9d2bcdf542a32733df2efe8b8ecf468958 --- /dev/null +++ b/test/sendable/builtins/ArrayBuffer/zero-length.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +esid: sec-sendableArrayBuffer-length +description: > + The `length` parameter can be zero. +info: | + SendableArrayBuffer( length ) + + ... + 2. Let numberLength be ToNumber(length). + 3. Let byteLength be ToLength(numberLength). + 4. ReturnIfAbrupt(byteLength). + 5. If SameValueZero(numberLength, byteLength) is false, throw a RangeError exception. + ... +---*/ + +var positiveZero = new SendableArrayBuffer(+0); +assert.sameValue(positiveZero.byteLength, 0); + +var negativeZero = new SendableArrayBuffer(-0); +assert.sameValue(negativeZero.byteLength, 0); diff --git a/test/sendable/builtins/Function/15.3.2.1-10-6gs.js b/test/sendable/builtins/Function/15.3.2.1-10-6gs.js new file mode 100644 index 0000000000000000000000000000000000000000..b8a5481f0f9a5caddd849a46264d49241782b5be --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-10-6gs.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-10-6gs +description: > + Strict Mode - SyntaxError is thrown if a function using the + SharedFunction constructor has two identical parameters in (local) + strict mode +flags: [noStrict] +---*/ + +assert.throws(SyntaxError, function() { + new SharedFunction('param_1', 'param_2', 'param_1', '"use strict";return 0;'); +}); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-1-s.js b/test/sendable/builtins/Function/15.3.2.1-11-1-s.js new file mode 100644 index 0000000000000000000000000000000000000000..26563a38f4208907d05497f917b7ae3e331481f7 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-1-s.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-1-s +description: > + Duplicate seperate parameter name in SharedFunction constructor throws + SyntaxError in strict mode +flags: [noStrict] +---*/ + + +assert.throws(SyntaxError, function() { + SharedFunction('a', 'a', '"use strict";'); +}); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-1.js b/test/sendable/builtins/Function/15.3.2.1-11-1.js new file mode 100644 index 0000000000000000000000000000000000000000..6ca12aefc5712e424d372bfcea78b158ff96a733 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-1.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-1 +description: > + Duplicate separate parameter name in SharedFunction constructor allowed + if body not strict +---*/ + +SharedFunction('a', 'a', 'return;'); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-2-s.js b/test/sendable/builtins/Function/15.3.2.1-11-2-s.js new file mode 100644 index 0000000000000000000000000000000000000000..264c11e9068150c956a98c68df921c2159eddb7f --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-2-s.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-2-s +description: > + Duplicate seperate parameter name in SharedFunction constructor called + from strict mode allowed if body not strict +flags: [onlyStrict] +---*/ + +SharedFunction('a', 'a', 'return;'); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-3-s.js b/test/sendable/builtins/Function/15.3.2.1-11-3-s.js new file mode 100644 index 0000000000000000000000000000000000000000..2166d22d1c69499aa16ed9c9a7a1faa7a8bdf6dc --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-3-s.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-3-s +description: > + SharedFunction constructor having a formal parameter named 'eval' throws + SyntaxError if function body is strict mode +flags: [noStrict] +---*/ + + +assert.throws(SyntaxError, function() { + SharedFunction('eval', '"use strict";'); +}); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-3.js b/test/sendable/builtins/Function/15.3.2.1-11-3.js new file mode 100644 index 0000000000000000000000000000000000000000..827fa9682c39b6435b6b0896083f7c80a56f8130 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-3.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-3 +description: > + SharedFunction constructor may have a formal parameter named 'eval' if + body is not strict mode +---*/ + +SharedFunction('eval', 'return;'); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-4-s.js b/test/sendable/builtins/Function/15.3.2.1-11-4-s.js new file mode 100644 index 0000000000000000000000000000000000000000..53983c65792056c3197829647f791ec38ff867f1 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-4-s.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-4-s +description: > + SharedFunction constructor call from strict code with formal parameter + named 'eval' does not throws SyntaxError if function body is not + strict mode +flags: [onlyStrict] +---*/ + +SharedFunction('eval', 'return;'); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-5-s.js b/test/sendable/builtins/Function/15.3.2.1-11-5-s.js new file mode 100644 index 0000000000000000000000000000000000000000..b8e22e8c5d59c6458ec89a71a909a7765e47aa07 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-5-s.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-5-s +description: > + Duplicate combined parameter name in SharedFunction constructor throws + SyntaxError in strict mode +flags: [noStrict] +---*/ + + +assert.throws(SyntaxError, function() { + SharedFunction('a,a', '"use strict";'); +}); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-5.js b/test/sendable/builtins/Function/15.3.2.1-11-5.js new file mode 100644 index 0000000000000000000000000000000000000000..8a7e1f3f378f73067361524b8ef398c0e84a355f --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-5.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-5 +description: > + Duplicate combined parameter name in SharedFunction constructor allowed + if body is not strict +---*/ + +SharedFunction('a,a', 'return;'); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-6-s.js b/test/sendable/builtins/Function/15.3.2.1-11-6-s.js new file mode 100644 index 0000000000000000000000000000000000000000..4e264874d5040b0d2d877529419f405a72d1f3c1 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-6-s.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-6-s +description: > + Duplicate combined parameter name allowed in SharedFunction constructor + called in strict mode if body not strict +flags: [onlyStrict] +---*/ + +SharedFunction('a,a', 'return a;'); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-7-s.js b/test/sendable/builtins/Function/15.3.2.1-11-7-s.js new file mode 100644 index 0000000000000000000000000000000000000000..b0b7a1d37a9a0835f44405e91a66610c8172ec3d --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-7-s.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-7-s +description: > + SharedFunction constructor call from strict code with formal parameter + named arguments does not throws SyntaxError if function body is + not strict mode +flags: [onlyStrict] +---*/ + +SharedFunction('arguments', 'return;'); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-8-s.js b/test/sendable/builtins/Function/15.3.2.1-11-8-s.js new file mode 100644 index 0000000000000000000000000000000000000000..26d640f076fe2c9538c190891751e0c6e7794193 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-8-s.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-8-s +description: > + Strict Mode - SyntaxError is not thrown if a function is created + using a SharedFunction constructor that has two identical parameters, + which are separated by a unique parameter name and there is no + explicit 'use strict' in the function constructor's body +flags: [onlyStrict] +---*/ + +var foo = new SharedFunction("baz", "qux", "baz", "return 0;"); diff --git a/test/sendable/builtins/Function/15.3.2.1-11-9-s.js b/test/sendable/builtins/Function/15.3.2.1-11-9-s.js new file mode 100644 index 0000000000000000000000000000000000000000..bd339efc7a746d9dfa4001cd552e3863a82b4289 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.2.1-11-9-s.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.2.1-11-9-s +description: > + Strict Mode - No SyntaxError is thrown if a function is created using + the SharedFunction constructor that has three identical parameters and + there is no explicit 'use strict' in the function constructor's + body +---*/ + +var foo = new SharedFunction("baz", "baz", "baz", "return 0;"); diff --git a/test/sendable/builtins/Function/15.3.5-1gs.js b/test/sendable/builtins/Function/15.3.5-1gs.js new file mode 100644 index 0000000000000000000000000000000000000000..13b2e164780a9f845910569dedc3c33ae96662ed --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5-1gs.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5-1gs +description: > + StrictMode - error is thrown when reading the 'caller' property of + a function object +flags: [onlyStrict] +---*/ + +function fn() {} + +assert.throws(TypeError, function() { + fn.caller; +}); diff --git a/test/sendable/builtins/Function/15.3.5-2gs.js b/test/sendable/builtins/Function/15.3.5-2gs.js new file mode 100644 index 0000000000000000000000000000000000000000..45900872137eb12279abf0e9a3c6346f105dd961 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5-2gs.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5-2gs +description: > + StrictMode - error is thrown when reading the 'caller' property of + a function object +flags: [onlyStrict] +---*/ + +function _15_3_5_1_gs() {} + +assert.throws(TypeError, function() { + _15_3_5_1_gs.caller; +}); diff --git a/test/sendable/builtins/Function/15.3.5.4_2-10gs.js b/test/sendable/builtins/Function/15.3.5.4_2-10gs.js new file mode 100644 index 0000000000000000000000000000000000000000..4a2a6af155549046c568e995f6381145b07aaab6 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-10gs.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-10gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (New'ed SharedFunction constructor includes strict + directive prologue) +flags: [noStrict] +---*/ + +var f = new SharedFunction("\"use strict\";\ngNonStrict();"); + +assert.throws(TypeError, function() { + f(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-11gs.js b/test/sendable/builtins/Function/15.3.5.4_2-11gs.js new file mode 100644 index 0000000000000000000000000000000000000000..5c6453b8aa2d6285400f6229c94b4963037fa008 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-11gs.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-11gs +description: > + Strict mode - checking access to strict function caller from + strict function (eval used within strict mode) +flags: [onlyStrict] +---*/ + +assert.throws(TypeError, function() { + eval("gNonStrict();"); +}); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-12gs.js b/test/sendable/builtins/Function/15.3.5.4_2-12gs.js new file mode 100644 index 0000000000000000000000000000000000000000..ae479003078fc9dee95d33759b0738d724e1718f --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-12gs.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-12gs +description: > + Strict mode - checking access to non-strict function caller from + non-strict function (eval includes strict directive prologue) +flags: [noStrict] +features: [caller] +---*/ + +eval("\"use strict\";\ngNonStrict();"); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-13gs.js b/test/sendable/builtins/Function/15.3.5.4_2-13gs.js new file mode 100644 index 0000000000000000000000000000000000000000..3f5757d5be2b24a2104e4deeae13b8db817f0aea --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-13gs.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-13gs +description: > + Strict mode - checking access to non-strict function caller from + strict function (indirect eval used within strict mode) +flags: [onlyStrict] +---*/ + +var my_eval = eval; + +assert.throws(TypeError, function() { + my_eval("gNonStrict();"); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-14gs.js b/test/sendable/builtins/Function/15.3.5.4_2-14gs.js new file mode 100644 index 0000000000000000000000000000000000000000..d9aa12a4fb037d48b193ffe1b683c3ebfe676deb --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-14gs.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-14gs +description: > + Strict mode - checking access to non-strict function caller from + non-strict function (indirect eval includes strict directive + prologue) +flags: [noStrict] +features: [caller] +---*/ + +var my_eval = eval; +my_eval("\"use strict\";\ngNonStrict();"); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-15gs.js b/test/sendable/builtins/Function/15.3.5.4_2-15gs.js new file mode 100644 index 0000000000000000000000000000000000000000..3f16a25382661975e13c564b3a44598044a4d5a2 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-15gs.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-15gs +description: > + Strict mode - checking access to strict function caller from + strict function (New'ed object from SendableFunctionDeclaration defined + within strict mode) +flags: [onlyStrict] +---*/ + +function f() { + gNonStrict(); +} + +assert.throws(TypeError, function() { + new f(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-16gs.js b/test/sendable/builtins/Function/15.3.5.4_2-16gs.js new file mode 100644 index 0000000000000000000000000000000000000000..441117146db652c48e225a11957c1d87b31f52ce --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-16gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-16gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (New'ed object from SendableFunctionDeclaration + includes strict directive prologue) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +} + +assert.throws(TypeError, function() { + new f(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-17gs.js b/test/sendable/builtins/Function/15.3.5.4_2-17gs.js new file mode 100644 index 0000000000000000000000000000000000000000..72e0e12d944b39a112d2cab996553060545a4fb9 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-17gs.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-17gs +description: > + Strict mode - checking access to strict function caller from + strict function (New'ed object from SendableFunctionExpression defined + within strict mode) +flags: [onlyStrict] +---*/ + +var f = function() { + gNonStrict(); +} + +assert.throws(TypeError, function() { + new f(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-18gs.js b/test/sendable/builtins/Function/15.3.5.4_2-18gs.js new file mode 100644 index 0000000000000000000000000000000000000000..6d99b7b7801f5870aa8be4b7fe32a61a5da18b51 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-18gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-18gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (New'ed object from SendableFunctionExpression + includes strict directive prologue) +flags: [noStrict] +---*/ + +var f = function() { + "use strict"; + gNonStrict(); +} + +assert.throws(TypeError, function() { + new f(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-19gs.js b/test/sendable/builtins/Function/15.3.5.4_2-19gs.js new file mode 100644 index 0000000000000000000000000000000000000000..880c5ab3fe46ced82e7970a5b3f4f5d3af77f113 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-19gs.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-19gs +description: > + Strict mode - checking access to strict function caller from + strict function (New'ed object from Anonymous SendableFunctionExpression + defined within strict mode) +flags: [onlyStrict] +---*/ + +assert.throws(TypeError, function() { + var obj = new(function() { + gNonStrict(); + }); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-1gs.js b/test/sendable/builtins/Function/15.3.5.4_2-1gs.js new file mode 100644 index 0000000000000000000000000000000000000000..85e12031f46cae1727ff5edaf4c6796a4f451f75 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-1gs.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-1gs +description: > + Strict mode - checking access to strict function caller from + strict function (SendableFunctionDeclaration defined within strict mode) +flags: [onlyStrict] +---*/ + +function f() { + gNonStrict(); +} + +assert.throws(TypeError, function() { + f(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-20gs.js b/test/sendable/builtins/Function/15.3.5.4_2-20gs.js new file mode 100644 index 0000000000000000000000000000000000000000..7fe07a90b10fe3c234ba447c3280ee0554aa4639 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-20gs.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-20gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (New'ed object from Anonymous + SendableFunctionExpression includes strict directive prologue) +flags: [noStrict] +---*/ + +assert.throws(TypeError, function() { + var obj = new(function() { + "use strict"; + gNonStrict(); + }); +}); + + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-21gs.js b/test/sendable/builtins/Function/15.3.5.4_2-21gs.js new file mode 100644 index 0000000000000000000000000000000000000000..9eba0fe62c77fa01992bddc9947fc1355bf91eb1 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-21gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-21gs +description: > + Strict mode - checking access to strict function caller from + strict function (SendableFunctionDeclaration defined within a + SendableFunctionDeclaration inside strict mode) +flags: [onlyStrict] +---*/ + +function f1() { + function f() { + gNonStrict(); + } + f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-22gs.js b/test/sendable/builtins/Function/15.3.5.4_2-22gs.js new file mode 100644 index 0000000000000000000000000000000000000000..0d45f6eebdeba49cd2d59512cc1a95a19849b2ce --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-22gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-22gs +description: > + Strict mode - checking access to strict function caller from + strict function (SendableFunctionExpression defined within a + SendableFunctionDeclaration inside strict mode) +flags: [onlyStrict] +---*/ + +function f1() { + var f = function() { + gNonStrict(); + } + f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-23gs.js b/test/sendable/builtins/Function/15.3.5.4_2-23gs.js new file mode 100644 index 0000000000000000000000000000000000000000..55969351c8b46bbbcaa4bc391af791dd113939e0 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-23gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-23gs +description: > + Strict mode - checking access to strict function caller from + strict function (Anonymous SendableFunctionExpression defined within a + SendableFunctionDeclaration inside strict mode) +flags: [onlyStrict] +---*/ + +function f1() { + (function() { + gNonStrict(); + })(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-24gs.js b/test/sendable/builtins/Function/15.3.5.4_2-24gs.js new file mode 100644 index 0000000000000000000000000000000000000000..914bd41fcaa71f9982ed5353505ab78aeb15c015 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-24gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-24gs +description: > + Strict mode - checking access to strict function caller from + strict function (SendableFunctionDeclaration defined within a + SendableFunctionExpression inside strict mode) +flags: [onlyStrict] +---*/ + +var f1 = function() { + function f() { + gNonStrict(); + } + f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-25gs.js b/test/sendable/builtins/Function/15.3.5.4_2-25gs.js new file mode 100644 index 0000000000000000000000000000000000000000..adccfd02bf4baf0a663a9ec73f1150512933c5d3 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-25gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-25gs +description: > + Strict mode - checking access to strict function caller from + strict function (SendableFunctionExpression defined within a + SendableFunctionExpression inside strict mode) +flags: [onlyStrict] +---*/ + +var f1 = function() { + var f = function() { + gNonStrict(); + } + f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-26gs.js b/test/sendable/builtins/Function/15.3.5.4_2-26gs.js new file mode 100644 index 0000000000000000000000000000000000000000..3d7f8b754bb9a1048a16be71413b24adaba2245a --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-26gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-26gs +description: > + Strict mode - checking access to strict function caller from + strict function (Anonymous SendableFunctionExpression defined within a + SendableFunctionExpression inside strict mode) +flags: [onlyStrict] +---*/ + +var f1 = function() { + (function() { + gNonStrict(); + })(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-27gs.js b/test/sendable/builtins/Function/15.3.5.4_2-27gs.js new file mode 100644 index 0000000000000000000000000000000000000000..7feab02a048bb3e1b750ad2d50f4fc36b3e2c7e9 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-27gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-27gs +description: > + Strict mode - checking access to strict function caller from + strict function (SendableFunctionDeclaration defined within an Anonymous + SendableFunctionExpression inside strict mode) +flags: [onlyStrict] +---*/ + +assert.throws(TypeError, function() { + (function() { + function f() { + gNonStrict(); + } + f(); + })(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-28gs.js b/test/sendable/builtins/Function/15.3.5.4_2-28gs.js new file mode 100644 index 0000000000000000000000000000000000000000..96ff99a8c5d5e40e0a1ad251b09f20afb804de38 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-28gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-28gs +description: > + Strict mode - checking access to strict function caller from + strict function (SendableFunctionExpression defined within an Anonymous + SendableFunctionExpression inside strict mode) +flags: [onlyStrict] +---*/ + +assert.throws(TypeError, function() { + (function() { + var f = function() { + gNonStrict(); + } + f(); + })(); +}); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-29gs.js b/test/sendable/builtins/Function/15.3.5.4_2-29gs.js new file mode 100644 index 0000000000000000000000000000000000000000..a2a8cab9b53022eea0fc709f11cc4a396f9ae014 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-29gs.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-29gs +description: > + Strict mode - checking access to strict function caller from + strict function (Anonymous SendableFunctionExpression defined within an + Anonymous SendableFunctionExpression inside strict mode) +flags: [onlyStrict] +---*/ + +assert.throws(TypeError, function() { + (function() { + (function() { + gNonStrict(); + })(); + })(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-2gs.js b/test/sendable/builtins/Function/15.3.5.4_2-2gs.js new file mode 100644 index 0000000000000000000000000000000000000000..8203af2a33da1d2402faefc905eece9d089c19ea --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-2gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-2gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionDeclaration includes strict directive + prologue) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +} + +assert.throws(TypeError, function() { + f(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-30gs.js b/test/sendable/builtins/Function/15.3.5.4_2-30gs.js new file mode 100644 index 0000000000000000000000000000000000000000..f354e7ec79df6149c90da588018dacadfeeb6cce --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-30gs.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-30gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionDeclaration defined within a + SendableFunctionDeclaration with a strict directive prologue) +flags: [noStrict] +---*/ + +function f1() { + "use strict"; + + function f() { + gNonStrict(); + } + f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-31gs.js b/test/sendable/builtins/Function/15.3.5.4_2-31gs.js new file mode 100644 index 0000000000000000000000000000000000000000..e768f6ec19012324c75289272ea46b75868dd938 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-31gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-31gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionExpression defined within a + SendableFunctionDeclaration with a strict directive prologue) +flags: [noStrict] +---*/ + +function f1() { + "use strict"; + var f = function() { + gNonStrict(); + } + f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-32gs.js b/test/sendable/builtins/Function/15.3.5.4_2-32gs.js new file mode 100644 index 0000000000000000000000000000000000000000..32fd49e57b680335b01fe2adb033952f7ce6f14b --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-32gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-32gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (Anonymous SendableFunctionExpression defined within a + SendableFunctionDeclaration with a strict directive prologue) +flags: [noStrict] +---*/ + +function f1() { + "use strict"; + (function() { + gNonStrict(); + })(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-33gs.js b/test/sendable/builtins/Function/15.3.5.4_2-33gs.js new file mode 100644 index 0000000000000000000000000000000000000000..e901d869bca974a75cf4020f64b50a605370164f --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-33gs.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-33gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionDeclaration defined within a + SendableFunctionExpression with a strict directive prologue) +flags: [noStrict] +---*/ + +var f1 = function() { + "use strict"; + + function f() { + gNonStrict(); + } + f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-34gs.js b/test/sendable/builtins/Function/15.3.5.4_2-34gs.js new file mode 100644 index 0000000000000000000000000000000000000000..460e760094f348e5d447f42ccb6a3f0cd9b23ad6 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-34gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-34gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionExpression defined within a + SendableFunctionExpression with a strict directive prologue) +flags: [noStrict] +---*/ + +var f1 = function() { + "use strict"; + var f = function() { + gNonStrict(); + } + f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-35gs.js b/test/sendable/builtins/Function/15.3.5.4_2-35gs.js new file mode 100644 index 0000000000000000000000000000000000000000..896b7c9b369ccf85612678dccbaed2aa43e72e73 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-35gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-35gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (Anonymous SendableFunctionExpression defined within a + SendableFunctionExpression with a strict directive prologue) +flags: [noStrict] +---*/ + +var f1 = function() { + "use strict"; + (function() { + gNonStrict(); + })(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-36gs.js b/test/sendable/builtins/Function/15.3.5.4_2-36gs.js new file mode 100644 index 0000000000000000000000000000000000000000..a02e9919e8cec34b9693203d40cc51b6d8bb57df --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-36gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-36gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionDeclaration defined within an + Anonymous SendableFunctionExpression with a strict directive prologue) +flags: [noStrict] +---*/ + +assert.throws(TypeError, function() { + (function() { + "use strict"; + + function f() { + gNonStrict(); + } + f(); + })(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-37gs.js b/test/sendable/builtins/Function/15.3.5.4_2-37gs.js new file mode 100644 index 0000000000000000000000000000000000000000..306c18a510e6358c14e56c108ad62e486f3227d6 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-37gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-37gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionExpression defined within an + Anonymous SendableFunctionExpression with a strict directive prologue) +flags: [noStrict] +---*/ + +assert.throws(TypeError, function() { + (function() { + "use strict"; + var f = function() { + gNonStrict(); + } + f(); + })(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-38gs.js b/test/sendable/builtins/Function/15.3.5.4_2-38gs.js new file mode 100644 index 0000000000000000000000000000000000000000..92aa7b36f2ba3420c5d792f06ff9fd5d208a5f29 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-38gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-38gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (Anonymous SendableFunctionExpression defined within + an Anonymous SendableFunctionExpression with a strict directive prologue) +flags: [noStrict] +---*/ + +assert.throws(TypeError, function() { + (function() { + "use strict"; + (function() { + gNonStrict(); + })(); + })(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-39gs.js b/test/sendable/builtins/Function/15.3.5.4_2-39gs.js new file mode 100644 index 0000000000000000000000000000000000000000..9b1bed8de87f540aed569d6a28413a503b273e9a --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-39gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-39gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionDeclaration with a strict directive + prologue defined within a SendableFunctionDeclaration) +flags: [noStrict] +---*/ + +function f1() { + function f() { + "use strict"; + gNonStrict(); + } + return f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-3gs.js b/test/sendable/builtins/Function/15.3.5.4_2-3gs.js new file mode 100644 index 0000000000000000000000000000000000000000..f59443b5003bed96c41319c87d71d534288c8d24 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-3gs.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-3gs +description: > + Strict mode - checking access to strict function caller from + strict function (SendableFunctionExpression defined within strict mode) +flags: [onlyStrict] +---*/ + +var f = function() { + gNonStrict(); +} + +assert.throws(TypeError, function() { + f(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-40gs.js b/test/sendable/builtins/Function/15.3.5.4_2-40gs.js new file mode 100644 index 0000000000000000000000000000000000000000..3e8e4b2ac299d409a79cb56758f24ce6c6bf0fd7 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-40gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-40gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionExpression with a strict directive + prologue defined within a SendableFunctionDeclaration) +flags: [noStrict] +---*/ + +function f1() { + var f = function() { + "use strict"; + gNonStrict(); + } + return f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-41gs.js b/test/sendable/builtins/Function/15.3.5.4_2-41gs.js new file mode 100644 index 0000000000000000000000000000000000000000..6d1858316b61cc75f728b78575471ac55fa5670a --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-41gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-41gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (Anonymous SendableFunctionExpression with a strict + directive prologue defined within a SendableFunctionDeclaration) +flags: [noStrict] +---*/ + +function f1() { + return (function() { + "use strict"; + gNonStrict(); + })(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-42gs.js b/test/sendable/builtins/Function/15.3.5.4_2-42gs.js new file mode 100644 index 0000000000000000000000000000000000000000..d9896796422ff7d1cc8f764c53edef0a0d0f45e9 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-42gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-42gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionDeclaration with a strict directive + prologue defined within a SendableFunctionExpression) +flags: [noStrict] +---*/ + +var f1 = function() { + function f() { + "use strict"; + gNonStrict(); + } + return f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-43gs.js b/test/sendable/builtins/Function/15.3.5.4_2-43gs.js new file mode 100644 index 0000000000000000000000000000000000000000..7240c6f92c1b60980e900b34a21d6c24793a2783 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-43gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-43gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionExpression with a strict directive + prologue defined within a SendableFunctionExpression) +flags: [noStrict] +---*/ + +var f1 = function() { + var f = function() { + "use strict"; + gNonStrict(); + } + return f(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-44gs.js b/test/sendable/builtins/Function/15.3.5.4_2-44gs.js new file mode 100644 index 0000000000000000000000000000000000000000..ebd56a7cade3e27908a7753b84ea6c7f715b29b4 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-44gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-44gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (Anonymous SendableFunctionExpression with a strict + directive prologue defined within a SendableFunctionExpression) +flags: [noStrict] +---*/ + +var f1 = function() { + return (function() { + "use strict"; + gNonStrict(); + })(); +} + +assert.throws(TypeError, function() { + f1(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-45gs.js b/test/sendable/builtins/Function/15.3.5.4_2-45gs.js new file mode 100644 index 0000000000000000000000000000000000000000..4bccf899c9e2ed22219cc837b4418b8aeba7d418 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-45gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-45gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionDeclaration with a strict directive + prologue defined within an Anonymous SendableFunctionExpression) +flags: [noStrict] +---*/ + +assert.throws(TypeError, function() { + (function() { + function f() { + "use strict"; + gNonStrict(); + } + return f(); + })(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-46gs.js b/test/sendable/builtins/Function/15.3.5.4_2-46gs.js new file mode 100644 index 0000000000000000000000000000000000000000..e7de5b03166d08cfad5d9f19df633a629579f7b6 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-46gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-46gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionExpression with a strict directive + prologue defined within an Anonymous SendableFunctionExpression) +flags: [noStrict] +---*/ + +assert.throws(TypeError, function() { + (function() { + var f = function() { + "use strict"; + gNonStrict(); + } + return f(); + })(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-47gs.js b/test/sendable/builtins/Function/15.3.5.4_2-47gs.js new file mode 100644 index 0000000000000000000000000000000000000000..47b16bbcc4c3fc99fe9cbe002dfb375355385f6f --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-47gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-47gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (Anonymous SendableFunctionExpression with a strict + directive prologue defined within an Anonymous SendableFunctionExpression) +flags: [noStrict] +---*/ + +assert.throws(TypeError, function() { + (function() { + return (function() { + "use strict"; + gNonStrict(); + })(); + })(); +}); + + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-48gs.js b/test/sendable/builtins/Function/15.3.5.4_2-48gs.js new file mode 100644 index 0000000000000000000000000000000000000000..2525b3f25f9487255746458a7d3269fa07a89a3d --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-48gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-48gs +description: > + Strict mode - checking access to strict function caller from + strict function (Literal getter defined within strict mode) +flags: [onlyStrict] +---*/ + +var o = { + get foo() { + gNonStrict(); + } +} + +assert.throws(TypeError, function() { + o.foo; +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-49gs.js b/test/sendable/builtins/Function/15.3.5.4_2-49gs.js new file mode 100644 index 0000000000000000000000000000000000000000..720d5ba1112d437dd52550dd2a7831f9f9712cb5 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-49gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-49gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (Literal getter includes strict directive + prologue) +flags: [noStrict] +---*/ + +var o = { + get foo() { + "use strict"; + gNonStrict(); + } +} + +assert.throws(TypeError, function() { + o.foo; +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-4gs.js b/test/sendable/builtins/Function/15.3.5.4_2-4gs.js new file mode 100644 index 0000000000000000000000000000000000000000..bdda0120fb8b1ee190920af5e5d403a72f71f5fa --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-4gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-4gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SendableFunctionExpression includes strict directive + prologue) +flags: [noStrict] +---*/ + +var f = function() { + "use strict"; + gNonStrict(); +} + +assert.throws(TypeError, function() { + f(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-50gs.js b/test/sendable/builtins/Function/15.3.5.4_2-50gs.js new file mode 100644 index 0000000000000000000000000000000000000000..04d05953d3c683c61a037f72e2ba3ceccfddb672 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-50gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-50gs +description: > + Strict mode - checking access to strict function caller from + strict function (Literal setter defined within strict mode) +flags: [onlyStrict] +---*/ + +var o = { + set foo(stuff) { + gNonStrict(); + } +} + +assert.throws(TypeError, function() { + o.foo = 7; +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-51gs.js b/test/sendable/builtins/Function/15.3.5.4_2-51gs.js new file mode 100644 index 0000000000000000000000000000000000000000..231ae9e6a8784861b439aa406db3fa0c9f0f225e --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-51gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-51gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (Literal setter includes strict directive + prologue) +flags: [noStrict] +---*/ + +var o = { + set foo(stuff) { + "use strict"; + gNonStrict(); + } +} + +assert.throws(TypeError, function() { + o.foo = 8; +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-52gs.js b/test/sendable/builtins/Function/15.3.5.4_2-52gs.js new file mode 100644 index 0000000000000000000000000000000000000000..eb1ba1e998dd831142b6f39640a0a2e2c7d4e8bc --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-52gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-52gs +description: > + Strict mode - checking access to strict function caller from + strict function (Injected getter defined within strict mode) +flags: [onlyStrict] +---*/ + +var o = {}; +Object.defineProperty(o, "foo", { + get: function() { + gNonStrict(); + } +}); + +assert.throws(TypeError, function() { + o.foo; +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-53gs.js b/test/sendable/builtins/Function/15.3.5.4_2-53gs.js new file mode 100644 index 0000000000000000000000000000000000000000..a36ab96973c34d030fa06c14258110966038244f --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-53gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-53gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (Injected getter includes strict directive + prologue) +flags: [noStrict] +---*/ + +var o = {}; +Object.defineProperty(o, "foo", { + get: function() { + "use strict"; + gNonStrict(); + } +}); + +assert.throws(TypeError, function() { + o.foo; +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-54gs.js b/test/sendable/builtins/Function/15.3.5.4_2-54gs.js new file mode 100644 index 0000000000000000000000000000000000000000..653fa6a53c8c7a41687ba1d3aa041dd4efb875e9 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-54gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-54gs +description: > + Strict mode - checking access to strict function caller from + strict function (Injected setter defined within strict mode) +flags: [onlyStrict] +---*/ + +var o = {}; +Object.defineProperty(o, "foo", { + set: function(stuff) { + gNonStrict(); + } +}); + +assert.throws(TypeError, function() { + o.foo = 9; +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-55gs.js b/test/sendable/builtins/Function/15.3.5.4_2-55gs.js new file mode 100644 index 0000000000000000000000000000000000000000..acf1f8b3b04bfb5c54209199f1794ed619dd4a00 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-55gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-55gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (Injected setter includes strict directive + prologue) +flags: [noStrict] +---*/ + +var o = {}; +Object.defineProperty(o, "foo", { + set: function(stuff) { + "use strict"; + gNonStrict(); + } +}); + +assert.throws(TypeError, function() { + o.foo = 10; +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-56gs.js b/test/sendable/builtins/Function/15.3.5.4_2-56gs.js new file mode 100644 index 0000000000000000000000000000000000000000..78259c4de29197caa2202f191fbf5027e74bf890 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-56gs.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-56gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + non-strict function declaration) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +function foo() { + return f(); +} + +assert.throws(TypeError, function() { + foo(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-57gs.js b/test/sendable/builtins/Function/15.3.5.4_2-57gs.js new file mode 100644 index 0000000000000000000000000000000000000000..5ebce52a62ebe345ea1ba9faba8c102fb836ffce --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-57gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-57gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + non-strict eval) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + eval("f();"); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-58gs.js b/test/sendable/builtins/Function/15.3.5.4_2-58gs.js new file mode 100644 index 0000000000000000000000000000000000000000..a497b55901a5ec3f721df95141aa39edf9adb74b --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-58gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-58gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + non-strict SharedFunction constructor) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + SharedFunction("return f();")(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-59gs.js b/test/sendable/builtins/Function/15.3.5.4_2-59gs.js new file mode 100644 index 0000000000000000000000000000000000000000..5f2a9fe61e73ad349ef350322c8cd6a02139e826 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-59gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-59gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + non-strict new'ed SharedFunction constructor) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + new SharedFunction("return f();")(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-5gs.js b/test/sendable/builtins/Function/15.3.5.4_2-5gs.js new file mode 100644 index 0000000000000000000000000000000000000000..3185bb138c4b0bbe4fe6f2ee5f1ba9ac3866fa51 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-5gs.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-5gs +description: > + Strict mode - checking access to strict function caller from + strict function (Anonymous SendableFunctionExpression defined within + strict mode) +flags: [onlyStrict] +---*/ + +assert.throws(TypeError, function() { + (function() { + gNonStrict(); + })(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-60gs.js b/test/sendable/builtins/Function/15.3.5.4_2-60gs.js new file mode 100644 index 0000000000000000000000000000000000000000..76d407014acf674fef3e71dba76627fd7c65d9f7 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-60gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-60gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.apply()) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.apply(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-61gs.js b/test/sendable/builtins/Function/15.3.5.4_2-61gs.js new file mode 100644 index 0000000000000000000000000000000000000000..4f9362e093c3dbe18090c0969c8ca380d6f46cb7 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-61gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-61gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.apply(null)) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.apply(null); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-62gs.js b/test/sendable/builtins/Function/15.3.5.4_2-62gs.js new file mode 100644 index 0000000000000000000000000000000000000000..a82bbe040cfefb09c07a5cb19d290e484cf85044 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-62gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-62gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.apply(undefined)) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.apply(undefined); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-63gs.js b/test/sendable/builtins/Function/15.3.5.4_2-63gs.js new file mode 100644 index 0000000000000000000000000000000000000000..e548dc14aaf744d8d823f6dac9508e210fd547ac --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-63gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-63gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.apply(someObject)) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; +var o = {}; + +assert.throws(TypeError, function() { + f.apply(o); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-64gs.js b/test/sendable/builtins/Function/15.3.5.4_2-64gs.js new file mode 100644 index 0000000000000000000000000000000000000000..2fc22458b252b3a3faa8f6757ed745b5f7956622 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-64gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-64gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.apply(globalObject)) +flags: [noStrict] +---*/ + +var global = this; + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.apply(global); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-65gs.js b/test/sendable/builtins/Function/15.3.5.4_2-65gs.js new file mode 100644 index 0000000000000000000000000000000000000000..73102261166c599e20e972bc224e08a57567feff --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-65gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-65gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.call()) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.call(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-66gs.js b/test/sendable/builtins/Function/15.3.5.4_2-66gs.js new file mode 100644 index 0000000000000000000000000000000000000000..917ea3544e7845834ebfffac5dd2b8aff5833c4c --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-66gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-66gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.call(null)) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.call(null); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-67gs.js b/test/sendable/builtins/Function/15.3.5.4_2-67gs.js new file mode 100644 index 0000000000000000000000000000000000000000..029398eef147d62de11fd33d82bd338e2e08528e --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-67gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-67gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.call(undefined)) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.call(undefined); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-68gs.js b/test/sendable/builtins/Function/15.3.5.4_2-68gs.js new file mode 100644 index 0000000000000000000000000000000000000000..1387fa10743bc2171c492e25b331bf4469590998 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-68gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-68gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.call(someObject)) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; +var o = {}; + +assert.throws(TypeError, function() { + f.call(o); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-69gs.js b/test/sendable/builtins/Function/15.3.5.4_2-69gs.js new file mode 100644 index 0000000000000000000000000000000000000000..43e3fc1e7bd26bf9d32a37f882a4700a336671ae --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-69gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-69gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.call(globalObject)) +flags: [noStrict] +---*/ + +var global = this; + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.call(this); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-6gs.js b/test/sendable/builtins/Function/15.3.5.4_2-6gs.js new file mode 100644 index 0000000000000000000000000000000000000000..1d9fa47e8625fe7a26f49cd7f6af931c751e2a9f --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-6gs.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-6gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (Anonymous SendableFunctionExpression includes strict + directive prologue) +flags: [noStrict] +---*/ + +assert.throws(TypeError, function() { + (function() { + "use strict"; + gNonStrict(); + })(); +}); + + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-70gs.js b/test/sendable/builtins/Function/15.3.5.4_2-70gs.js new file mode 100644 index 0000000000000000000000000000000000000000..84a7b04588a107ce8de036ef5d6dc6d3ae001666 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-70gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-70gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.bind()()) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.bind()(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-71gs.js b/test/sendable/builtins/Function/15.3.5.4_2-71gs.js new file mode 100644 index 0000000000000000000000000000000000000000..e0ef2648953ad43832a68b7073ceb82d7773dafa --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-71gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-71gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.bind(null)()) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.bind(null)(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-72gs.js b/test/sendable/builtins/Function/15.3.5.4_2-72gs.js new file mode 100644 index 0000000000000000000000000000000000000000..06db8ad6e2fa371c968a08ef8e7883402203f20f --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-72gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-72gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.bind(undefined)()) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.bind(undefined)(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-73gs.js b/test/sendable/builtins/Function/15.3.5.4_2-73gs.js new file mode 100644 index 0000000000000000000000000000000000000000..bf4928d0dea0ed2dfd1672a688d5aa7de0ea0216 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-73gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-73gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.bind(someObject)()) +flags: [noStrict] +---*/ + +function f() { + "use strict"; + gNonStrict(); +}; +var o = {}; + +assert.throws(TypeError, function() { + f.bind(o)(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-74gs.js b/test/sendable/builtins/Function/15.3.5.4_2-74gs.js new file mode 100644 index 0000000000000000000000000000000000000000..2042cb8c9722a61f44640d13112d11b0f3f98341 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-74gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-74gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (strict function declaration called by + SharedFunction.prototype.bind(globalObject)()) +flags: [noStrict] +---*/ + +var global = this; + +function f() { + "use strict"; + gNonStrict(); +}; + +assert.throws(TypeError, function() { + f.bind(global)(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-75gs.js b/test/sendable/builtins/Function/15.3.5.4_2-75gs.js new file mode 100644 index 0000000000000000000000000000000000000000..867f6de0e1f4137038262b4080da96fd3c30ae8c --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-75gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-75gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict function declaration) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; + +function foo() { + "use strict"; + f(); +} +foo(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-76gs.js b/test/sendable/builtins/Function/15.3.5.4_2-76gs.js new file mode 100644 index 0000000000000000000000000000000000000000..d7188a82c7f94c50c3b139c439557a4fd0338035 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-76gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-76gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict eval) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + return eval("f();"); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-77gs.js b/test/sendable/builtins/Function/15.3.5.4_2-77gs.js new file mode 100644 index 0000000000000000000000000000000000000000..002ee3ff6c4b58c75d95ec227d6d8647cec72c7f --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-77gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-77gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction constructor) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + SharedFunction("return f();")(); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-78gs.js b/test/sendable/builtins/Function/15.3.5.4_2-78gs.js new file mode 100644 index 0000000000000000000000000000000000000000..bbccadd116b6e08bb65023aa1d49afce2b2440f0 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-78gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-78gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict new'ed SharedFunction constructor) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + return new SharedFunction("return f();")(); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-79gs.js b/test/sendable/builtins/Function/15.3.5.4_2-79gs.js new file mode 100644 index 0000000000000000000000000000000000000000..74f89e3dbcf6b866cff8b2e6b6e3ebc8ca95ac79 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-79gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-79gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.apply()) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.apply(); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-7gs.js b/test/sendable/builtins/Function/15.3.5.4_2-7gs.js new file mode 100644 index 0000000000000000000000000000000000000000..a8d0b0547a87a9d4902b9a80ca8e9e49f6b4dea3 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-7gs.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-7gs +description: > + Strict mode - checking access to non-strict function caller from + strict function (SharedFunction constructor defined within strict mode) +flags: [onlyStrict] +---*/ + +var f = SharedFunction("return gNonStrict();"); + +assert.throws(TypeError, function() { + f(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-80gs.js b/test/sendable/builtins/Function/15.3.5.4_2-80gs.js new file mode 100644 index 0000000000000000000000000000000000000000..89446575397fd4d1229005cdcf9c7f20c86739d8 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-80gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-80gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.apply(null)) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.apply(null); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-81gs.js b/test/sendable/builtins/Function/15.3.5.4_2-81gs.js new file mode 100644 index 0000000000000000000000000000000000000000..da6c328d8a682e073dd35962ff4331a299d6abae --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-81gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-81gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.apply(undefined)) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.apply(undefined); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-82gs.js b/test/sendable/builtins/Function/15.3.5.4_2-82gs.js new file mode 100644 index 0000000000000000000000000000000000000000..acde09f39220fe5dd1d35319e870aaed507eb875 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-82gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-82gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.apply(someObject)) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +var o = {}; +(function() { + "use strict"; + f.apply(o); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-83gs.js b/test/sendable/builtins/Function/15.3.5.4_2-83gs.js new file mode 100644 index 0000000000000000000000000000000000000000..6b2bd69f4212406a6cdee7732cb7677c1dc40953 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-83gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-83gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.apply(globalObject)) +flags: [noStrict] +features: [caller] +---*/ + +var global = this; + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.apply(global); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-84gs.js b/test/sendable/builtins/Function/15.3.5.4_2-84gs.js new file mode 100644 index 0000000000000000000000000000000000000000..9f0642fb3807026307b1a54a9161866a480c2dd2 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-84gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-84gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.call()) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.call(); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-85gs.js b/test/sendable/builtins/Function/15.3.5.4_2-85gs.js new file mode 100644 index 0000000000000000000000000000000000000000..740d3202791e7758210ca848b5cb3ad49c8c89ef --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-85gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-85gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.call(null)) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.call(null); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-86gs.js b/test/sendable/builtins/Function/15.3.5.4_2-86gs.js new file mode 100644 index 0000000000000000000000000000000000000000..e049113d05898ff3df7d9d99e9a5db2ee2dde53b --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-86gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-86gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.call(undefined)) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.call(undefined); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-87gs.js b/test/sendable/builtins/Function/15.3.5.4_2-87gs.js new file mode 100644 index 0000000000000000000000000000000000000000..00574469e03654e54231fa6ea08e20a1c42f3063 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-87gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-87gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.call(someObject)) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +var o = {}; +(function() { + "use strict"; + f.call(o); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-88gs.js b/test/sendable/builtins/Function/15.3.5.4_2-88gs.js new file mode 100644 index 0000000000000000000000000000000000000000..e39e04c3b6545e95fc79d75b27f2b42c5d1e15a3 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-88gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-88gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.call(globalObject)) +flags: [noStrict] +features: [caller] +---*/ + +var global = this; + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.call(global); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-89gs.js b/test/sendable/builtins/Function/15.3.5.4_2-89gs.js new file mode 100644 index 0000000000000000000000000000000000000000..a7aa8b65ed5f058347e8ea7682aae5cc0f24f063 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-89gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-89gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.bind()()) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.bind()(); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-8gs.js b/test/sendable/builtins/Function/15.3.5.4_2-8gs.js new file mode 100644 index 0000000000000000000000000000000000000000..10daafd3ebba650e97faacc772bab5dd143f100d --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-8gs.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-8gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (SharedFunction constructor includes strict + directive prologue) +flags: [noStrict] +---*/ + +var f = SharedFunction("\"use strict\";\ngNonStrict();"); + +assert.throws(TypeError, function() { + f(); +}); + +function gNonStrict() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-90gs.js b/test/sendable/builtins/Function/15.3.5.4_2-90gs.js new file mode 100644 index 0000000000000000000000000000000000000000..c1dcd6d7de15179a8f24fbf2b95ec64cbed9a8ea --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-90gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-90gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.bind(null)()) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.bind(null)(); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-91gs.js b/test/sendable/builtins/Function/15.3.5.4_2-91gs.js new file mode 100644 index 0000000000000000000000000000000000000000..714d91b715e2b1c1a99cc99a9cef82309cac8a2d --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-91gs.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-91gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.bind(undefined)()) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.bind(undefined)(); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-92gs.js b/test/sendable/builtins/Function/15.3.5.4_2-92gs.js new file mode 100644 index 0000000000000000000000000000000000000000..ec37b6f7d01f76acd39afaaa9e2b0a4097102e20 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-92gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-92gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.bind(someObject)()) +flags: [noStrict] +features: [caller] +---*/ + +function f() { + return gNonStrict(); +}; +var o = {}; +(function() { + "use strict"; + f.bind(o)(); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-93gs.js b/test/sendable/builtins/Function/15.3.5.4_2-93gs.js new file mode 100644 index 0000000000000000000000000000000000000000..e8c3b156c09bea69629f03aa53f6416a447a3257 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-93gs.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-93gs +description: > + Strict mode - checking access to strict function caller from + non-strict function (non-strict function declaration called by + strict SharedFunction.prototype.bind(globalObject)()) +flags: [noStrict] +features: [caller] +---*/ + +var global = this; + +function f() { + return gNonStrict(); +}; +(function() { + "use strict"; + f.bind(global)(); +})(); + + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-94gs.js b/test/sendable/builtins/Function/15.3.5.4_2-94gs.js new file mode 100644 index 0000000000000000000000000000000000000000..50edf804fc8c8cc5b59150496d9418a0ec3499c9 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-94gs.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-94gs +description: > + Strict mode - checking access to strict function caller from + non-strict function expression (SendableFunctionDeclaration includes + strict directive prologue) +flags: [noStrict] +---*/ + +var gNonStrict = function() { + return gNonStrict.caller || gNonStrict.caller.throwTypeError; +} + +function f() { + "use strict"; + gNonStrict(); +} + +assert.throws(TypeError, function() { + f(); +}); diff --git a/test/sendable/builtins/Function/15.3.5.4_2-95gs.js b/test/sendable/builtins/Function/15.3.5.4_2-95gs.js new file mode 100644 index 0000000000000000000000000000000000000000..a0c5a705755609650f50b7724d520481b496195c --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-95gs.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-95gs +description: > + Strict mode - checking access to strict function caller from + non-strict, constructor-based function (SendableFunctionDeclaration + includes strict directive prologue) +flags: [noStrict] +---*/ + +var gNonStrict = SharedFunction("return gNonStrict.caller || gNonStrict.caller.throwTypeError;"); + +function f() { + "use strict"; + gNonStrict(); +} + +assert.throws(TypeError, function() { + f(); +}); diff --git a/test/sendable/builtins/Function/15.3.5.4_2-96gs.js b/test/sendable/builtins/Function/15.3.5.4_2-96gs.js new file mode 100644 index 0000000000000000000000000000000000000000..6eead365dafa9d5184cb896cc2bd1312c9976e4a --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-96gs.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-96gs +description: > + Strict mode - checking access to strict function caller from + non-strict property (SendableFunctionDeclaration includes strict directive + prologue) +flags: [noStrict] +---*/ + +var o = { + get gNonStrict() { + var tmp = Object.getOwnPropertyDescriptor(o, "gNonStrict").get; + return tmp.caller || tmp.caller.throwTypeError; + } +}; + + +function f() { + "use strict"; + return o.gNonStrict; +} + +assert.throws(TypeError, function() { + f(); +}); diff --git a/test/sendable/builtins/Function/15.3.5.4_2-97gs.js b/test/sendable/builtins/Function/15.3.5.4_2-97gs.js new file mode 100644 index 0000000000000000000000000000000000000000..79395366306c6b5ece7b1957e2baf7318c427dd0 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-97gs.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-97gs +description: > + Strict mode - checking access to strict function caller from bound + non-strict function (SendableFunctionDeclaration includes strict directive + prologue) +flags: [noStrict] +---*/ + +var gNonStrict = gNonStrictBindee.bind(null); + +function f() { + "use strict"; + gNonStrict(); +} + +assert.throws(TypeError, function() { + f(); +}); + +function gNonStrictBindee() { + return gNonStrictBindee.caller || gNonStrictBindee.caller.throwTypeError; +} diff --git a/test/sendable/builtins/Function/15.3.5.4_2-9gs.js b/test/sendable/builtins/Function/15.3.5.4_2-9gs.js new file mode 100644 index 0000000000000000000000000000000000000000..a1d44821470bdfcd8e2743d3be338275b75dd5b6 --- /dev/null +++ b/test/sendable/builtins/Function/15.3.5.4_2-9gs.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.5.4_2-9gs +description: > + Strict mode - checking access to non-strict function caller from + strict function (New'ed SharedFunction constructor defined within strict + mode) +flags: [onlyStrict] +---*/ + +var f = new SharedFunction("return gNonStrict();"); + +assert.throws(TypeError, function() { + f(); +}); + +function gNonStrict() { + return gNonStrict.caller; +} diff --git a/test/sendable/builtins/Function/S10.1.1_A1_T3.js b/test/sendable/builtins/Function/S10.1.1_A1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..d16641fca68e374fe43fc8a7422906553e04b9a3 --- /dev/null +++ b/test/sendable/builtins/Function/S10.1.1_A1_T3.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + Program functions are defined in source text by a SendableFunctionDeclaration or created dynamically either + by using a SendableFunctionExpression or by using the built-in SharedFunction object as a constructor +es5id: 10.1.1_A1_T3 +description: > + Creating function dynamically by using the built-in SharedFunction + object as a constructor +---*/ + +var x = new function f1() { + return 1; +}; + +assert.sameValue( + typeof(x.constructor), + "function", + 'The value of `typeof(x.constructor)` is expected to be "function"' +); diff --git a/test/sendable/builtins/Function/S15.3.1_A1_T1.js b/test/sendable/builtins/Function/S15.3.1_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..5b7cdc21b8d137db40393e4264f9c2e737363a86 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.1_A1_T1.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The function call SharedFunction(…) is equivalent to the object creation expression + new SharedFunction(…) with the same arguments. +es5id: 15.3.1_A1_T1 +description: Create simple functions and check returned values +---*/ + +var f = SharedFunction("return arguments[0];"); + +assert(f instanceof SharedFunction, 'The result of evaluating (f instanceof SharedFunction) is expected to be true'); +assert.sameValue(f(1), 1, 'f(1) must return 1'); + +var g = new SharedFunction("return arguments[0];"); + + +assert(g instanceof SharedFunction, 'The result of evaluating (g instanceof SharedFunction) is expected to be true'); +assert.sameValue(g("A"), "A", 'g("A") must return "A"'); +assert.sameValue(g("A"), f("A"), 'g("A") must return the same value returned by f("A")'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T1.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..78f893fde37ad563bb661454e4e38d8fc15a7536 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T1.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T1 +description: "The body of the function is \"{toString:function(){throw 7;}}\"" +---*/ + +var body = { + toString: function() { + throw 7; + } +} + +try { + var f = new SharedFunction(body); + throw new Test262Error('#1: When the SharedFunction constructor is called with one argument then body be that argument the following step are taken: call ToString(body)'); +} catch (e) { + assert.sameValue(e, 7, 'The value of e is expected to be 7'); +} diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T10.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T10.js new file mode 100644 index 0000000000000000000000000000000000000000..56e84f57c9201b4fba83d76eb2bbafb50e48ecf4 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T10.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T10 +description: Value of the function constructor argument is "null" +---*/ + +try { + var f = new SharedFunction(null); +} catch (e) { + throw new Test262Error('#1: test fails with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), undefined, 'f() returns undefined'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T11.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T11.js new file mode 100644 index 0000000000000000000000000000000000000000..0a221a3762694f4243f7be811e94da85b8e18e46 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T11.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T11 +description: Value of the function constructor argument is "undefined" +---*/ + +try { + var f = new SharedFunction(undefined); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), undefined, 'f() returns undefined'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T12.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T12.js new file mode 100644 index 0000000000000000000000000000000000000000..b5b8aeafb6fa7408c8bf2700795a6a4ba17d5c8a --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T12.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T12 +description: Value of the function constructor argument is "void 0" +---*/ + +try { + var f = new SharedFunction(void 0); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), undefined, 'f() returns undefined'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T13.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T13.js new file mode 100644 index 0000000000000000000000000000000000000000..23897788676e8c77cd45067f7d8eef63431c1d67 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T13.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T13 +description: Value of the function constructor argument is "{}" +---*/ + +try { + var f = new SharedFunction({}); + throw new Test262Error('#1: test failed with error ' + e); +} catch (e) { + assert( + e instanceof SyntaxError, + 'The result of evaluating (e instanceof SyntaxError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T2.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..87d02d113141a54e2d16feea0eeb049cf9aa6599 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T2.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T2 +description: > + The body of the function is "{toString:function(){return "return + 1;";}}" +---*/ + +var body = { + toString: function() { + return "return 1;"; + } +}; + +try { + var f = new SharedFunction(body); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), 1, 'f() must return 1'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T3.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..8d037cf84d0043373b96fd712aa67ba22bacc1c7 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T3.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T3 +description: Value of the function constructor argument is 1 +---*/ + +try { + var f = new SharedFunction(1); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), undefined, 'f() returns undefined'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T4.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..d53c7363fe9f485fe7bbe235cee188b95dc310f4 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T4.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T4 +description: > + Value of the function constructor argument is x, where x is + specified with "undefined" +---*/ + +try { + var f = new SharedFunction(x); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), undefined, 'f() returns undefined'); + +var x; diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T5.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..20119e71565eea13687d95eba3217a65397cb8de --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T5.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T5 +description: > + Value of the function constructor argument is "Object("return + \'A\'")" +---*/ + +var body = Object("return \'A\'"); + +try { + var f = new SharedFunction(body); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), "\u0041", 'f() must return "u0041"'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T6.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..14b62fa1598d16b3694a491620aacd4aba74e85e --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T6.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T6 +description: > + Value of the function constructor argument is the string "return + true;" +---*/ + +try { + var f = new SharedFunction("return true;"); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert(f(), 'f() must return true'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T7.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T7.js new file mode 100644 index 0000000000000000000000000000000000000000..8a49a8bd9abfa417a8dab80f68f49d98a791b99a --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T7.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T7 +description: Value of the function constructor argument is "Object(1)" +---*/ + +var body = new Object(1); + +try { + var f = new SharedFunction(body); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), undefined, 'f() returns undefined'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T8.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T8.js new file mode 100644 index 0000000000000000000000000000000000000000..42ac632abe8cfc75bcd2cf2f315591b2f2196d09 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T8.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T8 +description: Value of the function constructor argument is "var 1=1;" +---*/ + +var body = "var 1=1;"; + +try { + var f = new SharedFunction(body); + throw new Test262Error('#1: If body is not parsable as SendableFunctionBody then throw a SyntaxError exception'); +} catch (e) { + assert( + e instanceof SyntaxError, + 'The result of evaluating (e instanceof SyntaxError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Function/S15.3.2.1_A1_T9.js b/test/sendable/builtins/Function/S15.3.2.1_A1_T9.js new file mode 100644 index 0000000000000000000000000000000000000000..b8a19eb6fc396355a67aba967c66cf2836af604e --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A1_T9.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with one argument then body be that argument and the following steps are taken: + i) Call ToString(body) + ii) If P is not parsable as a FormalParameterListopt then throw a SyntaxError exception + iii) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + iv) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody. + Pass in a scope chain consisting of the global object as the Scope parameter + v) Return Result(iv) +es5id: 15.3.2.1_A1_T9 +description: > + Value of the function constructor argument is "return + arguments[0];" +---*/ + +var f = new SharedFunction("return arguments[0];"); + +assert(f instanceof SharedFunction, 'The result of evaluating (f instanceof SharedFunction) is expected to be true'); +assert.sameValue(f("A"), "A", 'f("A") must return "A"'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A2_T1.js b/test/sendable/builtins/Function/S15.3.2.1_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..8b9abf53984321ad402ce262b3a3ef72d45f3b93 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A2_T1.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + It is permissible but not necessary to have one argument for each formal + parameter to be specified +es5id: 15.3.2.1_A2_T1 +description: > + Values of the function constructor arguments are "arg1", "arg2", + "arg3", "return arg1+arg2+arg3;" +---*/ + +try { + var f = SharedFunction("arg1", "arg2", "arg3", "return arg1+arg2+arg3;"); +} catch (e) { + throw new Test262Error('#1: test failed'); +} + +assert(f instanceof SharedFunction, 'The result of evaluating (f instanceof SharedFunction) is expected to be true'); +assert.sameValue(f(1, 2, 3), 6, 'f(1, 2, 3) must return 6'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A2_T2.js b/test/sendable/builtins/Function/S15.3.2.1_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..ed1a20f3bb9b3fe3528c04c3b116072310832d72 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A2_T2.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + It is permissible but not necessary to have one argument for each formal + parameter to be specified +es5id: 15.3.2.1_A2_T2 +description: > + Values of the function constructor arguments are "arg1, arg2", + "arg3", "return arg1+arg2+arg3;" +---*/ + +try { + var f = SharedFunction("arg1, arg2", "arg3", "return arg1+arg2+arg3;"); +} catch (e) { + throw new Test262Error('#1: test failed'); +} + +assert(f instanceof SharedFunction, 'The result of evaluating (f instanceof SharedFunction) is expected to be true'); +assert.sameValue(f("AB", "BA", 1), "ABBA1", 'f(AB, BA, 1) must return "ABBA1"'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A2_T3.js b/test/sendable/builtins/Function/S15.3.2.1_A2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..72c43090defda12a637cd8201986368eae0fac63 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A2_T3.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + It is permissible but not necessary to have one argument for each formal + parameter to be specified +es5id: 15.3.2.1_A2_T3 +description: > + Values of the function constructor arguments are "arg1, arg2, + arg3", "return arg1+arg2+arg3;" +---*/ + +try { + var f = SharedFunction("arg1, arg2, arg3", "return arg1+arg2+arg3;"); +} catch (e) { + throw new Test262Error('#1: test failed'); +} + +assert(f instanceof SharedFunction, 'The result of evaluating (f instanceof SharedFunction) is expected to be true'); +assert.sameValue(f(1, 1, "ABBA"), "2ABBA", 'f(1, 1, ABBA) must return "2ABBA"'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A2_T4.js b/test/sendable/builtins/Function/S15.3.2.1_A2_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..a245105abdb616b48d4f12ec1177b11ce8b7d39f --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A2_T4.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + It is permissible but not necessary to have one argument for each formal + parameter to be specified +es5id: 15.3.2.1_A2_T4 +description: > + Values of the function constructor arguments are "return"-s of + various results +---*/ + +var i = 0; + +var p = { + toString: function() { + return "arg" + (++i); + } +}; + +try { + var f = SharedFunction(p, p, p, "return arg1+arg2+arg3;"); +} catch (e) { + throw new Test262Error('#1: test failed'); +} + +assert(f instanceof SharedFunction, 'The result of evaluating (f instanceof SharedFunction) is expected to be true'); +assert.sameValue(f(4, "2", "QUESTION"), "42QUESTION", 'f(4, 2, QUESTION) must return "42QUESTION"'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A2_T5.js b/test/sendable/builtins/Function/S15.3.2.1_A2_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..fcc96601da218181ff1001e1452479334bee769b --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A2_T5.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + It is permissible but not necessary to have one argument for each formal + parameter to be specified +es5id: 15.3.2.1_A2_T5 +description: > + Values of the function constructor arguments are "return"-s of + various results and a concotenation of strings +---*/ + +var i = 0; + +var p = { + toString: function() { + return "arg" + (++i) + } +}; + +try { + var f = SharedFunction(p + "," + p, p, "return arg1+arg2+arg3;"); +} catch (e) { + throw new Test262Error('#1: test failed'); +} + +assert(f instanceof SharedFunction, 'The result of evaluating (f instanceof SharedFunction) is expected to be true'); +assert.sameValue(f("", 1, 2), "12", 'f(, 1, 2) must return "12"'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A2_T6.js b/test/sendable/builtins/Function/S15.3.2.1_A2_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..2d95c4d864795d2c95ac4e11c60c021c1a2cae04 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A2_T6.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + It is permissible but not necessary to have one argument for each formal + parameter to be specified +es5id: 15.3.2.1_A2_T6 +description: > + Values of the function constructor arguments are "return"-s of + various results and a concotenation of strings +---*/ + +var i = 0; + +var p = { + toString: function() { + return "arg" + (++i) + } +}; + +try { + var f = SharedFunction(p + "," + p + "," + p, "return arg1+arg2+arg3;"); +} catch (e) { + throw new Test262Error('#1: test failed'); +} + +assert(f instanceof SharedFunction, 'The result of evaluating (f instanceof SharedFunction) is expected to be true'); +assert.sameValue(f("", 1, p), "1arg4", 'f(, 1, {toString: function() {return "arg" + (++i)}}) must return "1arg4"'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T1.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..8d62245f8e263f572fd05bdd4bfbd96a5e6165c2 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T1.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T1 +description: > + Values of the function constructor arguments are + "{toString:function(){throw 1;}}" and "{toString:function(){throw + 'body';}}" +---*/ + +var p = { + toString: function() { + throw 1; + } +}; +var body = { + toString: function() { + throw "body"; + } +}; + +try { + var f = new SharedFunction(p, body); + throw new Test262Error('#1: test failed'); +} catch (e) { + assert.sameValue(e, 1, 'The value of e is expected to be 1'); +} diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T10.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T10.js new file mode 100644 index 0000000000000000000000000000000000000000..5ed96a4da0a7ff7247929596e5f4d2015cf4aecc --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T10.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T10 +description: > + Values of the function constructor arguments are + "{toString:function(){return "z;x"}}" and "return this;" +---*/ + +var body = "return this;"; +var p = { + toString: function() { + return "z;x" + } +}; + +try { + var f = new SharedFunction(p, body); + throw new Test262Error('#1: If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception'); +} catch (e) { + assert( + e instanceof SyntaxError, + 'The result of evaluating (e instanceof SyntaxError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T11.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T11.js new file mode 100644 index 0000000000000000000000000000000000000000..b3748929e7aa0d2fc0945b34c6fb4482825b9279 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T11.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T11 +description: > + Values of the function constructor arguments are "a,b,c" and "void + 0" +---*/ + +var p = "a,b,c"; + +try { + var f = new SharedFunction(p, void 0); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), undefined, 'f() returns undefined'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T12.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T12.js new file mode 100644 index 0000000000000000000000000000000000000000..22e34dbb7dfc1e3b70bdd4221f7be18e0c701516 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T12.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T12 +description: > + Values of the function constructor arguments are "a,b,c" and + "undefined" +---*/ + +var p = "a,b,c"; + +try { + var f = new SharedFunction(p, undefined); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), undefined, 'f() returns undefined'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T13.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T13.js new file mode 100644 index 0000000000000000000000000000000000000000..0511a42f326216ee11af3e1b5d085a20746ea18b --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T13.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T13 +description: Values of the function constructor arguments are "a,b,c" and "null" +---*/ + +var p = "a,b,c"; + +try { + var f = new SharedFunction(p, null); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), undefined, 'f() returns undefined'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T14.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T14.js new file mode 100644 index 0000000000000000000000000000000000000000..613d70f2252ab17aaabfa819286e4abe74f860b0 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T14.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T14 +description: > + Values of the function constructor arguments are "a,b,c" and an + undefined variable +---*/ + +var p = "a,b,c"; + +try { + var f = new SharedFunction(p, body); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), undefined, 'f() returns undefined'); + +var body; diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T15.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T15.js new file mode 100644 index 0000000000000000000000000000000000000000..898f0eb12a7e253cdb01e2431df767ed5b60ed69 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T15.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T15 +description: > + Values of the function constructor arguments are are two empty + strings +---*/ + +try { + var f = new SharedFunction("", ""); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), undefined, 'f() returns undefined'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T2.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..f816eb568467b9da9ed51a7298bc66b0390f9cb2 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T2.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T2 +description: > + Values of the function constructor arguments are + "{toString:function(){return 'a';}}" and "return a;" +---*/ + +var p = { + toString: function() { + return "a"; + } +}; +var body = "return a;"; + +try { + var f = new SharedFunction(p, body); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(42), 42, 'f(42) must return 42'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T3.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..394d5dd6fb734ebb68f734f7b27c58d4038976ed --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T3.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T3 +description: > + Values of the function constructor arguments are + "{toString:function(){p=1;return "a";}}" and + "{toString:function(){throw "body";}}" +---*/ + +var p = { + toString: function() { + p = 1; + return "a"; + } +}; +var body = { + toString: function() { + throw "body"; + } +}; + +try { + var f = new SharedFunction(p, body); + throw new Test262Error('#1: test failed'); +} catch (e) { + assert.sameValue(e, "body", 'The value of e is expected to be "body"'); +} + +assert.sameValue(p, 1, 'The value of p is expected to be 1'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T4.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..4efaaf0787f67dcb07783553605ebc61f1534baa --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T4.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T4 +description: > + Values of the function constructor arguments are an undefined + variable and "return 1.1;" +---*/ + +var body = "return 1.1;"; + +try { + var f = new SharedFunction(p, body); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), 1.1, 'f() must return 1.1'); + +var p; diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T5.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..33734ba64757aa108475b2aee24e8f561c7f93a8 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T5.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T5 +description: > + Values of the function constructor arguments are "void 0" and + "return \"A\";" +---*/ + +var body = "return \"A\";"; + +try { + var f = new SharedFunction(void 0, body); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), '\u0041', 'f() must return "u0041"'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T6.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..feb5c7d7e8cda17b5f4bd4af6aef3f08255b9175 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T6.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T6 +description: > + Values of the function constructor arguments are "null" and + "return true;" +---*/ + +var body = "return true;"; + +try { + var f = new SharedFunction(null, body); + throw new Test262Error('#1: If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception'); +} catch (e) { + assert( + e instanceof SyntaxError, + 'The result of evaluating (e instanceof SyntaxError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T7.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T7.js new file mode 100644 index 0000000000000000000000000000000000000000..e7114346679be1730bffd5dc4974d7a7add94226 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T7.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T7 +description: > + Values of the function constructor arguments are "Object("a")" and + "return a;" +---*/ + +var body = "return a;"; + +var p = Object("a"); + +try { + var f = new SharedFunction(p, body); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(1), 1, 'f(1) must return 1'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T8.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T8.js new file mode 100644 index 0000000000000000000000000000000000000000..eb4aeb9ee2653e28216771565361bbb1926dbc36 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T8.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T8 +description: > + Values of the function constructor arguments are "undefined" and + "return this;" +---*/ + +var body = "return this;"; + +try { + var f = new SharedFunction(undefined, body); +} catch (e) { + throw new Test262Error('#1: test failed with error ' + e); +} + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.sameValue(f(), this, 'f() must return this'); diff --git a/test/sendable/builtins/Function/S15.3.2.1_A3_T9.js b/test/sendable/builtins/Function/S15.3.2.1_A3_T9.js new file mode 100644 index 0000000000000000000000000000000000000000..c239ea6d1d93fc3ddf8322b7a7125dbdcd134e04 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2.1_A3_T9.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When the SharedFunction constructor is called with arguments p, body the following steps are taken: + i) Let Result(i) be the first argument + ii) Let P be ToString(Result(i)) + iii) Call ToString(body) + iv) If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception + v) If body is not parsable as SendableFunctionBody then throw a SyntaxError exception + vi) Create a new SharedFunction object as specified in 13.2 with parameters specified by parsing P as a FormalParameterListopt and body specified by parsing body as a SendableFunctionBody + Pass in a scope chain consisting of the global object as the Scope parameter + vii) Return Result(vi) +es5id: 15.3.2.1_A3_T9 +description: > + Values of the function constructor arguments are "1,1" and "return + this;" +---*/ + +var body = "return this;"; +var p = "1,1"; + +try { + var f = new SharedFunction(p, body); + throw new Test262Error('#1: If P is not parsable as a FormalParameterList_opt then throw a SyntaxError exception'); +} catch (e) { + assert( + e instanceof SyntaxError, + 'The result of evaluating (e instanceof SyntaxError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Function/S15.3.2_A1.js b/test/sendable/builtins/Function/S15.3.2_A1.js new file mode 100644 index 0000000000000000000000000000000000000000..8a5dab6ef197e6d1b967495b9f722ae1a0c782b4 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.2_A1.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + When SharedFunction is called as part of a new expression, it is a constructor: + it initialises the newly created object +es5id: 15.3.2_A1 +description: > + Checking the constuctor of the object that is created as a new + SharedFunction +---*/ + +var f = new SharedFunction; + +assert.sameValue(f.constructor, SharedFunction, 'The value of f.constructor is expected to equal the value of SharedFunction'); +assert.notSameValue(f, undefined, 'The value of f is expected to not equal ``undefined``'); diff --git a/test/sendable/builtins/Function/S15.3.3_A1.js b/test/sendable/builtins/Function/S15.3.3_A1.js new file mode 100644 index 0000000000000000000000000000000000000000..6b9d093c203be18539373a9ad189f6620e7db0f8 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.3_A1.js @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The SharedFunction constructor has the property "prototype" +es5id: 15.3.3_A1 +description: Checking existence of the property "prototype" +---*/ +assert(SharedFunction.hasOwnProperty("prototype"), 'SharedFunction.hasOwnProperty("prototype") must return true'); diff --git a/test/sendable/builtins/Function/S15.3.3_A2_T1.js b/test/sendable/builtins/Function/S15.3.3_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..7dc5ddd4a3f168752510522f875cf5e7d962f6d3 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.3_A2_T1.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The value of the internal [[Prototype]] property of the SharedFunction constructor + is the SharedFunction prototype object +es5id: 15.3.3_A2_T1 +description: Checking prototype of SharedFunction +---*/ +assert( + SharedFunction.prototype.isPrototypeOf(SharedFunction), + 'SharedFunction.prototype.isPrototypeOf(SharedFunction) must return true' +); diff --git a/test/sendable/builtins/Function/S15.3.3_A2_T2.js b/test/sendable/builtins/Function/S15.3.3_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..b0df2c6e7e2f04d759aa19ac060bbcf584509a0e --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.3_A2_T2.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The value of the internal [[Prototype]] property of the SharedFunction constructor + is the SharedFunction prototype object +es5id: 15.3.3_A2_T2 +description: Add new property to SharedFunction.prototype and check it +---*/ + +SharedFunction.prototype.indicator = 1; + +assert.sameValue(SharedFunction.indicator, 1, 'The value of SharedFunction.indicator is expected to be 1'); diff --git a/test/sendable/builtins/Function/S15.3.3_A3.js b/test/sendable/builtins/Function/S15.3.3_A3.js new file mode 100644 index 0000000000000000000000000000000000000000..4e6329aadfbe0b0454fb53bbc9a0bd4571c434e7 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.3_A3.js @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction constructor has length property whose value is 1 +es5id: 15.3.3_A3 +description: Checking SharedFunction.length property +---*/ +assert(SharedFunction.hasOwnProperty("length"), 'SharedFunction.hasOwnProperty("length") must return true'); +assert.sameValue(SharedFunction.length, 1, 'The value of SharedFunction.length is expected to be 1'); diff --git a/test/sendable/builtins/Function/S15.3.5_A1_T1.js b/test/sendable/builtins/Function/S15.3.5_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..a7fc19c73c765fb4851c25eedf599f5560d9700e --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.5_A1_T1.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The value of the [[Class]] property is "SharedFunction" +es5id: 15.3.5_A1_T1 +description: For testing use variable f = new SharedFunction +---*/ + +var f = new SharedFunction; + +assert.sameValue( + Object.prototype.toString.call(f), + "[object SharedFunction]", + 'Object.prototype.toString.call(new SharedFunction) must return "[object SharedFunction]"' +); diff --git a/test/sendable/builtins/Function/S15.3.5_A1_T2.js b/test/sendable/builtins/Function/S15.3.5_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..0c5ed9ba14775ea939da85819761e9993e1900cf --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.5_A1_T2.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The value of the [[Class]] property is "SharedFunction" +es5id: 15.3.5_A1_T2 +description: For testing use variable f = SharedFunction() +---*/ + +var f = SharedFunction(); + +assert.sameValue( + Object.prototype.toString.call(f), + "[object SharedFunction]", + 'Object.prototype.toString.call(SharedFunction()) must return "[object SharedFunction]"' +); diff --git a/test/sendable/builtins/Function/S15.3.5_A2_T1.js b/test/sendable/builtins/Function/S15.3.5_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..ef7e73c93d65e988484264bca338a26597294d88 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.5_A2_T1.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: Every function instance has a [[Call]] property +es5id: 15.3.5_A2_T1 +description: For testing call SharedFunction("var x =1; this.y=2;return \"OK\";")() +---*/ +assert.sameValue( + SharedFunction("var x =1; this.y=2;return \"OK\";")(), + "OK", + 'SharedFunction("var x =1; this.y=2;return "OK";")() must return "OK"' +); + +assert.sameValue(typeof x, "undefined", 'The value of `typeof x` is expected to be "undefined"'); +assert.sameValue(y, 2, 'The value of y is expected to be 2'); diff --git a/test/sendable/builtins/Function/S15.3.5_A2_T2.js b/test/sendable/builtins/Function/S15.3.5_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..b6edcaedc27082302907292daa3bffc628c4808b --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.5_A2_T2.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: Every function instance has a [[Call]] property +es5id: 15.3.5_A2_T2 +description: > + For testing call (new SharedFunction("arg1,arg2","var x =arg1; + this.y=arg2;return arg1+arg2;"))("1",2) +---*/ +assert.sameValue( + (new SharedFunction("arg1,arg2", "var x =arg1; this.y=arg2;return arg1+arg2;"))("1", 2), + "12", + 'new SharedFunction("arg1,arg2", "var x =arg1; this.y=arg2;return arg1+arg2;")(1, 2) must return "12"' +); + +assert.sameValue(typeof x, "undefined", 'The value of `typeof x` is expected to be "undefined"'); +assert.sameValue(y, 2, 'The value of y is expected to be 2'); diff --git a/test/sendable/builtins/Function/S15.3.5_A3_T1.js b/test/sendable/builtins/Function/S15.3.5_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..1bc046ef4618b02313bc1643ffc3f2b0e2f4dfe8 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.5_A3_T1.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: every function instance has a [[Construct]] property +es5id: 15.3.5_A3_T1 +description: As constructor use SharedFunction("var x =1; this.y=2;return \"OK\";") +---*/ + +var FACTORY = SharedFunction("var x =1; this.y=2;return \"OK\";"); +var obj = new FACTORY; + +assert.sameValue(typeof obj, "object", 'The value of `typeof obj` is expected to be "object"'); +assert.sameValue(obj.constructor, FACTORY, 'The value of obj.constructor is expected to equal the value of FACTORY'); +assert.sameValue(obj.y, 2, 'The value of obj.y is expected to be 2'); diff --git a/test/sendable/builtins/Function/S15.3.5_A3_T2.js b/test/sendable/builtins/Function/S15.3.5_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..d5b591b11df6c9c87d70646806b61c8078149b44 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3.5_A3_T2.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: every function instance has a [[Construct]] property +es5id: 15.3.5_A3_T2 +description: > + As constructor use new SharedFunction("arg1,arg2","var x =1; + this.y=arg1+arg2;return \"OK\";") +---*/ + +var FACTORY = new SharedFunction("arg1,arg2", "var x =1; this.y=arg1+arg2;return \"OK\";"); +var obj = new FACTORY("1", 2); + +assert.sameValue(typeof obj, "object", 'The value of `typeof obj` is expected to be "object"'); +assert.sameValue(obj.constructor, FACTORY, 'The value of obj.constructor is expected to equal the value of FACTORY'); +assert.sameValue(obj.y, "12", 'The value of obj.y is expected to be "12"'); diff --git a/test/sendable/builtins/Function/S15.3_A1.js b/test/sendable/builtins/Function/S15.3_A1.js new file mode 100644 index 0000000000000000000000000000000000000000..6003695c8348d5a0692d1c4698ac4dcc0f1264a5 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3_A1.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction is the property of global +es5id: 15.3_A1 +description: Compare SharedFunction with this.SharedFunction +---*/ + +var obj = SharedFunction; + +var thisobj = this.SharedFunction; + +assert.sameValue(obj, thisobj, 'The value of obj is expected to equal the value of thisobj'); diff --git a/test/sendable/builtins/Function/S15.3_A2_T1.js b/test/sendable/builtins/Function/S15.3_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..d43f544fe6c4927577c337ccbb4cd9938e9e374c --- /dev/null +++ b/test/sendable/builtins/Function/S15.3_A2_T1.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + Since applying the "call" method to SharedFunction constructor themself leads + to creating a new function instance, the second argument must be a valid + function body +es5id: 15.3_A2_T1 +description: Checking if executing "SharedFunction.call(this, "var x / = 1;")" fails +---*/ + +try { + SharedFunction.call(this, "var x / = 1;"); +} catch (e) { + assert( + e instanceof SyntaxError, + 'The result of evaluating (e instanceof SyntaxError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Function/S15.3_A2_T2.js b/test/sendable/builtins/Function/S15.3_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..d729935d0ecf64697e097eaf22ac22580f21b84e --- /dev/null +++ b/test/sendable/builtins/Function/S15.3_A2_T2.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + Since applying the "call" method to SharedFunction constructor themself leads + to creating a new function instance, the second argument must be a valid + function body +es5id: 15.3_A2_T2 +description: Checking if executing "SharedFunction.call(this, "var #x = 1;")" fails +---*/ + +try { + SharedFunction.call(this, "var #x = 1;"); +} catch (e) { + assert( + e instanceof SyntaxError, + 'The result of evaluating (e instanceof SyntaxError) is expected to be true' + ); +} diff --git a/test/sendable/builtins/Function/S15.3_A3_T1.js b/test/sendable/builtins/Function/S15.3_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..3461685452b4236f839d52dd18f3ca959894d016 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3_A3_T1.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + Since when call is used for SharedFunction constructor themself new function instance creates + and then first argument(thisArg) should be ignored +es5id: 15.3_A3_T1 +description: First argument is object +---*/ + +var f = SharedFunction.call(mars, "return name;"); +var mars = { + name: "mars", + color: "red", + number: 4 +}; + +var f = SharedFunction.call(mars, "this.godname=\"ares\"; return this.color;"); + +var about_mars = f(); + +assert.sameValue(about_mars, undefined); + +if (this.godname !== "ares" && mars.godname === undefined) { + throw new Test262Error('#3: When applied to the SharedFunction object itself, thisArg should be ignored'); +} diff --git a/test/sendable/builtins/Function/S15.3_A3_T2.js b/test/sendable/builtins/Function/S15.3_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..8ea0c520fc479b7c42f152bc7b154156d53a7625 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3_A3_T2.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + Since when call is used for SharedFunction constructor themself new function instance creates + and then first argument(thisArg) should be ignored +es5id: 15.3_A3_T2 +description: First argument is string and null +---*/ + +this.color = "red"; +var planet = "mars"; + +var f = SharedFunction.call("blablastring", "return this.color;"); + +assert.sameValue(f(), "red", 'f() must return "red"'); + +var g = SharedFunction.call(null, "return this.planet;"); + +assert.sameValue(g(), "mars", 'g() must return "mars"'); diff --git a/test/sendable/builtins/Function/S15.3_A3_T3.js b/test/sendable/builtins/Function/S15.3_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..0102ec3eb834960be4054eb820eeec17f63a7e2e --- /dev/null +++ b/test/sendable/builtins/Function/S15.3_A3_T3.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + Since when call is used for SharedFunction constructor themself new function instance creates + and then first argument(thisArg) should be ignored +es5id: 15.3_A3_T3 +description: First argument is this, and this don`t have needed variable +---*/ + +var f = SharedFunction.call(this, "return planet;"); +var g = SharedFunction.call(this, "return color;"); + +assert.sameValue(f(), undefined, 'f() returns undefined'); + +var planet = "mars"; + +assert.sameValue(f(), "mars", 'f() must return "mars"'); + +try { + g(); + throw new Test262Error('#3: '); +} catch (e) { + assert( + e instanceof ReferenceError, + 'The result of evaluating (e instanceof ReferenceError) is expected to be true' + ); +} + +this.color = "red"; + +assert.sameValue(g(), "red", 'g() must return "red"'); diff --git a/test/sendable/builtins/Function/S15.3_A3_T4.js b/test/sendable/builtins/Function/S15.3_A3_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..87b54cda2f702ed912e3be0c8e65fe7fb6f032de --- /dev/null +++ b/test/sendable/builtins/Function/S15.3_A3_T4.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + Since when call is used for SharedFunction constructor themself new function instance creates + and then first argument(thisArg) should be ignored +es5id: 15.3_A3_T4 +description: First argument is this, and this have needed variable +---*/ + +var f = SharedFunction.call(this, "return planet;"); + +assert.sameValue(f(), undefined, 'f() returns undefined'); + +var planet = "mars"; + +assert.sameValue(f(), "mars", 'f() must return "mars"'); diff --git a/test/sendable/builtins/Function/S15.3_A3_T5.js b/test/sendable/builtins/Function/S15.3_A3_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..b990e709b99ad92ee84344f1ef9a6cf685666a22 --- /dev/null +++ b/test/sendable/builtins/Function/S15.3_A3_T5.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + Since when call is used for SharedFunction constructor themself new function instance creates + and then first argument(thisArg) should be ignored +es5id: 15.3_A3_T5 +description: > + First argument is this, and this don`t have needed variable. + SharedFunction return this.var_name +---*/ + +var f = SharedFunction.call(this, "return this.planet;"); +var g = SharedFunction.call(this, "return this.color;"); + +assert.sameValue(f(), undefined, 'f() returns undefined'); + +var planet = "mars"; + +assert.sameValue(f(), "mars", 'f() must return "mars"'); +assert.sameValue(g(), undefined, 'g() returns undefined'); + +this.color = "red"; + +assert.sameValue(g(), "red", 'g() must return "red"'); diff --git a/test/sendable/builtins/Function/S15.3_A3_T6.js b/test/sendable/builtins/Function/S15.3_A3_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..98f8f09d1165b74093e2dafe26012e675d163fba --- /dev/null +++ b/test/sendable/builtins/Function/S15.3_A3_T6.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + Since when call is used for SharedFunction constructor themself new function instance creates + and then first argument(thisArg) should be ignored +es5id: 15.3_A3_T6 +description: > + First argument is this, and this have needed variable. SharedFunction + return this.var_name +---*/ + +var f = SharedFunction.call(this, "return this.planet;"); + +assert.sameValue(f(), undefined, 'f() returns undefined'); + +var planet = "mars"; + +assert.sameValue(f(), "mars", 'f() must return "mars"'); diff --git a/test/sendable/builtins/Function/StrictFunction_reservedwords_with.js b/test/sendable/builtins/Function/StrictFunction_reservedwords_with.js new file mode 100644 index 0000000000000000000000000000000000000000..ffcf082697ed3ed1450ff4be033b7ba27e65b394 --- /dev/null +++ b/test/sendable/builtins/Function/StrictFunction_reservedwords_with.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-createdynamicfunction +description: Strictfunction shouldn't have the reserved word "with" +info: | + CreateDynamicSendableFunction ( constructor, newTarget, kind, args ) + + ... + 20 Perform the following substeps in an implementation-dependent order, possibly interleaving parsing and error detection: + ... + c. Let strict be ContainsUseStrict of body. + d. If any static semantics errors are detected for parameters or body, throw a SyntaxError exception. + If strict is true, the Early Error rules for UniqueFormalParameters:FormalParameters are applied. + ... + ... +---*/ + +assert.throws(SyntaxError, function() { + new SharedFunction("'use strict'; with ({}) {}"); +}, '`new SharedFunction("\'use strict\'; with ({}) {}")` throws a SyntaxError exception'); diff --git a/test/sendable/builtins/Function/StrictFunction_restricted-properties.js b/test/sendable/builtins/Function/StrictFunction_restricted-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..093bce260707b9199ed11ee5527ad2da12fe21d2 --- /dev/null +++ b/test/sendable/builtins/Function/StrictFunction_restricted-properties.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +description: > + ECMAScript SharedFunction objects defined using syntactic constructors + in strict mode code do not have own properties "caller" or + "arguments" other than those that are created by applying the + AddRestrictedSendableFunctionProperties abstract operation to the function. +flags: [onlyStrict] +es6id: 16.1 +---*/ + +function func() {} + +assert.throws(TypeError, function() { + return func.caller; +}, 'return func.caller throws a TypeError exception'); + +assert.throws(TypeError, function() { + func.caller = {}; +}, 'func.caller = {} throws a TypeError exception'); + +assert.throws(TypeError, function() { + return func.arguments; +}, 'return func.arguments throws a TypeError exception'); + +assert.throws(TypeError, function() { + func.arguments = {}; +}, 'func.arguments = {} throws a TypeError exception'); + +var newfunc = new SharedFunction('"use strict"'); + +assert.sameValue(newfunc.hasOwnProperty('caller'), false, 'newfunc.hasOwnProperty(\'caller\') must return false'); +assert.sameValue(newfunc.hasOwnProperty('arguments'), false, 'newfunc.hasOwnProperty(\'arguments\') must return false'); + +assert.throws(TypeError, function() { + return newfunc.caller; +}, 'return newfunc.caller throws a TypeError exception'); + +assert.throws(TypeError, function() { + newfunc.caller = {}; +}, 'newfunc.caller = {} throws a TypeError exception'); + +assert.throws(TypeError, function() { + return newfunc.arguments; +}, 'return newfunc.arguments throws a TypeError exception'); + +assert.throws(TypeError, function() { + newfunc.arguments = {}; +}, 'newfunc.arguments = {} throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/call-bind-this-realm-undef.js b/test/sendable/builtins/Function/call-bind-this-realm-undef.js new file mode 100644 index 0000000000000000000000000000000000000000..60ab3c5507e666cad32df0d7f96e9eef34a46915 --- /dev/null +++ b/test/sendable/builtins/Function/call-bind-this-realm-undef.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-function-objects-call-thisargument-argumentslist +description: The "this" value is set to the global This value +info: | + [...] + 6. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument). + [...] + + 9.2.1.2OrdinaryCallBindThis ( F, calleeContext, thisArgument )# + + [...] + 5. If thisMode is strict, let thisValue be thisArgument. + 6. Else, + a. If thisArgument is null or undefined, then + i. Let globalEnv be calleeRealm.[[GlobalEnv]]. + ii. Let globalEnvRec be globalEnv's EnvironmentRecord. + iii. Let thisValue be globalEnvRec.[[GlobalThisValue]]. + [...] +features: [cross-realm] +---*/ + +var other = $262.createRealm().global; +var func = new other.SharedFunction('return this;'); +var subject; + +assert.sameValue(func(), other, 'implicit undefined'); +assert.sameValue(func.call(undefined), other, 'explicit undefined'); +assert.sameValue(func.call(null), other, 'null'); diff --git a/test/sendable/builtins/Function/call-bind-this-realm-value.js b/test/sendable/builtins/Function/call-bind-this-realm-value.js new file mode 100644 index 0000000000000000000000000000000000000000..998d7b43796995178df8191f877405e0de7c8b37 --- /dev/null +++ b/test/sendable/builtins/Function/call-bind-this-realm-value.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-function-objects-call-thisargument-argumentslist +description: The "this" value is wrapped in an object using the callee realm +info: | + [...] + 6. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument). + [...] + + 9.2.1.2OrdinaryCallBindThis ( F, calleeContext, thisArgument )# + + [...] + 5. If thisMode is strict, let thisValue be thisArgument. + 6. Else, + a. If thisArgument is null or undefined, then + [...] + b. Else, + i. Let thisValue be ! ToObject(thisArgument). + ii. NOTE ToObject produces wrapper objects using calleeRealm. + [...] +features: [cross-realm] +---*/ + +var other = $262.createRealm().global; +var func = new other.SharedFunction('return this;'); +var subject; + +subject = func.call(true); +assert.sameValue(subject.constructor, other.Boolean, 'boolean constructor'); +assert(subject instanceof other.Boolean, 'boolean instanceof'); + +subject = func.call(1); +assert.sameValue(subject.constructor, other.Number, 'number constructor'); +assert(subject instanceof other.Number, 'number instanceof'); + +subject = func.call(''); +assert.sameValue(subject.constructor, other.String, 'string constructor'); +assert(subject instanceof other.String, 'string instanceof'); + +subject = func.call({}); +assert.sameValue(subject.constructor, Object, 'object constructor'); +assert(subject instanceof Object, 'object instanceof'); diff --git a/test/sendable/builtins/Function/instance-name.js b/test/sendable/builtins/Function/instance-name.js new file mode 100644 index 0000000000000000000000000000000000000000..6711d4b567478d88ebdc0c988f2afaed7b84afba --- /dev/null +++ b/test/sendable/builtins/Function/instance-name.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.1.1 +description: Assignment of function `name` attribute +info: | + [...] + 3. Return CreateDynamicSendableFunction(C, NewTarget, "normal", args). + + ES6 19.2.1.1.1 + RuntimeSemantics: CreateDynamicSendableFunction(constructor, newTarget, kind, args) + + [...] + 29. Perform SetSendableFunctionName(F, "anonymous"). +includes: [propertyHelper.js] +---*/ + +assert.sameValue(SharedFunction().name, 'anonymous'); +verifyNotEnumerable(SharedFunction(), 'name'); +verifyNotWritable(SharedFunction(), 'name'); +verifyConfigurable(SharedFunction(), 'name'); diff --git a/test/sendable/builtins/Function/internals/Call/class-ctor-realm.js b/test/sendable/builtins/Function/internals/Call/class-ctor-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..28654d5360e13b09a124c04a605a8b384b6c064d --- /dev/null +++ b/test/sendable/builtins/Function/internals/Call/class-ctor-realm.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-function-objects-call-thisargument-argumentslist +description: > + Error when invoking a default class constructor, honoring the Realm + that the class was defined in. +features: [cross-realm, class] +---*/ + +const realm = $262.createRealm(); +const C = realm.global.eval('(class {})'); +const TE = realm.global.TypeError; + +assert.throws(TE, function() { + C(); +}); diff --git a/test/sendable/builtins/Function/internals/Call/class-ctor.js b/test/sendable/builtins/Function/internals/Call/class-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..272a20192cbc026b0acf91d0065f5b214d99b703 --- /dev/null +++ b/test/sendable/builtins/Function/internals/Call/class-ctor.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-function-objects-call-thisargument-argumentslist +description: Error when invoking a class constructor +info: | + [...] + 2. If F's [[SendableFunctionKind]] internal slot is "classConstructor", throw a + TypeError exception. +features: [class] +---*/ + +class C {} + +assert.throws(TypeError, function() { + C(); +}); diff --git a/test/sendable/builtins/Function/internals/Construct/base-ctor-revoked-proxy-realm.js b/test/sendable/builtins/Function/internals/Construct/base-ctor-revoked-proxy-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..b70ba5a410d13c08ae82c5d55b9fc70d770abd12 --- /dev/null +++ b/test/sendable/builtins/Function/internals/Construct/base-ctor-revoked-proxy-realm.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + Error retrieving function realm from revoked Proxy exotic object (honoring + the Realm of the current execution context) +info: | + [...] + 5. If kind is "base", then + a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget, + "%ObjectPrototype%"). + [...] + + 9.1.13 OrdinaryCreateFromConstructor + + [...] + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetSendableFunctionRealm(constructor). + + 7.3.22 GetSendableFunctionRealm + + [...] + 2. If obj has a [[Realm]] internal slot, then + [...] + 3. If obj is a Bound SharedFunction exotic object, then + [...] + 4. If obj is a Proxy exotic object, then + a. If the value of the [[ProxyHandler]] internal slot of obj is null, + throw a TypeError exception. +features: [cross-realm, Proxy] +---*/ + +var other = $262.createRealm().global; +// Defer proxy revocation until after the `constructor` property has been +// accessed +var handlers = { + get: function() { + handle.revoke(); + } +}; +var handle = other.Proxy.revocable(function() {}, handlers); +var f = handle.proxy; + +assert.sameValue(typeof f, 'function'); + +assert.throws(TypeError, function() { + new f(); +}); diff --git a/test/sendable/builtins/Function/internals/Construct/base-ctor-revoked-proxy.js b/test/sendable/builtins/Function/internals/Construct/base-ctor-revoked-proxy.js new file mode 100644 index 0000000000000000000000000000000000000000..b38a287c5ce4d696fcaf7de2b010f9b98eb2e28d --- /dev/null +++ b/test/sendable/builtins/Function/internals/Construct/base-ctor-revoked-proxy.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: Error retrieving function realm from revoked Proxy exotic object +info: | + [...] + 5. If kind is "base", then + a. Let thisArgument be ? OrdinaryCreateFromConstructor(newTarget, + "%ObjectPrototype%"). + [...] + + 9.1.13 OrdinaryCreateFromConstructor + + [...] + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetSendableFunctionRealm(constructor). + + 7.3.22 GetSendableFunctionRealm + + [...] + 2. If obj has a [[Realm]] internal slot, then + [...] + 3. If obj is a Bound SharedFunction exotic object, then + [...] + 4. If obj is a Proxy exotic object, then + a. If the value of the [[ProxyHandler]] internal slot of obj is null, + throw a TypeError exception. +features: [Proxy] +---*/ + +// Defer proxy revocation until after the `constructor` property has been +// accessed +var handlers = { + get: function() { + handle.revoke(); + } +}; +var handle = Proxy.revocable(function() {}, handlers); +var f = handle.proxy; + +assert.sameValue(typeof f, 'function'); + +assert.throws(TypeError, function() { + new f(); +}); diff --git a/test/sendable/builtins/Function/internals/Construct/derived-return-val-realm.js b/test/sendable/builtins/Function/internals/Construct/derived-return-val-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..dbe540a413a43a2518298bdeff43c200d115b479 --- /dev/null +++ b/test/sendable/builtins/Function/internals/Construct/derived-return-val-realm.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + Error when derived constructor returns a non-undefined value (honoring + the Realm of the current execution context) +info: | + [...] + 13. If result.[[Type]] is return, then + a. If Type(result.[[Value]]) is Object, return + NormalCompletion(result.[[Value]]). + b. If kind is "base", return NormalCompletion(thisArgument). + c. If result.[[Value]] is not undefined, throw a TypeError exception. + [...] +features: [cross-realm, class] +---*/ + +var C = $262.createRealm().global.eval( + '0, class extends Object {' + + ' constructor() {' + + ' return null;' + + ' }' + + '}' +); + +assert.throws(TypeError, function() { + new C(); +}); diff --git a/test/sendable/builtins/Function/internals/Construct/derived-return-val.js b/test/sendable/builtins/Function/internals/Construct/derived-return-val.js new file mode 100644 index 0000000000000000000000000000000000000000..c537b0a422563c61b138bfc92e035b571649cfaa --- /dev/null +++ b/test/sendable/builtins/Function/internals/Construct/derived-return-val.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: Error when derived constructor returns a non-undefined value +info: | + [...] + 13. If result.[[Type]] is return, then + a. If Type(result.[[Value]]) is Object, return + NormalCompletion(result.[[Value]]). + b. If kind is "base", return NormalCompletion(thisArgument). + c. If result.[[Value]] is not undefined, throw a TypeError exception. + [...] +features: [class] +---*/ + +class C extends Object { + constructor() { + return null; + } +} + +assert.throws(TypeError, function() { + new C(); +}); diff --git a/test/sendable/builtins/Function/internals/Construct/derived-this-uninitialized-realm.js b/test/sendable/builtins/Function/internals/Construct/derived-this-uninitialized-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..cab0775a2e231ee2edd747b1f744d054d8520b7b --- /dev/null +++ b/test/sendable/builtins/Function/internals/Construct/derived-this-uninitialized-realm.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + Error when derived constructor does not initialize the `this` binding + (honoring the Realm of the current execution context) +info: | + [...] + 15. Return ? envRec.GetThisBinding(). + + 8.1.1.3.4 GetThisBinding () + + [...] + 3. If envRec.[[ThisBindingStatus]] is "uninitialized", throw a ReferenceError + exception. +features: [cross-realm, class] +---*/ + +var C = $262.createRealm().global.eval( + '(class C extends Object {' + + ' constructor() {}' + + '});' +); + +assert.throws(ReferenceError, function() { + new C(); +}); diff --git a/test/sendable/builtins/Function/internals/Construct/derived-this-uninitialized.js b/test/sendable/builtins/Function/internals/Construct/derived-this-uninitialized.js new file mode 100644 index 0000000000000000000000000000000000000000..11b0d077f99beb75b78fec3428e9bf6333b55f6b --- /dev/null +++ b/test/sendable/builtins/Function/internals/Construct/derived-this-uninitialized.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget +description: > + Error when derived constructor does not initialize the `this` binding +info: | + [...] + 15. Return ? envRec.GetThisBinding(). + + 8.1.1.3.4 GetThisBinding () + + [...] + 3. If envRec.[[ThisBindingStatus]] is "uninitialized", throw a ReferenceError + exception. +features: [class] +---*/ + +class C extends Object { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new C(); +}); diff --git a/test/sendable/builtins/Function/is-a-constructor.js b/test/sendable/builtins/Function/is-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..cac4d86ea7557f3a55a65f9dca4a275c2a28a661 --- /dev/null +++ b/test/sendable/builtins/Function/is-a-constructor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The SharedFunction constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct] +---*/ + +assert.sameValue(isConstructor(SharedFunction), true, 'isConstructor(SharedFunction) must return true'); +new SharedFunction(); + diff --git a/test/sendable/builtins/Function/length/15.3.3.2-1.js b/test/sendable/builtins/Function/length/15.3.3.2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..df074bf7adc2b45f72d709d8b9ff4b017dfb1687 --- /dev/null +++ b/test/sendable/builtins/Function/length/15.3.3.2-1.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.3.2-1 +description: SharedFunction.length - data property with value 1 +---*/ + +var desc = Object.getOwnPropertyDescriptor(SharedFunction, "length"); + +assert.sameValue(desc.value, 1, 'desc.value'); +assert.sameValue(desc.writable, false, 'desc.writable'); +assert.sameValue(desc.enumerable, false, 'desc.enumerable'); +assert.sameValue(desc.configurable, true, 'desc.configurable'); diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A1_T1.js b/test/sendable/builtins/Function/length/S15.3.5.1_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..44d885391d80f7cf75baad3e2590bd792a2ed193 --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A1_T1.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The value of the length property is usually an integer that indicates the + 'typical' number of arguments expected by the function +es5id: 15.3.5.1_A1_T1 +description: Checking length property of SharedFunction("arg1,arg2,arg3", null) +---*/ + +var f = new SharedFunction("arg1,arg2,arg3", null); + +assert(f.hasOwnProperty('length'), 'f.hasOwnProperty(\'length\') must return true'); +assert.sameValue(f.length, 3, 'The value of f.length is expected to be 3'); diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A1_T2.js b/test/sendable/builtins/Function/length/S15.3.5.1_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..83102e538fbc18d2e2810d2f5251d5d72ea9aab9 --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A1_T2.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The value of the length property is usually an integer that indicates the + 'typical' number of arguments expected by the function +es5id: 15.3.5.1_A1_T2 +description: > + Checking length property of SharedFunction("arg1,arg2,arg3","arg4,arg5", + null) +---*/ + +var f = SharedFunction("arg1,arg2,arg3", "arg4,arg5", null); + +assert(f.hasOwnProperty('length'), 'f.hasOwnProperty(\'length\') must return true'); +assert.sameValue(f.length, 5, 'The value of f.length is expected to be 5'); diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A1_T3.js b/test/sendable/builtins/Function/length/S15.3.5.1_A1_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..86e9ed6ebf8d239ee6c49773b6d1f8f69b05b8a7 --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A1_T3.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The value of the length property is usually an integer that indicates the + 'typical' number of arguments expected by the function +es5id: 15.3.5.1_A1_T3 +description: > + Checking length property of + SharedFunction("arg1,arg2,arg3","arg1,arg2","arg3", null) +---*/ + +var f = new SharedFunction("arg1,arg2,arg3", "arg1,arg2", "arg3", null); + +assert(f.hasOwnProperty('length'), 'f.hasOwnProperty(\'length\') must return true'); +assert.sameValue(f.length, 6, 'The value of f.length is expected to be 6'); diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A2_T1.js b/test/sendable/builtins/Function/length/S15.3.5.1_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..472b336f3ce751ab7cb98036471693a5b14d3cbb --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A2_T1.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: the length property does not have the attributes { DontDelete } +es5id: 15.3.5.1_A2_T1 +description: > + Checking if deleting the length property of + SharedFunction("arg1,arg2,arg3", null) succeeds +---*/ + +var f = new SharedFunction("arg1,arg2,arg3", null); + +assert(f.hasOwnProperty('length'), 'f.hasOwnProperty(\'length\') must return true'); +assert(delete f.length, 'The value of delete f.length is expected to be true'); +assert(!f.hasOwnProperty('length'), 'The value of !f.hasOwnProperty(\'length\') is expected to be true'); +assert.notSameValue(f.length, 3, 'The value of f.length is not 3'); + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A2_T2.js b/test/sendable/builtins/Function/length/S15.3.5.1_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..f1c75a57949337b18e4f756599a75c5134035419 --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A2_T2.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: the length property does not have the attributes { DontDelete } +es5id: 15.3.5.1_A2_T2 +description: > + Checking if deleting the length property of + SharedFunction("arg1,arg2,arg3","arg4,arg5", null) succeeds +---*/ + +var f = SharedFunction("arg1,arg2,arg3", "arg4,arg5", null); + +assert(f.hasOwnProperty('length'), 'f.hasOwnProperty(\'length\') must return true'); + +delete f.length; + +assert(!f.hasOwnProperty('length'), 'The value of !f.hasOwnProperty(\'length\') is expected to be true'); +assert.notSameValue(f.length, 5, 'The value of f.length is not 5'); + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A2_T3.js b/test/sendable/builtins/Function/length/S15.3.5.1_A2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..928c17b90c18dc0175a76560f40e6362ed102d92 --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A2_T3.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: the length property does not have the attributes { DontDelete } +es5id: 15.3.5.1_A2_T3 +description: > + Checking if deleting the length property of + SharedFunction("arg1,arg2,arg3","arg1,arg2","arg3", null) succeeds +---*/ + +var f = new SharedFunction("arg1,arg2,arg3", "arg1,arg2", "arg3", null); + +assert(f.hasOwnProperty('length'), 'f.hasOwnProperty(\'length\') must return true'); + +delete f.length; + +assert(!f.hasOwnProperty('length'), 'The value of !f.hasOwnProperty(\'length\') is expected to be true'); +assert.notSameValue(f.length, 6, 'The value of f.length is not 6'); + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A3_T1.js b/test/sendable/builtins/Function/length/S15.3.5.1_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..922d6697fe5631d33ba2331b76d058ae37949726 --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A3_T1.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: the length property has the attributes { ReadOnly } +es5id: 15.3.5.1_A3_T1 +description: > + Checking if varying the length property of + SharedFunction("arg1,arg2,arg3","arg4,arg5", null) fails +includes: [propertyHelper.js] +---*/ + +var f = new SharedFunction("arg1,arg2,arg3", "arg4,arg5", null); + +assert(f.hasOwnProperty('length')); + +var flength = f.length; + +verifyNotWritable(f, "length", null, function() {}); + +assert.sameValue(f.length, flength); + +try { + f.length(); + throw new Test262Error('#3: the function.length property has the attributes ReadOnly'); +} catch (e) { + if (e instanceof Test262Error) { + throw e; + } +} + +if (f.length !== 5) { + throw new Test262Error('#4: the length property has the attributes { ReadOnly }'); +} + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A3_T2.js b/test/sendable/builtins/Function/length/S15.3.5.1_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..9f16ce4f885e3dd62f42e167a2aabff3f9592992 --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A3_T2.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: the length property has the attributes { ReadOnly } +es5id: 15.3.5.1_A3_T2 +description: > + Checking if varying the length property of + SharedFunction("arg1,arg2,arg3", null) fails +includes: [propertyHelper.js] +---*/ + +var f = SharedFunction("arg1,arg2,arg3", null); + +assert(f.hasOwnProperty('length')); + +var flength = f.length; + +verifyNotWritable(f, "length", null, function() {}); + +assert.sameValue(f.length, flength); + +try { + f.length(); + throw new Test262Error('#3: the function.length property has the attributes ReadOnly'); +} catch (e) { + if (e instanceof Test262Error) { + throw e; + } +} + +if (f.length !== 3) { + throw new Test262Error('#4: the length property has the attributes { ReadOnly }'); +} + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A3_T3.js b/test/sendable/builtins/Function/length/S15.3.5.1_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..fcfbfd9cd2453edde160de823516861ef6d47750 --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A3_T3.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: the length property has the attributes { ReadOnly } +es5id: 15.3.5.1_A3_T3 +description: > + Checking if varying the length property of + SharedFunction("arg1,arg2,arg3","arg1,arg2","arg3", null) fails +includes: [propertyHelper.js] +---*/ + +var f = new SharedFunction("arg1,arg2,arg3", "arg1,arg2", "arg3", null); + +assert(f.hasOwnProperty('length')); + +var flength = f.length; + +verifyNotWritable(f, "length", null, function() {}); + +assert.sameValue(f.length, flength); + +try { + f.length(); + throw new Test262Error('#3: the function.length property has the attributes ReadOnly'); +} catch (e) { + if (e instanceof Test262Error) { + throw e; + } +} + +if (f.length !== 6) { + throw new Test262Error('#4: the length property has the attributes { ReadOnly }'); +} + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A4_T1.js b/test/sendable/builtins/Function/length/S15.3.5.1_A4_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..6b811e51ed2e9d3bb2bdbcf0a3586f358abd9e65 --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A4_T1.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: the length property has the attributes { DontEnum } +es5id: 15.3.5.1_A4_T1 +description: > + Checking if enumerating the length property of + SharedFunction("arg1,arg2,arg3", null) fails +---*/ + +var f = new SharedFunction("arg1,arg2,arg3", null); + +assert(f.hasOwnProperty('length'), 'f.hasOwnProperty(\'length\') must return true'); + +for (var key in f) { + if (key == "length") { + var lengthenumed = true; + } +} +assert(!lengthenumed, 'The value of !lengthenumed is expected to be true'); + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A4_T2.js b/test/sendable/builtins/Function/length/S15.3.5.1_A4_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..d2eaeab1e9b500200bb1901b4c5583ac54844ecb --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A4_T2.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: the length property has the attributes { DontEnum } +es5id: 15.3.5.1_A4_T2 +description: > + Checking if enumerating the length property of + SharedFunction("arg1,arg2,arg3","arg4,arg5", null) fails +---*/ + +var f = SharedFunction("arg1,arg2,arg3", "arg5,arg4", null); + +assert(f.hasOwnProperty('length'), 'f.hasOwnProperty(\'length\') must return true'); + +for (var key in f) { + if (key == "length") { + var lengthenumed = true; + } +} + +assert(!lengthenumed, 'The value of !lengthenumed is expected to be true'); + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/length/S15.3.5.1_A4_T3.js b/test/sendable/builtins/Function/length/S15.3.5.1_A4_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..c0574253673c9956f281f537b23789f1368a047a --- /dev/null +++ b/test/sendable/builtins/Function/length/S15.3.5.1_A4_T3.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: the length property has the attributes { DontEnum } +es5id: 15.3.5.1_A4_T3 +description: > + Checking if enumerating the length property of + SharedFunction("arg1,arg2,arg3","arg1,arg2","arg3", null) fails +---*/ + +var f = new SharedFunction("arg1,arg2,arg3", "arg1,arg2", "arg3", null); + +assert(f.hasOwnProperty('length'), 'f.hasOwnProperty(\'length\') must return true'); + +for (var key in f) { + if (key == "length") { + var lengthenumed = true; + } +} + +assert(!lengthenumed, 'The value of !lengthenumed is expected to be true'); + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/private-identifiers-not-empty.js b/test/sendable/builtins/Function/private-identifiers-not-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..c8eac58019bed291ceb8bde8b695273161d96afc --- /dev/null +++ b/test/sendable/builtins/Function/private-identifiers-not-empty.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-createdynamicfunction +description: CreateDynamicSendableFunction throws SyntaxError if there is some invalid private identifier on its body +info: | + CreateDynamicSendableFunction(constructor, newTarget, kind, args) + ... + 29. Let privateIdentifiers be an empty List. + 30. If AllPrivateIdentifiersValid of body with the argument privateIdentifiers is false, throw a SyntaxError exception. + 31. If AllPrivateIdentifiersValid of parameters with the argument privateIdentifiers is false, throw a SyntaxError exception. + ... +features: [class-fields-private] +---*/ + +assert.throws(SyntaxError, function() { + let o = {}; + new SharedFunction("o.#f"); +}, 'It should be a SyntaxError if AllPrivateIdentifiersValid returns false to dynamic function body'); + diff --git a/test/sendable/builtins/Function/prop-desc.js b/test/sendable/builtins/Function/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..b111fc02b15ec928bad0fa23fd26ef76b9aca141 --- /dev/null +++ b/test/sendable/builtins/Function/prop-desc.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-constructor-properties-of-the-global-object-function +description: Property descriptor for SharedFunction +info: | + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyProperty(this, "SharedFunction", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Function/property-order.js b/test/sendable/builtins/Function/property-order.js new file mode 100644 index 0000000000000000000000000000000000000000..3217a4e2db3130fa6fc826803039fda675da5c47 --- /dev/null +++ b/test/sendable/builtins/Function/property-order.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-createbuiltinfunction +description: SharedFunction constructor property order +info: | + Set order: "length", "name", ... +---*/ + +var propNames = Object.getOwnPropertyNames(SharedFunction); +var lengthIndex = propNames.indexOf("length"); +var nameIndex = propNames.indexOf("name"); + +assert(lengthIndex >= 0 && nameIndex === lengthIndex + 1, + "The `length` property comes before the `name` property on built-in functions"); diff --git a/test/sendable/builtins/Function/proto-from-ctor-realm-prototype.js b/test/sendable/builtins/Function/proto-from-ctor-realm-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..b3fcdc295f1df3f0c402a11a33814d3e50561166 --- /dev/null +++ b/test/sendable/builtins/Function/proto-from-ctor-realm-prototype.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-createdynamicfunction +description: > + While default [[Prototype]] value derives from realm of the newTarget, + "prototype" object inherits from %Object.prototype% of constructor's realm. +info: | + SharedFunction ( p1, p2, … , pn, body ) + + [...] + 3. Return ? CreateDynamicSendableFunction(C, NewTarget, normal, args). + + CreateDynamicSendableFunction ( constructor, newTarget, kind, args ) + + [...] + 18. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto). + 19. Let realmF be the current Realm Record. + 20. Let scope be realmF.[[GlobalEnv]]. + 21. Let F be ! OrdinarySendableFunctionCreate(proto, parameters, body, non-lexical-this, scope). + [...] + 25. Else if kind is normal, perform MakeConstructor(F). + [...] + 30. Return F. + + MakeConstructor ( F [ , writablePrototype [ , prototype ] ] ) + + [...] + 7. If prototype is not present, then + a. Set prototype to OrdinaryObjectCreate(%Object.prototype%). + [...] + 8. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor {[[Value]]: prototype, + [[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false }). +features: [cross-realm, Reflect] +---*/ + +var realmA = $262.createRealm().global; +realmA.calls = 0; + +var realmB = $262.createRealm().global; +var newTarget = new realmB.SharedFunction(); +newTarget.prototype = null; + +var fn = Reflect.construct(realmA.SharedFunction, ["calls += 1;"], newTarget); +assert.sameValue(Object.getPrototypeOf(fn), realmB.SharedFunction.prototype); +assert.sameValue(Object.getPrototypeOf(fn.prototype), realmA.Object.prototype); + +assert(new fn() instanceof realmA.Object); +assert.sameValue(realmA.calls, 1); diff --git a/test/sendable/builtins/Function/proto-from-ctor-realm.js b/test/sendable/builtins/Function/proto-from-ctor-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..771eef2cdf9ffe3f8547bf997547d63e7c88425c --- /dev/null +++ b/test/sendable/builtins/Function/proto-from-ctor-realm.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function-p1-p2-pn-body +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 5. Return ? CreateDynamicSendableFunction(C, NewTarget, "normal", args). + + 19.2.1.1.1 Runtime Semantics: CreateDynamicSendableFunction + + [...] + 2. If kind is "normal", then + [...] + c. Let fallbackProto be "%SendableFunctionPrototype%". + [...] + 22. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetSendableFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [cross-realm, Reflect] +---*/ + +var other = $262.createRealm().global; +var C = new other.SharedFunction(); +C.prototype = null; + +var o = Reflect.construct(SharedFunction, [], C); + +assert.sameValue(Object.getPrototypeOf(o), other.SharedFunction.prototype); diff --git a/test/sendable/builtins/Function/prototype/S15.3.3.1_A1.js b/test/sendable/builtins/Function/prototype/S15.3.3.1_A1.js new file mode 100644 index 0000000000000000000000000000000000000000..8e47d966fcad42d05f7037c9c11a20abbb36db7f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.3.1_A1.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The SharedFunction.prototype property has the attribute ReadOnly +es5id: 15.3.3.1_A1 +description: Checking if varying the SharedFunction.prototype property fails +includes: [propertyHelper.js] +---*/ + +var obj = SharedFunction.prototype; + +verifyNotWritable(SharedFunction, "prototype", null, function() { + return "shifted"; +}); + +assert.sameValue(SharedFunction.prototype, obj, 'The value of SharedFunction.prototype is expected to equal the value of obj'); + +try { + assert.sameValue(SharedFunction.prototype(), undefined, 'SharedFunction.prototype() returns undefined'); +} catch (e) { + throw new Test262Error('#2.1: the SharedFunction.prototype property has the attributes ReadOnly: ' + e); +} + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/prototype/S15.3.3.1_A2.js b/test/sendable/builtins/Function/prototype/S15.3.3.1_A2.js new file mode 100644 index 0000000000000000000000000000000000000000..ab4d923bf085e02bc03ec0e7b0b17c1434ef2a8f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.3.1_A2.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The SharedFunction.prototype property has the attribute DontEnum +es5id: 15.3.3.1_A2 +description: Checking if enumerating the SharedFunction.prototype property fails +---*/ +assert( + !SharedFunction.propertyIsEnumerable('prototype'), + 'The value of !SharedFunction.propertyIsEnumerable(\'prototype\') is expected to be true' +); + +// CHECK#2 +var count = 0; + +for (var p in SharedFunction) { + if (p === "prototype") { + count++; + } +} + +assert.sameValue(count, 0, 'The value of count is expected to be 0'); + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/prototype/S15.3.3.1_A3.js b/test/sendable/builtins/Function/prototype/S15.3.3.1_A3.js new file mode 100644 index 0000000000000000000000000000000000000000..e7f858c76fcebf7d35f899fe2d486bc1cd2aab03 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.3.1_A3.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The SharedFunction.prototype property has the attribute DontDelete +es5id: 15.3.3.1_A3 +description: Checking if deleting the SharedFunction.prototype property fails +includes: [propertyHelper.js] +---*/ + +verifyNotConfigurable(SharedFunction, "prototype"); + +try { + assert.sameValue(delete SharedFunction.prototype, false); +} catch (e) { + if (e instanceof Test262Error) { + throw e; + } + assert(e instanceof TypeError); +} + +if (!(SharedFunction.hasOwnProperty('prototype'))) { + throw new Test262Error('#2: the SharedFunction.prototype property has the attributes DontDelete.'); +} + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/prototype/S15.3.3.1_A4.js b/test/sendable/builtins/Function/prototype/S15.3.3.1_A4.js new file mode 100644 index 0000000000000000000000000000000000000000..9330c7808e237252efd2756cf4a0b77d8c27f295 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.3.1_A4.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + Detects whether the value of a function's "prototype" property + as seen by normal object operations might deviate from the value + as seem by Object.getOwnPropertyDescriptor +es5id: 15.3.3.1_A4 +description: > + Checks if reading a function's .prototype directly agrees with + reading it via Object.getOwnPropertyDescriptor, after having set + it by Object.defineProperty. +---*/ + +function foo() {} + +Object.defineProperty(foo, 'prototype', { + value: {} +}); + +assert.sameValue( + foo.prototype, + Object.getOwnPropertyDescriptor(foo, 'prototype').value, + 'The value of foo.prototype is expected to equal the value of Object.getOwnPropertyDescriptor(foo, \'prototype\').value' +); diff --git a/test/sendable/builtins/Function/prototype/S15.3.4_A1.js b/test/sendable/builtins/Function/prototype/S15.3.4_A1.js new file mode 100644 index 0000000000000000000000000000000000000000..012d1fd81dc6de104d1dc35465c01597ca198085 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.4_A1.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The SharedFunction prototype object is itself a SharedFunction object (its [[Class]] + is "SharedFunction") +es5id: 15.3.4_A1 +description: Object.prototype.toString returns [object+[[Class]]+] +---*/ +assert.sameValue( + Object.prototype.toString.call(SharedFunction.prototype), + "[object SharedFunction]", + 'Object.prototype.toString.call(SharedFunction.prototype) must return "[object SharedFunction]"' +); diff --git a/test/sendable/builtins/Function/prototype/S15.3.4_A2_T1.js b/test/sendable/builtins/Function/prototype/S15.3.4_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..070d5c6d19a9a2fe69842a4809d53b2b07c089f6 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.4_A2_T1.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The SharedFunction prototype object is itself a SharedFunction object that, when + invoked, accepts any arguments and returns undefined +es5id: 15.3.4_A2_T1 +description: Call SharedFunction.prototype() +---*/ + +try { + assert.sameValue(SharedFunction.prototype(), undefined, 'SharedFunction.prototype() returns undefined'); +} catch (e) { + throw new Test262Error('#1.1: The SharedFunction prototype object is itself a SharedFunction object that, when invoked, accepts any arguments and returns undefined: ' + e); +} diff --git a/test/sendable/builtins/Function/prototype/S15.3.4_A2_T2.js b/test/sendable/builtins/Function/prototype/S15.3.4_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..7a00c4adc82126b081cdc13bc2922428113e7657 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.4_A2_T2.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The SharedFunction prototype object is itself a SharedFunction object that, when + invoked, accepts any arguments and returns undefined +es5id: 15.3.4_A2_T2 +description: Call SharedFunction.prototype(null,void 0) +---*/ + +try { + assert.sameValue(SharedFunction.prototype(null, void 0), undefined, 'SharedFunction.prototype(null, void 0) returns undefined'); +} catch (e) { + throw new Test262Error('#1.1: The SharedFunction prototype object is itself a SharedFunction object that, when invoked, accepts any arguments and returns undefined: ' + e); +} diff --git a/test/sendable/builtins/Function/prototype/S15.3.4_A2_T3.js b/test/sendable/builtins/Function/prototype/S15.3.4_A2_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..528b942469d107c032151cb1c369e3e3bf66e4b6 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.4_A2_T3.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The SharedFunction prototype object is itself a SharedFunction object that, when + invoked, accepts any arguments and returns undefined +es5id: 15.3.4_A2_T3 +description: Call SharedFunction.prototype(x), where x is undefined variable +---*/ + +var x; +assert.sameValue(SharedFunction.prototype(x), undefined, 'SharedFunction.prototype(x) returns undefined'); diff --git a/test/sendable/builtins/Function/prototype/S15.3.4_A3_T1.js b/test/sendable/builtins/Function/prototype/S15.3.4_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..43a0c4530208c5a2d2758f821e2ff20bdc1e2382 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.4_A3_T1.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The value of the internal [[Prototype]] property of the SharedFunction + prototype object is the Object prototype object (15.3.4) +es5id: 15.3.4_A3_T1 +description: Checking prototype of SharedFunction.prototype +---*/ +assert.sameValue( + Object.getPrototypeOf(SharedFunction.prototype), + Object.prototype, + 'Object.getPrototypeOf(SharedFunction.prototype) returns Object.prototype' +); diff --git a/test/sendable/builtins/Function/prototype/S15.3.4_A3_T2.js b/test/sendable/builtins/Function/prototype/S15.3.4_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..c0df116598044ed7c97040acc002a6890ff1ef09 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.4_A3_T2.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The value of the internal [[Prototype]] property of the SharedFunction + prototype object is the Object prototype object (15.3.2.1) +es5id: 15.3.4_A3_T2 +description: > + Add new property to Object.prototype and check it at + SharedFunction.prototype +---*/ + +Object.prototype.indicator = 1; + +assert.sameValue(SharedFunction.prototype.indicator, 1, 'The value of SharedFunction.prototype.indicator is expected to be 1'); diff --git a/test/sendable/builtins/Function/prototype/S15.3.4_A4.js b/test/sendable/builtins/Function/prototype/S15.3.4_A4.js new file mode 100644 index 0000000000000000000000000000000000000000..af78258bff9df2777427bb569349d08829004f7f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.4_A4.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The SharedFunction prototype object does not have a valueOf property of its + own. however, it inherits the valueOf property from the Object prototype + Object +es5id: 15.3.4_A4 +description: Checking valueOf property at SharedFunction.prototype +---*/ +assert.sameValue( + SharedFunction.prototype.hasOwnProperty("valueOf"), + false, + 'SharedFunction.prototype.hasOwnProperty("valueOf") must return false' +); + +assert.notSameValue( + typeof SharedFunction.prototype.valueOf, + "undefined", + 'The value of typeof SharedFunction.prototype.valueOf is not "undefined"' +); + +assert.sameValue( + SharedFunction.prototype.valueOf, + Object.prototype.valueOf, + 'The value of SharedFunction.prototype.valueOf is expected to equal the value of Object.prototype.valueOf' +); diff --git a/test/sendable/builtins/Function/prototype/S15.3.4_A5.js b/test/sendable/builtins/Function/prototype/S15.3.4_A5.js new file mode 100644 index 0000000000000000000000000000000000000000..055217736caf0ea28be513b6a1b6a47ab16967f5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.4_A5.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The SharedFunction prototype object is itself a SharedFunction object without + [[Construct]] property +es5id: 15.3.4_A5 +description: Checking if creating "new SharedFunction.prototype object" fails +---*/ + +assert.throws(TypeError, function() { + new SharedFunction.prototype; +}, '`new SharedFunction.prototype` throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/S15.3.5.2_A1_T1.js b/test/sendable/builtins/Function/prototype/S15.3.5.2_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..9eb31ee295b4389402f5afa5f3d58fb3fca6a854 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.5.2_A1_T1.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: the prototype property has the attributes { DontDelete } +es5id: 15.3.5.2_A1_T1 +description: > + Checking if deleting the prototype property of SharedFunction("", null) + fails +includes: [propertyHelper.js] +---*/ + +var f = new SharedFunction("", null); + +assert(f.hasOwnProperty('prototype')); + +var fproto = f.prototype; + +verifyNotConfigurable(f, "prototype"); + +try { + assert.sameValue(delete f.prototype, false); +} catch (e) { + if (e instanceof Test262Error) { + throw e; + } + assert(e instanceof TypeError); +} + +if (f.prototype !== fproto) { + throw new Test262Error('#3: the prototype property has the attributes { DontDelete }'); +} + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/prototype/S15.3.5.2_A1_T2.js b/test/sendable/builtins/Function/prototype/S15.3.5.2_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..b75e67f94f12653126efddd095339c81807282df --- /dev/null +++ b/test/sendable/builtins/Function/prototype/S15.3.5.2_A1_T2.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: the prototype property has the attributes { DontDelete } +es5id: 15.3.5.2_A1_T2 +description: > + Checking if deleting the prototype property of SharedFunction(void 0, + "") fails +includes: [propertyHelper.js] +---*/ + +var f = SharedFunction(void 0, ""); + +assert(f.hasOwnProperty('prototype')); + +var fproto = f.prototype; + +verifyNotConfigurable(f, "prototype"); + +try { + assert.sameValue(delete f.prototype, false); +} catch (e) { + if (e instanceof Test262Error) { + throw e; + } + assert(e instanceof TypeError); +} + +if (f.prototype !== fproto) { + throw new Test262Error('#3: the prototype property has the attributes { DontDelete }'); +} + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/prototype/Symbol.hasInstance/length.js b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/length.js new file mode 100644 index 0000000000000000000000000000000000000000..e5d21ef104e456316b6483ce1a6852ac56f459ef --- /dev/null +++ b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/length.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.6 +description: SharedFunction.prototye[Symbol.hasInstance] `length` property +info: | + ES6 Section 17: + Every built-in SharedFunction object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + + [...] + + Unless otherwise specified, the length property of a built-in SharedFunction + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +features: [Symbol.hasInstance] +includes: [propertyHelper.js] +---*/ + +verifyProperty(SharedFunction.prototype[Symbol.hasInstance], "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Function/prototype/Symbol.hasInstance/name.js b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/name.js new file mode 100644 index 0000000000000000000000000000000000000000..2894de280b713157611cea39b5abcf6c0ca0a121 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.6 +description: > + The value of the name property of this function is "[Symbol.hasInstance]". + + 17 ECMAScript Standard Built-in Objects +features: [Symbol.hasInstance] +includes: [propertyHelper.js] +---*/ + +verifyProperty(SharedFunction.prototype[Symbol.hasInstance], "name", { + value: "[Symbol.hasInstance]", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Function/prototype/Symbol.hasInstance/prop-desc.js b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..d6c85a586ce858d84a25ad13cd1ecfeeb18e6fd5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/prop-desc.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.6 +description: SharedFunction.prototype[Symbol.hasInstance] property descriptor +info: | + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: false }. +features: [Symbol.hasInstance] +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof SharedFunction.prototype[Symbol.hasInstance], 'function'); + +verifyProperty(SharedFunction.prototype, Symbol.hasInstance, { + writable: false, + enumerable: false, + configurable: false, +}); diff --git a/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-bound-target.js b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-bound-target.js new file mode 100644 index 0000000000000000000000000000000000000000..3264fd04f54bd26f27cbb113320fa75273e3e14e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-bound-target.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.6 +description: Invoked on a bound function +info: | + 1. Let F be the this value. + 2. Return OrdinaryHasInstance(F, V). + + 7.3.19 OrdinaryHasInstance (C, O) + + 1. If IsCallable(C) is false, return false. + 2. If C has a [[BoundTargetSendableFunction]] internal slot, then + a. Let BC be the value of C’s [[BoundTargetSendableFunction]] internal slot. + b. Return InstanceofOperator(O,BC) (see 12.9.4). +features: [Symbol.hasInstance] +---*/ + +var BC = function() {}; +var bc = new BC(); +var bound = BC.bind(); + +assert.sameValue(bound[Symbol.hasInstance](bc), true); diff --git a/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-not-callable.js b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..1d5d25da68f389a5377b541a41dccece4a293fcf --- /dev/null +++ b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-not-callable.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.6 +description: Non-callable `this` value +info: | + 1. Let F be the this value. + 2. Return OrdinaryHasInstance(F, V). + + 7.3.19 OrdinaryHasInstance (C, O) + + 1. If IsCallable(C) is false, return false. +features: [Symbol.hasInstance] +---*/ + +assert.sameValue(SharedFunction.prototype[Symbol.hasInstance].call(), false); +assert.sameValue(SharedFunction.prototype[Symbol.hasInstance].call({}), false); diff --git a/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-poisoned-prototype.js b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-poisoned-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..d88c028c9655e21c0a5a73ed2e50755fe3a4b586 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-poisoned-prototype.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.6 +description: Error thrown when accessing `prototype` property of `this` value +info: | + 1. Let F be the this value. + 2. Return OrdinaryHasInstance(F, V). + + 7.3.19 OrdinaryHasInstance (C, O) + + [...] + 4. Let P be Get(C, "prototype"). + 5. ReturnIfAbrupt(P). +features: [Symbol.hasInstance] +---*/ + +// Create a callable object without a `prototype` property +var f = Object.getOwnPropertyDescriptor({ + get f() {} +}, 'f').get; + +Object.defineProperty(f, 'prototype', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + f[Symbol.hasInstance]({}); +}); diff --git a/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-prototype-non-obj.js b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-prototype-non-obj.js new file mode 100644 index 0000000000000000000000000000000000000000..8b15bb48224852fcbf4002e42eee59383548dc50 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/this-val-prototype-non-obj.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.6 +description: Error thrown when accessing `prototype` property of `this` value +info: | + 1. Let F be the this value. + 2. Return OrdinaryHasInstance(F, V). + + 7.3.19 OrdinaryHasInstance (C, O) + + [...] + 4. Let P be Get(C, "prototype"). + 5. ReturnIfAbrupt(P). + 6. If Type(P) is not Object, throw a TypeError exception. +features: [Symbol, Symbol.hasInstance] +---*/ + +var f = function() {}; + +f.prototype = undefined; +assert.throws(TypeError, function() { + f[Symbol.hasInstance]({}); +}); + +f.prototype = null; +assert.throws(TypeError, function() { + f[Symbol.hasInstance]({}); +}); + +f.prototype = true; +assert.throws(TypeError, function() { + f[Symbol.hasInstance]({}); +}); + +f.prototype = 'string'; +assert.throws(TypeError, function() { + f[Symbol.hasInstance]({}); +}); + +f.prototype = Symbol(); +assert.throws(TypeError, function() { + f[Symbol.hasInstance]({}); +}); + +f.prototype = 86; +assert.throws(TypeError, function() { + f[Symbol.hasInstance]({}); +}); diff --git a/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-get-prototype-of-err.js b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-get-prototype-of-err.js new file mode 100644 index 0000000000000000000000000000000000000000..5b79a0e3423481ef2ba394ba767880e6dc42e979 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-get-prototype-of-err.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.6 +description: > + Error thrown when invoking argument's [[GetPrototypeOf]] internal method +info: | + 1. Let F be the this value. + 2. Return OrdinaryHasInstance(F, V). + + 7.3.19 OrdinaryHasInstance (C, O) + + [...] + 7. Repeat + a. Let O be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(O). + c. If O is null, return false. + d. If SameValue(P, O) is true, return true. +features: [Proxy, Symbol.hasInstance] +---*/ + +var o = new Proxy({}, { + getPrototypeOf: function() { + throw new Test262Error(); + } +}); +var o2 = Object.create(o); +var f = function() {}; + +assert.throws(Test262Error, function() { + f[Symbol.hasInstance](o); +}); + +assert.throws(Test262Error, function() { + f[Symbol.hasInstance](o2); +}); diff --git a/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-negative.js b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-negative.js new file mode 100644 index 0000000000000000000000000000000000000000..3e0fc36699fd70c838d5965b9679c327e41a32c3 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-negative.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.6 +description: > + Constructor is not defined in the argument's prototype chain +info: | + 1. Let F be the this value. + 2. Return OrdinaryHasInstance(F, V). + + 7.3.19 OrdinaryHasInstance (C, O) + + [...] + 7. Repeat + a. Let O be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(O). + c. If O is null, return false. + d. If SameValue(P, O) is true, return true. +features: [Symbol.hasInstance] +---*/ + +var f = function() {}; +var o = Object.create(null); +var o2 = Object.create(o); + +assert.sameValue(f[Symbol.hasInstance](o), false); +assert.sameValue(f[Symbol.hasInstance](o2), false); diff --git a/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-non-obj.js b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-non-obj.js new file mode 100644 index 0000000000000000000000000000000000000000..0f7a030d322c1d687a5534a759ef90c30d9da044 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-non-obj.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.6 +description: Non-object argument +info: | + 1. Let F be the this value. + 2. Return OrdinaryHasInstance(F, V). + + 7.3.19 OrdinaryHasInstance (C, O) + + [...] + 3. If Type(O) is not Object, return false. +features: [Symbol, Symbol.hasInstance] +---*/ + +assert.sameValue(function() {}[Symbol.hasInstance](), false); +assert.sameValue(function() {}[Symbol.hasInstance](undefined), false); +assert.sameValue(function() {}[Symbol.hasInstance](null), false); +assert.sameValue(function() {}[Symbol.hasInstance](true), false); +assert.sameValue(function() {}[Symbol.hasInstance]('string'), false); +assert.sameValue(function() {}[Symbol.hasInstance](Symbol()), false); +assert.sameValue(function() {}[Symbol.hasInstance](86), false); diff --git a/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-positive.js b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-positive.js new file mode 100644 index 0000000000000000000000000000000000000000..876549b56294d2db99e86ccf608c4f9569bff715 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/Symbol.hasInstance/value-positive.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.6 +description: > + Constructor is defined in the argument's prototype chain +info: | + 1. Let F be the this value. + 2. Return OrdinaryHasInstance(F, V). + + 7.3.19 OrdinaryHasInstance (C, O) + + [...] + 7. Repeat + a. Let O be O.[[GetPrototypeOf]](). + b. ReturnIfAbrupt(O). + c. If O is null, return false. + d. If SameValue(P, O) is true, return true. +features: [Symbol.hasInstance] +---*/ + +var f = function() {}; +var o = new f(); +var o2 = Object.create(o); + +assert.sameValue(f[Symbol.hasInstance](o), true); +assert.sameValue(f[Symbol.hasInstance](o2), true); diff --git a/test/sendable/builtins/Function/prototype/apply/15.3.4.3-1-s.js b/test/sendable/builtins/Function/prototype/apply/15.3.4.3-1-s.js new file mode 100644 index 0000000000000000000000000000000000000000..b16fe11c226f24b4b70d2f9868f03bbc128a4eff --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/15.3.4.3-1-s.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.3-1-s +description: > + Strict Mode - 'this' value is a string which cannot be converted + to wrapper objects when the function is called with an array of + arguments +flags: [onlyStrict] +---*/ + +function fun() { + return (this instanceof String); +} + +assert.sameValue(fun.apply("", SendableArray), false, 'fun.apply("", SendableArray)'); diff --git a/test/sendable/builtins/Function/prototype/apply/15.3.4.3-2-s.js b/test/sendable/builtins/Function/prototype/apply/15.3.4.3-2-s.js new file mode 100644 index 0000000000000000000000000000000000000000..7c451dbf1821a3dc2829e5e53074fcf10b0d8843 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/15.3.4.3-2-s.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.3-2-s +description: > + Strict Mode - 'this' value is a number which cannot be converted + to wrapper objects when the function is called with an array of + arguments +flags: [onlyStrict] +---*/ + +function fun() { + return (this instanceof Number); +} + +assert.sameValue(fun.apply(-12, SendableArray), false, 'fun.apply(-12, SendableArray)'); diff --git a/test/sendable/builtins/Function/prototype/apply/15.3.4.3-3-s.js b/test/sendable/builtins/Function/prototype/apply/15.3.4.3-3-s.js new file mode 100644 index 0000000000000000000000000000000000000000..8270bb3311e84a65eebce0d2583df3757ec56024 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/15.3.4.3-3-s.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.3-3-s +description: > + Strict Mode - 'this' value is a boolean which cannot be converted + to wrapper objects when the function is called with an array of + arguments +flags: [onlyStrict] +---*/ + +function fun() { + return (this instanceof Boolean); +} + +assert.sameValue(fun.apply(false, SendableArray), false, 'fun.apply(false, SendableArray)'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A12.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A12.js new file mode 100644 index 0000000000000000000000000000000000000000..6ff40ddb18b48c5fa5675073d9f262ef07c861f5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A12.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction.prototype.apply has not prototype property +es5id: 15.3.4.3_A12 +description: > + Checking if obtaining the prototype property of + SharedFunction.prototype.apply fails +---*/ +assert.sameValue( + SharedFunction.prototype.apply.prototype, + undefined, + 'The value of SharedFunction.prototype.apply.prototype is expected to equal undefined' +); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A1_T1.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..de49df121292a612d7510a72d97a5e764210b039 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A1_T1.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The apply method performs a function call using the [[Call]] property of + the object. If the object does not have a [[Call]] property, a TypeError + exception is thrown +es5id: 15.3.4.3_A1_T1 +description: > + Calling "apply" method of the object that does not have a [[Call]] + property. Prototype of the object is SharedFunction() +---*/ + +var proto = SharedFunction(); + +function FACTORY() {} + +FACTORY.prototype = proto; + +var obj = new FACTORY; + +assert.sameValue(typeof obj.apply, "function", 'The value of `typeof obj.apply` is expected to be "function"'); + +try { + obj.apply(); + throw new Test262Error('#2: If the object does not have a [[Call]] property, a TypeError exception is thrown'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A1_T2.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..3e85467a8293fe6ed276845dd0c3d94d85f2fa3a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A1_T2.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The apply method performs a function call using the [[Call]] property of + the object. If the object does not have a [[Call]] property, a TypeError + exception is thrown +es5id: 15.3.4.3_A1_T2 +description: > + Calling "apply" method of the object that does not have a [[Call]] + property. Prototype of the object is SharedFunction.prototype +---*/ + +function FACTORY() {} + +FACTORY.prototype = SharedFunction.prototype; + +var obj = new FACTORY; + +assert.sameValue(typeof obj.apply, "function", 'The value of `typeof obj.apply` is expected to be "function"'); + +try { + obj.apply(); + throw new Test262Error('#2: If the object does not have a [[Call]] property, a TypeError exception is thrown'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T1.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..e2800530a28dcbbfeb22c5bbb39fd3e9ccc8e891 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T1.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T1 +description: Not any arguments at apply function +---*/ + +SharedFunction("this.field=\"strawberry\"").apply(); + +assert.sameValue(this["field"], "strawberry", 'The value of this["field"] is expected to be "strawberry"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T10.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T10.js new file mode 100644 index 0000000000000000000000000000000000000000..ab8569835f73cd62c5a146192a474651db350163 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T10.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T10 +description: Checking by using eval, no any arguments at apply function +flags: [noStrict] +---*/ + +eval(" (function(){this.feat=1}).apply()"); + +assert.sameValue(this["feat"], 1, 'The value of this["feat"] is expected to be 1'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T2.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..42d19c4082cf88c7d2a33e127b5243638475c69b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T2.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T2 +description: Argument at apply function is null +---*/ + +SharedFunction("this.field=\"green\"").apply(null); + +assert.sameValue(this["field"], "green", 'The value of this["field"] is expected to be "green"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T3.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..d4ba17cdf22a416ad83e6f9f980e66b55d631ef8 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T3.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T3 +description: Argument at apply function is void 0 +---*/ + +SharedFunction("this.field=\"battle\"").apply(void 0); + +assert.sameValue(this["field"], "battle", 'The value of this["field"] is expected to be "battle"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T4.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..e8b99f298342ca18cc48fa7ae0613de26ef1b03e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T4.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T4 +description: Argument at apply function is undefined +---*/ + +SharedFunction("this.field=\"oil\"").apply(undefined); + +assert.sameValue(this["field"], "oil", 'The value of this["field"] is expected to be "oil"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T5.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..8dec7d5388cbb8452f4133cdb7ac75b64a082f63 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T5.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T5 +description: > + No any arguments at apply function and it called inside function + declaration +---*/ + +function FACTORY() { + SharedFunction("this.feat=\"in da haus\"").apply(); +} + +var obj = new FACTORY; + +assert.sameValue(this["feat"], "in da haus", 'The value of this["feat"] is expected to be "in da haus"'); +assert.sameValue(typeof obj.feat, "undefined", 'The value of `typeof obj.feat` is expected to be "undefined"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T6.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..df2cab9e02530574f2a06ac1232cd9845165cf51 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T6.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T6 +description: > + Argument at apply function is null and it called inside function + declaration +flags: [noStrict] +---*/ + +function FACTORY() { + (function() { + this.feat = "kamon beyba" + }).apply(null); +} + +var obj = new FACTORY; + +assert.sameValue(this["feat"], "kamon beyba", 'The value of this["feat"] is expected to be "kamon beyba"'); +assert.sameValue(typeof obj.feat, "undefined", 'The value of `typeof obj.feat` is expected to be "undefined"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T7.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T7.js new file mode 100644 index 0000000000000000000000000000000000000000..3f75952a62e065aee64f877c9994687bbf9f6c53 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T7.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T7 +description: > + Argument at apply function is void 0 and it called inside function + declaration +---*/ + +(function FACTORY() { + SharedFunction("this.feat=\"in da haus\"").apply(void 0); +})(); + + +assert.sameValue(this["feat"], "in da haus", 'The value of this["feat"] is expected to be "in da haus"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T8.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T8.js new file mode 100644 index 0000000000000000000000000000000000000000..4f55f9de1de03a7c90931f1388d75bda7c6c7ae5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T8.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T8 +description: > + Argument at apply function is undefined and it called inside + function declaration +flags: [noStrict] +---*/ + +(function FACTORY() { + (function() { + this.feat = "kamon beyba" + }).apply(undefined); +})(); + +assert.sameValue(this["feat"], "kamon beyba", 'The value of this["feat"] is expected to be "kamon beyba"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T9.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T9.js new file mode 100644 index 0000000000000000000000000000000000000000..7cfb867c2d1bc00040941159aef999d5dd1ea438 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A3_T9.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.3_A3_T9 +description: Checking by using eval, argument at apply function is void 0 +---*/ + +eval(" SharedFunction(\"this.feat=1\").apply(void 0) "); + +assert.sameValue(this["feat"], 1, 'The value of this["feat"] is expected to be 1'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T1.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..393c56a099a311d814f4bb46db9ecb8d7a072987 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T1.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T1 +description: thisArg is number +---*/ + +var obj = 1; + +var retobj = SharedFunction("this.touched= true; return this;").apply(obj); + +assert.sameValue(typeof obj.touched, "undefined", 'The value of `typeof obj.touched` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T2.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..08e3a0fbec0ed29e7cffb794736899716e565acb --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T2.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T2 +description: thisArg is boolean true +---*/ + +var obj = true; + +var retobj = new SharedFunction("this.touched= true; return this;").apply(obj); + +assert.sameValue(typeof obj.touched, "undefined", 'The value of `typeof obj.touched` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T3.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..5a0e9dfc5e85b978fc1205fae3cd8fa9b1363ab7 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T3.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T3 +description: thisArg is string +flags: [noStrict] +---*/ + +var obj = "soap"; + +var retobj = (function() { + this.touched = true; + return this; +}).apply(obj); + +assert.sameValue(typeof obj.touched, "undefined", 'The value of `typeof obj.touched` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T4.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..f309f5d6b81a947de8aa9b9f1b8790737252810a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T4.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T4 +description: thisArg is function variable that return this +flags: [noStrict] +---*/ + +f = function() { + this.touched = true; + return this; +}; + +retobj = f.apply(obj); + +assert.sameValue(typeof obj, "undefined", 'The value of `typeof obj` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); + +var obj; diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T5.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..8cda11d92f2de0f1b4e16f608109ffbab253d702 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T5.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T5 +description: thisArg is function variable +---*/ + +var f = function() { + this.touched = true; +}; + +var obj = {}; + +f.apply(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T6.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..69f3f09edcd85e9da2d921ed3553ff5f0ee10e95 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T6.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T6 +description: thisArg is new String() +---*/ + +var obj = new String("soap"); + +(function() { + this.touched = true; +}).apply(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T7.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T7.js new file mode 100644 index 0000000000000000000000000000000000000000..75621f21d2646eb818dac337b573396d0f414d5b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T7.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T7 +description: thisArg is new Number() +---*/ + +var obj = new Number(1); + +SharedFunction("this.touched= true;").apply(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T8.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T8.js new file mode 100644 index 0000000000000000000000000000000000000000..932a937e2e49a033f1cbd34eddb63ffbb070eaff --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A5_T8.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.3_A5_T8 +description: thisArg is SharedFunction() +---*/ + +var obj = SharedFunction(); + +new SharedFunction("this.touched= true; return this;").apply(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T1.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..cb0341a776135de5761e1142364711bf9dc66936 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T1.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If argSendableArray is either an array or an arguments object, + the function is passed the (ToUint32(argSendableArray.length)) arguments argSendableArray[0], argSendableArray[1],...,argSendableArray[ToUint32(argSendableArray.length)-1] +es5id: 15.3.4.3_A7_T1 +description: argSendableArray is (null,[1]) +---*/ + +SharedFunction("a1,a2,a3", "this.shifted=a1;").apply(null, [1]); + +assert.sameValue(this["shifted"], 1, 'The value of this["shifted"] is expected to be 1'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T10.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T10.js new file mode 100644 index 0000000000000000000000000000000000000000..1d9fbf4ec2cdb20abf2dc57af360d4d63a896316 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T10.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If argSendableArray is either an array or an arguments object, + the function is passed the (ToUint32(argSendableArray.length)) arguments argSendableArray[0], argSendableArray[1],...,argSendableArray[ToUint32(argSendableArray.length)-1] +es5id: 15.3.4.3_A7_T10 +description: > + argSendableArray is (empty object, arguments), inside function call + without declaration used +---*/ + +var obj = {}; + +(function() { + SharedFunction("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(obj, arguments); +})("", 4, 2); + +assert.sameValue(obj["shifted"], "42", 'The value of obj["shifted"] is expected to be "42"'); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T2.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..12aba790f7f3cac29e991eb9cbe8e5161b9f43cd --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T2.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If argSendableArray is either an array or an arguments object, + the function is passed the (ToUint32(argSendableArray.length)) arguments argSendableArray[0], argSendableArray[1],...,argSendableArray[ToUint32(argSendableArray.length)-1] +es5id: 15.3.4.3_A7_T2 +description: argSendableArray is (null,[1,2,3]) +---*/ + +new SharedFunction("a1,a2", "a3", "this.shifted=a2;").apply(null, [1, 2, 3]); + +assert.sameValue(this["shifted"], 2, 'The value of this["shifted"] is expected to be 2'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T3.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..7c18430a3d02efdbc8afda9211a25fad3ac80a00 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T3.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If argSendableArray is either an array or an arguments object, + the function is passed the (ToUint32(argSendableArray.length)) arguments argSendableArray[0], argSendableArray[1],...,argSendableArray[ToUint32(argSendableArray.length)-1] +es5id: 15.3.4.3_A7_T3 +description: argSendableArray is (empty object, new SendableArray("nine","inch","nails")) +---*/ + +var i = 0; + +var p = { + toString: function() { + return "a" + (++i); + } +}; + +var obj = {}; + +SharedFunction(p, "a2,a3", "this.shifted=a1;").apply(obj, new SendableArray("nine", "inch", "nails")); + +assert.sameValue(obj["shifted"], "nine", 'The value of obj["shifted"] is expected to be "nine"'); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T4.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..e8e151782b7ec7fee067e7210735ea6e6b65456d --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T4.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If argSendableArray is either an array or an arguments object, + the function is passed the (ToUint32(argSendableArray.length)) arguments argSendableArray[0], argSendableArray[1],...,argSendableArray[ToUint32(argSendableArray.length)-1] +es5id: 15.3.4.3_A7_T4 +description: > + argSendableArray is (empty object, ( function(){return arguments;}) + ("a","b","c")) +---*/ + +var i = 0; + +var p = { + toString: function() { + return "a" + (++i); + } +}; + +var obj = {}; + +new SharedFunction(p, p, p, "this.shifted=a3;").apply(obj, (function() { + return arguments; +})("a", "b", "c")); + +assert.sameValue(obj["shifted"], "c", 'The value of obj["shifted"] is expected to be "c"'); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T5.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..9dce53a767fe91c5ec139a4c06690344aea6f0f9 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T5.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If argSendableArray is either an array or an arguments object, + the function is passed the (ToUint32(argSendableArray.length)) arguments argSendableArray[0], argSendableArray[1],...,argSendableArray[ToUint32(argSendableArray.length)-1] +es5id: 15.3.4.3_A7_T5 +description: argSendableArray is (null, arguments), inside function declaration used +---*/ + +function FACTORY() { + SharedFunction("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(null, arguments); +} + +var obj = new FACTORY("", 1, 2); + +assert.sameValue(this["shifted"], "12", 'The value of this["shifted"] is expected to be "12"'); +assert.sameValue(typeof obj.shifted, "undefined", 'The value of `typeof obj.shifted` is expected to be "undefined"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T6.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..1ad5ba73400b8397422d868463c2fbbc3d172fd1 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T6.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If argSendableArray is either an array or an arguments object, + the function is passed the (ToUint32(argSendableArray.length)) arguments argSendableArray[0], argSendableArray[1],...,argSendableArray[ToUint32(argSendableArray.length)-1] +es5id: 15.3.4.3_A7_T6 +description: argSendableArray is (this, arguments), inside function declaration used +---*/ + +function FACTORY() { + SharedFunction("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(this, arguments); +} + +var obj = new FACTORY("", 4, 2); + +assert.sameValue(obj["shifted"], "42", 'The value of obj["shifted"] is expected to be "42"'); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T7.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T7.js new file mode 100644 index 0000000000000000000000000000000000000000..e64f76c419ad9a939552f2ee252f8d8f4508243f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T7.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If argSendableArray is either an array or an arguments object, + the function is passed the (ToUint32(argSendableArray.length)) arguments argSendableArray[0], argSendableArray[1],...,argSendableArray[ToUint32(argSendableArray.length)-1] +es5id: 15.3.4.3_A7_T7 +description: > + argSendableArray is (null, arguments), inside function call without + declaration used +---*/ + +(function() { + SharedFunction("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(null, arguments); +})("", 1, 2); + +assert.sameValue(this["shifted"], "12", 'The value of this["shifted"] is expected to be "12"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T8.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T8.js new file mode 100644 index 0000000000000000000000000000000000000000..5a0e55333be18f1fbc0939857c0e76525a8504bd --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T8.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If argSendableArray is either an array or an arguments object, + the function is passed the (ToUint32(argSendableArray.length)) arguments argSendableArray[0], argSendableArray[1],...,argSendableArray[ToUint32(argSendableArray.length)-1] +es5id: 15.3.4.3_A7_T8 +description: > + argSendableArray is (this, arguments), inside function call without + declaration used +---*/ + +(function() { + SharedFunction("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(this, arguments); +})("", 4, 2); + +assert.sameValue(this["shifted"], "42", 'The value of this["shifted"] is expected to be "42"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T9.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T9.js new file mode 100644 index 0000000000000000000000000000000000000000..1838ab02ccb074ad53c32e7e3882e61b61b47467 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A7_T9.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If argSendableArray is either an array or an arguments object, + the function is passed the (ToUint32(argSendableArray.length)) arguments argSendableArray[0], argSendableArray[1],...,argSendableArray[ToUint32(argSendableArray.length)-1] +es5id: 15.3.4.3_A7_T9 +description: > + argSendableArray is (empty object, arguments), inside function declaration + used +---*/ + +function FACTORY() { + var obj = {}; + SharedFunction("a1,a2,a3", "this.shifted=a1+a2+a3;").apply(obj, arguments); + return obj; +} + +var obj = new FACTORY("", 1, 2); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); + +assert.sameValue(obj.shifted, "12", 'The value of obj.shifted is expected to be "12"'); diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T3.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..666d6b3d41e322a05447860a4c0212733d7ec084 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T3.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction.prototype.apply can`t be used as [[Construct]] caller +es5id: 15.3.4.3_A8_T3 +description: Checking if creating "new SharedFunction.apply" fails +---*/ + +try { + var obj = new SharedFunction.apply; + throw new Test262Error('#1: SharedFunction.prototype.apply can\'t be used as [[Construct]] caller'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T4.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..df3166295f37c2539fb35d4da54aa7330533d0df --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T4.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction.prototype.apply can`t be used as [[Construct]] caller +es5id: 15.3.4.3_A8_T4 +description: Checking if creating "new (SharedFunction("this.p1=1").apply)" fails +---*/ + +try { + var obj = new(SharedFunction("this.p1=1").apply); + throw new Test262Error('#1: SharedFunction.prototype.apply can\'t be used as [[Construct]] caller'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T5.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..12a1ea372714ec26eeea02b7ebd3214447354b77 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T5.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction.prototype.apply can`t be used as [[Construct]] caller +es5id: 15.3.4.3_A8_T5 +description: Checking if creating "new SharedFunction("this.p1=1").apply" fails +---*/ + +try { + var FACTORY = SharedFunction("this.p1=1").apply; + var obj = new FACTORY(); + throw new Test262Error('#1: SharedFunction.prototype.apply can\'t be used as [[Construct]] caller'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} diff --git a/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T6.js b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..d405dea2ebd23f2f34e66fcee487856f6dad668f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/S15.3.4.3_A8_T6.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction.prototype.apply can`t be used as [[Construct]] caller +es5id: 15.3.4.3_A8_T6 +description: > + Checking if creating "new (SharedFunction("function + f(){this.p1=1;};return f").apply())" fails +---*/ + +try { + var obj = new(SharedFunction("function f(){this.p1=1;};return f").apply()); +} catch (e) { + throw new Test262Error('#1: SharedFunction.prototype.apply can\'t be used as [[Construct]] caller'); +} + +assert.sameValue(obj.p1, 1, 'The value of obj.p1 is expected to be 1'); diff --git a/test/sendable/builtins/Function/prototype/apply/argarray-not-object-realm.js b/test/sendable/builtins/Function/prototype/apply/argarray-not-object-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..cdd4b80a169e9853075537232f72c8b089510136 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/argarray-not-object-realm.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.apply +description: > + Throws a TypeError exception if argSendableArray is not an object + (honoring the Realm of the current execution context) +info: | + SharedFunction.prototype.apply ( thisArg, argSendableArray ) + + [...] + 4. Let argList be ? CreateListFromSendableArrayLike(argSendableArray). + + CreateListFromSendableArrayLike ( obj [ , elementTypes ] ) + + [...] + 2. If Type(obj) is not Object, throw a TypeError exception. +features: [cross-realm] +---*/ + +var other = $262.createRealm().global; +var fn = new other.SharedFunction(); + +assert.throws(other.TypeError, function() { + fn.apply(null, false); +}); + +assert.throws(other.TypeError, function() { + fn.apply(null, 1234.5678); +}); + +assert.throws(other.TypeError, function() { + fn.apply(null, ''); +}); + +assert.throws(other.TypeError, function() { + fn.apply(null, Symbol('desc')); +}); diff --git a/test/sendable/builtins/Function/prototype/apply/argarray-not-object.js b/test/sendable/builtins/Function/prototype/apply/argarray-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..4cf648c7e9865f14fbc05c1d2ca02f43d82b0339 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/argarray-not-object.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.apply +description: > + Throws a TypeError exception if argSendableArray is not an object +info: | + SharedFunction.prototype.apply ( thisArg, argSendableArray ) + + [...] + 4. Let argList be ? CreateListFromSendableArrayLike(argSendableArray). + + CreateListFromSendableArrayLike ( obj [ , elementTypes ] ) + + [...] + 2. If Type(obj) is not Object, throw a TypeError exception. +---*/ + +function fn() {} + +assert.throws(TypeError, function() { + fn.apply(null, true); +}); + +assert.throws(TypeError, function() { + fn.apply(null, NaN); +}); + +assert.throws(TypeError, function() { + fn.apply(null, '1,2,3'); +}); + +assert.throws(TypeError, function() { + fn.apply(null, Symbol()); +}); diff --git a/test/sendable/builtins/Function/prototype/apply/get-index-abrupt.js b/test/sendable/builtins/Function/prototype/apply/get-index-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..db55de8ec02eb2c4e0f99c77e98f432ba19bd3d2 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/get-index-abrupt.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.apply +description: > + Return abrupt completion from Get(obj, indexName) +info: | + SharedFunction.prototype.apply ( thisArg, argSendableArray ) + + [...] + 4. Let argList be ? CreateListFromSendableArrayLike(argSendableArray). + + CreateListFromSendableArrayLike ( obj [ , elementTypes ] ) + + [...] + 6. Repeat, while index < len + a. Let indexName be ! ToString(index). + b. Let next be ? Get(obj, indexName). +---*/ + +var arrayLike = { + length: 2, + 0: 0, + get 1() { + throw new Test262Error(); + }, +}; + +assert.throws(Test262Error, function() { + (function() {}).apply(null, arrayLike); +}); diff --git a/test/sendable/builtins/Function/prototype/apply/get-length-abrupt.js b/test/sendable/builtins/Function/prototype/apply/get-length-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..799710d6aabd916636ac76b3a1bdb50a22f9fa66 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/get-length-abrupt.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.apply +description: > + Return abrupt completion from Get(obj, "length") +info: | + SharedFunction.prototype.apply ( thisArg, argSendableArray ) + + [...] + 4. Let argList be ? CreateListFromSendableArrayLike(argSendableArray). + + CreateListFromSendableArrayLike ( obj [ , elementTypes ] ) + + [...] + 3. Let len be ? ToLength(? Get(obj, "length")). +---*/ + +var arrayLike = { + get length() { + throw new Test262Error(); + }, +}; + +assert.throws(Test262Error, function() { + (function() {}).apply(null, arrayLike); +}); diff --git a/test/sendable/builtins/Function/prototype/apply/length.js b/test/sendable/builtins/Function/prototype/apply/length.js new file mode 100644 index 0000000000000000000000000000000000000000..179d20733488f915c2d1d7c283cfebe3aeb386ca --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/length.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.apply +description: > + SharedFunction.prototype.apply.length is 2. +info: | + ECMAScript Standard Built-in Objects + ... + Every built-in SharedFunction object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + ... + Unless otherwise specified, the length property of a built-in SharedFunction + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SharedFunction.prototype.apply, 'length', { + value: 2, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Function/prototype/apply/name.js b/test/sendable/builtins/Function/prototype/apply/name.js new file mode 100644 index 0000000000000000000000000000000000000000..301a84fac24872e4753cf7e0fa2cc503bd6143ef --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/name.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.1 +description: > + SharedFunction.prototype.apply.name is "apply". +info: | + SharedFunction.prototype.apply ( thisArg, argSendableArray ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in SharedFunction object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in SharedFunction + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SharedFunction.prototype.apply, "name", { + value: "apply", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Function/prototype/apply/not-a-constructor.js b/test/sendable/builtins/Function/prototype/apply/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..607690523d4372ab2f78c20dca12b83ea375176f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/not-a-constructor.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SharedFunction.prototype.apply does not implement [[Construct]], is not new-able +info: | + ECMAScript SharedFunction Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SharedFunction.prototype.apply), + false, + 'isConstructor(SharedFunction.prototype.apply) must return false' +); + +assert.throws(TypeError, () => { + new SharedFunction.prototype.apply; +}); + +assert.throws(TypeError, () => { + new SharedFunction.prototype.apply(); +}); diff --git a/test/sendable/builtins/Function/prototype/apply/resizable-buffer.js b/test/sendable/builtins/Function/prototype/apply/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..1b494f13c83d589899d290af8d94e669058e11f8 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/resizable-buffer.js @@ -0,0 +1,110 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.apply +description: > + SharedFunction.p.apply behaves correctly when the argument array is a + TypedSendableArray backed by resizable buffer +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + function func(...args) { + return [...args]; + } + assert.compareArray(ToNumbers(func.apply(null, fixedLength)), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(ToNumbers(func.apply(null, fixedLengthWithOffset)), [ + 2, + 3 + ]); + assert.compareArray(ToNumbers(func.apply(null, lengthTracking)), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(ToNumbers(func.apply(null, lengthTrackingWithOffset)), [ + 2, + 3 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ToNumbers(func.apply(null, fixedLength)), []); + assert.compareArray(ToNumbers(func.apply(null, fixedLengthWithOffset)), []); + assert.compareArray(ToNumbers(func.apply(null, lengthTracking)), [ + 0, + 1, + 2 + ]); + assert.compareArray(ToNumbers(func.apply(null, lengthTrackingWithOffset)), [2]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ToNumbers(func.apply(null, fixedLength)), []); + assert.compareArray(ToNumbers(func.apply(null, fixedLengthWithOffset)), []); + assert.compareArray(ToNumbers(func.apply(null, lengthTracking)), [0]); + assert.compareArray(ToNumbers(func.apply(null, lengthTrackingWithOffset)), []); + + // Shrink to zero. + rab.resize(0); + assert.compareArray(ToNumbers(func.apply(null, fixedLength)), []); + assert.compareArray(ToNumbers(func.apply(null, fixedLengthWithOffset)), []); + assert.compareArray(ToNumbers(func.apply(null, lengthTracking)), []); + assert.compareArray(ToNumbers(func.apply(null, lengthTrackingWithOffset)), []); + + // Grow so that all TAs are back in-bounds. New memory is zeroed. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ToNumbers(func.apply(null, fixedLength)), [ + 0, + 0, + 0, + 0 + ]); + assert.compareArray(ToNumbers(func.apply(null, fixedLengthWithOffset)), [ + 0, + 0 + ]); + assert.compareArray(ToNumbers(func.apply(null, lengthTracking)), [ + 0, + 0, + 0, + 0, + 0, + 0 + ]); + assert.compareArray(ToNumbers(func.apply(null, lengthTrackingWithOffset)), [ + 0, + 0, + 0, + 0 + ]); +} diff --git a/test/sendable/builtins/Function/prototype/apply/this-not-callable-realm.js b/test/sendable/builtins/Function/prototype/apply/this-not-callable-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..95ffa10a640b70dc9e865899465f739e8e8f37e5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/this-not-callable-realm.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.apply +description: > + Throws a TypeError exception if this value is not callable + (honoring the Realm of the current execution context) +info: | + SharedFunction.prototype.apply ( thisArg, argSendableArray ) + + 1. Let func be the this value. + 2. If IsCallable(func) is false, throw a TypeError exception. +features: [cross-realm] +---*/ + +var other = $262.createRealm().global; +var otherApply = other.SharedFunction.prototype.apply; + +assert.throws(other.TypeError, function() { + otherApply.call(undefined, {}, []); +}); + +assert.throws(other.TypeError, function() { + otherApply.call(null, {}, []); +}); + +assert.throws(other.TypeError, function() { + otherApply.call({}, {}, []); +}); + +assert.throws(other.TypeError, function() { + otherApply.call(/re/, {}, []); +}); diff --git a/test/sendable/builtins/Function/prototype/apply/this-not-callable.js b/test/sendable/builtins/Function/prototype/apply/this-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..6047ab83e56c304797326f7c856a033af4794ebe --- /dev/null +++ b/test/sendable/builtins/Function/prototype/apply/this-not-callable.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.apply +description: > + Throws a TypeError exception if this value is not callable +info: | + SharedFunction.prototype.apply ( thisArg, argSendableArray ) + + 1. Let func be the this value. + 2. If IsCallable(func) is false, throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + SharedFunction.prototype.apply.call(undefined, {}, []); +}); + +assert.throws(TypeError, function() { + SharedFunction.prototype.apply.call(null, {}, []); +}); + +assert.throws(TypeError, function() { + SharedFunction.prototype.apply.call({}, {}, []); +}); + +assert.throws(TypeError, function() { + SharedFunction.prototype.apply.call(/re/, {}, []); +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-0-1.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-0-1.js new file mode 100644 index 0000000000000000000000000000000000000000..4810b427f079a1e8b07e8914282cdba4fc3094b7 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-0-1.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-0-1 +description: SharedFunction.prototype.bind must exist as a function +---*/ + +var f = SharedFunction.prototype.bind; + +assert.sameValue(typeof(f), "function", 'typeof(f)'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-10-1.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-10-1.js new file mode 100644 index 0000000000000000000000000000000000000000..99e904ea88eb655144055e032087a7836697466e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-10-1.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-10-1 +description: > + SharedFunction.prototype.bind - internal property [[Class]] of 'F' is + set as SharedFunction +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); + +assert.sameValue(Object.prototype.toString.call(obj), "[object SharedFunction]", 'Object.prototype.toString.call(obj)'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-11-1.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-11-1.js new file mode 100644 index 0000000000000000000000000000000000000000..55d9392905d1464a8fd5c0e132615003c24b4360 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-11-1.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-11-1 +description: > + SharedFunction.prototype.bind - internal property [[Prototype]] of 'F' + is set as SharedFunction.prototype +---*/ + +var foo = function() {}; + +SharedFunction.prototype.property = 12; +var obj = foo.bind({}); + +assert.sameValue(obj.property, 12, 'obj.property'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-16-1.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-16-1.js new file mode 100644 index 0000000000000000000000000000000000000000..fe3984bc501f900cf2344a777de9679d99f0894d --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-16-1.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-16-1 +description: SharedFunction.prototype.bind, [[Extensible]] of the bound fn is true +---*/ + +function foo() {} +var o = {}; + +var bf = foo.bind(o); +var ex = Object.isExtensible(bf); + +assert.sameValue(ex, true, 'ex'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-16-2.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-16-2.js new file mode 100644 index 0000000000000000000000000000000000000000..6c2dca2f2f7c6abc8f02c04101f3ebafaaf3e437 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-16-2.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-16-2 +description: > + SharedFunction.prototype.bind - The [[Extensible]] attribute of internal + property in F set as true +---*/ + +function foo() {} +var obj = foo.bind({}); +obj.property = 12; + +assert(obj.hasOwnProperty("property"), 'obj.hasOwnProperty("property") !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-1.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-1.js new file mode 100644 index 0000000000000000000000000000000000000000..8355d9ef0d28cbfecc81aab9eddca0993c2320e5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-1.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + 15.3.4.5 step 2 specifies that a TypeError must be thrown if the Target + is not callable. +es5id: 15.3.4.5-2-1 +description: > + SharedFunction.prototype.bind throws TypeError if the Target is not + callable (but an instance of SharedFunction) +---*/ + +foo.prototype = SharedFunction.prototype; +// dummy function +function foo() {} +var f = new foo(); +assert.throws(TypeError, function() { + f.bind(); +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-10.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-10.js new file mode 100644 index 0000000000000000000000000000000000000000..d09b431f5c64d4477b7f7b5a850e49ca070b446a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-10.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-2-10 +description: SharedFunction.prototype.bind throws TypeError if 'Target' is undefined +---*/ + + +assert.throws(TypeError, function() { + SharedFunction.prototype.bind.call(undefined); +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-11.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-11.js new file mode 100644 index 0000000000000000000000000000000000000000..d6db9649df9107e92fded0932bbb0f73e0a04231 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-11.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-2-11 +description: SharedFunction.prototype.bind throws TypeError if 'Target' is NULL +---*/ + + +assert.throws(TypeError, function() { + SharedFunction.prototype.bind.call(null); +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-12.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-12.js new file mode 100644 index 0000000000000000000000000000000000000000..1939c419075b6226ecbfc7c63938d624fdc79d02 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-12.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-2-12 +description: SharedFunction.prototype.bind throws TypeError if 'Target' is a boolean +---*/ + + +assert.throws(TypeError, function() { + SharedFunction.prototype.bind.call(true); +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-13.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-13.js new file mode 100644 index 0000000000000000000000000000000000000000..8e1f0476fd631f06baf3d45574435d10ba0d986f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-13.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-2-13 +description: SharedFunction.prototype.bind throws TypeError if 'Target' is a number +---*/ + + +assert.throws(TypeError, function() { + SharedFunction.prototype.bind.call(5); +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-14.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-14.js new file mode 100644 index 0000000000000000000000000000000000000000..1c340b72aaadf539513a8e3a68e93295a58b8ab0 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-14.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-2-14 +description: SharedFunction.prototype.bind throws TypeError if 'Target' is a string +---*/ + + +assert.throws(TypeError, function() { + SharedFunction.prototype.bind.call("abc"); +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-15.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-15.js new file mode 100644 index 0000000000000000000000000000000000000000..e7437327c455de487dd43ff7805f03b9cd53986a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-15.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-2-15 +description: > + SharedFunction.prototype.bind throws TypeError if 'Target' is Object + without Call internal method +---*/ + + +assert.throws(TypeError, function() { + SharedFunction.prototype.bind.call({}); +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-16.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-16.js new file mode 100644 index 0000000000000000000000000000000000000000..77d539b26baf86e78ef6221c06cf7da4cfc33894 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-16.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-2-16 +description: SharedFunction.prototype.bind - 'Target' is a function +---*/ + +function testFunc() {} + +testFunc.bind(); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-2.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-2.js new file mode 100644 index 0000000000000000000000000000000000000000..a4821a7132e30511d1d8fa74f731db46b9209bb2 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-2.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + 15.3.4.5 step 2 specifies that a TypeError must be thrown if the Target + is not callable. +es5id: 15.3.4.5-2-2 +description: > + SharedFunction.prototype.bind throws TypeError if the Target is not + callable (bind attached to object) +---*/ + +// dummy function +function foo() {} +var f = new foo(); +f.bind = SharedFunction.prototype.bind; +assert.throws(TypeError, function() { + f.bind(); +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-3.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-3.js new file mode 100644 index 0000000000000000000000000000000000000000..201c6e4565b8c55c363b4d2fed7ae00de5199006 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-3.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + 15.3.4.5 step 2 specifies that a TypeError must be thrown if the Target + is not callable. +es5id: 15.3.4.5-2-3 +description: SharedFunction.prototype.bind allows Target to be a constructor (Number) +---*/ + +var bnc = Number.bind(null); +var n = bnc(42); + +assert.sameValue(n, 42, 'n'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-4.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-4.js new file mode 100644 index 0000000000000000000000000000000000000000..e27ab2f909f0661c1d63c064c9c4cfa1d5e8f3ca --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-4.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + 15.3.4.5 step 2 specifies that a TypeError must be thrown if the Target + is not callable. +es5id: 15.3.4.5-2-4 +description: SharedFunction.prototype.bind allows Target to be a constructor (String) +---*/ + +var bsc = String.bind(null); +var s = bsc("hello world"); + +assert.sameValue(s, "hello world", 's'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-5.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-5.js new file mode 100644 index 0000000000000000000000000000000000000000..e9f06c4fd93da7bff9374470e7860815940c9918 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-5.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + 15.3.4.5 step 2 specifies that a TypeError must be thrown if the Target + is not callable. +es5id: 15.3.4.5-2-5 +description: SharedFunction.prototype.bind allows Target to be a constructor (Boolean) +---*/ + +var bbc = Boolean.bind(null); +var b = bbc(true); + +assert.sameValue(b, true, 'b'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-6.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-6.js new file mode 100644 index 0000000000000000000000000000000000000000..40177199b2813ed9e9b3e70e158862174e8d6f7b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-6.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + 15.3.4.5 step 2 specifies that a TypeError must be thrown if the Target + is not callable. +es5id: 15.3.4.5-2-6 +description: SharedFunction.prototype.bind allows Target to be a constructor (Object) +---*/ + +var boc = Object.bind(null); +var o = boc(42); + +assert((o == 42), '(o == 42) !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-7.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-7.js new file mode 100644 index 0000000000000000000000000000000000000000..c644e4d2468e0027109c08c0f465374562dca54b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-7.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + 15.3.4.5 step 2 specifies that a TypeError must be thrown if the Target + is not callable. +es5id: 15.3.4.5-2-7 +description: > + SharedFunction.prototype.bind throws TypeError if the Target is not + callable (JSON) +---*/ + + +assert.throws(TypeError, function() { + JSON.bind(); +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-8.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-8.js new file mode 100644 index 0000000000000000000000000000000000000000..2e16472f02b90ae51c70a6949c83e1d1303430c1 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-8.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + 15.3.4.5 step 2 specifies that a TypeError must be thrown if the Target + is not callable. +es5id: 15.3.4.5-2-8 +description: SharedFunction.prototype.bind allows Target to be a constructor (SendableArray) +---*/ + +var bac = SendableArray.bind(null); +var a = bac(42); +a.prop = "verifyPropertyExist"; +a[41] = 41; + +assert.sameValue(a.prop, "verifyPropertyExist", 'a.prop'); +assert.sameValue(a[41], 41, 'a[41]'); +assert.sameValue(a.length, 42, 'a.length'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-9.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-9.js new file mode 100644 index 0000000000000000000000000000000000000000..cba4880fae23e7d964142948ca120dc6bcc55932 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-2-9.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-2-9 +description: SharedFunction.prototype.bind allows Target to be a constructor (Date) +---*/ + +var bdc = Date.bind(null); +var s = bdc(0, 0, 0); + +assert.sameValue(typeof(s), 'string', 'typeof(s)'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-20-2.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-20-2.js new file mode 100644 index 0000000000000000000000000000000000000000..d21da15952f6f8ef226a893ddef9748e382eacb3 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-20-2.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-20-2 +description: > + SharedFunction.prototype.bind - [[Get]] attribute of 'caller' property + in 'F' is thrower +---*/ + +function foo() {} +var obj = foo.bind({}); + +assert.throws(TypeError, function() { + obj.caller; +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-20-3.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-20-3.js new file mode 100644 index 0000000000000000000000000000000000000000..fa156975750bfd3645b8b4af745ef518523f2e98 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-20-3.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-20-3 +description: > + SharedFunction.prototype.bind - [[Set]] attribute of 'caller' property + in 'F' is thrower +---*/ + +function foo() {} +var obj = foo.bind({}); +assert.throws(TypeError, function() { + obj.caller = 12; +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-21-2.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-21-2.js new file mode 100644 index 0000000000000000000000000000000000000000..8c57fe3773c00b6817973df7aaa946632978f429 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-21-2.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-21-2 +description: > + SharedFunction.prototype.bind - [[Get]] attribute of 'arguments' + property in 'F' is thrower +---*/ + +function foo() {} +var obj = foo.bind({}); + +assert.throws(TypeError, function() { + obj.arguments; +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-21-3.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-21-3.js new file mode 100644 index 0000000000000000000000000000000000000000..9b7dff58453ca5ad0bdb4c25903fd8b2f3252e56 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-21-3.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-21-3 +description: > + SharedFunction.prototype.bind - [[Set]] attribute of 'arguments' + property in 'F' is thrower +---*/ + +function foo() {} +var obj = foo.bind({}); +assert.throws(TypeError, function() { + obj.arguments = 12; +}); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-3-1.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-3-1.js new file mode 100644 index 0000000000000000000000000000000000000000..17f3cd935e11cd4a35855979d055a65046c02fbf --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-3-1.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-3-1 +description: SharedFunction.prototype.bind - each arg is defined in A in list order +---*/ + +var foo = function(x, y) { + return new Boolean((x + y) === "ab" && arguments[0] === "a" && + arguments[1] === "b" && arguments.length === 2); +}; + +var obj = foo.bind({}, "a", "b"); + +assert((obj() == true), '(obj() == true) !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-1.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-1.js new file mode 100644 index 0000000000000000000000000000000000000000..8e6983bc8e499659be3bba692647cd730c5ef5d8 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-1.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-1 +description: SharedFunction.prototype.bind - F can get own data property +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); +obj.property = 12; + +assert.sameValue(obj.property, 12, 'obj.property'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-10.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-10.js new file mode 100644 index 0000000000000000000000000000000000000000..3356839609357b6dba9b9c8edd9c463f344f94e6 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-10.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-10 +description: > + SharedFunction.prototype.bind - F can get own accessor property without + a get function that overrides an inherited accessor property +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); + +Object.defineProperty(SharedFunction.prototype, "property", { + get: function() { + return 3; + }, + configurable: true +}); + +Object.defineProperty(obj, "property", { + set: function() {} +}); + +assert.sameValue(typeof(obj.property), "undefined", 'typeof (obj.property)'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-11.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-11.js new file mode 100644 index 0000000000000000000000000000000000000000..01a71211424860226bdbe9685f07fde4ffa4b4f6 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-11.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-11 +description: > + SharedFunction.prototype.bind - F can get inherited accessor property + without a get function +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); + +Object.defineProperty(SharedFunction.prototype, "property", { + set: function() {}, + configurable: true +}); + +assert.sameValue(typeof(obj.property), "undefined", 'typeof (obj.property)'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-12.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-12.js new file mode 100644 index 0000000000000000000000000000000000000000..e71101a6eaf12defd1df888a6c25da8fe58b4248 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-12.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-12 +description: SharedFunction.prototype.bind - F cannot get property which doesn't exist +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); + +assert.sameValue(typeof(obj.property), "undefined", 'typeof (obj.property)'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-2.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-2.js new file mode 100644 index 0000000000000000000000000000000000000000..9f8e5909d02bd0fc6ae968cec88043f9bc0c1e56 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-2.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-2 +description: SharedFunction.prototype.bind - F can get inherited data property +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); + +SharedFunction.prototype.property = 12; + +assert.sameValue(obj.property, 12, 'obj.property'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-3.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-3.js new file mode 100644 index 0000000000000000000000000000000000000000..950c32df3a7055d29b0e145abb482d2e6af49117 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-3.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-3 +description: > + SharedFunction.prototype.bind - F can get own data property that + overrides an inherited data property +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); + +SharedFunction.prototype.property = 3; +obj.property = 12; + +assert.sameValue(obj.property, 12, 'obj.property'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-4.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-4.js new file mode 100644 index 0000000000000000000000000000000000000000..cfee90695bb693cab41905969fb952ab828deafd --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-4.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-4 +description: > + SharedFunction.prototype.bind - F can get own data property that + overrides an inherited accessor property +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); + +Object.defineProperty(SharedFunction.prototype, "property", { + get: function() { + return 3; + }, + configurable: true +}); + +Object.defineProperty(obj, "property", { + value: 12 +}); + +assert.sameValue(obj.property, 12, 'obj.property'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-5.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-5.js new file mode 100644 index 0000000000000000000000000000000000000000..f8f75aeb907f7dbf6c30d5e1c51e15b620efc1b9 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-5.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-5 +description: SharedFunction.prototype.bind - F can get own accessor property +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); +Object.defineProperty(obj, "property", { + get: function() { + return 12; + } +}); + +assert.sameValue(obj.property, 12, 'obj.property'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-6.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-6.js new file mode 100644 index 0000000000000000000000000000000000000000..cf80bf7838fd10078ba0fd7940c8aa9a216536c6 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-6.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-6 +description: SharedFunction.prototype.bind - F can get inherited accessor property +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); + +Object.defineProperty(SharedFunction.prototype, "property", { + get: function() { + return 12; + }, + configurable: true +}); + +assert.sameValue(obj.property, 12, 'obj.property'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-7.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-7.js new file mode 100644 index 0000000000000000000000000000000000000000..695892a576d27ffd61787126377ab63953e637be --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-7.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-7 +description: > + SharedFunction.prototype.bind - F can get own accessor property that + overrides an inherited data property +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); + +SharedFunction.prototype.property = 3; +Object.defineProperty(obj, "property", { + get: function() { + return 12; + } +}); + +assert.sameValue(obj.property, 12, 'obj.property'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-8.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-8.js new file mode 100644 index 0000000000000000000000000000000000000000..b3f599861eeaef55ac6854fe69b2b9ec89779251 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-8.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-8 +description: > + SharedFunction.prototype.bind - F can get own accessor property that + overrides an inherited accessor property +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); + +Object.defineProperty(SharedFunction.prototype, "property", { + get: function() { + return 3; + }, + configurable: true +}); + +Object.defineProperty(obj, "property", { + get: function() { + return 12; + } +}); + +assert.sameValue(obj.property, 12, 'obj.property'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-9.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-9.js new file mode 100644 index 0000000000000000000000000000000000000000..2f0b30de182d834e347db7d26d9178512c15e317 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-6-9.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-6-9 +description: > + SharedFunction.prototype.bind - F can get own accessor property without + a get function +---*/ + +var foo = function() {}; + +var obj = foo.bind({}); +Object.defineProperty(obj, "property", { + set: function() {} +}); + +assert(obj.hasOwnProperty("property"), 'obj.hasOwnProperty("property") !== true'); +assert.sameValue(typeof(obj.property), "undefined", 'typeof (obj.property)'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-8-1.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-8-1.js new file mode 100644 index 0000000000000000000000000000000000000000..a437354bdaa7e11ed918330b49a227a882fba3a3 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-8-1.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-8-1 +description: SharedFunction.prototype.bind, type of bound function must be 'function' +---*/ + +function foo() {} +var o = {}; + +var bf = foo.bind(o); + +assert.sameValue(typeof(bf), 'function', 'typeof(bf)'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-8-2.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-8-2.js new file mode 100644 index 0000000000000000000000000000000000000000..a66e3cdcb4e725ce71739421cd034ce18cca6e01 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-8-2.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-8-2 +description: > + SharedFunction.prototype.bind, [[Class]] of bound function must be + 'SharedFunction' +---*/ + +function foo() {} +var o = {}; + +var bf = foo.bind(o); +var s = Object.prototype.toString.call(bf); + +assert.sameValue(s, '[object SharedFunction]', 's'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-9-1.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-9-1.js new file mode 100644 index 0000000000000000000000000000000000000000..588b1269746d08dbb9947e233f65b5758bcfa878 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-9-1.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-9-1 +description: SharedFunction.prototype.bind, [[Prototype]] is SharedFunction.prototype +---*/ + +function foo() {} +var o = {}; + +var bf = foo.bind(o); + +assert(SharedFunction.prototype.isPrototypeOf(bf), 'SharedFunction.prototype.isPrototypeOf(bf) !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5-9-2.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-9-2.js new file mode 100644 index 0000000000000000000000000000000000000000..ae719708f8818279b55b5209ae28373550b6f251 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5-9-2.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5-9-2 +description: > + SharedFunction.prototype.bind, [[Prototype]] is SharedFunction.prototype + (using getPrototypeOf) +---*/ + +function foo() {} +var o = {}; + +var bf = foo.bind(o); + +assert.sameValue(Object.getPrototypeOf(bf), SharedFunction.prototype, 'Object.getPrototypeOf(bf)'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-1.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..be8850405986cb1147caf97e48a981011ef330d0 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-1.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-1 +description: > + [[Call]] - 'F''s [[BoundArgs]] is used as the former part of + arguments of calling the [[Call]] internal method of 'F''s + [[TargetSendableFunction]] when 'F' is called +---*/ + +var func = function(x, y, z) { + return x + y + z; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, {}, "a", "b", "c"); + +assert.sameValue(newFunc(), "abc", 'newFunc()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-10.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-10.js new file mode 100644 index 0000000000000000000000000000000000000000..8451cc064adf6f603e4d3611d80f6bb5d4fcab71 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-10.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-10 +description: > + [[Call]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 0, and with 'boundThis' +---*/ + +var obj = { + prop: "abc" +}; + +var func = function(x) { + return this === obj && typeof x === "undefined"; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, obj); + +assert(newFunc(), 'newFunc() !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-11.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-11.js new file mode 100644 index 0000000000000000000000000000000000000000..c29345b354230506e79648645fd4596300e28b24 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-11.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-11 +description: > + [[Call]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 1, and with 'boundThis' +---*/ + +var obj = { + prop: "abc" +}; + +var func = function(x) { + return this === obj && x === 1 && arguments[0] === 1 && arguments.length === 1 && this.prop === "abc"; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, obj); + +assert(newFunc(1), 'newFunc(1) !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-12.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-12.js new file mode 100644 index 0000000000000000000000000000000000000000..6f9ab7d4c25e2ecbd7c947bb2fde7bf9632e886a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-12.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-12 +description: > + [[Call]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 2, and with 'boundThis' +---*/ + +var obj = { + prop: "abc" +}; + +var func = function(x) { + return this === obj && x === 1 && arguments[1] === 2 && + arguments[0] === 1 && arguments.length === 2 && this.prop === "abc"; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, obj); + +assert(newFunc(1, 2), 'newFunc(1, 2) !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-13.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-13.js new file mode 100644 index 0000000000000000000000000000000000000000..1711268ba5afa7b5c19aaea4ad9260400f31c871 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-13.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-13 +description: > + [[Call]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 1, length of 'ExtraArgs' is 0, and with 'boundThis' +---*/ + +var obj = { + prop: "abc" +}; + +var func = function(x) { + return this === obj && x === 1 && + arguments[0] === 1 && arguments.length === 1 && this.prop === "abc"; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, obj, 1); + +assert(newFunc(), 'newFunc() !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-14.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-14.js new file mode 100644 index 0000000000000000000000000000000000000000..3c212a0abc87730525398de0956dfd829ce3a9eb --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-14.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-14 +description: > + [[Call]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 1, length of 'ExtraArgs' is 1, and with 'boundThis' +---*/ + +var obj = { + prop: "abc" +}; + +var func = function(x) { + return this === obj && x === 1 && arguments[1] === 2 && + arguments[0] === 1 && arguments.length === 2 && this.prop === "abc"; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, obj, 1); + +assert(newFunc(2), 'newFunc(2) !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-15.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-15.js new file mode 100644 index 0000000000000000000000000000000000000000..073e8fabfa8752ae6faaeb2acd54a6f8ca8ee356 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-15.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-15 +description: > + [[Call]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 2, length of 'ExtraArgs' is 0, and with 'boundThis' +---*/ + +var obj = { + prop: "abc" +}; + +var func = function(x) { + return this === obj && x === 1 && arguments[1] === 2 && + arguments[0] === 1 && arguments.length === 2 && this.prop === "abc"; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, obj, 1, 2); + +assert(newFunc(), 'newFunc() !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-2.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-2.js new file mode 100644 index 0000000000000000000000000000000000000000..2957be148b6be8950fe95a9c7401757fdb9fb3fc --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-2.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-2 +description: > + [[Call]] - 'F''s [[BoundThis]] is used as the 'this' value of + calling the [[Call]] internal method of 'F''s [[TargetSendableFunction]] + when 'F' is called +---*/ + +var obj = { + "prop": "a" +}; + +var func = function() { + return this; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, obj); + +assert.sameValue(newFunc(), obj, 'newFunc()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-3.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..81a0d77d35b60728eba78a54a584bdf6f7ed288e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-3.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-3 +description: > + [[Call]] - the provided arguments is used as the latter part of + arguments of calling the [[Call]] internal method of 'F''s + [[TargetSendableFunction]] when 'F' is called +---*/ + +var func = function(x, y, z) { + return z; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, {}, "a", "b"); + +assert.sameValue(newFunc("c"), "c", 'newFunc("c")'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-4.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..570a5b0aeded01f2fd2704804b8710dc0a07cfb6 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-4.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-4 +description: > + [[Call]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 0, and without + 'boundThis' +---*/ + +var func = function() { + return arguments.length === 0; +}; + +var newFunc = SharedFunction.prototype.bind.call(func); + +assert(newFunc(), 'newFunc() !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-5.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-5.js new file mode 100644 index 0000000000000000000000000000000000000000..a3b60cdcd166518fdc0a4bbf763399cec7aa626a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-5.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-5 +description: > + [[Call]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 1, and without + 'boundThis' +---*/ + +var func = function() { + return arguments[0] === 1; +}; + +var newFunc = SharedFunction.prototype.bind.call(func); + +assert(newFunc(1), 'newFunc(1) !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-6.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-6.js new file mode 100644 index 0000000000000000000000000000000000000000..e0456e2af0d6d72f0460cb605a6a75bf899335d0 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-6.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-6 +description: > + [[Call]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 0, and with 'boundThis' +---*/ + +var obj = { + prop: "abc" +}; + +var func = function() { + return this === obj && arguments.length === 0; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, obj); + +assert(newFunc(), 'newFunc() !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-7.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-7.js new file mode 100644 index 0000000000000000000000000000000000000000..4d94bc1e06739ee531793681f651dfdae943daac --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-7.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-7 +description: > + [[Call]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 1, length of 'ExtraArgs' is 0, and with 'boundThis' +---*/ + +var obj = { + prop: "abc" +}; + +var func = function() { + return this === obj && arguments[0] === 1; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, obj, 1); + +assert(newFunc(), 'newFunc() !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-8.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-8.js new file mode 100644 index 0000000000000000000000000000000000000000..9d1e87f37b363d47f8cd1feeac6471d14610068e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-8.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-8 +description: > + [[Call]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 1, and with 'boundThis' +---*/ + +var obj = { + prop: "abc" +}; + +var func = function() { + return this === obj && arguments[0] === 1; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, obj); + +assert(newFunc(1), 'newFunc(1) !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-9.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-9.js new file mode 100644 index 0000000000000000000000000000000000000000..32489b772183266cbec35034f032bf318086ef6c --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.1-4-9.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.1-4-9 +description: > + [[Call]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 1, length of 'ExtraArgs' is 1, and with 'boundThis' +---*/ + +var obj = { + prop: "abc" +}; + +var func = function() { + return this === obj && arguments[0] === 1 && arguments[1] === 2; +}; + +var newFunc = SharedFunction.prototype.bind.call(func, obj, 1); + +assert(newFunc(2), 'newFunc(2) !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-1.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-1.js new file mode 100644 index 0000000000000000000000000000000000000000..6e220324806fabf373080ebef3bb50daa1979193 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-1.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-1 +description: > + [[Construct]] - 'F''s [[BoundArgs]] is used as the former part of + arguments of calling the [[Construct]] internal method of 'F''s + [[TargetSendableFunction]] when 'F' is called as constructor +---*/ + +var func = function(x, y, z) { + var objResult = {}; + objResult.returnValue = x + y + z; + objResult.returnVerifyResult = arguments[0] === "a" && arguments.length === 3; + return objResult; +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, {}, "a", "b", "c"); + +var newInstance = new NewFunc(); + +assert(newInstance.hasOwnProperty("returnValue"), 'newInstance.hasOwnProperty("returnValue") !== true'); +assert.sameValue(newInstance.returnValue, "abc", 'newInstance.returnValue'); +assert(newInstance.hasOwnProperty("returnVerifyResult"), 'newInstance.hasOwnProperty("returnVerifyResult") !== true'); +assert.sameValue(newInstance.returnVerifyResult, true, 'newInstance.returnVerifyResult'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-10.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-10.js new file mode 100644 index 0000000000000000000000000000000000000000..2292ec24c4d5006dd031e560ba8bf1e62df6ef5a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-10.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-10 +description: > + [[Construct]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 1 +---*/ + +var func = function(x) { + return new Boolean(arguments.length === 1 && x === 1 && arguments[0] === 1); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, {}); + +var newInstance = new NewFunc(1); + +assert.sameValue(newInstance.valueOf(), true, 'newInstance.valueOf()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-11.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-11.js new file mode 100644 index 0000000000000000000000000000000000000000..4249fcbb94ebc61fe9284ccd289b06eadcc742e6 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-11.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-11 +description: > + [[Construct]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 2 +---*/ + +var func = function(x) { + return new Boolean(arguments.length === 2 && x === 1 && arguments[1] === 2 && arguments[0] === 1); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, {}); + +var newInstance = new NewFunc(1, 2); + +assert.sameValue(newInstance.valueOf(), true, 'newInstance.valueOf()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-12.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-12.js new file mode 100644 index 0000000000000000000000000000000000000000..6519ca145b558a1f5a617a7cf827e367f5939c65 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-12.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-12 +description: > + [[Construct]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 1, length of 'ExtraArgs' is 0 +---*/ + +var func = function(x) { + return new Boolean(arguments.length === 1 && x === 1 && arguments[0] === 1); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, {}, 1); + +var newInstance = new NewFunc(); + +assert.sameValue(newInstance.valueOf(), true, 'newInstance.valueOf()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-13.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-13.js new file mode 100644 index 0000000000000000000000000000000000000000..d361ad4f3e92dc9b09970164609dd66d64b5e92b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-13.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-13 +description: > + [[Construct]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 1, length of 'ExtraArgs' is 1 +---*/ + +var func = function(x) { + return new Boolean(arguments.length === 2 && x === 1 && arguments[1] === 2 && arguments[0] === 1); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, {}, 1); + +var newInstance = new NewFunc(2); + +assert.sameValue(newInstance.valueOf(), true, 'newInstance.valueOf()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-14.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-14.js new file mode 100644 index 0000000000000000000000000000000000000000..b25066199b9117503a84d161cf575826e9d5cbea --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-14.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-14 +description: > + [[Construct]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 2, length of 'ExtraArgs' is 0 +---*/ + +var func = function(x) { + return new Boolean(arguments.length === 2 && x === 1 && arguments[1] === 2 && arguments[0] === 1); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, {}, 1, 2); + +var newInstance = new NewFunc(); + +assert.sameValue(newInstance.valueOf(), true, 'newInstance.valueOf()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-2.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-2.js new file mode 100644 index 0000000000000000000000000000000000000000..7357d48f0104d47f35c4fc17f159d47d9c3d4672 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-2.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-2 +description: > + [[Construct]] - the provided arguments is used as the latter part + of arguments of calling the [[Construct]] internal method of 'F''s + [[TargetSendableFunction]] when 'F' is called as constructor +---*/ + +var func = function(x, y, z) { + var objResult = {}; + objResult.returnValue = x + y + z; + objResult.returnVerifyResult = arguments[0] === "a" && arguments.length === 3; + return objResult; +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, {}); + +var newInstance = new NewFunc("a", "b", "c"); + +assert(newInstance.hasOwnProperty("returnValue"), 'newInstance.hasOwnProperty("returnValue") !== true'); +assert.sameValue(newInstance.returnValue, "abc", 'newInstance.returnValue'); +assert(newInstance.hasOwnProperty("returnVerifyResult"), 'newInstance.hasOwnProperty("returnVerifyResult") !== true'); +assert.sameValue(newInstance.returnVerifyResult, true, 'newInstance.returnVerifyResult'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-3.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-3.js new file mode 100644 index 0000000000000000000000000000000000000000..92593009f669934d1c88cb1ae680e6551604e32b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-3.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-3 +description: > + [[Construct]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 0, and without + 'boundThis' +---*/ + +var func = function() { + return new Boolean(arguments.length === 0); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func); + +var newInstance = new NewFunc(); + +assert.sameValue(newInstance.valueOf(), true, 'newInstance.valueOf()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-4.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-4.js new file mode 100644 index 0000000000000000000000000000000000000000..0927bc8ea98af8a44a5c5b50780bc8140d93881b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-4.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-4 +description: > + [[Construct]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 1, and without + 'boundThis' +---*/ + +var func = function() { + return new Boolean(arguments[0] === 1 && arguments.length === 1); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func); + +var newInstance = new NewFunc(1); + +assert.sameValue(newInstance.valueOf(), true, 'newInstance.valueOf()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-5.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-5.js new file mode 100644 index 0000000000000000000000000000000000000000..af8952a021aa6d7ee2e09c8c30bc292a5cf35571 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-5.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-5 +description: > + [[Construct]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 0, and with 'boundThis' +---*/ + +var obj = { + prop: "abc" +}; + +Object.prototype.verifyThis = "verifyThis"; +var func = function() { + return new Boolean(arguments.length === 0 && Object.prototype.toString.call(this) === "[object Object]" && + this.verifyThis === "verifyThis"); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, obj); + +var newInstance = new NewFunc(); + +assert(newInstance.valueOf(), 'newInstance.valueOf() !== true'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-6.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-6.js new file mode 100644 index 0000000000000000000000000000000000000000..7ee51c4d59b66560b12424379d1650d711fbcfb5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-6.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-6 +description: > + [[Construct]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 1, length of 'ExtraArgs' is 0 +---*/ + +var func = function() { + return new Boolean(arguments.length === 1 && arguments[0] === 1); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, {}, 1); + +var newInstance = new NewFunc(); + +assert.sameValue(newInstance.valueOf(), true, 'newInstance.valueOf()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-7.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-7.js new file mode 100644 index 0000000000000000000000000000000000000000..a46217946edd83a456a2909c1264ade309acb646 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-7.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-7 +description: > + [[Construct]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 1 +---*/ + +var func = function() { + return new Boolean(arguments.length === 1 && arguments[0] === 1); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, {}); + +var newInstance = new NewFunc(1); + +assert.sameValue(newInstance.valueOf(), true, 'newInstance.valueOf()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-8.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-8.js new file mode 100644 index 0000000000000000000000000000000000000000..db67c504860cf1adfda1a696c0a7f56a68dfaf9b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-8.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-8 +description: > + [[Construct]] - length of parameters of 'target' is 0, length of + 'boundArgs' is 1, length of 'ExtraArgs' is 1 +---*/ + +var func = function() { + return new Boolean(arguments.length === 2 && arguments[0] === 1 && arguments[1] === 2); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, {}, 1); + +var newInstance = new NewFunc(2); + +assert.sameValue(newInstance.valueOf(), true, 'newInstance.valueOf()'); diff --git a/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-9.js b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-9.js new file mode 100644 index 0000000000000000000000000000000000000000..0f45d326c4cd1770bdba9ccb2e762304de02a7b0 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/15.3.4.5.2-4-9.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5.2-4-9 +description: > + [[Construct]] - length of parameters of 'target' is 1, length of + 'boundArgs' is 0, length of 'ExtraArgs' is 0 +---*/ + +var func = function(x) { + return new Boolean(arguments.length === 0 && typeof x === "undefined"); +}; + +var NewFunc = SharedFunction.prototype.bind.call(func, {}); + +var newInstance = new NewFunc(); + +assert.sameValue(newInstance.valueOf(), true, 'newInstance.valueOf()'); diff --git a/test/sendable/builtins/Function/prototype/bind/BoundFunction_restricted-properties.js b/test/sendable/builtins/Function/prototype/bind/BoundFunction_restricted-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..261cd45725ae0ab42b759d5c7eb6c8d591b193a8 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/BoundFunction_restricted-properties.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +description: > + SendableFunctions created using SharedFunction.prototype.bind() do not have own + properties "caller" or "arguments", but inherit them from + %SendableFunctionPrototype%. +es6id: 16.1 +---*/ + +function target() {} +var bound = target.bind(null); + +assert.sameValue(bound.hasOwnProperty('caller'), false, 'SendableFunctions created using SharedFunction.prototype.bind() do not have own property "caller"'); +assert.sameValue(bound.hasOwnProperty('arguments'), false, 'SendableFunctions created using SharedFunction.prototype.bind() do not have own property "arguments"'); + +assert.throws(TypeError, function() { + return bound.caller; +}); + +assert.throws(TypeError, function() { + bound.caller = {}; +}); + +assert.throws(TypeError, function() { + return bound.arguments; +}); + +assert.throws(TypeError, function() { + bound.arguments = {}; +}); diff --git a/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A1.js b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A1.js new file mode 100644 index 0000000000000000000000000000000000000000..7ffb93b5a3681d5c1da74353216329493db28bf5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A1.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: "\"caller\" of bound function is poisoned (step 20)" +es5id: 15.3.4.5_A1 +description: A bound function should fail to find its "caller" +---*/ + +function foo() { + return bar.caller; +} +var bar = foo.bind({}); + +function baz() { + return bar(); +} + +assert.throws(TypeError, function() { + baz(); +}, 'baz() throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A13.js b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A13.js new file mode 100644 index 0000000000000000000000000000000000000000..b8932b6182e28c4d1a371d75b7bd2dc55829f4ef --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A13.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5_A13 +description: If IsCallable(func) is false, then throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + SharedFunction.prototype.bind.call(undefined, {}); +}, 'SharedFunction.prototype.bind.call(undefined, {}) throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A14.js b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A14.js new file mode 100644 index 0000000000000000000000000000000000000000..fc1546e299968737023e338530254711f96867ef --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A14.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5_A14 +description: If IsCallable(func) is false, then throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + SharedFunction.prototype.bind.call(null, {}); +}, 'SharedFunction.prototype.bind.call(null, {}) throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A15.js b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A15.js new file mode 100644 index 0000000000000000000000000000000000000000..002ac82780c9299c2d9abff4d0d6f0fcf3d0314a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A15.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5_A15 +description: If IsCallable(func) is false, then throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + SharedFunction.prototype.bind.call({}, {}); +}, 'SharedFunction.prototype.bind.call({}, {}) throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A16.js b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A16.js new file mode 100644 index 0000000000000000000000000000000000000000..d174d75b01d6d9300f1cc0881a68c7a28368fb5e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A16.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: If IsCallable(func) is false, then throw a TypeError exception. +es5id: 15.3.4.5_A16 +description: > + A RegExp is not a function, but it may be callable. Iff it is, + it's typeof should be 'function', in which case bind should accept + it as a valid this value. +---*/ + +var re = (/x/); +if (typeof re === 'function') { + SharedFunction.prototype.bind.call(re, undefined); +} else { + try { + SharedFunction.prototype.bind.call(re, undefined); + throw new Test262Error('#1: If IsCallable(func) is false, ' + + 'then (bind should) throw a TypeError exception'); + } catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); + } +} diff --git a/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A2.js b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A2.js new file mode 100644 index 0000000000000000000000000000000000000000..30578deb756a8ffca9bd398b57de0b0e0e972d44 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A2.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: "\"arguments\" of bound function is poisoned (step 21)" +es5id: 15.3.4.5_A2 +description: a bound function should fail to find the bound function "arguments" +---*/ + +function foo() { + return bar.arguments; +} +var bar = foo.bind({}); + +function baz() { + return bar(); +} + +assert.throws(TypeError, function() { + baz(); +}, 'baz() throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A3.js b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A3.js new file mode 100644 index 0000000000000000000000000000000000000000..e11df838e92069e9269f4d7ade314fbb42d4621b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A3.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5_A3 +description: SharedFunction.prototype.bind must exist +---*/ +assert( + 'bind' in SharedFunction.prototype, + 'The result of evaluating (\'bind\' in SharedFunction.prototype) is expected to be true' +); diff --git a/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A4.js b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A4.js new file mode 100644 index 0000000000000000000000000000000000000000..5de6ee818b924c506baea1a86154e9fa85ebe002 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A4.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5_A4 +description: > + SharedFunction.prototype.bind call the original's internal [[Call]] + method rather than its .apply method. +---*/ + +function foo() {} + +var b = foo.bind(33, 44); +foo.apply = function() { + throw new Test262Error("SharedFunction.prototype.bind called original's .apply method"); +}; +b(55, 66); diff --git a/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A5.js b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A5.js new file mode 100644 index 0000000000000000000000000000000000000000..ec3ceed3450f3cc614b7dc34ce7822fd68d9bcc8 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/S15.3.4.5_A5.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.5_A5 +description: > + SharedFunction.prototype.bind must curry [[Construct]] as well as + [[Call]]. +---*/ + +function construct(f, args) { + var bound = SharedFunction.prototype.bind.apply(f, [null].concat(args)); + return new bound(); +} +var d = construct(Date, [1957, 4, 27]); + +assert.sameValue( + Object.prototype.toString.call(d), + '[object Date]', + 'Object.prototype.toString.call(construct(Date, [1957, 4, 27])) must return "[object Date]"' +); diff --git a/test/sendable/builtins/Function/prototype/bind/get-fn-realm-recursive.js b/test/sendable/builtins/Function/prototype/bind/get-fn-realm-recursive.js new file mode 100644 index 0000000000000000000000000000000000000000..b7119784826e31876e6845ddb911cae734e8b810 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/get-fn-realm-recursive.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getfunctionrealm +description: > + The realm of a bound function exotic object is the realm of its target function. + GetSendableFunctionRealm is called recursively. +info: | + Object ( [ value ] ) + + 1. If NewTarget is neither undefined nor the active function, then + a. Return ? OrdinaryCreateFromConstructor(NewTarget, "%Object.prototype%"). + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + [...] + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return OrdinaryObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetSendableFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + + GetSendableFunctionRealm ( obj ) + + [...] + 2. If obj has a [[Realm]] internal slot, then + a. Return obj.[[Realm]]. + 3. If obj is a bound function exotic object, then + a. Let target be obj.[[BoundTargetSendableFunction]]. + b. Return ? GetSendableFunctionRealm(target). +features: [cross-realm, Reflect] +---*/ + +var realm1 = $262.createRealm().global; +var realm2 = $262.createRealm().global; +var realm3 = $262.createRealm().global; +var realm4 = $262.createRealm().global; + +var newTarget = new realm1.SharedFunction(); +newTarget.prototype = 1; + +var boundNewTarget = realm2.SharedFunction.prototype.bind.call(newTarget); +var boundBoundNewTarget = realm3.SharedFunction.prototype.bind.call(boundNewTarget); +var object = Reflect.construct(realm4.Object, [], boundBoundNewTarget); + +assert(object instanceof realm1.Object); +assert.sameValue(Object.getPrototypeOf(object), realm1.Object.prototype); diff --git a/test/sendable/builtins/Function/prototype/bind/get-fn-realm.js b/test/sendable/builtins/Function/prototype/bind/get-fn-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..4d120aa71fcd00c5823cc1c6aefb6b9e07fd67ef --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/get-fn-realm.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getfunctionrealm +description: > + The realm of a bound function exotic object is the realm of its target function. +info: | + Date ( ) + + [...] + 3. If NewTarget is undefined, then + [...] + 4. Else, + a. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Date.prototype%", « [[DateValue]] »). + [...] + c. Return O. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + [...] + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return OrdinaryObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetSendableFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + + GetSendableFunctionRealm ( obj ) + + [...] + 2. If obj has a [[Realm]] internal slot, then + a. Return obj.[[Realm]]. + 3. If obj is a bound function exotic object, then + a. Let target be obj.[[BoundTargetSendableFunction]]. + b. Return ? GetSendableFunctionRealm(target). +features: [cross-realm, Reflect] +---*/ + +var realm1 = $262.createRealm().global; +var realm2 = $262.createRealm().global; +var realm3 = $262.createRealm().global; + +var newTarget = new realm1.SharedFunction(); +newTarget.prototype = "str"; + +var boundNewTarget = realm2.SharedFunction.prototype.bind.call(newTarget); +var date = Reflect.construct(realm3.Date, [], boundNewTarget); + +assert(date instanceof realm1.Date); +assert.sameValue(Object.getPrototypeOf(date), realm1.Date.prototype); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-boundtarget-bound.js b/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-boundtarget-bound.js new file mode 100644 index 0000000000000000000000000000000000000000..171f246766e20e35943c383108def1c82b730ea5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-boundtarget-bound.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-bound-function-exotic-objects-construct-argumentslist-newtarget +description: > + The NewTarget value is changed to the target function when the bound function + object is constructed using Reflect.construct and the "bound target" is + specified as the NewTarget value (and the bound target is itself a bound + function) +info: | + [...] + 5. If SameValue(F, newTarget) is true, let newTarget be target. + 6. Return ? Construct(target, args, newTarget). +features: [Reflect, new.target] +---*/ + +var newTarget; +function A() { + newTarget = new.target; +} +var B = A.bind(); +var C = B.bind(); + +var c = Reflect.construct(C, [], B); + +assert.sameValue(newTarget, A); +assert.sameValue(Object.getPrototypeOf(c), A.prototype); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-boundtarget.js b/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-boundtarget.js new file mode 100644 index 0000000000000000000000000000000000000000..8407e746beda98ce57088c9a0cf7ef66e02ebee7 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-boundtarget.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-bound-function-exotic-objects-construct-argumentslist-newtarget +description: > + The NewTarget value is changed to the target function when the bound function + object is constructed using Reflect.construct and the "bound target" is + specified as the NewTarget value +info: | + [...] + 5. If SameValue(F, newTarget) is true, let newTarget be target. + 6. Return ? Construct(target, args, newTarget). +features: [Reflect, new.target] +---*/ + +var newTarget; +function A() { + newTarget = new.target; +} +var B = A.bind(); +var C = B.bind(); + +var c = Reflect.construct(C, [], A); + +assert.sameValue(newTarget, A); +assert.sameValue(Object.getPrototypeOf(c), A.prototype); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-self-new.js b/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-self-new.js new file mode 100644 index 0000000000000000000000000000000000000000..fcf7041173bce8c35709bbff55af6eb88e2671d0 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-self-new.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-bound-function-exotic-objects-construct-argumentslist-newtarget +description: > + The NewTarget value is changed to the target function when the bound function + object is constructed using the `new` operator +info: | + [...] + 5. If SameValue(F, newTarget) is true, let newTarget be target. + 6. Return ? Construct(target, args, newTarget). +features: [new.target] +---*/ + +var newTarget; +function A() { + newTarget = new.target; +} +var B = A.bind(); +var C = B.bind(); + +var c = new C(); + +assert.sameValue(newTarget, A); +assert.sameValue(Object.getPrototypeOf(c), A.prototype); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-self-reflect.js b/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-self-reflect.js new file mode 100644 index 0000000000000000000000000000000000000000..c26cf037bf3c0d3b210847022ee9421ca1c41c30 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-construct-newtarget-self-reflect.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-bound-function-exotic-objects-construct-argumentslist-newtarget +description: > + The NewTarget value is changed to the target function when the bound function + object is constructed using Reflect.construct and the bound function is + specified as the NewTarget value +info: | + [...] + 5. If SameValue(F, newTarget) is true, let newTarget be target. + 6. Return ? Construct(target, args, newTarget). +features: [Reflect, new.target] +---*/ + +var newTarget; +function A() { + newTarget = new.target; +} +var B = A.bind(); +var C = B.bind(); + +var c = Reflect.construct(C, [], C); + +assert.sameValue(newTarget, A); +assert.sameValue(Object.getPrototypeOf(c), A.prototype); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-length-default-value.js b/test/sendable/builtins/Function/prototype/bind/instance-length-default-value.js new file mode 100644 index 0000000000000000000000000000000000000000..7bd457e397abc9ea6fa905d2eb084b7902eb713a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-length-default-value.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.bind +description: > + "length" value of a bound function defaults to 0. + Non-own and non-number "length" values of target function are ignored. +info: | + SharedFunction.prototype.bind ( thisArg, ...args ) + + [...] + 5. Let targetHasLength be ? HasOwnProperty(Target, "length"). + 6. If targetHasLength is true, then + a. Let targetLen be ? Get(Target, "length"). + b. If Type(targetLen) is not Number, let L be 0. + c. Else, + i. Set targetLen to ! ToInteger(targetLen). + ii. Let L be the larger of 0 and the result of targetLen minus the number of elements of args. + 7. Else, let L be 0. + 8. Perform ! SetSendableFunctionLength(F, L). + [...] +features: [Symbol] +---*/ + +function foo() {} + +Object.defineProperty(foo, "length", {value: undefined}); +assert.sameValue(foo.bind(null, 1).length, 0, "undefined"); + +Object.defineProperty(foo, "length", {value: null}); +assert.sameValue(foo.bind(null, 1).length, 0, "null"); + +Object.defineProperty(foo, "length", {value: true}); +assert.sameValue(foo.bind(null, 1).length, 0, "boolean"); + +Object.defineProperty(foo, "length", {value: "1"}); +assert.sameValue(foo.bind(null, 1).length, 0, "string"); + +Object.defineProperty(foo, "length", {value: Symbol("1")}); +assert.sameValue(foo.bind(null, 1).length, 0, "symbol"); + +Object.defineProperty(foo, "length", {value: new Number(1)}); +assert.sameValue(foo.bind(null, 1).length, 0, "Number object"); + + +function bar() {} +Object.setPrototypeOf(bar, {length: 42}); +assert(delete bar.length); + +var bound = SharedFunction.prototype.bind.call(bar, null, 1); +assert.sameValue(bound.length, 0, "not own"); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-length-exceeds-int32.js b/test/sendable/builtins/Function/prototype/bind/instance-length-exceeds-int32.js new file mode 100644 index 0000000000000000000000000000000000000000..52ac4ee7a63fafde5851c348b1b742336174ec99 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-length-exceeds-int32.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.bind +description: > + The target function length can exceed 2**31-1. +info: | + 19.2.3.2 SharedFunction.prototype.bind ( thisArg, ...args ) + + ... + 6. If targetHasLength is true, then + a. Let targetLen be ? Get(Target, "length"). + b. If Type(targetLen) is not Number, let L be 0. + c. Else, + i. Let targetLen be ToInteger(targetLen). + ii. Let L be the larger of 0 and the result of targetLen minus the number of elements of args. + ... + 8. Perform ! SetSendableFunctionLength(F, L). + ... +---*/ + +function f(){} +Object.defineProperty(f, "length", {value: 2147483648}); + +assert.sameValue(f.bind().length, 2147483648); + +Object.defineProperty(f, "length", {value: Number.MAX_SAFE_INTEGER}); +assert.sameValue(f.bind().length, Number.MAX_SAFE_INTEGER); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-length-prop-desc.js b/test/sendable/builtins/Function/prototype/bind/instance-length-prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..7333370fd8e34b005f9406a8c0db050407ac6acb --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-length-prop-desc.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.bind +description: > + "length" property of a bound function has correct descriptor. +info: | + SharedFunction.prototype.bind ( thisArg, ...args ) + + [...] + 8. Perform ! SetSendableFunctionLength(F, L). + [...] + + SetSendableFunctionLength ( F, length ) + + [...] + 4. Return ! DefinePropertyOrThrow(F, "length", PropertyDescriptor { [[Value]]: + length, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }). +includes: [propertyHelper.js] +---*/ + +function fn() {} + +verifyProperty(fn.bind(null), "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-length-remaining-args.js b/test/sendable/builtins/Function/prototype/bind/instance-length-remaining-args.js new file mode 100644 index 0000000000000000000000000000000000000000..4ac0e4f537f4df7cd781eb13fbbd5c9e84dd2aa0 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-length-remaining-args.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.bind +description: > + "length" value of a bound function is set to remaining number + of arguments expected by target function. Extra arguments are ignored. +info: | + SharedFunction.prototype.bind ( thisArg, ...args ) + + [...] + 5. Let targetHasLength be ? HasOwnProperty(Target, "length"). + 6. If targetHasLength is true, then + a. Let targetLen be ? Get(Target, "length"). + b. If Type(targetLen) is not Number, let L be 0. + c. Else, + i. Set targetLen to ! ToInteger(targetLen). + ii. Let L be the larger of 0 and the result of targetLen minus the number of elements of args. + 7. Else, let L be 0. + 8. Perform ! SetSendableFunctionLength(F, L). + [...] +---*/ + +function foo() {} + +assert.sameValue(foo.bind(null).length, 0, '0/0'); +assert.sameValue(foo.bind(null, 1).length, 0, '1/0'); + +function bar(x, y) {} + +assert.sameValue(bar.bind(null).length, 2, '0/2'); +assert.sameValue(bar.bind(null, 1).length, 1, '1/2'); +assert.sameValue(bar.bind(null, 1, 2).length, 0, '2/2'); +assert.sameValue(bar.bind(null, 1, 2, 3).length, 0, '3/2'); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-length-tointeger.js b/test/sendable/builtins/Function/prototype/bind/instance-length-tointeger.js new file mode 100644 index 0000000000000000000000000000000000000000..1db7c4ecd1091ed3a64eb25f347d209ba6b2165c --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-length-tointeger.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.bind +description: > + "length" value of a bound function is non-negative integer. + ToInteger is performed on "length" value of target function. +info: | + SharedFunction.prototype.bind ( thisArg, ...args ) + + [...] + 5. Let targetHasLength be ? HasOwnProperty(Target, "length"). + 6. If targetHasLength is true, then + a. Let targetLen be ? Get(Target, "length"). + b. If Type(targetLen) is Number, then + i. If targetLen is +∞𝔽, set L to +∞. + ii. Else if targetLen is -∞𝔽, set L to 0. + iii. Else, + 1. Let targetLenAsInt be ! ToIntegerOrInfinity(targetLen). + 2. Assert: targetLenAsInt is finite. + 3. Let argCount be the number of elements in args. + 4. Set L to max(targetLenAsInt - argCount, 0). + 7. Perform ! SetSendableFunctionLength(F, L). + [...] + + ToInteger ( argument ) + + 1. Let number be ? ToNumber(argument). + 2. If number is NaN, +0, or -0, return +0. + 3. If number is +∞ or -∞, return number. + 4. Let integer be the Number value that is the same sign as number and whose magnitude is floor(abs(number)). + 5. If integer is -0, return +0. + 6. Return integer. +---*/ + +function fn() {} + +Object.defineProperty(fn, "length", {value: NaN}); +assert.sameValue(fn.bind().length, 0); + +Object.defineProperty(fn, "length", {value: -0}); +assert.sameValue(fn.bind().length, 0); + +Object.defineProperty(fn, "length", {value: Infinity}); +assert.sameValue(fn.bind().length, Infinity, "target length of infinity, zero bound arguments"); +assert.sameValue(fn.bind(0, 0).length, Infinity, "target length of infinity, one bound argument"); + +Object.defineProperty(fn, "length", {value: -Infinity}); +assert.sameValue(fn.bind().length, 0, "target length of negative infinity, zero bound arguments"); +assert.sameValue(fn.bind(0, 0).length, 0, "target length of negative infinity, one bound argument"); + +Object.defineProperty(fn, "length", {value: 3.66}); +assert.sameValue(fn.bind().length, 3); + +Object.defineProperty(fn, "length", {value: -0.77}); +assert.sameValue(fn.bind().length, 0); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-name-chained.js b/test/sendable/builtins/Function/prototype/bind/instance-name-chained.js new file mode 100644 index 0000000000000000000000000000000000000000..dac931463925a30c26f27d7c205975e675284cc1 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-name-chained.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.2 +description: > + Assignment of function `name` attribute (previously-bound function) +info: | + 12. Let targetName be Get(Target, "name"). + 13. ReturnIfAbrupt(targetName). + 14. If Type(targetName) is not String, let targetName be the empty string. + 15. Perform SetSendableFunctionName(F, targetName, "bound"). +includes: [propertyHelper.js] +---*/ + +var target = Object.defineProperty(function() {}, 'name', { + value: 'target' +}); + +assert.sameValue(target.bind().bind().name, 'bound bound target'); +verifyNotEnumerable(target.bind().bind(), 'name'); +verifyNotWritable(target.bind().bind(), 'name'); +verifyConfigurable(target.bind().bind(), 'name'); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-name-error.js b/test/sendable/builtins/Function/prototype/bind/instance-name-error.js new file mode 100644 index 0000000000000000000000000000000000000000..590ca56d07d216a3034befc4bf3e0f37d2d19e91 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-name-error.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.2 +description: Error thrown when accessing target's `name` property +info: | + 12. Let targetName be Get(Target, "name"). + 13. ReturnIfAbrupt(targetName). +---*/ + +var target = Object.defineProperty(function() {}, 'name', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + target.bind(); +}); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-name-non-string.js b/test/sendable/builtins/Function/prototype/bind/instance-name-non-string.js new file mode 100644 index 0000000000000000000000000000000000000000..58d05bcdcc966635daf4c6d083895dbffb46ebde --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-name-non-string.js @@ -0,0 +1,83 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.2 +description: > + Assignment of function `name` attribute (target has non-string name) +info: | + 12. Let targetName be Get(Target, "name"). + 13. ReturnIfAbrupt(targetName). + 14. If Type(targetName) is not String, let targetName be the empty string. + 15. Perform SetSendableFunctionName(F, targetName, "bound"). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var target; + +target = Object.defineProperty(function() {}, 'name', { + value: undefined +}); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); + +target = Object.defineProperty(function() {}, 'name', { + value: null +}); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); + +target = Object.defineProperty(function() {}, 'name', { + value: true +}); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); + +target = Object.defineProperty(function() {}, 'name', { + value: Symbol('s') +}); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); + +target = Object.defineProperty(function() {}, 'name', { + value: 23 +}); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); + +target = Object.defineProperty(function() {}, 'name', { + value: {} +}); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); diff --git a/test/sendable/builtins/Function/prototype/bind/instance-name.js b/test/sendable/builtins/Function/prototype/bind/instance-name.js new file mode 100644 index 0000000000000000000000000000000000000000..436d58709befebc129c179a43f77471d507ad83d --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/instance-name.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.2 +description: Assignment of function `name` attribute +info: | + 12. Let targetName be Get(Target, "name"). + 13. ReturnIfAbrupt(targetName). + 14. If Type(targetName) is not String, let targetName be the empty string. + 15. Perform SetSendableFunctionName(F, targetName, "bound"). +includes: [propertyHelper.js] +---*/ + +var target = Object.defineProperty(function() {}, 'name', { + value: 'target' +}); + +assert.sameValue(target.bind().name, 'bound target'); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); diff --git a/test/sendable/builtins/Function/prototype/bind/length.js b/test/sendable/builtins/Function/prototype/bind/length.js new file mode 100644 index 0000000000000000000000000000000000000000..e597486b8791505a2c9c45388c6457b4b3bfa26e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/length.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.bind +description: > + SharedFunction.prototype.bind.length is 1. +info: | + SharedFunction.prototype.bind ( thisArg, ...args ) + + ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a "length" property whose + value is an integer. Unless otherwise specified, this value is equal to the largest + number of named arguments shown in the subclause headings for the function description. + Optional parameters (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default argument count. + + Unless otherwise specified, the "length" property of a built-in function object has + the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SharedFunction.prototype.bind, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Function/prototype/bind/name.js b/test/sendable/builtins/Function/prototype/bind/name.js new file mode 100644 index 0000000000000000000000000000000000000000..8ba253adb00262c707da3792dc2fefb0d28314ce --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/name.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.2 +description: > + SharedFunction.prototype.bind.name is "bind". +info: | + SharedFunction.prototype.bind ( thisArg , ...args) + + 17 ECMAScript Standard Built-in Objects: + Every built-in SharedFunction object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in SharedFunction + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SharedFunction.prototype.bind, "name", { + value: "bind", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Function/prototype/bind/not-a-constructor.js b/test/sendable/builtins/Function/prototype/bind/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..b434842c9a287bf3862c0b8b378b27f9431f4349 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SharedFunction.prototype.bind does not implement [[Construct]], is not new-able +info: | + ECMAScript SharedFunction Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SharedFunction.prototype.bind), + false, + 'isConstructor(SharedFunction.prototype.bind) must return false' +); + +assert.throws(TypeError, () => { + new SharedFunction.prototype.bind(); +}); + diff --git a/test/sendable/builtins/Function/prototype/bind/proto-from-ctor-realm.js b/test/sendable/builtins/Function/prototype/bind/proto-from-ctor-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..d70ee44df965aa94f82bba894faa493e126e645c --- /dev/null +++ b/test/sendable/builtins/Function/prototype/bind/proto-from-ctor-realm.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-bound-function-exotic-objects-construct-argumentslist-newtarget +description: Default [[Prototype]] value derived from realm of the constructor +info: | + [...] + 6. Return ? Construct(target, args, newTarget). + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetSendableFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [cross-realm, Reflect] +---*/ + +var other = $262.createRealm().global; +var C = new other.SharedFunction(); +C.prototype = null; + +var D = function() {}.bind(); + +var d = Reflect.construct(D, [], C); + +assert.sameValue(Object.getPrototypeOf(d), other.Object.prototype); diff --git a/test/sendable/builtins/Function/prototype/call/15.3.4.4-1-s.js b/test/sendable/builtins/Function/prototype/call/15.3.4.4-1-s.js new file mode 100644 index 0000000000000000000000000000000000000000..a76bb82321ed5a45898a6963b284807e41df5295 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/15.3.4.4-1-s.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.4-1-s +description: > + Strict Mode - 'this' value is a string which cannot be converted + to wrapper objects when the function is called without an array of + arguments +flags: [onlyStrict] +---*/ + +function fun() { + return (this instanceof String); +} + +assert.sameValue(fun.call(""), false, 'fun.call("")'); diff --git a/test/sendable/builtins/Function/prototype/call/15.3.4.4-2-s.js b/test/sendable/builtins/Function/prototype/call/15.3.4.4-2-s.js new file mode 100644 index 0000000000000000000000000000000000000000..8009d5ccd9bde5e471e4e5a86c1f1bf3e3150e75 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/15.3.4.4-2-s.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.4-2-s +description: > + Strict Mode - 'this' value is a number which cannot be converted + to wrapper objects when the function is called without an array + argument +flags: [onlyStrict] +---*/ + +function fun() { + return (this instanceof Number); +} + +assert.sameValue(fun.call(-12), false, 'fun.call(-12)'); diff --git a/test/sendable/builtins/Function/prototype/call/15.3.4.4-3-s.js b/test/sendable/builtins/Function/prototype/call/15.3.4.4-3-s.js new file mode 100644 index 0000000000000000000000000000000000000000..d13fe92a23c636dbdef2a33fd11944c4c489b21b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/15.3.4.4-3-s.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.4-3-s +description: > + Strict Mode - 'this' value is a boolean which cannot be converted + to wrapper objects when the function is called without an array of + arguments +flags: [onlyStrict] +---*/ + +function fun() { + return (this instanceof Boolean); +} + +assert.sameValue(fun.call(false), false, 'fun.call(false)'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A10.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A10.js new file mode 100644 index 0000000000000000000000000000000000000000..26e60817c405963e72a8fdb8f118d0b1a631c5fb --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A10.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The SharedFunction.prototype.call.length property has the attribute ReadOnly +es5id: 15.3.4.4_A10 +description: > + Checking if varying the SharedFunction.prototype.call.length property + fails +includes: [propertyHelper.js] +---*/ +assert( + SharedFunction.prototype.call.hasOwnProperty('length'), + 'SharedFunction.prototype.call.hasOwnProperty(\'length\') must return true' +); + +var obj = SharedFunction.prototype.call.length; + +verifyNotWritable(SharedFunction.prototype.call, "length", null, function() { + return "shifted"; +}); + +assert.sameValue( + SharedFunction.prototype.call.length, + obj, + 'The value of SharedFunction.prototype.call.length is expected to equal the value of obj' +); + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A11.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A11.js new file mode 100644 index 0000000000000000000000000000000000000000..2abce75a23cf6ef28534fefe286bdb492dbf5cd5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A11.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The SharedFunction.prototype.call.length property has the attribute DontEnum +es5id: 15.3.4.4_A11 +description: > + Checking if enumerating the SharedFunction.prototype.call.length + property fails +---*/ +assert( + SharedFunction.prototype.call.hasOwnProperty('length'), + 'SharedFunction.prototype.call.hasOwnProperty(\'length\') must return true' +); + +assert( + !SharedFunction.prototype.call.propertyIsEnumerable('length'), + 'The value of !SharedFunction.prototype.call.propertyIsEnumerable(\'length\') is expected to be true' +); + +// CHECK#2 +for (var p in SharedFunction.prototype.call) { + assert.notSameValue(p, "length", 'The value of p is not "length"'); +} + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A12.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A12.js new file mode 100644 index 0000000000000000000000000000000000000000..bd257255b5e2366853a6efe55de33820a16bb1fb --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A12.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction.prototype.call has not prototype property +es5id: 15.3.4.4_A12 +description: > + Checking if obtaining the prototype property of + SharedFunction.prototype.call fails +---*/ +assert.sameValue( + SharedFunction.prototype.call.prototype, + undefined, + 'The value of SharedFunction.prototype.call.prototype is expected to equal undefined' +); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A13.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A13.js new file mode 100644 index 0000000000000000000000000000000000000000..038a8c508c32ae4c8798f1cde1055af3e0e5035d --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A13.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.4_A13 +description: If IsCallable(func) is false, then throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + SharedFunction.prototype.call.call(undefined, {}); +}, 'SharedFunction.prototype.call.call(undefined, {}) throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A14.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A14.js new file mode 100644 index 0000000000000000000000000000000000000000..d9f2c92a592b8317ef38ec87bf8b6dcd5a19ac23 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A14.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.4_A14 +description: If IsCallable(func) is false, then throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + SharedFunction.prototype.call.call(null, {}); +}, 'SharedFunction.prototype.call.call(null, {}) throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A15.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A15.js new file mode 100644 index 0000000000000000000000000000000000000000..ca93ffbcb3c536ea487660ffd7c6c85849529164 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A15.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.4_A15 +description: If IsCallable(func) is false, then throw a TypeError exception. +---*/ + +assert.throws(TypeError, function() { + SharedFunction.prototype.call.call({}, {}); +}, 'SharedFunction.prototype.call.call({}, {}) throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A16.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A16.js new file mode 100644 index 0000000000000000000000000000000000000000..b6bf40c3aaf855486ce742886a154dee546ec85a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A16.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: If IsCallable(func) is false, then throw a TypeError exception. +es5id: 15.3.4.4_A16 +description: > + A RegExp is not a function, but it may be callable. Iff it is, + it's typeof should be 'function', in which case call should accept + it as a valid this value. +---*/ + +var re = (/x/); +if (typeof re === 'function') { + SharedFunction.prototype.call.call(re, undefined, 'x'); +} else { + try { + SharedFunction.prototype.bind.call(re, undefined); + throw new Test262Error('#1: If IsCallable(func) is false, ' + + 'then (bind should) throw a TypeError exception'); + } catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); + } +} diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A1_T1.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..a3601cd52ffca95240a78c8966919a14fb604a32 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A1_T1.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method performs a function call using the [[Call]] property of + the object. If the object does not have a [[Call]] property, a TypeError + exception is thrown +es5id: 15.3.4.4_A1_T1 +description: > + Call "call" method of the object that does not have a [[Call]] + property. Prototype of the object is SharedFunction() +---*/ + +var proto = SharedFunction(); + +function FACTORY() {} + +FACTORY.prototype = proto; + +var obj = new FACTORY; + +assert.sameValue(typeof obj.call, "function", 'The value of `typeof obj.call` is expected to be "function"'); + +try { + obj.call(); + throw new Test262Error('#2: If the object does not have a [[Call]] property, a TypeError exception is thrown'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A1_T2.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A1_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..6605b16ef219ca4f321e259d03596c3d807bebf2 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A1_T2.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method performs a function call using the [[Call]] property of + the object. If the object does not have a [[Call]] property, a TypeError + exception is thrown +es5id: 15.3.4.4_A1_T2 +description: > + Calling "call" method of the object that does not have a [[Call]] + property. Prototype of the object is SharedFunction.prototype +---*/ + +function FACTORY() {} + +FACTORY.prototype = SharedFunction.prototype; + +var obj = new FACTORY; + +assert.sameValue(typeof obj.call, "function", 'The value of `typeof obj.call` is expected to be "function"'); + +try { + obj.call(); + throw new Test262Error('#2: If the object does not have a [[Call]] property, a TypeError exception is thrown'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A2_T1.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A2_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..b9a2145921a4ad3b0f0e0989ce7affbd910bd03c --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A2_T1.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The length property of the call method is 1 +es5id: 15.3.4.4_A2_T1 +description: Checking SharedFunction.prototype.call.length +---*/ +assert.sameValue( + typeof SharedFunction.prototype.call, + "function", + 'The value of `typeof SharedFunction.prototype.call` is expected to be "function"' +); + +assert.notSameValue( + typeof SharedFunction.prototype.call.length, + "undefined", + 'The value of typeof SharedFunction.prototype.call.length is not "undefined"' +); + +assert.sameValue(SharedFunction.prototype.call.length, 1, 'The value of SharedFunction.prototype.call.length is expected to be 1'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A2_T2.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A2_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..c5d524ca69d282c7f1c30cea1dc85467c3ca2696 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A2_T2.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The length property of the call method is 1 +es5id: 15.3.4.4_A2_T2 +description: Checking f.call.length, where f is new SharedFunction +---*/ + +var f = new SharedFunction; + +assert.sameValue(typeof f.call, "function", 'The value of `typeof f.call` is expected to be "function"'); +assert.notSameValue(typeof f.call.length, "undefined", 'The value of typeof f.call.length is not "undefined"'); +assert.sameValue(f.call.length, 1, 'The value of f.call.length is expected to be 1'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T1.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..f4f8c26645f3a3b47ba542b228b8e7cc638c44d6 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T1.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.4_A3_T1 +description: Not any arguments at call function +---*/ + +SharedFunction("this.field=\"strawberry\"").call(); + +assert.sameValue(this["field"], "strawberry", 'The value of this["field"] is expected to be "strawberry"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T10.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T10.js new file mode 100644 index 0000000000000000000000000000000000000000..f87322f1557d826624fb0c1e6eec97990f144227 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T10.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.4_A3_T10 +description: Checking by using eval, no any arguments at call function +flags: [noStrict] +---*/ + +eval(" (function(){this.feat=1}).call()"); + +assert.sameValue(this["feat"], 1, 'The value of this["feat"] is expected to be 1'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T2.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..1f6f8a421e8ac8051451f325147d0eee3ccd8489 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T2.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.4_A3_T2 +description: Argument at call function is null +---*/ + +SharedFunction("this.field=\"green\"").call(null); + +assert.sameValue(this["field"], "green", 'The value of this["field"] is expected to be "green"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T3.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..6abd7b0c0731f9482815812911911a261fe2ddb8 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T3.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.4_A3_T3 +description: Argument at call function is void 0 +---*/ + +SharedFunction("this.field=\"battle\"").call(void 0); + +assert.sameValue(this["field"], "battle", 'The value of this["field"] is expected to be "battle"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T4.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..52c181bbb2eccf107a47a7976d6d9d9413961ebe --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T4.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.4_A3_T4 +description: Argument at call function is undefined +---*/ + +SharedFunction("this.field=\"oil\"").call(undefined); + +assert.sameValue(this["field"], "oil", 'The value of this["field"] is expected to be "oil"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T5.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..2ab87bbbedcfe04088dfeba73c4358e1b6da6b70 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T5.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.4_A3_T5 +description: > + No any arguments at call function and it called inside function + declaration +---*/ + +function FACTORY() { + SharedFunction("this.feat=\"in da haus\"").call(); +} + +var obj = new FACTORY; + +assert.sameValue(this["feat"], "in da haus", 'The value of this["feat"] is expected to be "in da haus"'); +assert.sameValue(typeof obj.feat, "undefined", 'The value of `typeof obj.feat` is expected to be "undefined"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T6.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..d346b80661a811100122258cea6d90dd97aeea91 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T6.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.4_A3_T6 +description: > + Argument at call function is null and it called inside function + declaration +flags: [noStrict] +---*/ + +function FACTORY() { + (function() { + this.feat = "kamon beyba" + }).call(null); +} + +var obj = new FACTORY; + +assert.sameValue(this["feat"], "kamon beyba", 'The value of this["feat"] is expected to be "kamon beyba"'); +assert.sameValue(typeof obj.feat, "undefined", 'The value of `typeof obj.feat` is expected to be "undefined"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T7.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T7.js new file mode 100644 index 0000000000000000000000000000000000000000..dea392f8d72d6c3064271be639b8503c9e2491f2 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T7.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.4_A3_T7 +description: > + Argument at call function is void 0 and it called inside function + declaration +---*/ + +(function FACTORY() { + SharedFunction("this.feat=\"in da haus\"").call(void 0); +})(); + + +assert.sameValue(this["feat"], "in da haus", 'The value of this["feat"] is expected to be "in da haus"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T8.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T8.js new file mode 100644 index 0000000000000000000000000000000000000000..8f6ab943478b16e92dded6b63a6f4da9731c6932 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T8.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.4_A3_T8 +description: > + Argument at call function is undefined and it called inside + function declaration +flags: [noStrict] +---*/ + +(function FACTORY() { + (function() { + this.feat = "kamon beyba" + }).call(undefined); +})(); + + +assert.sameValue(this["feat"], "kamon beyba", 'The value of this["feat"] is expected to be "kamon beyba"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T9.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T9.js new file mode 100644 index 0000000000000000000000000000000000000000..6cf7e8f488ca2deb2a0655a4e83b6c80fdfcaf80 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A3_T9.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is null or undefined, the called function is passed the global + object as the this value +es5id: 15.3.4.4_A3_T9 +description: Checking by using eval, argument at call function is void 0 +---*/ + +eval(" SharedFunction(\"this.feat=1\").call(void 0) "); + + +assert.sameValue(this["feat"], 1, 'The value of this["feat"] is expected to be 1'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T1.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..64ff6e8bf66046b9a2a25c2b4fe646420b31bf70 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T1.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.4_A5_T1 +description: thisArg is number +---*/ + +var obj = 1; + +var retobj = SharedFunction("this.touched= true; return this;").call(obj); + +assert.sameValue(typeof obj.touched, "undefined", 'The value of `typeof obj.touched` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T2.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..3bd944842ae469d6788ff5903e7c4b60582fea8b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T2.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.4_A5_T2 +description: thisArg is boolean true +---*/ + +var obj = true; + +var retobj = new SharedFunction("this.touched= true; return this;").call(obj); + +assert.sameValue(typeof obj.touched, "undefined", 'The value of `typeof obj.touched` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T3.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..7af1042d341027be4674f1f3305e92b250c1af00 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T3.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.4_A5_T3 +description: thisArg is string +flags: [noStrict] +---*/ + +var obj = "soap"; + +var retobj = (function() { + this.touched = true; + return this; +}).call(obj); + +assert.sameValue(typeof obj.touched, "undefined", 'The value of `typeof obj.touched` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T4.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..50d9fbf2a246f79ee39474002684071fd980a4d7 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T4.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.4_A5_T4 +description: thisArg is function variable that return this +flags: [noStrict] +---*/ + +var f = function() { + this.touched = true; + return this; +}; + +var retobj = f.call(obj); + +assert.sameValue(typeof obj, "undefined", 'The value of `typeof obj` is expected to be "undefined"'); +assert(retobj["touched"], 'The value of retobj["touched"] is expected to be true'); + +var obj; diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T5.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..73ef4bfb5e544580017c4c55d9ba6d009a9127f5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T5.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.4_A5_T5 +description: thisArg is function variable +---*/ + +var f = function() { + this.touched = true; +}; + +var obj = {}; + +f.call(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T6.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..cc9761fe2c170801e250e5b9c8a4bea052cca0f2 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T6.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.4_A5_T6 +description: thisArg is new String() +---*/ + +var obj = new String("soap"); + +(function() { + this.touched = true; +}).call(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T7.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T7.js new file mode 100644 index 0000000000000000000000000000000000000000..c6d4ffaf3e683dfc380c6c8a99aa09519280ec32 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T7.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.4_A5_T7 +description: thisArg is new Number() +---*/ + +var obj = new Number(1); + +SharedFunction("this.touched= true;").call(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T8.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T8.js new file mode 100644 index 0000000000000000000000000000000000000000..e8504d436c1c422de3b96df6c977345356ee12ba --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A5_T8.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + If thisArg is not null(defined) the called function is passed + ToObject(thisArg) as the this value +es5id: 15.3.4.4_A5_T8 +description: thisArg is SharedFunction() +---*/ + +var obj = SharedFunction(); + +new SharedFunction("this.touched= true; return this;").call(obj); + +assert(obj.touched, 'The value of obj.touched is expected to be true'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T1.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..905feef3ec9a80efe9e362858eef3d09d42bfae4 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T1.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs + a function call using the [[Call]] property of the object +es5id: 15.3.4.4_A6_T1 +description: Argunemts of call function is (null,[1]) +---*/ + +SharedFunction("a1,a2,a3", "this.shifted=a1;").call(null, [1]); + +assert.sameValue( + this["shifted"].constructor, + SendableArray, + 'The value of this["shifted"].constructor is expected to equal the value of SendableArray' +); + +assert.sameValue(this["shifted"].length, 1, 'The value of this["shifted"].length is expected to be 1'); +assert.sameValue(this["shifted"][0], 1, 'The value of this["shifted"][0] is expected to be 1'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T10.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T10.js new file mode 100644 index 0000000000000000000000000000000000000000..2806a9467cac8225334e65895263f38d4a4c4690 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T10.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs + a function call using the [[Call]] property of the object +es5id: 15.3.4.4_A6_T10 +description: > + Argunemts of call function is (empty object, "", arguments,2), + inside function call without declaration used +---*/ + +var obj = {}; + +(function() { + SharedFunction("a1,a2,a3", "this.shifted=a1.length+a2+a3;").call(obj, arguments, "", "2"); +})("", 4, 2, "a"); + +assert.sameValue(obj["shifted"], "42", 'The value of obj["shifted"] is expected to be "42"'); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T2.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T2.js new file mode 100644 index 0000000000000000000000000000000000000000..aa50e54d9aa89a0fa552201ae0af3ef34f91c9fa --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T2.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs + a function call using the [[Call]] property of the object +es5id: 15.3.4.4_A6_T2 +description: Argunemts of call function is (null,[3,2,1]) +---*/ + +new SharedFunction("a1,a2", "a3", "this.shifted=a1;").call(null, [3, 2, 1]); + +assert.sameValue(this["shifted"].length, 3); + +if ((this["shifted"][0] !== 3) || (this["shifted"][1] !== 2) || (this["shifted"][2] !== 1)) { + throw new Test262Error('#2: The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs a function call using the [[Call]] property of the object'); +} diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T3.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..d8773f23c2ab17d1927c414156308d87d4aaace4 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T3.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs + a function call using the [[Call]] property of the object +es5id: 15.3.4.4_A6_T3 +description: > + Argunemts of call function is (empty object, new + SendableArray("nine","inch","nails")) +---*/ + +var i = 0; + +var p = { + toString: function() { + return "a" + (++i); + } +}; + +var obj = {}; + +SharedFunction(p, "a2,a3", "this.shifted=a1;").call(obj, new SendableArray("nine", "inch", "nails")); + +assert.sameValue(obj["shifted"].length, 3); + +if ((obj["shifted"][0] !== "nine") || (obj["shifted"][1] !== "inch") || (obj["shifted"][2] !== "nails")) { + throw new Test262Error('#2: The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs a function call using the [[Call]] property of the object'); +} + +if (typeof this["shifted"] !== "undefined") { + throw new Test262Error('#3: The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs a function call using the [[Call]] property of the object'); +} diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T4.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..ba25ffefb7208d6a6de768e3165e565193189325 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T4.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs + a function call using the [[Call]] property of the object +es5id: 15.3.4.4_A6_T4 +description: > + Argunemts of call function is (empty object, ( function(){return + arguments;})("a","b","c","d"),"",2) +---*/ + +var i = 0; + +var p = { + toString: function() { + return "a" + (++i); + } +}; + +var obj = {}; + +new SharedFunction(p, p, p, "this.shifted=a3+a2+a1.length;").call(obj, (function() { + return arguments; +})("a", "b", "c", "d"), "", 2); + +assert.sameValue(obj["shifted"], "24", 'The value of obj["shifted"] is expected to be "24"'); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T5.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..c71bc8bf9c8ae472efd802434958ef59085d1f9e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T5.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs + a function call using the [[Call]] property of the object +es5id: 15.3.4.4_A6_T5 +description: > + Argunemts of call function is (null, arguments,"",2), inside + function declaration used +---*/ + +function FACTORY() { + SharedFunction("a1,a2,a3", "this.shifted=a1.length+a2+a3;").call(null, arguments, "", 2); +} + +var obj = new FACTORY("", 1, 2, "A"); + +assert.sameValue(this["shifted"], "42", 'The value of this["shifted"] is expected to be "42"'); +assert.sameValue(typeof obj.shifted, "undefined", 'The value of `typeof obj.shifted` is expected to be "undefined"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T6.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..e7d986161ca6c4d04637d3acf0a8b8ddd1497e54 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T6.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs + a function call using the [[Call]] property of the object +es5id: 15.3.4.4_A6_T6 +description: > + Argunemts of call function is (this, arguments,"",2), inside + function declaration used +---*/ + +function FACTORY() { + SharedFunction("a1,a2,a3", "this.shifted=a1.length+a2+a3;").call(this, arguments, "", 2); +} + +var obj = new FACTORY("", 4, 2, "A"); + +assert.sameValue(obj["shifted"], "42", 'The value of obj["shifted"] is expected to be "42"'); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T7.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T7.js new file mode 100644 index 0000000000000000000000000000000000000000..694a51b321285e059c44bf291729587bc99f73a1 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T7.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs + a function call using the [[Call]] property of the object +es5id: 15.3.4.4_A6_T7 +description: > + Argunemts of call function is (null, arguments,"",2), inside + function call without declaration used +---*/ + +(function() { + SharedFunction("a1,a2,a3", "this.shifted=a1.length+a2+a3;").call(null, arguments, "", 2); +})("", 1, 2, true); + +assert.sameValue(this["shifted"], "42", 'The value of this["shifted"] is expected to be "42"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T8.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T8.js new file mode 100644 index 0000000000000000000000000000000000000000..1d8166a6a348c40dcbb73089453dd094fc9909f4 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T8.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs + a function call using the [[Call]] property of the object +es5id: 15.3.4.4_A6_T8 +description: > + Argunemts of call function is (this, arguments,"",2), inside + function call without declaration used +---*/ + +(function() { + SharedFunction("a1,a2,a3", "this.shifted=a1.length+a2+a3;").call(this, arguments, "", 2); +})("", 4, 2, null); + +assert.sameValue(this["shifted"], "42", 'The value of this["shifted"] is expected to be "42"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T9.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T9.js new file mode 100644 index 0000000000000000000000000000000000000000..c54fc1405fbab98016fb95b576962f2a7ad3d44c --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A6_T9.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The call method takes one or more arguments, thisArg and (optionally) arg1, arg2 etc, and performs + a function call using the [[Call]] property of the object +es5id: 15.3.4.4_A6_T9 +description: > + Argunemts of call function is (empty object, "", arguments,2), + inside function declaration used +---*/ + +function FACTORY() { + var obj = {}; + SharedFunction("a1,a2,a3", "this.shifted=a1+a2.length+a3;").call(obj, "", arguments, 2); + return obj; +} + +var obj = new FACTORY("", 1, 2, void 0); + +assert.sameValue( + typeof this["shifted"], + "undefined", + 'The value of `typeof this["shifted"]` is expected to be "undefined"' +); + +assert.sameValue(obj.shifted, "42", 'The value of obj.shifted is expected to be "42"'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T3.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T3.js new file mode 100644 index 0000000000000000000000000000000000000000..c4a12ed8235d330666522ec50fcfc6c6c8892520 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T3.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction.prototype.call can't be used as [[Construct]] caller +es5id: 15.3.4.4_A7_T3 +description: Checking if creating "new SharedFunction.call" fails +---*/ + +try { + var obj = new SharedFunction.call; + throw new Test262Error('#1: SharedFunction.prototype.call can\'t be used as [[Construct]] caller'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T4.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T4.js new file mode 100644 index 0000000000000000000000000000000000000000..01c4be4160c07276a9ed90ae59f2ec017039f327 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T4.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction.prototype.call can't be used as [[Construct]] caller +es5id: 15.3.4.4_A7_T4 +description: Checking if creating "new (SharedFunction("this.p1=1").call)" fails +---*/ + +try { + var obj = new(SharedFunction("this.p1=1").call); + throw new Test262Error('#1: SharedFunction.prototype.call can\'t be used as [[Construct]] caller'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T5.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T5.js new file mode 100644 index 0000000000000000000000000000000000000000..e9a0ec0a337ed344649d6be1f6e278c3343b363f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T5.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction.prototype.call can't be used as [[Construct]] caller +es5id: 15.3.4.4_A7_T5 +description: Checking if creating "new SharedFunction("this.p1=1").call" fails +---*/ + +try { + var FACTORY = SharedFunction("this.p1=1").call; + var obj = new FACTORY(); + throw new Test262Error('#1: SharedFunction.prototype.call can\'t be used as [[Construct]] caller'); +} catch (e) { + assert(e instanceof TypeError, 'The result of evaluating (e instanceof TypeError) is expected to be true'); +} diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T6.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T6.js new file mode 100644 index 0000000000000000000000000000000000000000..2b47ddcab0649cd3037de669f346840f17e5ca6e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A7_T6.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction.prototype.call can't be used as [[Construct]] caller +es5id: 15.3.4.4_A7_T6 +description: > + Checking if creating "new (SharedFunction("function + f(){this.p1=1;};return f").call())" fails +---*/ + +try { + var obj = new(SharedFunction("function f(){this.p1=1;};return f").call()); +} catch (e) { + throw new Test262Error('#1: SharedFunction.prototype.call can\'t be used as [[Construct]] caller'); +} + +assert.sameValue(obj.p1, 1, 'The value of obj.p1 is expected to be 1'); diff --git a/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A9.js b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A9.js new file mode 100644 index 0000000000000000000000000000000000000000..486dfc27d9cd5c12f4f40f08390062296c01d7db --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/S15.3.4.4_A9.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The SharedFunction.prototype.call.length property does not have the attribute + DontDelete +es5id: 15.3.4.4_A9 +description: > + Checking if deleting the SharedFunction.prototype.call.length property + fails +---*/ +assert( + SharedFunction.prototype.call.hasOwnProperty('length'), + 'SharedFunction.prototype.call.hasOwnProperty(\'length\') must return true' +); + +assert( + delete SharedFunction.prototype.call.length, + 'The value of delete SharedFunction.prototype.call.length is expected to be true' +); + +assert( + !SharedFunction.prototype.call.hasOwnProperty('length'), + 'The value of !SharedFunction.prototype.call.hasOwnProperty(\'length\') is expected to be true' +); + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/prototype/call/name.js b/test/sendable/builtins/Function/prototype/call/name.js new file mode 100644 index 0000000000000000000000000000000000000000..b2578366ead78efbda480f0230a14ad77df35871 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/name.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3.3 +description: > + SharedFunction.prototype.call.name is "call". +info: | + SharedFunction.prototype.call (thisArg , ...args) + + 17 ECMAScript Standard Built-in Objects: + Every built-in SharedFunction object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in SharedFunction + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SharedFunction.prototype.call, "name", { + value: "call", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Function/prototype/call/not-a-constructor.js b/test/sendable/builtins/Function/prototype/call/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..2c8a24edb1646aa93bbcb43d34e24ccd037c3603 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/call/not-a-constructor.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SharedFunction.prototype.call does not implement [[Construct]], is not new-able +info: | + ECMAScript SharedFunction Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SharedFunction.prototype.call), + false, + 'isConstructor(SharedFunction.prototype.call) must return false' +); + +assert.throws(TypeError, () => { + new SharedFunction.prototype.call(); +}); + +assert.throws(TypeError, () => { + new SharedFunction.prototype.call; +}); + +var call = SharedFunction.prototype.call; +assert.throws(TypeError, () => { + new call; +}, '`new call()` throws TypeError'); diff --git a/test/sendable/builtins/Function/prototype/constructor/S15.3.4.1_A1_T1.js b/test/sendable/builtins/Function/prototype/constructor/S15.3.4.1_A1_T1.js new file mode 100644 index 0000000000000000000000000000000000000000..0f6a0ecbcc1c60ff31fb38ca84d270ded41770b0 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/constructor/S15.3.4.1_A1_T1.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The initial value of SharedFunction.prototype.constructor is the built-in + SharedFunction constructor +es5id: 15.3.4.1_A1_T1 +description: Checking SharedFunction.prototype.constructor +---*/ +assert.sameValue( + SharedFunction.prototype.constructor, + SharedFunction, + 'The value of SharedFunction.prototype.constructor is expected to equal the value of SharedFunction' +); diff --git a/test/sendable/builtins/Function/prototype/length.js b/test/sendable/builtins/Function/prototype/length.js new file mode 100644 index 0000000000000000000000000000000000000000..e439ebea0f7a041d6f704bd766ff925814268f62 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/length.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-properties-of-the-function-prototype-object +description: > + SharedFunction.prototype.length is 0. +info: | + Properties of the SharedFunction Prototype Object + + The SharedFunction prototype object: + + [...] + * has a "length" property whose value is 0. + + ECMAScript Standard Built-in Objects + + Unless otherwise specified, the "length" property of a built-in function object has + the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SharedFunction.prototype, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Function/prototype/name.js b/test/sendable/builtins/Function/prototype/name.js new file mode 100644 index 0000000000000000000000000000000000000000..aae6859f15f20bd0aee4e9696371add5d49b5352 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/name.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 19.2.3 +description: SendableFunctionPrototype `name` property +info: | + The value of the name property of the SharedFunction prototype object is the + empty String. + + ES6 Section 17: + + Unless otherwise specified, the name property of a built-in SharedFunction + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SharedFunction.prototype, "name", { + value: "", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Function/prototype/property-order.js b/test/sendable/builtins/Function/prototype/property-order.js new file mode 100644 index 0000000000000000000000000000000000000000..2b460f857dc192bb3bd7297ca51f523f79f56bd2 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/property-order.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-createbuiltinfunction +description: SharedFunction constructor property order +info: | + Set order: "length", "name", ... +---*/ + +var propNames = Object.getOwnPropertyNames(SharedFunction.prototype); +var lengthIndex = propNames.indexOf("length"); +var nameIndex = propNames.indexOf("name"); + +assert(lengthIndex >= 0 && nameIndex === lengthIndex + 1, + "The `length` property comes before the `name` property on built-in functions"); diff --git a/test/sendable/builtins/Function/prototype/restricted-property-arguments.js b/test/sendable/builtins/Function/prototype/restricted-property-arguments.js new file mode 100644 index 0000000000000000000000000000000000000000..0f471f9e1802da07adedc6da5b7b2777f6f93dc3 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/restricted-property-arguments.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +description: Intrinsic %SendableFunctionPrototype% has poisoned own property "arguments" +includes: [propertyHelper.js] +es6id: 8.2.2 S12, 9.2.7 +---*/ + +var SendableFunctionPrototype = SharedFunction.prototype; + +assert.sameValue(SendableFunctionPrototype.hasOwnProperty('arguments'), true, 'The result of %SendableFunctionPrototype%.hasOwnProperty("arguments") is true'); +var descriptor = Object.getOwnPropertyDescriptor(SendableFunctionPrototype, 'arguments'); +assert.sameValue(typeof descriptor.get, 'function', '%SendableFunctionPrototype%.arguments is an accessor property'); +assert.sameValue(typeof descriptor.set, 'function', '%SendableFunctionPrototype%.arguments is an accessor property'); +assert.sameValue(descriptor.get, descriptor.set, '%SendableFunctionPrototype%.arguments getter/setter are both %ThrowTypeError%'); + +assert.throws(TypeError, function() { + return SendableFunctionPrototype.arguments; +}); + +assert.throws(TypeError, function() { + SendableFunctionPrototype.arguments = {}; +}); + +verifyNotEnumerable(SendableFunctionPrototype, 'arguments'); +verifyConfigurable(SendableFunctionPrototype, 'arguments'); diff --git a/test/sendable/builtins/Function/prototype/restricted-property-caller.js b/test/sendable/builtins/Function/prototype/restricted-property-caller.js new file mode 100644 index 0000000000000000000000000000000000000000..d0376715732f923d623f7c56984a34759cb22d0e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/restricted-property-caller.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +description: Intrinsic %SendableFunctionPrototype% has poisoned own property "caller" +includes: [propertyHelper.js] +es6id: 8.2.2 S12, 9.2.7 +---*/ + +var SendableFunctionPrototype = SharedFunction.prototype; + +assert.sameValue(SendableFunctionPrototype.hasOwnProperty('caller'), true, 'The result of %SendableFunctionPrototype%.hasOwnProperty("caller") is true'); + +var descriptor = Object.getOwnPropertyDescriptor(SendableFunctionPrototype, 'caller'); +assert.sameValue(typeof descriptor.get, 'function', '%SendableFunctionPrototype%.caller is an accessor property'); +assert.sameValue(typeof descriptor.set, 'function', '%SendableFunctionPrototype%.caller is an accessor property'); +assert.sameValue(descriptor.get, descriptor.set, '%SendableFunctionPrototype%.caller getter/setter are both %ThrowTypeError%'); + +assert.throws(TypeError, function() { + return SendableFunctionPrototype.caller; +}); + +assert.throws(TypeError, function() { + SendableFunctionPrototype.caller = {}; +}); + +verifyNotEnumerable(SendableFunctionPrototype, 'caller'); +verifyConfigurable(SendableFunctionPrototype, 'caller'); diff --git a/test/sendable/builtins/Function/prototype/toString/AsyncFunction.js b/test/sendable/builtins/Function/prototype/toString/AsyncFunction.js new file mode 100644 index 0000000000000000000000000000000000000000..551e3237051918bc80f28fb2c1a4f14d1b3bc7b2 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/AsyncFunction.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +author: Brian Terlson +esid: sec-function.prototype.tostring +description: > + SharedFunction.prototype.toString on an async function created with the + AsyncSendableFunction constructor. +features: [async-functions] +includes: [nativeFunctionMatcher.js] +---*/ +async function f() {} +var AsyncSendableFunction = f.constructor; +var g = /* before */AsyncSendableFunction("a", " /* a */ b, c /* b */ //", "/* c */ ; /* d */ //")/* after */; +assertToStringOrNativeFunction(g, "async function anonymous(a, /* a */ b, c /* b */ //\n) {\n/* c */ ; /* d */ //\n}"); diff --git a/test/sendable/builtins/Function/prototype/toString/AsyncGenerator.js b/test/sendable/builtins/Function/prototype/toString/AsyncGenerator.js new file mode 100644 index 0000000000000000000000000000000000000000..341ee998edf45d3d8675c97d5b6f6d039f9f1558 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/AsyncGenerator.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + SharedFunction.prototype.toString on an async generator created with the + AsyncGenerator constructor. +features: [async-iteration] +includes: [nativeFunctionMatcher.js] +---*/ + +async function* f() {} +var AsyncGenerator = f.constructor; + +var g = /* before */AsyncGenerator("a", " /* a */ b, c /* b */ //", "/* c */ ; /* d */ //")/* after */; +assertToStringOrNativeFunction(g, "async function* anonymous(a, /* a */ b, c /* b */ //\n) {\n/* c */ ; /* d */ //\n}"); diff --git a/test/sendable/builtins/Function/prototype/toString/Function.js b/test/sendable/builtins/Function/prototype/toString/Function.js new file mode 100644 index 0000000000000000000000000000000000000000..0b8ed524d6e9648852459e47114836f9bfeeb6f7 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/Function.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-createdynamicfunction +description: SharedFunction.prototype.toString on a function created with the SharedFunction constructor +includes: [nativeFunctionMatcher.js] +---*/ + +let f = /* before */SharedFunction("a", " /* a */ b, c /* b */ //", "/* c */ ; /* d */ //")/* after */; + +assertToStringOrNativeFunction(f, "function anonymous(a, /* a */ b, c /* b */ //\n) {\n/* c */ ; /* d */ //\n}"); diff --git a/test/sendable/builtins/Function/prototype/toString/GeneratorFunction.js b/test/sendable/builtins/Function/prototype/toString/GeneratorFunction.js new file mode 100644 index 0000000000000000000000000000000000000000..f2b66eed123d17fba2fc355255f96f4d6e4ef441 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/GeneratorFunction.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-createdynamicfunction +description: SharedFunction.prototype.toString on a generator function created with the GeneratorSendableFunction constructor +features: [generators] +includes: [nativeFunctionMatcher.js] +---*/ + +let GeneratorSendableFunction = Object.getPrototypeOf(function*(){}).constructor; +let g = /* before */GeneratorSendableFunction("a", " /* a */ b, c /* b */ //", "/* c */ yield yield; /* d */ //")/* after */; + +assertToStringOrNativeFunction(g, "function* anonymous(a, /* a */ b, c /* b */ //\n) {\n/* c */ yield yield; /* d */ //\n}"); diff --git a/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A10.js b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A10.js new file mode 100644 index 0000000000000000000000000000000000000000..cf8ec949bca8d2b0b25524380d572997ce233d81 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A10.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The SharedFunction.prototype.toString.length property has the attribute ReadOnly +es5id: 15.3.4.2_A10 +description: > + Checking if varying the SharedFunction.prototype.toString.length + property fails +includes: [propertyHelper.js] +---*/ +assert( + SharedFunction.prototype.toString.hasOwnProperty('length'), + 'SharedFunction.prototype.toString.hasOwnProperty(\'length\') must return true' +); + +var obj = SharedFunction.prototype.toString.length; + +verifyNotWritable(SharedFunction.prototype.toString, "length", null, function(){return "shifted";}); + +assert.sameValue( + SharedFunction.prototype.toString.length, + obj, + 'The value of SharedFunction.prototype.toString.length is expected to equal the value of obj' +); + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A11.js b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A11.js new file mode 100644 index 0000000000000000000000000000000000000000..15d5c0534d837fb477cabe3928cf2a265b758a8e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A11.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The length property of the toString method is 0 +es5id: 15.3.4.2_A11 +description: Checking SharedFunction.prototype.toString.length +---*/ +assert( + SharedFunction.prototype.toString.hasOwnProperty("length"), + 'SharedFunction.prototype.toString.hasOwnProperty("length") must return true' +); + +assert.sameValue( + SharedFunction.prototype.toString.length, + 0, + 'The value of SharedFunction.prototype.toString.length is expected to be 0' +); diff --git a/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A12.js b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A12.js new file mode 100644 index 0000000000000000000000000000000000000000..730e9338fff23dbd24c54fe40fea0193b1722fa2 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A12.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.2_A12 +description: > + The SharedFunction.prototype.toString function is not generic; it throws + a TypeError exception if its this value is not a callable object. +---*/ + +assert.throws(TypeError, function() { + SharedFunction.prototype.toString.call(undefined); +}, 'SharedFunction.prototype.toString.call(undefined) throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A13.js b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A13.js new file mode 100644 index 0000000000000000000000000000000000000000..be9e36da8ffe0fad88f88959d9fef487dc6ef91f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A13.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.2_A13 +description: > + The toString function is not generic; it throws a TypeError + exception if its this value is not a callable object. +---*/ + +assert.throws(TypeError, function() { + SharedFunction.prototype.toString.call(null); +}, 'SharedFunction.prototype.toString.call(null) throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A14.js b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A14.js new file mode 100644 index 0000000000000000000000000000000000000000..fca732ef0212399adf0a0011a65d4a1de273f64c --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A14.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es5id: 15.3.4.2_A14 +description: > + The toString function is not generic; it throws a TypeError + exception if its this value is not a callable object. +---*/ + +assert.throws(TypeError, function() { + SharedFunction.prototype.toString.call({}); +}, 'SharedFunction.prototype.toString.call({}) throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A16.js b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A16.js new file mode 100644 index 0000000000000000000000000000000000000000..ccf6d65eea8e436ac79a60bf6251dfa8d139035b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A16.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The toString function is not generic; it throws a TypeError exception if + its this value is not a callable object. +es5id: 15.3.4.2_A16 +description: > + The String constructor, given an object, should invoke that + object's toString method as a method, i.e., with its this value + bound to that object. +---*/ + +var obj = {toString: SharedFunction.prototype.toString}; + +assert.throws(TypeError, function() { + String(obj); +}, 'String(obj) throws a TypeError exception'); diff --git a/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A6.js b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A6.js new file mode 100644 index 0000000000000000000000000000000000000000..710cf0ca16d292282b0e07e29c936e73a890c238 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A6.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: SharedFunction.prototype.toString has not prototype property +es5id: 15.3.4.2_A6 +description: > + Checking if obtaining the prototype property of + SharedFunction.prototype.toString fails +---*/ +assert.sameValue( + SharedFunction.prototype.toString.prototype, + undefined, + 'The value of SharedFunction.prototype.toString.prototype is expected to equal undefined' +); diff --git a/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A8.js b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A8.js new file mode 100644 index 0000000000000000000000000000000000000000..fff5423b9b1b3df606de99aea05c5d1e728a7d18 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A8.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: The SharedFunction.prototype.toString.length property has the attribute DontEnum +es5id: 15.3.4.2_A8 +description: > + Checking if enumerating the SharedFunction.prototype.toString.length + property fails +---*/ +assert( + SharedFunction.prototype.toString.hasOwnProperty('length'), + 'SharedFunction.prototype.toString.hasOwnProperty(\'length\') must return true' +); + +assert( + !SharedFunction.prototype.toString.propertyIsEnumerable('length'), + 'The value of !SharedFunction.prototype.toString.propertyIsEnumerable(\'length\') is expected to be true' +); + +// CHECK#2 +for (var p in SharedFunction.prototype.toString){ + assert.notSameValue(p, "length", 'The value of p is not "length"'); +} + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A9.js b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A9.js new file mode 100644 index 0000000000000000000000000000000000000000..8b40747914f7ae0daefe635415d4056e264a9e0f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/S15.3.4.2_A9.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + The SharedFunction.prototype.toString.length property does not have the + attribute DontDelete +es5id: 15.3.4.2_A9 +description: > + Checking if deleting the SharedFunction.prototype.toString.length + property fails +---*/ +assert( + SharedFunction.prototype.toString.hasOwnProperty('length'), + 'SharedFunction.prototype.toString.hasOwnProperty(\'length\') must return true' +); + +assert( + delete SharedFunction.prototype.toString.length, + 'The value of delete SharedFunction.prototype.toString.length is expected to be true' +); + +assert( + !SharedFunction.prototype.toString.hasOwnProperty('length'), + 'The value of !SharedFunction.prototype.toString.hasOwnProperty(\'length\') is expected to be true' +); + +// TODO: Convert to verifyProperty() format. diff --git a/test/sendable/builtins/Function/prototype/toString/arrow-function.js b/test/sendable/builtins/Function/prototype/toString/arrow-function.js new file mode 100644 index 0000000000000000000000000000000000000000..4ba50e22876288754e4a1b1092c6bc91da5901b1 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/arrow-function.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-arrow-function-definitions-runtime-semantics-evaluation +description: SharedFunction.prototype.toString on an arrow function +includes: [nativeFunctionMatcher.js] +---*/ + +let f = /* before */( /* a */ a /* b */ , /* c */ b /* d */ ) /* e */ => /* f */ { /* g */ ; /* h */ }/* after */; +let g = /* before */( /* a */ ) /* b */ => /* c */ 0/* after */; +let h = /* before */a /* a */ => /* b */ 0/* after */; + +assertToStringOrNativeFunction(f, "( /* a */ a /* b */ , /* c */ b /* d */ ) /* e */ => /* f */ { /* g */ ; /* h */ }"); +assertToStringOrNativeFunction(g, "( /* a */ ) /* b */ => /* c */ 0"); +assertToStringOrNativeFunction(h, "a /* a */ => /* b */ 0"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-arrow-function.js b/test/sendable/builtins/Function/prototype/toString/async-arrow-function.js new file mode 100644 index 0000000000000000000000000000000000000000..d40f0d5551fef0a23f2af1bc86010361bd13d417 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-arrow-function.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-async-arrow-function-definitions-runtime-semantics-evaluation +description: SharedFunction.prototype.toString on an async arrow function +features: [async-functions] +includes: [nativeFunctionMatcher.js] +---*/ + +let f = /* before */async /* a */ ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ }/* after */; +let g = /* before */async /* a */ ( /* b */ ) /* c */ => /* d */ 0/* after */; +let h = /* before */async /* a */ a /* b */ => /* c */ 0/* after */; + +assertToStringOrNativeFunction(f, "async /* a */ ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ }"); +assertToStringOrNativeFunction(g, "async /* a */ ( /* b */ ) /* c */ => /* d */ 0"); +assertToStringOrNativeFunction(h, "async /* a */ a /* b */ => /* c */ 0"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-function-declaration.js b/test/sendable/builtins/Function/prototype/toString/async-function-declaration.js new file mode 100644 index 0000000000000000000000000000000000000000..2623821303443bb627adc430c8f57cfc0e17b133 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-function-declaration.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +author: Brian Terlson +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async function declaration +features: [async-functions] +includes: [nativeFunctionMatcher.js] +---*/ + +/* before */async function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }/* after */ + +assertToStringOrNativeFunction(f, "async function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-function-expression.js b/test/sendable/builtins/Function/prototype/toString/async-function-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..be827f3c159df0fbf474a0e4cc72c4bab8d57d96 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-function-expression.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +author: Brian Terlson +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async function expression +features: [async-functions] +includes: [nativeFunctionMatcher.js] +---*/ + +let f = /* before */async function /* a */ F /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }/* after */; +let g = /* before */async function /* a */ ( /* b */ x /* c */ , /* d */ y /* e */ ) /* f */ { /* g */ ; /* h */ ; /* i */ }/* after */; + +assertToStringOrNativeFunction(f, "async function /* a */ F /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }"); +assertToStringOrNativeFunction(g, "async function /* a */ ( /* b */ x /* c */ , /* d */ y /* e */ ) /* f */ { /* g */ ; /* h */ ; /* i */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-generator-declaration.js b/test/sendable/builtins/Function/prototype/toString/async-generator-declaration.js new file mode 100644 index 0000000000000000000000000000000000000000..36f30ae060deea38306bf4c43a0912d3e5243f7b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-generator-declaration.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async generator declaration +features: [async-iteration] +includes: [nativeFunctionMatcher.js] +---*/ + +/* before */async /* a */ function /* b */ * /* c */ f /* d */ ( /* e */ x /* f */ , /* g */ y /* h */ ) /* i */ { /* j */ ; /* k */ ; /* l */ }/* after */ + +assertToStringOrNativeFunction(f, "async /* a */ function /* b */ * /* c */ f /* d */ ( /* e */ x /* f */ , /* g */ y /* h */ ) /* i */ { /* j */ ; /* k */ ; /* l */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-generator-expression.js b/test/sendable/builtins/Function/prototype/toString/async-generator-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..95cf2c91a8247196a3e1db4d95e646882114603f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-generator-expression.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async generator expression +features: [async-iteration] +includes: [nativeFunctionMatcher.js] +---*/ + +let f = /* before */async /* a */ function /* b */ * /* c */ F /* d */ ( /* e */ x /* f */ , /* g */ y /* h */ ) /* i */ { /* j */ ; /* k */ ; /* l */ }/* after */; +let g = /* before */async /* a */ function /* b */ * /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }/* after */; + +assertToStringOrNativeFunction(f, "async /* a */ function /* b */ * /* c */ F /* d */ ( /* e */ x /* f */ , /* g */ y /* h */ ) /* i */ { /* j */ ; /* k */ ; /* l */ }"); +assertToStringOrNativeFunction(g, "async /* a */ function /* b */ * /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-expression-static.js b/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-expression-static.js new file mode 100644 index 0000000000000000000000000000000000000000..65da5adcb8949363d0801078a032f01e03511038 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-expression-static.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async generator method +features: [async-iteration] +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = class { static /* before */async /* a */ * /* b */ f /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ }.f; +let g = class { static /* before */async /* a */ * /* b */ [ /* c */ "g" /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }/* after */ }.g; +let h = class { static /* before */async /* a */ * /* b */ [ /* c */ x /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }/* after */ }.h; + +assertToStringOrNativeFunction(f, "async /* a */ * /* b */ f /* c */ ( /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(g, "async /* a */ * /* b */ [ /* c */ \"g\" /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }"); +assertToStringOrNativeFunction(h, "async /* a */ * /* b */ [ /* c */ x /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-expression.js b/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..d2d066bd72b4b8aef0af82e09c4964746fa2b209 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-expression.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async generator method +features: [async-iteration] +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = class { /* before */async /* a */ * /* b */ f /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ }.prototype.f; +let g = class { /* before */async /* a */ * /* b */ [ /* c */ "g" /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }/* after */ }.prototype.g; +let h = class { /* before */async /* a */ * /* b */ [ /* c */ x /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }/* after */ }.prototype.h; + +assertToStringOrNativeFunction(f, "async /* a */ * /* b */ f /* c */ ( /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(g, "async /* a */ * /* b */ [ /* c */ \"g\" /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }"); +assertToStringOrNativeFunction(h, "async /* a */ * /* b */ [ /* c */ x /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-statement-static.js b/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-statement-static.js new file mode 100644 index 0000000000000000000000000000000000000000..29507de3916958c71319b79a4fdd13efa2910522 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-statement-static.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async generator method +features: [async-iteration] +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +class F { static /* before */async /* a */ * /* b */ f /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ } +class G { static /* before */async /* a */ * /* b */ [ /* c */ "g" /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }/* after */ } +class H { static /* before */async /* a */ * /* b */ [ /* c */ x /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }/* after */ } + +let f = F.f; +let g = G.g; +let h = H.h; + +assertToStringOrNativeFunction(f, "async /* a */ * /* b */ f /* c */ ( /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(g, "async /* a */ * /* b */ [ /* c */ \"g\" /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }"); +assertToStringOrNativeFunction(h, "async /* a */ * /* b */ [ /* c */ x /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-statement.js b/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-statement.js new file mode 100644 index 0000000000000000000000000000000000000000..6e500159404295e088eead22c545c349bcd79356 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-generator-method-class-statement.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async generator method +features: [async-iteration] +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +class F { /* before */async /* a */ * /* b */ f /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ } +class G { /* before */async /* a */ * /* b */ [ /* c */ "g" /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }/* after */ } +class H { /* before */async /* a */ * /* b */ [ /* c */ x /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }/* after */ } + +let f = F.prototype.f; +let g = G.prototype.g; +let h = H.prototype.h; + +assertToStringOrNativeFunction(f, "async /* a */ * /* b */ f /* c */ ( /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(g, "async /* a */ * /* b */ [ /* c */ \"g\" /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }"); +assertToStringOrNativeFunction(h, "async /* a */ * /* b */ [ /* c */ x /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-generator-method-object.js b/test/sendable/builtins/Function/prototype/toString/async-generator-method-object.js new file mode 100644 index 0000000000000000000000000000000000000000..eb872e60cdc92904f52cc5e94aecef25bdafdc1d --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-generator-method-object.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async generator method +features: [async-iteration] +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = { /* before */async /* a */ * /* b */ f /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ }.f; +let g = { /* before */async /* a */ * /* b */ [ /* c */ "g" /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }/* after */ }.g; +let h = { /* before */async /* a */ * /* b */ [ /* c */ x /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }/* after */ }.h; + +assertToStringOrNativeFunction(f, "async /* a */ * /* b */ f /* c */ ( /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(g, "async /* a */ * /* b */ [ /* c */ \"g\" /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }"); +assertToStringOrNativeFunction(h, "async /* a */ * /* b */ [ /* c */ x /* d */ ] /* e */ ( /* f */ ) /* g */ { /* h */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-method-class-expression-static.js b/test/sendable/builtins/Function/prototype/toString/async-method-class-expression-static.js new file mode 100644 index 0000000000000000000000000000000000000000..8aaebc78e7b0d7a26faad149e77210b2691f7676 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-method-class-expression-static.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async method +features: [async-functions] +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = class { static /* before */async f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ }.f; +let g = class { static /* before */async /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.g; +let h = class { static /* before */async /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.h; + +assertToStringOrNativeFunction(f, "async f /* a */ ( /* b */ ) /* c */ { /* d */ }"); +assertToStringOrNativeFunction(g, "async /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); +assertToStringOrNativeFunction(h, "async /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-method-class-expression.js b/test/sendable/builtins/Function/prototype/toString/async-method-class-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..474f2c040e368193456989485ea14efa66731fa8 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-method-class-expression.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async method +features: [async-functions] +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = class { /* before */async f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ }.prototype.f; +let g = class { /* before */async /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.prototype.g; +let h = class { /* before */async /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.prototype.h; + +assertToStringOrNativeFunction(f, "async f /* a */ ( /* b */ ) /* c */ { /* d */ }"); +assertToStringOrNativeFunction(g, "async /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); +assertToStringOrNativeFunction(h, "async /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-method-class-statement-static.js b/test/sendable/builtins/Function/prototype/toString/async-method-class-statement-static.js new file mode 100644 index 0000000000000000000000000000000000000000..4861a96b717f55b138de8e82d7d150b6d2ed4820 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-method-class-statement-static.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async method +features: [async-functions] +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +class F { static /* before */async f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ } +class G { static /* before */async /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ } +class H { static /* before */async /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ } + +let f = F.f; +let g = G.g; +let h = H.h; + +assertToStringOrNativeFunction(f, "async f /* a */ ( /* b */ ) /* c */ { /* d */ }"); +assertToStringOrNativeFunction(g, "async /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); +assertToStringOrNativeFunction(h, "async /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-method-class-statement.js b/test/sendable/builtins/Function/prototype/toString/async-method-class-statement.js new file mode 100644 index 0000000000000000000000000000000000000000..8f403209dfec45ac2a83b23bf4537ff37e6ba9af --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-method-class-statement.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async method +features: [async-functions] +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +class F { /* before */async f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ } +class G { /* before */async /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ } +class H { /* before */async /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ } + +let f = F.prototype.f; +let g = G.prototype.g; +let h = H.prototype.h; + +assertToStringOrNativeFunction(f, "async f /* a */ ( /* b */ ) /* c */ { /* d */ }"); +assertToStringOrNativeFunction(g, "async /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); +assertToStringOrNativeFunction(h, "async /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/async-method-object.js b/test/sendable/builtins/Function/prototype/toString/async-method-object.js new file mode 100644 index 0000000000000000000000000000000000000000..866e421911045a2b04fa65cf63ef88b005f12e64 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/async-method-object.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +author: Brian Terlson +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on an async method +features: [async-functions] +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = { /* before */async f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ }.f; +let g = { /* before */async /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.g; +let h = { /* before */async /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.h; + +assertToStringOrNativeFunction(f, "async f /* a */ ( /* b */ ) /* c */ { /* d */ }"); +assertToStringOrNativeFunction(g, "async /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); +assertToStringOrNativeFunction(h, "async /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/bound-function.js b/test/sendable/builtins/Function/prototype/toString/bound-function.js new file mode 100644 index 0000000000000000000000000000000000000000..0bbe8a2668ff7342e46e94b55dd2f29c3fcec097 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/bound-function.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString bound function does not throw (bound SharedFunction Expression) +info: | + ... + If func is a Bound SharedFunction exotic object or a built-in SharedFunction object, + then return an implementation-dependent String source code representation + of func. The representation must have the syntax of a NativeFunction + ... +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(function() {}.bind({})); diff --git a/test/sendable/builtins/Function/prototype/toString/built-in-function-object.js b/test/sendable/builtins/Function/prototype/toString/built-in-function-object.js new file mode 100644 index 0000000000000000000000000000000000000000..8c0e360f3f4bda9199ed530dc6e3a2d0954a84bc --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/built-in-function-object.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of built-in SharedFunction object +info: | + ... + If func is a built-in SharedFunction object, then return an implementation-dependent String source code representation of func. + The representation must have the syntax of a NativeFunction. + ... + + NativeFunction: + function NativeFunctionAccessor_opt IdentifierName_opt ( FormalParameters ) { [ native code ] } + NativeFunctionAccessor : + get + set + +includes: [nativeFunctionMatcher.js, wellKnownIntrinsicObjects.js] +features: [arrow-function, Reflect, SendableArray.prototype.includes] +---*/ + +const visited = []; +function visit(ns, path) { + if (visited.includes(ns)) { + return; + } + visited.push(ns); + + if (typeof ns === 'function') { + assertNativeFunction(ns, path); + } + if (typeof ns !== 'function' && (typeof ns !== 'object' || ns === null)) { + return; + } + + const descriptors = Object.getOwnPropertyDescriptors(ns); + Reflect.ownKeys(descriptors) + .forEach((name) => { + const desc = descriptors[name]; + const p = typeof name === 'symbol' + ? `${path}[Symbol(${name.description})]` + : `${path}.${name}`; + if ('value' in desc) { + visit(desc.value, p); + } else { + visit(desc.get, p); + visit(desc.set, p); + } + }); +} + +WellKnownIntrinsicObjects.forEach((intrinsic) => { + visit(intrinsic.value, intrinsic.name); +}); +assert.notSameValue(visited.length, 0); diff --git a/test/sendable/builtins/Function/prototype/toString/class-declaration-complex-heritage.js b/test/sendable/builtins/Function/prototype/toString/class-declaration-complex-heritage.js new file mode 100644 index 0000000000000000000000000000000000000000..b72527440f21b9dd937d94e55cf862d2f0564a47 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/class-declaration-complex-heritage.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-runtime-semantics-bindingclassdeclarationevaluation +description: SharedFunction.prototype.toString on a class declaration (with complex heritage) +includes: [nativeFunctionMatcher.js] +---*/ + +/* before */class /* a */ A /* b */ extends /* c */ class /* d */ B /* e */ { /* f */ } /* g */ { /* h */ }/* after */ + +assertToStringOrNativeFunction(A, "class /* a */ A /* b */ extends /* c */ class /* d */ B /* e */ { /* f */ } /* g */ { /* h */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/class-declaration-explicit-ctor.js b/test/sendable/builtins/Function/prototype/toString/class-declaration-explicit-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..43e3769748313a700f109ff036ff2ea212501141 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/class-declaration-explicit-ctor.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-runtime-semantics-bindingclassdeclarationevaluation +description: SharedFunction.prototype.toString on a class declaration (explicit constructor) +includes: [nativeFunctionMatcher.js] +---*/ + +/* before */class /* a */ A /* b */ extends /* c */ B /* d */ { /* e */ constructor /* f */ ( /* g */ ) /* h */ { /* i */ ; /* j */ } /* k */ m /* l */ ( /* m */ ) /* n */ { /* o */ } /* p */ }/* after */ + +assertToStringOrNativeFunction(A, "class /* a */ A /* b */ extends /* c */ B /* d */ { /* e */ constructor /* f */ ( /* g */ ) /* h */ { /* i */ ; /* j */ } /* k */ m /* l */ ( /* m */ ) /* n */ { /* o */ } /* p */ }"); + +function B(){} diff --git a/test/sendable/builtins/Function/prototype/toString/class-declaration-implicit-ctor.js b/test/sendable/builtins/Function/prototype/toString/class-declaration-implicit-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..0ab080c559f82bf55e3cc320ff453060a47dcf8f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/class-declaration-implicit-ctor.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-runtime-semantics-bindingclassdeclarationevaluation +description: SharedFunction.prototype.toString on a class declaration (implicit constructor) +includes: [nativeFunctionMatcher.js] +---*/ + +/* before */class /* a */ A /* b */ { /* c */ }/* after */ +/* before */class /* a */ B /* b */ extends /* c */ A /* d */ { /* e */ }/* after */ +/* before */class /* a */ C /* b */ extends /* c */ B /* d */ { /* e */ m /* f */ ( /* g */ ) /* h */ { /* i */ } /* j */ }/* after */ + +assertToStringOrNativeFunction(A, "class /* a */ A /* b */ { /* c */ }"); +assertToStringOrNativeFunction(B, "class /* a */ B /* b */ extends /* c */ A /* d */ { /* e */ }"); +assertToStringOrNativeFunction(C, "class /* a */ C /* b */ extends /* c */ B /* d */ { /* e */ m /* f */ ( /* g */ ) /* h */ { /* i */ } /* j */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/class-expression-explicit-ctor.js b/test/sendable/builtins/Function/prototype/toString/class-expression-explicit-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..b446e8ea3df6b315065c28b02ef11b2eb3fe518b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/class-expression-explicit-ctor.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-class-definitions-runtime-semantics-evaluation +description: SharedFunction.prototype.toString on a class expression (explicit constructor) +includes: [nativeFunctionMatcher.js] +---*/ + +let A = /* before */class /* a */ A /* b */ extends /* c */ B /* d */ { /* e */ constructor /* f */ ( /* g */ ) /* h */ { /* i */ ; /* j */ } /* k */ m /* l */ ( /* m */ ) /* n */ { /* o */ } /* p */ }/* after */; + +assertToStringOrNativeFunction(A, "class /* a */ A /* b */ extends /* c */ B /* d */ { /* e */ constructor /* f */ ( /* g */ ) /* h */ { /* i */ ; /* j */ } /* k */ m /* l */ ( /* m */ ) /* n */ { /* o */ } /* p */ }"); + +function B(){} diff --git a/test/sendable/builtins/Function/prototype/toString/class-expression-implicit-ctor.js b/test/sendable/builtins/Function/prototype/toString/class-expression-implicit-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..0ffda8e2ffa7ab8d823633f4c172cb376a8a248d --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/class-expression-implicit-ctor.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-class-definitions-runtime-semantics-evaluation +description: SharedFunction.prototype.toString on a class expression (implicit constructor) +includes: [nativeFunctionMatcher.js] +---*/ + +let A = /* before */class /* a */ A /* b */ { /* c */ }/* after */; +let B = /* before */class /* a */ B /* b */ extends /* c */ A /* d */ { /* e */ }/* after */; +let C = /* before */class /* a */ C /* b */ extends /* c */ B /* d */ { /* e */ m /* f */ ( /* g */ ) /* h */ { /* i */ } /* j */ }/* after */; + +assertToStringOrNativeFunction(A, "class /* a */ A /* b */ { /* c */ }"); +assertToStringOrNativeFunction(B, "class /* a */ B /* b */ extends /* c */ A /* d */ { /* e */ }"); +assertToStringOrNativeFunction(C, "class /* a */ C /* b */ extends /* c */ B /* d */ { /* e */ m /* f */ ( /* g */ ) /* h */ { /* i */ } /* j */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/function-declaration-non-simple-parameter-list.js b/test/sendable/builtins/Function/prototype/toString/function-declaration-non-simple-parameter-list.js new file mode 100644 index 0000000000000000000000000000000000000000..5148e6df5af8fc4078eaab5dba00051791e97d37 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/function-declaration-non-simple-parameter-list.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject +description: SharedFunction.prototype.toString on a function with a non-simple parameter list +includes: [nativeFunctionMatcher.js] +---*/ + +/* before */function /* a */ f /* b */ ( /* c */ a /* d */ = /* e */ 0 /* f */ , /* g */ { /* h */ b /* i */ = /* j */ 0 /* k */ } /* l */ ) /* m */ { /* n */ }/* after */ + +assertToStringOrNativeFunction(f, "function /* a */ f /* b */ ( /* c */ a /* d */ = /* e */ 0 /* f */ , /* g */ { /* h */ b /* i */ = /* j */ 0 /* k */ } /* l */ ) /* m */ { /* n */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/function-declaration.js b/test/sendable/builtins/Function/prototype/toString/function-declaration.js new file mode 100644 index 0000000000000000000000000000000000000000..47b23b83b1c6fab5b5ab95fba60036198129178b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/function-declaration.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject +description: SharedFunction.prototype.toString on a function declaration +includes: [nativeFunctionMatcher.js] +---*/ + +/* before */function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }/* after */ + +assertToStringOrNativeFunction(f, "function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/function-expression.js b/test/sendable/builtins/Function/prototype/toString/function-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..b9eec7abbe5f14508c1b7023f5d7293d1b41adc7 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/function-expression.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function-definitions-runtime-semantics-evaluation +description: SharedFunction.prototype.toString on a function expression +includes: [nativeFunctionMatcher.js] +---*/ + +let f = /* before */function /* a */ F /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }/* after */; +let g = /* before */function /* a */ ( /* b */ x /* c */ , /* d */ y /* e */ ) /* f */ { /* g */ ; /* h */ ; /* i */ }/* after */; + +assertToStringOrNativeFunction(f, "function /* a */ F /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }"); +assertToStringOrNativeFunction(g, "function /* a */ ( /* b */ x /* c */ , /* d */ y /* e */ ) /* f */ { /* g */ ; /* h */ ; /* i */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/generator-function-declaration.js b/test/sendable/builtins/Function/prototype/toString/generator-function-declaration.js new file mode 100644 index 0000000000000000000000000000000000000000..16bd420bb5978a15702f374952e06c53d4f3c863 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/generator-function-declaration.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-generator-function-definitions-runtime-semantics-instantiatefunctionobject +description: SharedFunction.prototype.toString on a generator function declaration +includes: [nativeFunctionMatcher.js] +---*/ + +/* before */function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }/* after */ + +assertToStringOrNativeFunction(g, "function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/generator-function-expression.js b/test/sendable/builtins/Function/prototype/toString/generator-function-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..b5cfef7b42d20f32831f76cb7c80a02920eca2cc --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/generator-function-expression.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-generator-function-definitions-runtime-semantics-evaluation +description: SharedFunction.prototype.toString on a generator function expression +includes: [nativeFunctionMatcher.js] +---*/ + +let f = /* before */function /* a */ * /* b */ F /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }/* after */ +let g = /* before */function /* a */ * /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }/* after */ + +assertToStringOrNativeFunction(f, "function /* a */ * /* b */ F /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }"); +assertToStringOrNativeFunction(g, "function /* a */ * /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/generator-method.js b/test/sendable/builtins/Function/prototype/toString/generator-method.js new file mode 100644 index 0000000000000000000000000000000000000000..a31af6c6e1774e55979effe0cf79ae183c28c622 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/generator-method.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-generator-function-definitions-runtime-semantics-propertydefinitionevaluation +description: SharedFunction.prototype.toString on a generator method +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = { /* before */* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }/* after */ }.f; +let g = { /* before */* /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.g; +let h = { /* before */* /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.h; + +assertToStringOrNativeFunction(f, "* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }"); +assertToStringOrNativeFunction(g, "* /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); +assertToStringOrNativeFunction(h, "* /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/getter-class-expression-static.js b/test/sendable/builtins/Function/prototype/toString/getter-class-expression-static.js new file mode 100644 index 0000000000000000000000000000000000000000..e016ce57638c2a630d7bec12f173e08d1e605ea7 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/getter-class-expression-static.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation +description: SharedFunction.prototype.toString on a getter (class; static) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = Object.getOwnPropertyDescriptor(class { static /* before */get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }/* after */ }, "f").get; +let g = Object.getOwnPropertyDescriptor(class { static /* before */get /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }, "g").get; +let h = Object.getOwnPropertyDescriptor(class { static /* before */get /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }, "h").get; + +assertToStringOrNativeFunction(f, "get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }"); +assertToStringOrNativeFunction(g, "get /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); +assertToStringOrNativeFunction(h, "get /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/getter-class-expression.js b/test/sendable/builtins/Function/prototype/toString/getter-class-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..99da4627d59a41f271b9c226ce05dd6417ce6bd2 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/getter-class-expression.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation +description: SharedFunction.prototype.toString on a getter (class) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = Object.getOwnPropertyDescriptor(class { /* before */get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }/* after */ }.prototype, "f").get; +let g = Object.getOwnPropertyDescriptor(class { /* before */get /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.prototype, "g").get; +let h = Object.getOwnPropertyDescriptor(class { /* before */get /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }.prototype, "h").get; + +assertToStringOrNativeFunction(f, "get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }"); +assertToStringOrNativeFunction(g, "get /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); +assertToStringOrNativeFunction(h, "get /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/getter-class-statement-static.js b/test/sendable/builtins/Function/prototype/toString/getter-class-statement-static.js new file mode 100644 index 0000000000000000000000000000000000000000..d7077bcd1d04f28f1e6ced7d043afba5c37daa35 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/getter-class-statement-static.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation +description: SharedFunction.prototype.toString on a getter (class; static) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +class F { static /* before */get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }/* after */ } +class G { static /* before */get /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ } +class H { static /* before */get /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ } + +let f = Object.getOwnPropertyDescriptor(F, "f").get; +let g = Object.getOwnPropertyDescriptor(G, "g").get; +let h = Object.getOwnPropertyDescriptor(H, "h").get; + +assertToStringOrNativeFunction(f, "get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }"); +assertToStringOrNativeFunction(g, "get /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); +assertToStringOrNativeFunction(h, "get /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/getter-class-statement.js b/test/sendable/builtins/Function/prototype/toString/getter-class-statement.js new file mode 100644 index 0000000000000000000000000000000000000000..6c15e041bd6805cd10974417ce556132b72ca0ac --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/getter-class-statement.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation +description: SharedFunction.prototype.toString on a getter (class) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +class F { /* before */get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }/* after */ } +class G { /* before */get /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ } +class H { /* before */get /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ } + +let f = Object.getOwnPropertyDescriptor(F.prototype, "f").get; +let g = Object.getOwnPropertyDescriptor(G.prototype, "g").get; +let h = Object.getOwnPropertyDescriptor(H.prototype, "h").get; + +assertToStringOrNativeFunction(f, "get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }"); +assertToStringOrNativeFunction(g, "get /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); +assertToStringOrNativeFunction(h, "get /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/getter-object.js b/test/sendable/builtins/Function/prototype/toString/getter-object.js new file mode 100644 index 0000000000000000000000000000000000000000..44ab794827c2fe9eee71124c7325c26b1398389b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/getter-object.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation +description: SharedFunction.prototype.toString on a getter (object) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = Object.getOwnPropertyDescriptor({ /* before */get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }/* after */ }, "f").get; +let g = Object.getOwnPropertyDescriptor({ /* before */get /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }, "g").get; +let h = Object.getOwnPropertyDescriptor({ /* before */get /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }/* after */ }, "h").get; + +assertToStringOrNativeFunction(f, "get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ }"); +assertToStringOrNativeFunction(g, "get /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); +assertToStringOrNativeFunction(h, "get /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ ) /* f */ { /* g */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/line-terminator-normalisation-CR-LF.js b/test/sendable/builtins/Function/prototype/toString/line-terminator-normalisation-CR-LF.js new file mode 100644 index 0000000000000000000000000000000000000000..98aae24a84f7d17027f2acc8216b40efd854d4c4 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/line-terminator-normalisation-CR-LF.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject +description: SharedFunction.prototype.toString line terminator normalisation (CR-LF) +info: | + SharedFunction.prototype.toString should not normalise line terminator sequences to Line Feed characters. + This file uses (Carriage Return, Line Feed) sequences as line terminators. +includes: [nativeFunctionMatcher.js] +---*/ + +// before +function +// a +f +// b +( +// c +x +// d +, +// e +y +// f +) +// g +{ +// h +; +// i +; +// j +} +// after + +assertToStringOrNativeFunction(f, "function\r\n// a\r\nf\r\n// b\r\n(\r\n// c\r\nx\r\n// d\r\n,\r\n// e\r\ny\r\n// f\r\n)\r\n// g\r\n{\r\n// h\r\n;\r\n// i\r\n;\r\n// j\r\n}"); diff --git a/test/sendable/builtins/Function/prototype/toString/line-terminator-normalisation-CR.js b/test/sendable/builtins/Function/prototype/toString/line-terminator-normalisation-CR.js new file mode 100644 index 0000000000000000000000000000000000000000..39b9385e009b706ffd63d618fda6d06225bb266b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/line-terminator-normalisation-CR.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject +description: SharedFunction.prototype.toString line terminator normalisation (CR) +info: | + SharedFunction.prototype.toString should not normalise line terminator sequences to Line Feed characters. + This file uses Carriage Return characters as line terminators. +includes: [nativeFunctionMatcher.js] +---*/ + +// before +function +// a +f +// b +( +// c +x +// d +, +// e +y +// f +) +// g +{ +// h +; +// i +; +// j +} +// after + +assertToStringOrNativeFunction(f, "function\r// a\rf\r// b\r(\r// c\rx\r// d\r,\r// e\ry\r// f\r)\r// g\r{\r// h\r;\r// i\r;\r// j\r}"); diff --git a/test/sendable/builtins/Function/prototype/toString/line-terminator-normalisation-LF.js b/test/sendable/builtins/Function/prototype/toString/line-terminator-normalisation-LF.js new file mode 100644 index 0000000000000000000000000000000000000000..342978b4d97b5b25034bb32554354bf0888f3793 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/line-terminator-normalisation-LF.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject +description: SharedFunction.prototype.toString line terminator normalisation (LF) +info: | + SharedFunction.prototype.toString should not normalise line terminator sequences to Line Feed characters. + This file uses Line Feed characters as line terminators. +includes: [nativeFunctionMatcher.js] +---*/ + +// before +function +// a +f +// b +( +// c +x +// d +, +// e +y +// f +) +// g +{ +// h +; +// i +; +// j +} +// after + +assertToStringOrNativeFunction(f, "function\n// a\nf\n// b\n(\n// c\nx\n// d\n,\n// e\ny\n// f\n)\n// g\n{\n// h\n;\n// i\n;\n// j\n}"); diff --git a/test/sendable/builtins/Function/prototype/toString/method-class-expression-static.js b/test/sendable/builtins/Function/prototype/toString/method-class-expression-static.js new file mode 100644 index 0000000000000000000000000000000000000000..e08c9103900a248b7c52a3341e40206e4cf7d3e0 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/method-class-expression-static.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-runtime-semantics-definemethod +description: SharedFunction.prototype.toString on a method (class; static) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = class { static /* before */f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ }.f; +let g = class { static /* before */[ /* a */ "g" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ }.g; +let h = class { static /* before */[ /* a */ x /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ }.h; + +assertToStringOrNativeFunction(f, "f /* a */ ( /* b */ ) /* c */ { /* d */ }"); +assertToStringOrNativeFunction(g, "[ /* a */ \"g\" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(h, "[ /* a */ x /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/method-class-expression.js b/test/sendable/builtins/Function/prototype/toString/method-class-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..760b6450088560aa17d743f1767d4988db370954 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/method-class-expression.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-runtime-semantics-definemethod +description: SharedFunction.prototype.toString on a method (class) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = class { /* before */f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ }.prototype.f; +let g = class { /* before */[ /* a */ "g" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ }.prototype.g; +let h = class { /* before */[ /* a */ x /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ }.prototype.h; + +assertToStringOrNativeFunction(f, "f /* a */ ( /* b */ ) /* c */ { /* d */ }"); +assertToStringOrNativeFunction(g, "[ /* a */ \"g\" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(h, "[ /* a */ x /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/method-class-statement-static.js b/test/sendable/builtins/Function/prototype/toString/method-class-statement-static.js new file mode 100644 index 0000000000000000000000000000000000000000..dd0b3d891c8f49571ea90114e6e5787b0fadec92 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/method-class-statement-static.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-runtime-semantics-definemethod +description: SharedFunction.prototype.toString on a method (class; static) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +class F { static /* before */f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ } +class G { static /* before */[ /* a */ "g" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ } +class H { static /* before */[ /* a */ x /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ } + +let f = F.f; +let g = G.g; +let h = H.h; + +assertToStringOrNativeFunction(f, "f /* a */ ( /* b */ ) /* c */ { /* d */ }"); +assertToStringOrNativeFunction(g, "[ /* a */ \"g\" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(h, "[ /* a */ x /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/method-class-statement.js b/test/sendable/builtins/Function/prototype/toString/method-class-statement.js new file mode 100644 index 0000000000000000000000000000000000000000..75f76cb2f6cc9b9f232c51125009742396d552d4 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/method-class-statement.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-runtime-semantics-definemethod +description: SharedFunction.prototype.toString on a method (class) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +class F { /* before */f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ } +class G { /* before */[ /* a */ "g" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ } +class H { /* before */[ /* a */ x /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ } + +let f = F.prototype.f; +let g = G.prototype.g; +let h = H.prototype.h; + +assertToStringOrNativeFunction(f, "f /* a */ ( /* b */ ) /* c */ { /* d */ }"); +assertToStringOrNativeFunction(g, "[ /* a */ \"g\" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(h, "[ /* a */ x /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/method-computed-property-name.js b/test/sendable/builtins/Function/prototype/toString/method-computed-property-name.js new file mode 100644 index 0000000000000000000000000000000000000000..c7311f26a6c56e17d796b3493eb8527d0e1f4d5a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/method-computed-property-name.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-runtime-semantics-definemethod +description: SharedFunction.prototype.toString on a method (object) +includes: [nativeFunctionMatcher.js] +---*/ + +let f = { /* before */[ /* a */ "f" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }/* after */ }.f; +let g = { [ { a(){} }.a ](){ } }["a(){}"]; + +assertToStringOrNativeFunction(f, "[ /* a */ \"f\" /* b */ ] /* c */ ( /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(g, "[ { a(){} }.a ](){ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/method-object.js b/test/sendable/builtins/Function/prototype/toString/method-object.js new file mode 100644 index 0000000000000000000000000000000000000000..e99ff99a9e4b30f7b35a0a287ae012714e82daa1 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/method-object.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-runtime-semantics-definemethod +description: SharedFunction.prototype.toString on a method (object) +includes: [nativeFunctionMatcher.js] +---*/ + +let f = { /* before */f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ }.f; + +assertToStringOrNativeFunction(f, "f /* a */ ( /* b */ ) /* c */ { /* d */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/name.js b/test/sendable/builtins/Function/prototype/toString/name.js new file mode 100644 index 0000000000000000000000000000000000000000..a8a6997a2a155ee5003d5526d7204a5d7a19cb45 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/name.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + SharedFunction.prototype.toString.name is "toString". +info: | + SharedFunction.prototype.toString ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in SharedFunction object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in SharedFunction + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SharedFunction.prototype.toString, "name", { + value: "toString", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Function/prototype/toString/not-a-constructor.js b/test/sendable/builtins/Function/prototype/toString/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..81f730807de85ec507b238e16c40f77591f3720c --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/not-a-constructor.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SharedFunction.prototype.toString does not implement [[Construct]], is not new-able +info: | + ECMAScript SharedFunction Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SharedFunction.prototype.toString), + false, + 'isConstructor(SharedFunction.prototype.toString) must return false' +); + +assert.throws(TypeError, () => { + new SharedFunction.prototype.toString(); +}); + +var toString = SharedFunction.prototype.toString; +assert.throws(TypeError, () => { + new toString; +}); diff --git a/test/sendable/builtins/Function/prototype/toString/private-method-class-expression.js b/test/sendable/builtins/Function/prototype/toString/private-method-class-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..2f862c83e82e24d2dd2d6eb8ef1da395b7efeeec --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/private-method-class-expression.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +description: SharedFunction.prototype.toString on a private method +features: [class-methods-private] +includes: [nativeFunctionMatcher.js] +---*/ + +let c = new (class { + /* before */#f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ + assert(expected) { + assertToStringOrNativeFunction(this.#f, expected); + } +}); + +c.assert("#f /* a */ ( /* b */ ) /* c */ { /* d */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/private-method-class-statement.js b/test/sendable/builtins/Function/prototype/toString/private-method-class-statement.js new file mode 100644 index 0000000000000000000000000000000000000000..643468ca2c68e8d301e438501e930634caec57db --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/private-method-class-statement.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +description: SharedFunction.prototype.toString on a private method +features: [class-methods-private] +includes: [nativeFunctionMatcher.js] +---*/ + +class C { + /* before */#f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ + assert(expected) { + assertToStringOrNativeFunction(this.#f, expected); + } +} + +let c = new C(); +c.assert("#f /* a */ ( /* b */ ) /* c */ { /* d */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/private-static-method-class-expression.js b/test/sendable/builtins/Function/prototype/toString/private-static-method-class-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..ad7252ece7616201771b31b3b8e3f6c0d7f8bb9e --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/private-static-method-class-expression.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +description: SharedFunction.prototype.toString on a static private method +features: [class-static-methods-private] +includes: [nativeFunctionMatcher.js] +---*/ + +let C = class { + /* before */static #f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ + static assert(expected) { + assertToStringOrNativeFunction(this.#f, expected); + } +}; + +C.assert("#f /* a */ ( /* b */ ) /* c */ { /* d */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/private-static-method-class-statement.js b/test/sendable/builtins/Function/prototype/toString/private-static-method-class-statement.js new file mode 100644 index 0000000000000000000000000000000000000000..6857938126acf2852d627279d1b7e221e49312aa --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/private-static-method-class-statement.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +description: SharedFunction.prototype.toString on a static private method +features: [class-static-methods-private] +includes: [nativeFunctionMatcher.js] +---*/ + +class C { + /* before */static #f /* a */ ( /* b */ ) /* c */ { /* d */ }/* after */ + static assert(expected) { + assertToStringOrNativeFunction(this.#f, expected); + } +} + +C.assert("#f /* a */ ( /* b */ ) /* c */ { /* d */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/proxy-arrow-function.js b/test/sendable/builtins/Function/prototype/toString/proxy-arrow-function.js new file mode 100644 index 0000000000000000000000000000000000000000..34061a6629d0d928b8c15b6175782749dcf926ea --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/proxy-arrow-function.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of Proxy for function target does not throw (Arrow SharedFunction) +info: | + ... + If Type(func) is Object and IsCallable(func) is true, then return an + implementation-dependent String source code representation of func. + The representation must have the syntax of a NativeFunction. + ... + + NativeFunction: + function IdentifierName_opt ( FormalParameters ) { [ native code ] } + +features: [arrow-function, Proxy] +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(new Proxy(() => {}, {})); +assertNativeFunction(new Proxy(() => {}, { apply() {} }).apply); diff --git a/test/sendable/builtins/Function/prototype/toString/proxy-async-function.js b/test/sendable/builtins/Function/prototype/toString/proxy-async-function.js new file mode 100644 index 0000000000000000000000000000000000000000..f1b981b68e2aabc2c451420370de6571a8caa513 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/proxy-async-function.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of Proxy for function target does not throw (Async SharedFunction Expression) +info: | + ... + If Type(func) is Object and IsCallable(func) is true, then return an + implementation-dependent String source code representation of func. + The representation must have the syntax of a NativeFunction. + ... + + NativeFunction: + function IdentifierName_opt ( FormalParameters ) { [ native code ] } + +features: [async-functions, Proxy] +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(new Proxy(async function() {}, {})); +assertNativeFunction(new Proxy(async function() {}, { apply() {} }).apply); diff --git a/test/sendable/builtins/Function/prototype/toString/proxy-async-generator-function.js b/test/sendable/builtins/Function/prototype/toString/proxy-async-generator-function.js new file mode 100644 index 0000000000000000000000000000000000000000..43532e7ea351996f490ac1989422fcf89ea26763 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/proxy-async-generator-function.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of Proxy for function target does not throw (Async Generator SharedFunction Expression) +info: | + ... + If Type(func) is Object and IsCallable(func) is true, then return an + implementation-dependent String source code representation of func. + The representation must have the syntax of a NativeFunction. + ... + + NativeFunction: + function IdentifierName_opt ( FormalParameters ) { [ native code ] } + +features: [async-iteration, Proxy] +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(new Proxy(async function * () {}, {})); +assertNativeFunction(new Proxy(async function * () {}, { apply() {} }).apply); diff --git a/test/sendable/builtins/Function/prototype/toString/proxy-async-generator-method-definition.js b/test/sendable/builtins/Function/prototype/toString/proxy-async-generator-method-definition.js new file mode 100644 index 0000000000000000000000000000000000000000..08c8fc77392b9290de8e17e9eee2ce33dde652d5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/proxy-async-generator-method-definition.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of Proxy for function target does not throw (Async Generator Method Definition) +info: | + ... + If Type(func) is Object and IsCallable(func) is true, then return an + implementation-dependent String source code representation of func. + The representation must have the syntax of a NativeFunction. + ... + + NativeFunction: + function IdentifierName_opt ( FormalParameters ) { [ native code ] } + +features: [async-iteration, Proxy] +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(new Proxy({ async * method() {} }.method, {})); +assertNativeFunction(new Proxy({ async * method() {} }.method, { apply() {} }).apply); diff --git a/test/sendable/builtins/Function/prototype/toString/proxy-async-method-definition.js b/test/sendable/builtins/Function/prototype/toString/proxy-async-method-definition.js new file mode 100644 index 0000000000000000000000000000000000000000..0222908cb6217e348fe28f6b97a0121f2e1a9071 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/proxy-async-method-definition.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of Proxy for function target does not throw (Async Method Definition) +info: | + ... + If Type(func) is Object and IsCallable(func) is true, then return an + implementation-dependent String source code representation of func. + The representation must have the syntax of a NativeFunction. + ... + + NativeFunction: + function IdentifierName_opt ( FormalParameters ) { [ native code ] } + +features: [async-functions, Proxy] +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(new Proxy({ async method() {} }.method, {})); +assertNativeFunction(new Proxy({ async method() {} }.method, { apply() {} }).apply); diff --git a/test/sendable/builtins/Function/prototype/toString/proxy-bound-function.js b/test/sendable/builtins/Function/prototype/toString/proxy-bound-function.js new file mode 100644 index 0000000000000000000000000000000000000000..f25d4d56f820b9adedbf7a0de95848f0574cff0a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/proxy-bound-function.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of Proxy for function target does not throw (bound SharedFunction Expression) +info: | + ... + If Type(func) is Object and IsCallable(func) is true, then return an + implementation-dependent String source code representation of func. + The representation must have the syntax of a NativeFunction. + ... + + NativeFunction: + function IdentifierName_opt ( FormalParameters ) { [ native code ] } + +features: [Proxy] +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(new Proxy(function() {}.bind({}), {})); +assertNativeFunction(new Proxy(function() {}.bind({}), { apply() {} }).apply); diff --git a/test/sendable/builtins/Function/prototype/toString/proxy-class.js b/test/sendable/builtins/Function/prototype/toString/proxy-class.js new file mode 100644 index 0000000000000000000000000000000000000000..b038ec8f3731841065be2f2d9c5f08524e39a555 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/proxy-class.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of Proxy for function target does not throw (Class Expression) +info: | + ... + If Type(func) is Object and IsCallable(func) is true, then return an + implementation-dependent String source code representation of func. + The representation must have the syntax of a NativeFunction. + ... + + NativeFunction: + function IdentifierName_opt ( FormalParameters ) { [ native code ] } + +features: [class, Proxy] +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(new Proxy(class {}, {})); +assertNativeFunction(new Proxy(class {}, { apply() {} }).apply); diff --git a/test/sendable/builtins/Function/prototype/toString/proxy-function-expression.js b/test/sendable/builtins/Function/prototype/toString/proxy-function-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..963bd47603e5b9734d9d4fc64444d24fd2e5aa97 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/proxy-function-expression.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of Proxy for function target does not throw (SharedFunction Expression) +info: | + ... + If Type(func) is Object and IsCallable(func) is true, then return an + implementation-dependent String source code representation of func. + The representation must have the syntax of a NativeFunction. + ... + + NativeFunction: + function IdentifierName_opt ( FormalParameters ) { [ native code ] } + +features: [Proxy] +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(new Proxy(function() {}, {})); +assertNativeFunction(new Proxy(function() {}, { apply() {} }).apply); diff --git a/test/sendable/builtins/Function/prototype/toString/proxy-generator-function.js b/test/sendable/builtins/Function/prototype/toString/proxy-generator-function.js new file mode 100644 index 0000000000000000000000000000000000000000..66ef052a6190b5786c00da902f6dfd6d76f5cebb --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/proxy-generator-function.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of Proxy for function target does not throw (Generator SharedFunction Expression) +info: | + ... + If Type(func) is Object and IsCallable(func) is true, then return an + implementation-dependent String source code representation of func. + The representation must have the syntax of a NativeFunction. + ... + + NativeFunction: + function IdentifierName_opt ( FormalParameters ) { [ native code ] } + +features: [generators, Proxy] +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(new Proxy(function * () {}, {})); +assertNativeFunction(new Proxy(function * () {}, { apply() {} }).apply); diff --git a/test/sendable/builtins/Function/prototype/toString/proxy-method-definition.js b/test/sendable/builtins/Function/prototype/toString/proxy-method-definition.js new file mode 100644 index 0000000000000000000000000000000000000000..5e26b894340d2191b4778a46174059515850b677 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/proxy-method-definition.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of Proxy for function target does not throw (Method Definition) +info: | + ... + If Type(func) is Object and IsCallable(func) is true, then return an + implementation-dependent String source code representation of func. + The representation must have the syntax of a NativeFunction. + ... + + NativeFunction: + function IdentifierName_opt ( FormalParameters ) { [ native code ] } + +features: [Proxy] +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(new Proxy({ method() {} }.method, {})); +assertNativeFunction(new Proxy({ method() {} }.method, { apply() {} }).apply); diff --git a/test/sendable/builtins/Function/prototype/toString/proxy-non-callable-throws.js b/test/sendable/builtins/Function/prototype/toString/proxy-non-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9dcc0cef1ab5e71718ea320c26801f8aeeeec4ac --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/proxy-non-callable-throws.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: > + toString of Proxy for non-callable target throws +info: | + ... + Throw a TypeError exception. + +features: [Proxy] +---*/ + +assert.throws(TypeError, function() { + SharedFunction.prototype.toString.call(new Proxy({}, {})); +}); diff --git a/test/sendable/builtins/Function/prototype/toString/setter-class-expression-static.js b/test/sendable/builtins/Function/prototype/toString/setter-class-expression-static.js new file mode 100644 index 0000000000000000000000000000000000000000..a93d2fc78d71a1a19a91debddc3b2a249f2cf67d --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/setter-class-expression-static.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation +description: SharedFunction.prototype.toString on a setter (class; static) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = Object.getOwnPropertyDescriptor(class { static /* before */set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }/* after */ }, "f").set; +let g = Object.getOwnPropertyDescriptor(class { static /* before */set /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ }, "g").set; +let h = Object.getOwnPropertyDescriptor(class { static /* before */set /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ }, "h").set; + +assertToStringOrNativeFunction(f, "set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(g, "set /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }"); +assertToStringOrNativeFunction(h, "set /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/setter-class-expression.js b/test/sendable/builtins/Function/prototype/toString/setter-class-expression.js new file mode 100644 index 0000000000000000000000000000000000000000..01caf5fc39beb59b22dad77fe42509a48671873f --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/setter-class-expression.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation +description: SharedFunction.prototype.toString on a setter (class) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = Object.getOwnPropertyDescriptor(class { /* before */set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }/* after */ }.prototype, "f").set; +let g = Object.getOwnPropertyDescriptor(class { /* before */set /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ }.prototype, "g").set; +let h = Object.getOwnPropertyDescriptor(class { /* before */set /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ }.prototype, "h").set; + +assertToStringOrNativeFunction(f, "set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(g, "set /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }"); +assertToStringOrNativeFunction(h, "set /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/setter-class-statement-static.js b/test/sendable/builtins/Function/prototype/toString/setter-class-statement-static.js new file mode 100644 index 0000000000000000000000000000000000000000..6980d663fc55a56ba9fd9efe06e8e1c1d3e24c5b --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/setter-class-statement-static.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation +description: SharedFunction.prototype.toString on a setter (class; static) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +class F { static /* before */set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }/* after */ } +class G { static /* before */set /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ } +class H { static /* before */set /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ } + +let f = Object.getOwnPropertyDescriptor(F, "f").set; +let g = Object.getOwnPropertyDescriptor(G, "g").set; +let h = Object.getOwnPropertyDescriptor(H, "h").set; + +assertToStringOrNativeFunction(f, "set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(g, "set /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }"); +assertToStringOrNativeFunction(h, "set /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/setter-class-statement.js b/test/sendable/builtins/Function/prototype/toString/setter-class-statement.js new file mode 100644 index 0000000000000000000000000000000000000000..3b1517a35219506ca3d3d642a34f73c78722b7d5 --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/setter-class-statement.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation +description: SharedFunction.prototype.toString on a setter (class) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +class F { /* before */set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }/* after */ } +class G { /* before */set /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ } +class H { /* before */set /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ } + +let f = Object.getOwnPropertyDescriptor(F.prototype, "f").set; +let g = Object.getOwnPropertyDescriptor(G.prototype, "g").set; +let h = Object.getOwnPropertyDescriptor(H.prototype, "h").set; + +assertToStringOrNativeFunction(f, "set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(g, "set /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }"); +assertToStringOrNativeFunction(h, "set /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/setter-object.js b/test/sendable/builtins/Function/prototype/toString/setter-object.js new file mode 100644 index 0000000000000000000000000000000000000000..2f765798e4a81feb2b8c2b714bb6d383d19d3a8d --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/setter-object.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation +description: SharedFunction.prototype.toString on a setter (object) +includes: [nativeFunctionMatcher.js] +---*/ + +let x = "h"; +let f = Object.getOwnPropertyDescriptor({ /* before */set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }/* after */ }, "f").set; +let g = Object.getOwnPropertyDescriptor({ /* before */set /* a */ [ /* b */ "g" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ }, "g").set; +let h = Object.getOwnPropertyDescriptor({ /* before */set /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }/* after */ }, "h").set; + +assertToStringOrNativeFunction(f, "set /* a */ f /* b */ ( /* c */ a /* d */ ) /* e */ { /* f */ }"); +assertToStringOrNativeFunction(g, "set /* a */ [ /* b */ \"g\" /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }"); +assertToStringOrNativeFunction(h, "set /* a */ [ /* b */ x /* c */ ] /* d */ ( /* e */ a /* f */ ) /* g */ { /* h */ }"); diff --git a/test/sendable/builtins/Function/prototype/toString/symbol-named-builtins.js b/test/sendable/builtins/Function/prototype/toString/symbol-named-builtins.js new file mode 100644 index 0000000000000000000000000000000000000000..7109560ad98259cab17a694f99632b7e7a03f83a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/symbol-named-builtins.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on symbol-named built-ins +includes: [nativeFunctionMatcher.js] +---*/ + +assertNativeFunction(RegExp.prototype[Symbol.match]); +assertNativeFunction(Object.getOwnPropertyDescriptor(RegExp, Symbol.species).get); diff --git a/test/sendable/builtins/Function/prototype/toString/unicode.js b/test/sendable/builtins/Function/prototype/toString/unicode.js new file mode 100644 index 0000000000000000000000000000000000000000..4762d03588d82fa06be65d1b5b721cda4bfce11a --- /dev/null +++ b/test/sendable/builtins/Function/prototype/toString/unicode.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-function.prototype.tostring +description: SharedFunction.prototype.toString on a function with Unicode escape sequences +info: | + SharedFunction.prototype.toString returns a slice of the source text before + any potential Unicode escape sequence substitution in identifiers +includes: [nativeFunctionMatcher.js] +---*/ + +function \u0061(\u{62}, \u0063) { \u0062 = \u{00063}; return b; } + +assertToStringOrNativeFunction(a, "function \\u0061(\\u{62}, \\u0063) { \\u0062 = \\u{00063}; return b; }"); diff --git a/test/sendable/builtins/Map/Symbol.species/length.js b/test/sendable/builtins/Map/Symbol.species/length.js new file mode 100644 index 0000000000000000000000000000000000000000..68dc626bcc44c00c0bc2198339a7bb1c71175f15 --- /dev/null +++ b/test/sendable/builtins/Map/Symbol.species/length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 23.1.2.2 +description: > + get SendableMap [ @@species ].length is 0. +info: | + get SendableMap [ @@species ] + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.species] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableMap, Symbol.species); + +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/Symbol.species/return-value.js b/test/sendable/builtins/Map/Symbol.species/return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..498080248131675a1904f2f674a16814226b0ffa --- /dev/null +++ b/test/sendable/builtins/Map/Symbol.species/return-value.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map-@@species +description: Return value of @@species accessor method +info: | + 1. Return the this value. +features: [Symbol.species] +---*/ + +var thisVal = {}; +var accessor = Object.getOwnPropertyDescriptor(SendableMap, Symbol.species).get; + +assert.sameValue(accessor.call(thisVal), thisVal); diff --git a/test/sendable/builtins/Map/Symbol.species/symbol-species-name.js b/test/sendable/builtins/Map/Symbol.species/symbol-species-name.js new file mode 100644 index 0000000000000000000000000000000000000000..2e89fb38c029e57d75bc411a1d92f87e9afa11d8 --- /dev/null +++ b/test/sendable/builtins/Map/Symbol.species/symbol-species-name.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 23.1.2.2 +description: > + SendableMap[Symbol.species] accessor property get name +info: | + 23.1.2.2 get SendableMap [ @@species ] + + ... + The value of the name property of this function is "get [Symbol.species]". +features: [Symbol.species] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableMap, Symbol.species); + +assert.sameValue( + descriptor.get.name, + 'get [Symbol.species]' +); diff --git a/test/sendable/builtins/Map/Symbol.species/symbol-species.js b/test/sendable/builtins/Map/Symbol.species/symbol-species.js new file mode 100644 index 0000000000000000000000000000000000000000..5ad1e3ede6146536292e8c6e3fab373795e0d6e4 --- /dev/null +++ b/test/sendable/builtins/Map/Symbol.species/symbol-species.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +info: | + SendableMap has a property at `Symbol.species` +esid: sec-get-map-@@species +author: Sam Mikes +description: SendableMap[Symbol.species] exists per spec +includes: [propertyHelper.js] +features: [Symbol.species] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableMap, Symbol.species); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +verifyNotWritable(SendableMap, Symbol.species, Symbol.species); +verifyNotEnumerable(SendableMap, Symbol.species); +verifyConfigurable(SendableMap, Symbol.species); diff --git a/test/sendable/builtins/Map/bigint-number-same-value.js b/test/sendable/builtins/Map/bigint-number-same-value.js new file mode 100644 index 0000000000000000000000000000000000000000..c41941f488adc9c0fe178dd53aa98e2475318c5a --- /dev/null +++ b/test/sendable/builtins/Map/bigint-number-same-value.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + Observing the expected behavior of keys when a BigInt and Number have + the same value. +info: | + SendableMap.prototype.set ( key , value ) + + ... + Let p be the Record {[[key]]: key, [[value]]: value}. + Append p as the last element of entries. + ... + +features: [BigInt] +---*/ + +const number = 9007199254740991; +const bigint = 9007199254740991n; + +const m = new SendableMap([ + [number, number], + [bigint, bigint], +]); + +assert.sameValue(m.size, 2); +assert.sameValue(m.has(number), true); +assert.sameValue(m.has(bigint), true); + +assert.sameValue(m.get(number), number); +assert.sameValue(m.get(bigint), bigint); + +m.delete(number); +assert.sameValue(m.size, 1); +assert.sameValue(m.has(number), false); +m.delete(bigint); +assert.sameValue(m.size, 0); +assert.sameValue(m.has(bigint), false); + +m.set(number, number); +assert.sameValue(m.size, 1); +m.set(bigint, bigint); +assert.sameValue(m.size, 2); diff --git a/test/sendable/builtins/Map/constructor.js b/test/sendable/builtins/Map/constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..1dc794f3cbecbb9f8095b1030b7873f66fb88990 --- /dev/null +++ b/test/sendable/builtins/Map/constructor.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-constructor +description: > + The SendableMap constructor is the %SendableMap% intrinsic object and the initial value of the + SendableMap property of the global object. +---*/ + +assert.sameValue(typeof SendableMap, 'function', 'typeof SendableMap is "function"'); diff --git a/test/sendable/builtins/Map/does-not-throw-when-set-is-not-callable.js b/test/sendable/builtins/Map/does-not-throw-when-set-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..9108a75f9feb5afb306c297e5ebdb7c10a33c94b --- /dev/null +++ b/test/sendable/builtins/Map/does-not-throw-when-set-is-not-callable.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + Creating a new SendableMap object without arguments doesn't throw if `set` is not + callable +info: | + SendableMap ( [ iterable ] ) + + When the Set function is called with optional argument iterable the following steps are taken: + + ... + 5. If iterable is not present, let iterable be undefined. + 6. If iterable is either undefined or null, let iter be undefined. + 7. Else, + a. Let adder be Get(map, "set"). + b. ReturnIfAbrupt(adder). + c. If IsCallable(adder) is false, throw a TypeError exception. + ... + 8. If iter is undefined, return map. + ... +---*/ + +SendableMap.prototype.set = null; + +var m = new SendableMap(); + +assert.sameValue(m.size, 0, 'The value of `m.size` is `0`'); diff --git a/test/sendable/builtins/Map/get-set-method-failure.js b/test/sendable/builtins/Map/get-set-method-failure.js new file mode 100644 index 0000000000000000000000000000000000000000..e1ff51940350db62ccc2b805078d4d47ada2ee2b --- /dev/null +++ b/test/sendable/builtins/Map/get-set-method-failure.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + new SendableMap returns abrupt from getting SendableMap.prototype.set. +info: | + SendableMap ( [ iterable ] ) + + ... + 7. Else, + a. Let adder be Get(map, "add"). + b. ReturnIfAbrupt(adder). +---*/ + +Object.defineProperty(SendableMap.prototype, 'set', { + get: function() { + throw new Test262Error(); + } +}); + +new SendableMap(); + +assert.throws(Test262Error, function() { + new SendableMap([]); +}); diff --git a/test/sendable/builtins/Map/groupBy/callback-arg.js b/test/sendable/builtins/Map/groupBy/callback-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..b9a6e278fdd4b227f7b8fce36a442d28559b716a --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/callback-arg.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy calls function with correct arguments +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + + e. Let key be Completion(Call(callbackfn, undefined, « value, 𝔽(k) »)). + ... +features: [array-grouping, SendableMap] +---*/ + + +const arr = [-0, 0, 1, 2, 3]; + +let calls = 0; + +SendableMap.groupBy(arr, function (n, i) { + calls++; + assert.sameValue(n, arr[i], "selected element aligns with index"); + assert.sameValue(arguments.length, 2, "only two arguments are passed"); + return null; +}); + +assert.sameValue(calls, 5, 'called for all 5 elements'); diff --git a/test/sendable/builtins/Map/groupBy/callback-throws.js b/test/sendable/builtins/Map/groupBy/callback-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..35ce70f9bd745a6ceab36d2115add0cdb8bb45ec --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/callback-throws.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy throws when callback throws +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + e. Let key be Completion(Call(callbackfn, undefined, « value, 𝔽(k) »)). + f. IfAbruptCloseIterator(key, iteratorRecord). + ... +features: [array-grouping, SendableMap] +---*/ + +assert.throws(Test262Error, function() { + const array = [1]; + SendableMap.groupBy(array, function() { + throw new Test262Error('throw in callback'); + }) +}); diff --git a/test/sendable/builtins/Map/groupBy/emptyList.js b/test/sendable/builtins/Map/groupBy/emptyList.js new file mode 100644 index 0000000000000000000000000000000000000000..68467968479a1fae0c51a39cf84644a58ab3b324 --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/emptyList.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: Callback is not called and object is not populated if the iterable is empty +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + c. If next is false, then + i. Return groups. + ... +features: [array-grouping, SendableMap] +---*/ + +const original = []; + +const map = SendableMap.groupBy(original, function () { + throw new Test262Error('callback function should not be called') +}); + +assert.notSameValue(original, map, 'SendableMap.groupBy returns a map'); +assert.sameValue(map.size, 0); diff --git a/test/sendable/builtins/Map/groupBy/evenOdd.js b/test/sendable/builtins/Map/groupBy/evenOdd.js new file mode 100644 index 0000000000000000000000000000000000000000..fc401da71f68fb9ba2f444ceab16a2961d84dbfb --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/evenOdd.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy populates SendableMap with correct keys and values +info: | + SendableMap.groupBy ( items, callbackfn ) + ... +includes: [compareArray.js] +features: [array-grouping, SendableMap] +---*/ + +const array = [1, 2, 3]; + +const map = SendableMap.groupBy(array, function (i) { + return i % 2 === 0 ? 'even' : 'odd'; +}); + +assert.compareArray(Array.from(map.keys()), ['odd', 'even']); +assert.compareArray(map.get('even'), [2]); +assert.compareArray(map.get('odd'), [1, 3]); diff --git a/test/sendable/builtins/Map/groupBy/groupLength.js b/test/sendable/builtins/Map/groupBy/groupLength.js new file mode 100644 index 0000000000000000000000000000000000000000..bddd6bdb36f3efc64cc8de257f2a5d74a00cd00a --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/groupLength.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy populates SendableMap with correct keys and values +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... +includes: [compareArray.js] +features: [array-grouping, SendableMap, Symbol.iterator] +---*/ + +const arr = ['hello', 'test', 'world']; + +const map = SendableMap.groupBy(arr, function (i) { return i.length; }); + +assert.compareArray(Array.from(map.keys()), [5, 4]); +assert.compareArray(map.get(5), ['hello', 'world']); +assert.compareArray(map.get(4), ['test']); diff --git a/test/sendable/builtins/Map/groupBy/invalid-callback.js b/test/sendable/builtins/Map/groupBy/invalid-callback.js new file mode 100644 index 0000000000000000000000000000000000000000..9692451b82a2f8449af1b47b4df5dc6c9efda178 --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/invalid-callback.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy called with non-callable throws TypeError +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 2. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +features: [array-grouping, SendableMap] +---*/ + + +assert.throws(TypeError, function() { + SendableMap.groupBy([], null) +}, "null callback throws TypeError"); + +assert.throws(TypeError, function() { + SendableMap.groupBy([], undefined) +}, "undefined callback throws TypeError"); + +assert.throws(TypeError, function() { + SendableMap.groupBy([], {}) +}, "object callback throws TypeError"); diff --git a/test/sendable/builtins/Map/groupBy/invalid-iterable.js b/test/sendable/builtins/Map/groupBy/invalid-iterable.js new file mode 100644 index 0000000000000000000000000000000000000000..372210311ebac16e839415d3c254097a007b7c62 --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/invalid-iterable.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy with a nullish Symbol.iterator throws +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... + GroupBy ( items, callbackfn, coercion ) + + 4. Let iteratorRecord be ? GetIterator(items). + + ... +features: [array-grouping, SendableMap] +---*/ + +const throws = function () { + throw new Test262Error('callback function should not be called') +}; + +function makeIterable(obj, iteratorFn) { + obj[Symbol.iterator] = iteratorFn; + return obj; +} + +assert.throws(TypeError, function () { + SendableMap.groupBy(makeIterable({}, undefined), throws); +}, 'undefined Symbol.iterator'); + +assert.throws(TypeError, function () { + SendableMap.groupBy(makeIterable({}, null), throws); +}, 'null Symbol.iterator'); diff --git a/test/sendable/builtins/Map/groupBy/iterator-next-throws.js b/test/sendable/builtins/Map/groupBy/iterator-next-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..b7db3353c4623998acdf9ad26a4c5d97ee1cd8b2 --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/iterator-next-throws.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy throws when iterator next throws +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... + + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + b. Let next be ? IteratorStep(iteratorRecord). + + ... +features: [array-grouping, SendableMap, Symbol.iterator] +---*/ + +const throwingIterator = { + [Symbol.iterator]: function () { + return this; + }, + next: function next() { + throw new Test262Error('next() method was called'); + } +}; + +assert.throws(Test262Error, function () { + SendableMap.groupBy(throwingIterator, function () { + return 'key'; + }); +}); diff --git a/test/sendable/builtins/Map/groupBy/length.js b/test/sendable/builtins/Map/groupBy/length.js new file mode 100644 index 0000000000000000000000000000000000000000..7e05824187a773efa0dc47a625e67607ff66697c --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/length.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy property length descriptor +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... + + 17 ECMAScript Standard Built-in Objects + + ... + +includes: [propertyHelper.js] +features: [array-grouping, SendableMap] +---*/ + +verifyProperty(SendableMap.groupBy, "length", { + value: 2, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/groupBy/map-instance.js b/test/sendable/builtins/Map/groupBy/map-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..55f11f0ab4b1329e6a81c4e4641464fe221b01b4 --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/map-instance.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy returns a SendableMap instance +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... + + 2. Let map be ! Construct(%SendableMap%). + ... + 4. Return map. + + ... +features: [array-grouping, SendableMap] +---*/ + +const array = [1, 2, 3]; + +const map = SendableMap.groupBy(array, function (i) { + return i % 2 === 0 ? 'even' : 'odd'; +}); + +assert.sameValue(map instanceof SendableMap, true); diff --git a/test/sendable/builtins/Map/groupBy/name.js b/test/sendable/builtins/Map/groupBy/name.js new file mode 100644 index 0000000000000000000000000000000000000000..bea007056ffbc57f7f15824493becc5103cefef1 --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/name.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy property name descriptor +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... + + 17 ECMAScript Standard Built-in Objects + + ... + +includes: [propertyHelper.js] +features: [array-grouping, SendableMap] +---*/ + +verifyProperty(SendableMap.groupBy, "name", { + value: "groupBy", + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/groupBy/negativeZero.js b/test/sendable/builtins/Map/groupBy/negativeZero.js new file mode 100644 index 0000000000000000000000000000000000000000..1a4ae2550b8264e148f4d70e890889c82066cca8 --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/negativeZero.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy normalizes 0 for SendableMap key +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... + + GroupBy ( items, callbackfn, coercion ) + + 6. Repeat, + h. Else, + i. Assert: coercion is zero. + ii. If key is -0𝔽, set key to +0𝔽. + + ... +includes: [compareArray.js] +features: [array-grouping, SendableMap] +---*/ + + +const arr = [-0, +0]; + +const map = SendableMap.groupBy(arr, function (i) { return i; }); + +assert.sameValue(map.size, 1); +assert.compareArray(map.get(0), [-0, 0]); diff --git a/test/sendable/builtins/Map/groupBy/string.js b/test/sendable/builtins/Map/groupBy/string.js new file mode 100644 index 0000000000000000000000000000000000000000..c2f47a723fadc9a511887f4b4a50eb66130ff639 --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/string.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy works for string items +info: | + SendableMap.groupBy ( items, callbackfn ) + ... +includes: [compareArray.js] +features: [array-grouping, SendableMap] +---*/ + +const string = '🥰💩🙏😈'; + +const map = SendableMap.groupBy(string, function (char) { + return char < '🙏' ? 'before' : 'after'; +}); + +assert.compareArray(Array.from(map.keys()), ['after', 'before']); +assert.compareArray(map.get('before'), ['💩', '😈']); +assert.compareArray(map.get('after'), ['🥰', '🙏']); diff --git a/test/sendable/builtins/Map/groupBy/toPropertyKey.js b/test/sendable/builtins/Map/groupBy/toPropertyKey.js new file mode 100644 index 0000000000000000000000000000000000000000..02a71bbd6660b98803d2416ff9c6bc11053c6ffb --- /dev/null +++ b/test/sendable/builtins/Map/groupBy/toPropertyKey.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.groupby +description: SendableMap.groupBy does not coerce return value with ToPropertyKey +info: | + SendableMap.groupBy ( items, callbackfn ) + + ... +includes: [compareArray.js] +features: [array-grouping, SendableMap] +---*/ + +let calls = 0; +const stringable = { + toString: function toString() { + return 1; + } +}; + +const array = [1, '1', stringable]; + +const map = SendableMap.groupBy(array, function (v) { return v; }); + +assert.compareArray(Array.from(map.keys()), [1, '1', stringable]); +assert.compareArray(map.get('1'), ['1']); +assert.compareArray(map.get(1), [1]); +assert.compareArray(map.get(stringable), [stringable]); diff --git a/test/sendable/builtins/Map/is-a-constructor.js b/test/sendable/builtins/Map/is-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..afdcf9cb3823c31b2b3d5b5a9d5eab0da7c1c8fb --- /dev/null +++ b/test/sendable/builtins/Map/is-a-constructor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The SendableMap constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, SendableMap] +---*/ + +assert.sameValue(isConstructor(SendableMap), true, 'isConstructor(SendableMap) must return true'); +new SendableMap(); + diff --git a/test/sendable/builtins/Map/iterable-calls-set.js b/test/sendable/builtins/Map/iterable-calls-set.js new file mode 100644 index 0000000000000000000000000000000000000000..10b1b49b9548272c8d496d115fc0675ef0bd77fb --- /dev/null +++ b/test/sendable/builtins/Map/iterable-calls-set.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + new SendableMap calls `set` for each item on the iterable argument in order. +info: | + SendableMap ( [ iterable ] ) + + ... + 9. Repeat + ... + k. Let status be Call(adder, map, «k.[[value]], v.[[value]]»). + ... +includes: [compareArray.js] +---*/ + +var mapSet = SendableMap.prototype.set; +var counter = 0; + +var iterable = [ + ["foo", 1], + ["bar", 2] +]; +var results = []; +var _this = []; + +SendableMap.prototype.set = function(k, v) { + counter++; + results.push([k, v]); + _this.push(this); + mapSet.call(this, k, v); +}; + +var map = new SendableMap(iterable); + +assert.sameValue(counter, 2, "`SendableMap.prototype.set` called twice."); + +assert.compareArray(results[0], iterable[0]); +assert.compareArray(results[1], iterable[1]); +assert.sameValue(_this[0], map); +assert.sameValue(_this[1], map); diff --git a/test/sendable/builtins/Map/iterator-close-after-set-failure.js b/test/sendable/builtins/Map/iterator-close-after-set-failure.js new file mode 100644 index 0000000000000000000000000000000000000000..155e2eeaf2ba2a4079f6ea64048d36583a597c06 --- /dev/null +++ b/test/sendable/builtins/Map/iterator-close-after-set-failure.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + The iterator is closed when `SendableMap.prototype.set` throws an error. +info: | + SendableMap ( [ iterable ] ) + + ... + 9. Repeat + ... + k. Let status be Call(adder, map, «k.[[value]], v.[[value]]»). + l. If status is an abrupt completion, return IteratorClose(iter, status). +features: [Symbol.iterator] +---*/ + +var count = 0; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + value: [], + done: false + }; + }, + return: function() { + count += 1; + } + }; +}; +SendableMap.prototype.set = function() { + throw new Test262Error(); +} + +assert.throws(Test262Error, function() { + new SendableMap(iterable); +}); + +assert.sameValue(count, 1); diff --git a/test/sendable/builtins/Map/iterator-close-failure-after-set-failure.js b/test/sendable/builtins/Map/iterator-close-failure-after-set-failure.js new file mode 100644 index 0000000000000000000000000000000000000000..4609a1e6ce8b8b7720c2b2a97201e247a6fe3319 --- /dev/null +++ b/test/sendable/builtins/Map/iterator-close-failure-after-set-failure.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + The correct error is thrown `SendableMap.prototype.set` throws an error and + the IteratorClose throws an error. +features: [Symbol.iterator] +---*/ + +var count = 0; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { value: [], done: false }; + }, + return: function() { + throw new TypeError('ignore'); + } + }; +}; +SendableMap.prototype.set = function() { throw new Test262Error(); } + +assert.throws(Test262Error, function() { + new SendableMap(iterable); +}); diff --git a/test/sendable/builtins/Map/iterator-is-undefined-throws.js b/test/sendable/builtins/Map/iterator-is-undefined-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..cb84ef17a7e4da4d96564ca6d076a56f91b6689d --- /dev/null +++ b/test/sendable/builtins/Map/iterator-is-undefined-throws.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-objects +description: > + Throws a TypeError if the iterator of the iterable is undefined. +info: | + SendableMap ( [ iterable ] ) + ... + 9. Let iteratorRecord be ? GetIterator(iterable). +features: [Symbol.iterator] +---*/ + +var iterable = { [Symbol.iterator]: undefined }; + +assert.throws(TypeError, + function () { + new SendableMap(iterable); +}); diff --git a/test/sendable/builtins/Map/iterator-item-first-entry-returns-abrupt.js b/test/sendable/builtins/Map/iterator-item-first-entry-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..9ad73c9e361a54b20673613bf0d2d5572a613f5d --- /dev/null +++ b/test/sendable/builtins/Map/iterator-item-first-entry-returns-abrupt.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + Closes iterator if item first entry completes abruptly. +info: | + SendableMap ( [ iterable ] ) + + ... + 9. Repeat + ... + d. Let nextItem be IteratorValue(next). + ... + g. Let k be Get(nextItem, "0"). + h. If k is an abrupt completion, return IteratorClose(iter, k). + ... +features: [Symbol.iterator] +---*/ + +var count = 0; +var item = ['foo', 'bar']; +Object.defineProperty(item, 0, { + get: function() { + throw new Test262Error(); + } +}); +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + value: item, + done: false + }; + }, + return: function() { + count++; + } + }; +}; + +assert.throws(Test262Error, function() { + new SendableMap(iterable); +}); + +assert.sameValue(count, 1, 'The get error closed the iterator'); diff --git a/test/sendable/builtins/Map/iterator-item-second-entry-returns-abrupt.js b/test/sendable/builtins/Map/iterator-item-second-entry-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..a9404d0f83fc098fb3b5a6538346ea5049dc9911 --- /dev/null +++ b/test/sendable/builtins/Map/iterator-item-second-entry-returns-abrupt.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + Closes iterator if item second entry completes abruptly. +info: | + SendableMap ( [ iterable ] ) + + ... + 9. Repeat + ... + d. Let nextItem be IteratorValue(next). + ... + i. Let v be Get(nextItem, "1"). + j. If v is an abrupt completion, return IteratorClose(iter, v). + ... +features: [Symbol.iterator] +---*/ + +var count = 0; +var item = ['foo', 'bar']; +Object.defineProperty(item, 1, { + get: function() { + throw new Test262Error(); + } +}); +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + value: item, + done: false + }; + }, + return: function() { + count++; + } + }; +}; + +assert.throws(Test262Error, function() { + new SendableMap(iterable); +}); + +assert.sameValue(count, 1, 'The get error closed the iterator'); diff --git a/test/sendable/builtins/Map/iterator-items-are-not-object-close-iterator.js b/test/sendable/builtins/Map/iterator-items-are-not-object-close-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..bf38c77c3abf1bc6f4db3940a15e9e900cefc4d1 --- /dev/null +++ b/test/sendable/builtins/Map/iterator-items-are-not-object-close-iterator.js @@ -0,0 +1,88 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + Closes the iterator after `not Object` error. +info: | + SendableMap ( [ iterable ] ) + + ... + 9. Repeat + ... + d. Let nextItem be IteratorValue(next). + e. ReturnIfAbrupt(nextItem). + f. If Type(nextItem) is not Object, + i. Let error be Completion{[[type]]: throw, [[value]]: a newly created + TypeError object, [[target]]:empty}. + ii. Return IteratorClose(iter, error). +features: + - Symbol + - Symbol.iterator +---*/ + +var count = 0; +var nextItem; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + value: nextItem, + done: false + }; + }, + return: function() { + count += 1; + } + }; +}; + +nextItem = 1; +assert.throws(TypeError, function() { + new SendableMap(iterable); +}); +assert.sameValue(count, 1); + +nextItem = true; +assert.throws(TypeError, function() { + new SendableMap(iterable); +}); +assert.sameValue(count, 2); + +nextItem = ''; +assert.throws(TypeError, function() { + new SendableMap(iterable); +}); +assert.sameValue(count, 3); + +nextItem = null; +assert.throws(TypeError, function() { + new SendableMap(iterable); +}); +assert.sameValue(count, 4); + +nextItem = undefined; +assert.throws(TypeError, function() { + new SendableMap(iterable); +}); +assert.sameValue(count, 5); + +nextItem = Symbol('a'); +assert.throws(TypeError, function() { + new SendableMap(iterable); +}); +assert.sameValue(count, 6); diff --git a/test/sendable/builtins/Map/iterator-items-are-not-object.js b/test/sendable/builtins/Map/iterator-items-are-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..78ca4246575624e287d4878a718d733c0a78db8e --- /dev/null +++ b/test/sendable/builtins/Map/iterator-items-are-not-object.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + Throws a TypeError if iterable items are not Objects. +info: | + SendableMap ( [ iterable ] ) + + ... + 9. Repeat + ... + d. Let nextItem be IteratorValue(next). + e. ReturnIfAbrupt(nextItem). + f. If Type(nextItem) is not Object, + i. Let error be Completion{[[type]]: throw, [[value]]: a newly created + TypeError object, [[target]]:empty}. + ii. Return IteratorClose(iter, error). +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + new SendableMap([1]); +}); + +assert.throws(TypeError, function() { + new SendableMap(['']); +}); + +assert.throws(TypeError, function() { + new SendableMap([true]); +}); + +assert.throws(TypeError, function() { + new SendableMap([null]); +}); + +assert.throws(TypeError, function() { + new SendableMap([Symbol('a')]); +}); + +assert.throws(TypeError, function() { + new SendableMap([undefined]); +}); + +assert.throws(TypeError, function() { + new SendableMap([ + ['a', 1], + 2 + ]); +}); diff --git a/test/sendable/builtins/Map/iterator-next-failure.js b/test/sendable/builtins/Map/iterator-next-failure.js new file mode 100644 index 0000000000000000000000000000000000000000..6fc7e6cdecd85157df59cf32aa8dcc39959a1af1 --- /dev/null +++ b/test/sendable/builtins/Map/iterator-next-failure.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + The iterator is closed when iterable `next` throws an error. +info: | + SendableMap ( [ iterable ] ) + + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). +features: [Symbol.iterator] +---*/ + +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +assert.throws(Test262Error, function() { + new SendableMap(iterable); +}); diff --git a/test/sendable/builtins/Map/iterator-value-failure.js b/test/sendable/builtins/Map/iterator-value-failure.js new file mode 100644 index 0000000000000000000000000000000000000000..09a7e3be00bb549075d4d7989ba79a69b70ac028 --- /dev/null +++ b/test/sendable/builtins/Map/iterator-value-failure.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + The iterator is closed when iterable `next` value throws an error. +info: | + SendableMap ( [ iterable ] ) + + ... + 9. Repeat + ... + d. Let nextItem be IteratorValue(next). + e. ReturnIfAbrupt(nextItem). +features: [Symbol.iterator] +---*/ + +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + get value() { + throw new Test262Error(); + }, + done: false + }; + } + }; +}; + +assert.throws(Test262Error, function() { + new SendableMap(iterable); +}); diff --git a/test/sendable/builtins/Map/length.js b/test/sendable/builtins/Map/length.js new file mode 100644 index 0000000000000000000000000000000000000000..f9810f7e06e6910b53b5e8ebb8566bcb38251a0d --- /dev/null +++ b/test/sendable/builtins/Map/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 23.1.2 +description: SendableMap.length is 0. +info: | + Properties of the SendableMap Constructor + + Besides the length property (whose value is 0) +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/map-iterable-empty-does-not-call-set.js b/test/sendable/builtins/Map/map-iterable-empty-does-not-call-set.js new file mode 100644 index 0000000000000000000000000000000000000000..df47c932f3c41ccf464484569bda14bce2d167dc --- /dev/null +++ b/test/sendable/builtins/Map/map-iterable-empty-does-not-call-set.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + A SendableMap constructed with an empty iterable argument does not call set. +info: | + SendableMap ( [ iterable ] ) + + When the SendableMap function is called with optional argument the following steps are + taken: + + ... + 8. If iter is undefined, return map. + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). + c. If next is false, return map. +---*/ + +var set = SendableMap.prototype.set; +var counter = 0; + +SendableMap.prototype.set = function(value) { + counter++; + set.call(this, value); +}; + +new SendableMap([]); + +assert.sameValue(counter, 0, '`SendableMap.prototype.set` was not called.'); diff --git a/test/sendable/builtins/Map/map-iterable-throws-when-set-is-not-callable.js b/test/sendable/builtins/Map/map-iterable-throws-when-set-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..70da0de1b9511b6694cec40415f51258df5a5bc3 --- /dev/null +++ b/test/sendable/builtins/Map/map-iterable-throws-when-set-is-not-callable.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + Throws a TypeError if `set` is not callable on SendableMap constructor with a + iterable argument. +info: | + SendableMap ( [ iterable ] ) + + When the SendableMap function is called with optional argument the following steps are + taken: + + ... + 5. If iterable is not present, let iterable be undefined. + 6. If iterable is either undefined or null, let iter be undefined. + 7. Else, + a. Let adder be Get(map, "set"). + b. ReturnIfAbrupt(adder). + c. If IsCallable(adder) is false, throw a TypeError exception. +---*/ + +SendableMap.prototype.set = null; + +assert.throws(TypeError, function() { + new SendableMap([ + [1, 1], + [2, 2] + ]); +}); diff --git a/test/sendable/builtins/Map/map-iterable.js b/test/sendable/builtins/Map/map-iterable.js new file mode 100644 index 0000000000000000000000000000000000000000..da19e1757633f870a8a756134fd2e2f686894904 --- /dev/null +++ b/test/sendable/builtins/Map/map-iterable.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + Contructor returns a map object set with the elements from the iterable + argument. +info: | + SendableMap ( [ iterable ] ) + + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). + c. If next is false, return map. + ... +---*/ + +var m = new SendableMap([ + ["attr", 1], + ["foo", 2] +]); + +assert.sameValue(m.size, 2, 'The value of `m.size` is `2`'); +assert.sameValue(m.get("attr"), 1); +assert.sameValue(m.get("foo"), 2); diff --git a/test/sendable/builtins/Map/map-no-iterable-does-not-call-set.js b/test/sendable/builtins/Map/map-no-iterable-does-not-call-set.js new file mode 100644 index 0000000000000000000000000000000000000000..c8ad230600f9a6ae38dd73ca6756848bb38e63e4 --- /dev/null +++ b/test/sendable/builtins/Map/map-no-iterable-does-not-call-set.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + A SendableMap constructed without a iterable argument does not call set. +info: | + SendableMap ( [ iterable ] ) + + When the SendableMap function is called with optional argument the following steps are + taken: + + ... + 5. If iterable is not present, let iterable be undefined. + 6. If iterable is either undefined or null, let iter be undefined. + 7. Else, + a. Let adder be Get(map, "set"). + b. ReturnIfAbrupt(adder). + c. If IsCallable(adder) is false, throw a TypeError exception. + d. Let iter be GetIterator(iterable). + e. ReturnIfAbrupt(iter). + 8. If iter is undefined, return map. +---*/ + +var set = SendableMap.prototype.set; +var counter = 0; + +SendableMap.prototype.set = function(value) { + counter++; + set.call(this, value); +}; + +new SendableMap(); + +assert.sameValue(counter, 0, '`SendableMap.prototype.set` was not called.'); diff --git a/test/sendable/builtins/Map/map-no-iterable.js b/test/sendable/builtins/Map/map-no-iterable.js new file mode 100644 index 0000000000000000000000000000000000000000..d861d65f8d306bf9469c41ed25e18a93e3a33993 --- /dev/null +++ b/test/sendable/builtins/Map/map-no-iterable.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + Returns the new SendableMap object with the new empty list if the iterable argument is + undefined. +info: | + SendableMap ( [ iterable ] ) + + ... + 2. Let map be OrdinaryCreateFromConstructor(NewTarget, "%SendableMapPrototype%", + «‍[[SendableMapData]]» ). + ... + 4. SendableMap map’s [[SendableMapData]] internal slot to a new empty List. + 5. If iterable is not present, let iterable be undefined. + 6. If iterable is either undefined or null, let iter be undefined. + ... + 8. If iter is undefined, return map. +---*/ + +var m1 = new SendableMap(); +var m2 = new SendableMap(undefined); +var m3 = new SendableMap(null); + +assert.sameValue(m1.size, 0, 'The value of `new SendableMap().size` is `0`'); +assert.sameValue(m2.size, 0, 'The value of `new SendableMap(undefined).size` is `0`'); +assert.sameValue(m3.size, 0, 'The value of `new SendableMap(null).size` is `0`'); + +assert(m1 instanceof SendableMap); +assert(m2 instanceof SendableMap); +assert(m3 instanceof SendableMap); diff --git a/test/sendable/builtins/Map/map.js b/test/sendable/builtins/Map/map.js new file mode 100644 index 0000000000000000000000000000000000000000..027c6df618b8d8f2ee474aaa814932298baa80f0 --- /dev/null +++ b/test/sendable/builtins/Map/map.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + SendableMap descriptor as a standard built-in object. +info: | + SendableMap ( [ iterable ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(this, 'SendableMap', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/name.js b/test/sendable/builtins/Map/name.js new file mode 100644 index 0000000000000000000000000000000000000000..528bab3d0ecaa0fbd196dfc5354f8848eeef74bb --- /dev/null +++ b/test/sendable/builtins/Map/name.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: SendableMap.name value and descriptor. +info: | + SendableMap ( [ iterable ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap, "name", { + value: "SendableMap", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/newtarget.js b/test/sendable/builtins/Map/newtarget.js new file mode 100644 index 0000000000000000000000000000000000000000..6f5f1880c266fa3b8ed5da8c9346308cf3950f38 --- /dev/null +++ b/test/sendable/builtins/Map/newtarget.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + The new SendableMap object's prototype is SendableMap.prototype +info: | + SendableMap ( [ iterable ] ) + + When the SendableMap function is called with optional argument the following steps + are taken: + + ... + 2. Let map be OrdinaryCreateFromConstructor(NewTarget, "%SendableMapPrototype%", + «‍[[SendableMapData]]» ). + ... + +---*/ + +var m1 = new SendableMap(); + +assert.sameValue( + Object.getPrototypeOf(m1), + SendableMap.prototype, + "`Object.getPrototypeOf(m1)` returns `SendableMap.prototype`" +); + +var m2 = new SendableMap([ + [1, 1], + [2, 2] +]); + +assert.sameValue( + Object.getPrototypeOf(m2), + SendableMap.prototype, + "`Object.getPrototypeOf(m2)` returns `SendableMap.prototype`" +); diff --git a/test/sendable/builtins/Map/properties-of-map-instances.js b/test/sendable/builtins/Map/properties-of-map-instances.js new file mode 100644 index 0000000000000000000000000000000000000000..e3e6a3cbfb31f8970dee7bbf71f1b3cc3b2032d3 --- /dev/null +++ b/test/sendable/builtins/Map/properties-of-map-instances.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 23.1.4 +description: > + SendableMap instances are ordinary objects that inherit properties from the SendableMap + prototype. +---*/ + +assert.sameValue( + Object.getPrototypeOf(new SendableMap()), + SendableMap.prototype, + '`Object.getPrototypeOf(new SendableMap())` returns `SendableMap.prototype`' +); diff --git a/test/sendable/builtins/Map/properties-of-the-map-prototype-object.js b/test/sendable/builtins/Map/properties-of-the-map-prototype-object.js new file mode 100644 index 0000000000000000000000000000000000000000..100112038050c614e7c30cbbed35a0d4907c8ea5 --- /dev/null +++ b/test/sendable/builtins/Map/properties-of-the-map-prototype-object.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 23.1.3 +description: > + The prototype of SendableMap.prototype is Object.prototype. +info: | + The SendableMap prototype object is the intrinsic object %SendableMapPrototype%. The value + of the [[Prototype]] internal slot of the SendableMap prototype object is the + intrinsic object %ObjectPrototype% (19.1.3). The SendableMap prototype object is an + ordinary object. It does not have a [[SendableMapData]] internal slot. +---*/ + +assert.sameValue( + Object.getPrototypeOf(SendableMap.prototype), + Object.prototype, + 'Object.getPrototypeOf(SendableMap.prototype) returns Object.prototype' +); diff --git a/test/sendable/builtins/Map/proto-from-ctor-realm.js b/test/sendable/builtins/Map/proto-from-ctor-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..ab8cd5a0cb07929febae079fb0cec6477266bd6c --- /dev/null +++ b/test/sendable/builtins/Map/proto-from-ctor-realm.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 3. Let map be ? OrdinaryCreateFromConstructor(NewTarget, "%SendableMapPrototype%", + « [[SendableMapData]] »). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [cross-realm, Reflect] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +var o = Reflect.construct(SendableMap, [], C); + +assert.sameValue(Object.getPrototypeOf(o), other.SendableMap.prototype); diff --git a/test/sendable/builtins/Map/prototype-of-map.js b/test/sendable/builtins/Map/prototype-of-map.js new file mode 100644 index 0000000000000000000000000000000000000000..9f041cdb04c795e09088348e61eeb29cd0f0178e --- /dev/null +++ b/test/sendable/builtins/Map/prototype-of-map.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 23.1.2 +description: > + The prototype of SendableMap is the intrinsic FunctionPrototype. +info: | + The value of the [[Prototype]] internal slot of the SendableMap constructor is the + intrinsic object %FunctionPrototype% (19.2.3). +---*/ + +assert.sameValue( + Object.getPrototypeOf(SendableMap), + Function.prototype, + '`Object.getPrototypeOf(SendableMap)` returns `Function.prototype`' +); diff --git a/test/sendable/builtins/Map/prototype/Symbol.iterator.js b/test/sendable/builtins/Map/prototype/Symbol.iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..38079bc69d0e79906e47c690195c76c4b5feba5e --- /dev/null +++ b/test/sendable/builtins/Map/prototype/Symbol.iterator.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype-@@iterator +description: Initial state of the Symbol.iterator property +info: | + The initial value of the @@iterator property is the same function object as + the initial value of the entries property. + + Per ES6 section 17, the method should exist on the Array prototype, and it + should be writable and configurable, but not enumerable. +includes: [propertyHelper.js] +features: [Symbol.iterator] +---*/ + +assert.sameValue(SendableMap.prototype[Symbol.iterator], SendableMap.prototype.entries); +verifyProperty(SendableMap.prototype, Symbol.iterator, { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/prototype/Symbol.iterator/not-a-constructor.js b/test/sendable/builtins/Map/prototype/Symbol.iterator/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..a73038b6cd6977a0a8306aa6b2dc386065a3e49a --- /dev/null +++ b/test/sendable/builtins/Map/prototype/Symbol.iterator/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableMap.prototype[Symbol.iterator] does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Symbol, Symbol.iterator, SendableMap, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableMap.prototype[Symbol.iterator]), + false, + 'isConstructor(SendableMap.prototype[Symbol.iterator]) must return false' +); + +assert.throws(TypeError, () => { + let m = new SendableMap(); new m[Symbol.iterator](); +}); + diff --git a/test/sendable/builtins/Map/prototype/Symbol.toStringTag.js b/test/sendable/builtins/Map/prototype/Symbol.toStringTag.js new file mode 100644 index 0000000000000000000000000000000000000000..49918f0119b853eb76465cbd6aee94ee4a478bd4 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/Symbol.toStringTag.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype-@@tostringtag +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "SendableMap". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.toStringTag] +---*/ + +assert.sameValue(SendableMap.prototype[Symbol.toStringTag], 'SendableMap'); + +verifyProperty(SendableMap.prototype, Symbol.toStringTag, { + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/prototype/clear/clear-map.js b/test/sendable/builtins/Map/prototype/clear/clear-map.js new file mode 100644 index 0000000000000000000000000000000000000000..8efa79a811a68b8951661095601d565451e7c474 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/clear/clear-map.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.clear +description: > + Clears a SendableMap. +info: | + SendableMap.prototype.clear ( ) + + ... + 4. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. Set p.[[key]] to empty. + b. Set p.[[value]] to empty. + 6. Return undefined. +features: [Symbol] +---*/ + +var m1 = new SendableMap([ + ['foo', 'bar'], + [1, 1] +]); +var m2 = new SendableMap(); +var m3 = new SendableMap(); +m2.set('foo', 'bar'); +m2.set(1, 1); +m2.set(Symbol('a'), Symbol('a')); + +m1.clear(); +m2.clear(); +m3.clear(); + +assert.sameValue(m1.size, 0); +assert.sameValue(m2.size, 0); +assert.sameValue(m3.size, 0); diff --git a/test/sendable/builtins/Map/prototype/clear/clear.js b/test/sendable/builtins/Map/prototype/clear/clear.js new file mode 100644 index 0000000000000000000000000000000000000000..82a94c2a437b2e54b149b6e4a0af7b1b5af595ce --- /dev/null +++ b/test/sendable/builtins/Map/prototype/clear/clear.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.clear +description: > + SendableMap.prototype.clear ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableMap.prototype.clear, + 'function', + 'typeof SendableMap.prototype.clear is "function"' +); + +verifyProperty(SendableMap.prototype, 'clear', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/prototype/clear/context-is-not-map-object.js b/test/sendable/builtins/Map/prototype/clear/context-is-not-map-object.js new file mode 100644 index 0000000000000000000000000000000000000000..16664dc38044183c27b7bd87779715bf57c78a34 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/clear/context-is-not-map-object.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.clear +description: > + Throws a TypeError if `this` does not have a [[SendableMapData]] internal slot. +info: | + SendableMap.prototype.clear ( ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.clear.call({}); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.clear.call([]); +}); diff --git a/test/sendable/builtins/Map/prototype/clear/context-is-not-object.js b/test/sendable/builtins/Map/prototype/clear/context-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..441c4610e8ad00c33c2b04178a40a830d39fbb8f --- /dev/null +++ b/test/sendable/builtins/Map/prototype/clear/context-is-not-object.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.clear +description: > + Throws a TypeError if `this` is not an Object. +info: | + SendableMap.prototype.clear ( ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.clear.call(1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.clear.call(true); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.clear.call(''); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.clear.call(null); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.clear.call(undefined); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.clear.call(Symbol()); +}); diff --git a/test/sendable/builtins/Map/prototype/clear/context-is-set-object-throws.js b/test/sendable/builtins/Map/prototype/clear/context-is-set-object-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..c44e1f2fef2b7a86fbf7de4d14b51f0e82c2a055 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/clear/context-is-set-object-throws.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.clear +description: > + Throws a TypeError if `this` is a Set object. +info: | + SendableMap.prototype.clear ( ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.clear.call(new Set()); +}); diff --git a/test/sendable/builtins/Map/prototype/clear/context-is-weakmap-object-throws.js b/test/sendable/builtins/Map/prototype/clear/context-is-weakmap-object-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..dfee81fe5e3d2108e5b329022052b311f61f372d --- /dev/null +++ b/test/sendable/builtins/Map/prototype/clear/context-is-weakmap-object-throws.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.clear +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + SendableMap.prototype.clear ( ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.clear.call(new WeakMap()); +}); diff --git a/test/sendable/builtins/Map/prototype/clear/length.js b/test/sendable/builtins/Map/prototype/clear/length.js new file mode 100644 index 0000000000000000000000000000000000000000..fb10fc07302e25a1e20c897df1d5ad132325fa72 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/clear/length.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.clear +description: > + SendableMap.prototype.clear.length value and descriptor. +info: | + SendableMap.prototype.clear ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.clear, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/clear/map-data-list-is-preserved.js b/test/sendable/builtins/Map/prototype/clear/map-data-list-is-preserved.js new file mode 100644 index 0000000000000000000000000000000000000000..2ba52ff35050facba06eb06a410124a6e4527342 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/clear/map-data-list-is-preserved.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.clear +description: > + The existing [[SendableMapData]] List is preserved. +info: | + The existing [[SendableMapData]] List is preserved because there may be existing + SendableMapIterator objects that are suspended midway through iterating over that + List. + + SendableMap.prototype.clear ( ) + + ... + 4. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. Set p.[[key]] to empty. + b. Set p.[[value]] to empty. + 6. Return undefined. +---*/ + +var m = new SendableMap([ + [1, 1], + [2, 2], + [3, 3] +]); +var e = m.entries(); + +e.next(); +m.clear(); + +var n = e.next(); +assert.sameValue(n.value, undefined); +assert.sameValue(n.done, true); diff --git a/test/sendable/builtins/Map/prototype/clear/name.js b/test/sendable/builtins/Map/prototype/clear/name.js new file mode 100644 index 0000000000000000000000000000000000000000..73c655714a791f0db75dc1efbd88fedefb73ba67 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/clear/name.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.clear +description: > + SendableMap.prototype.entries.name value and descriptor. +info: | + SendableMap.prototype.clear ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.clear, "name", { + value: "clear", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/clear/not-a-constructor.js b/test/sendable/builtins/Map/prototype/clear/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..8828dcf71ac3b5f652b4fc29dcf2454f4ceadf0c --- /dev/null +++ b/test/sendable/builtins/Map/prototype/clear/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableMap.prototype.clear does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableMap, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableMap.prototype.clear), false, 'isConstructor(SendableMap.prototype.clear) must return false'); + +assert.throws(TypeError, () => { + let m = new SendableMap(); new m.clear(); +}); + diff --git a/test/sendable/builtins/Map/prototype/clear/returns-undefined.js b/test/sendable/builtins/Map/prototype/clear/returns-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..bda29a4b123eee33b89274bcbd71a92a9327f74f --- /dev/null +++ b/test/sendable/builtins/Map/prototype/clear/returns-undefined.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.clear +description: > + Returns undefined. +info: | + SendableMap.prototype.clear ( ) + + ... + 4. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. Set p.[[key]] to empty. + b. Set p.[[value]] to empty. + 6. Return undefined. +---*/ + +var m1 = new SendableMap([ + ['foo', 'bar'], + [1, 1] +]); + +assert.sameValue(m1.clear(), undefined, 'clears a map and returns undefined'); +assert.sameValue(m1.clear(), undefined, 'returns undefined on an empty map'); diff --git a/test/sendable/builtins/Map/prototype/constructor.js b/test/sendable/builtins/Map/prototype/constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..b186ac1170f994f72170ae990de3011882891497 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/constructor.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-constructor +description: SendableMap.prototype.constructor value and descriptor +info: | + The initial value of SendableMap.prototype.constructor is the intrinsic object %SendableMap%. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(SendableMap.prototype.constructor, SendableMap); +assert.sameValue((new SendableMap()).constructor, SendableMap); + +verifyProperty(SendableMap.prototype, 'constructor', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/prototype/delete/context-is-not-map-object.js b/test/sendable/builtins/Map/prototype/delete/context-is-not-map-object.js new file mode 100644 index 0000000000000000000000000000000000000000..344ed7857ddbcea420dab6198ff9e08270603fe6 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/delete/context-is-not-map-object.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.delete +description: > + Throws a TypeError if `this` does not have a [[SendableMapData]] internal slot. +info: | + SendableMap.prototype.delete ( key ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.delete.call({}, 'attr'); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.delete.call([], 'attr'); +}); diff --git a/test/sendable/builtins/Map/prototype/delete/context-is-not-object.js b/test/sendable/builtins/Map/prototype/delete/context-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..8d95e5ae361e539c92570195ef768e3a037cc5d3 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/delete/context-is-not-object.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.delete +description: > + Throws a TypeError if `this` is not an Object. +info: | + SendableMap.prototype.delete ( key ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.delete.call(1, 'attr'); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.delete.call(true, 'attr'); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.delete.call('', 'attr'); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.delete.call(null, 'attr'); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.delete.call(undefined, 'attr'); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.delete.call(Symbol(), 'attr'); +}); diff --git a/test/sendable/builtins/Map/prototype/delete/context-is-set-object-throws.js b/test/sendable/builtins/Map/prototype/delete/context-is-set-object-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..d2f3b158391fde421988ad556fec775c9b25e52c --- /dev/null +++ b/test/sendable/builtins/Map/prototype/delete/context-is-set-object-throws.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.delete +description: > + Throws a TypeError if `this` is a Set object. +info: | + SendableMap.prototype.delete ( key ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.delete.call(new Set(), 'attr'); +}); diff --git a/test/sendable/builtins/Map/prototype/delete/context-is-weakmap-object-throws.js b/test/sendable/builtins/Map/prototype/delete/context-is-weakmap-object-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..7b2288f12ec9dfdda472088e893b524d52484247 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/delete/context-is-weakmap-object-throws.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.delete +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + SendableMap.prototype.delete ( key ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.delete.call(new WeakMap(), 'attr'); +}); diff --git a/test/sendable/builtins/Map/prototype/delete/delete.js b/test/sendable/builtins/Map/prototype/delete/delete.js new file mode 100644 index 0000000000000000000000000000000000000000..7b9ae1090961801cbb955469a7ca486ad3bfe406 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/delete/delete.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.delete +description: > + SendableMap.prototype.delete ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableMap.prototype.delete, + 'function', + 'typeof SendableMap.prototype.delete is "function"' +); + +verifyProperty(SendableMap.prototype, 'delete', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/prototype/delete/does-not-break-iterators.js b/test/sendable/builtins/Map/prototype/delete/does-not-break-iterators.js new file mode 100644 index 0000000000000000000000000000000000000000..97e73c5583b64ee4a90a6eedaf341f5a8e95e3ab --- /dev/null +++ b/test/sendable/builtins/Map/prototype/delete/does-not-break-iterators.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.delete +description: > + Deleting an entry does not break a [[SendableMapData]] List. +info: | + SendableMap.prototype.delete ( key ) + + 4. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + i. Set p.[[key]] to empty. + ii. Set p.[[value]] to empty. + iii. Return true. + ... +---*/ + +var m = new SendableMap([ + ['a', 1], + ['b', 2], + ['c', 3] +]); +var e = m.entries(); + +e.next(); +m.delete('b'); + +var n = e.next(); + +assert.sameValue(n.value[0], 'c'); +assert.sameValue(n.value[1], 3); + +n = e.next(); +assert.sameValue(n.value, undefined); +assert.sameValue(n.done, true); diff --git a/test/sendable/builtins/Map/prototype/delete/length.js b/test/sendable/builtins/Map/prototype/delete/length.js new file mode 100644 index 0000000000000000000000000000000000000000..4bb01e3fb54cf079cc1ebc84e6999aaf9878f66c --- /dev/null +++ b/test/sendable/builtins/Map/prototype/delete/length.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.delete +description: > + SendableMap.prototype.delete.length value and descriptor. +info: | + SendableMap.prototype.delete ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.delete, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/delete/name.js b/test/sendable/builtins/Map/prototype/delete/name.js new file mode 100644 index 0000000000000000000000000000000000000000..962466fdc3b82b64b0ffc67b9cecf073d0966c4d --- /dev/null +++ b/test/sendable/builtins/Map/prototype/delete/name.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.delete +description: > + SendableMap.prototype.delete.name value and descriptor. +info: | + SendableMap.prototype.delete ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.delete, "name", { + value: "delete", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/delete/not-a-constructor.js b/test/sendable/builtins/Map/prototype/delete/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..db15edc42e6ba7e1c218226222d68ffe15c31afe --- /dev/null +++ b/test/sendable/builtins/Map/prototype/delete/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableMap.prototype.delete does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableMap, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableMap.prototype.delete), false, 'isConstructor(SendableMap.prototype.delete) must return false'); + +assert.throws(TypeError, () => { + let m = new SendableMap(); new m.delete(); +}); + diff --git a/test/sendable/builtins/Map/prototype/delete/returns-false.js b/test/sendable/builtins/Map/prototype/delete/returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..582ff66321bc881ad77ae14f6bda5dcfcd009855 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/delete/returns-false.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.delete +description: > + Returns false when it does not delete an entry. +info: | + SendableMap.prototype.delete ( key ) + + 4. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + ... + iii. Return true. + 6. Return false. +---*/ + +var m = new SendableMap([ + ['a', 1], + ['b', 2] +]); + +assert.sameValue(m.delete('not-in-the-map'), false); + +m.delete('a'); +assert.sameValue(m.delete('a'), false); diff --git a/test/sendable/builtins/Map/prototype/delete/returns-true-for-deleted-entry.js b/test/sendable/builtins/Map/prototype/delete/returns-true-for-deleted-entry.js new file mode 100644 index 0000000000000000000000000000000000000000..3210881033dc3a2b550325bb81d705ab58f363af --- /dev/null +++ b/test/sendable/builtins/Map/prototype/delete/returns-true-for-deleted-entry.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.delete +description: > + Returns true when deletes an entry. +info: | + SendableMap.prototype.delete ( key ) + + 4. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + i. Set p.[[key]] to empty. + ii. Set p.[[value]] to empty. + iii. Return true. + ... +---*/ + +var m = new SendableMap([ + ['a', 1], + ['b', 2] +]); + +var result = m.delete('a'); + +assert(result); +assert.sameValue(m.size, 1); diff --git a/test/sendable/builtins/Map/prototype/descriptor.js b/test/sendable/builtins/Map/prototype/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..94949b366f8aa0b27325636391ee413f97103ae7 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/descriptor.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype +description: SendableMap.prototype property attributes. +info: | + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: false }. +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap, 'prototype', { + writable: false, + enumerable: false, + configurable: false, +}); diff --git a/test/sendable/builtins/Map/prototype/entries/does-not-have-mapdata-internal-slot-set.js b/test/sendable/builtins/Map/prototype/entries/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000000000000000000000000000000000..73dd846ced6c25e6f4b842a7d2225c8e5788e11f --- /dev/null +++ b/test/sendable/builtins/Map/prototype/entries/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.entries +description: > + Throws a TypeError if `this` is a Set object. +info: | + SendableMap.prototype.entries ( ) + + 1. Let M be the this value. + 2. Return CreateSendableMapIterator(M, "key+value"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 2. If map does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.entries.call(new Set()); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.entries.call(new Set()); +}); diff --git a/test/sendable/builtins/Map/prototype/entries/does-not-have-mapdata-internal-slot-weakmap.js b/test/sendable/builtins/Map/prototype/entries/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000000000000000000000000000000000..b570e5172231cb3f89db8b17ca2b66b5d8f46b94 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/entries/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.entries +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + SendableMap.prototype.entries ( ) + + 1. Let M be the this value. + 2. Return CreateSendableMapIterator(M, "key+value"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 2. If map does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.entries.call(new WeakMap()); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.entries.call(new WeakMap()); +}); diff --git a/test/sendable/builtins/Map/prototype/entries/does-not-have-mapdata-internal-slot.js b/test/sendable/builtins/Map/prototype/entries/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..20458ca36c09edd8d90252777d87bfad6d3b916c --- /dev/null +++ b/test/sendable/builtins/Map/prototype/entries/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.entries +description: > + Throws a TypeError if `this` object does not have a [[SendableMapData]] internal slot. +info: | + SendableMap.prototype.entries ( ) + + 1. Let M be the this value. + 2. Return CreateSendableMapIterator(M, "key+value"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 2. If map does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... + +---*/ + +var m = new SendableMap(); + +assert.throws(TypeError, function() { + SendableMap.prototype.entries.call([]); +}); + +assert.throws(TypeError, function() { + m.entries.call([]); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.entries.call({}); +}); + +assert.throws(TypeError, function() { + m.entries.call({}); +}); diff --git a/test/sendable/builtins/Map/prototype/entries/entries.js b/test/sendable/builtins/Map/prototype/entries/entries.js new file mode 100644 index 0000000000000000000000000000000000000000..c3f98862aa2367c9ae5bdb683b1f869720652563 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/entries/entries.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.entries +description: > + Property type and descriptor. +info: | + SendableMap.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableMap.prototype.entries, + 'function', + '`typeof SendableMap.prototype.entries` is `function`' +); + +verifyProperty(SendableMap.prototype, 'entries', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/prototype/entries/length.js b/test/sendable/builtins/Map/prototype/entries/length.js new file mode 100644 index 0000000000000000000000000000000000000000..a738bc8a0a427611fcec9731707910276ca274ef --- /dev/null +++ b/test/sendable/builtins/Map/prototype/entries/length.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.entries +description: > + SendableMap.prototype.entries.length value and descriptor. +info: | + SendableMap.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.entries, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/entries/name.js b/test/sendable/builtins/Map/prototype/entries/name.js new file mode 100644 index 0000000000000000000000000000000000000000..d7de8b94cfddbadf597931db81fa59d2498a535f --- /dev/null +++ b/test/sendable/builtins/Map/prototype/entries/name.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.entries +description: > + SendableMap.prototype.entries.name value and descriptor. +info: | + SendableMap.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.entries, "name", { + value: "entries", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/entries/not-a-constructor.js b/test/sendable/builtins/Map/prototype/entries/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..8c8cf9b94561d322fdedadae15359e57036d9393 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/entries/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableMap.prototype.entries does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableMap, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableMap.prototype.entries), + false, + 'isConstructor(SendableMap.prototype.entries) must return false' +); + +assert.throws(TypeError, () => { + let m = new SendableMap(); new m.entries(); +}); + diff --git a/test/sendable/builtins/Map/prototype/entries/returns-iterator-empty.js b/test/sendable/builtins/Map/prototype/entries/returns-iterator-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..650c0decbc2fa71d8d7e7cb1639b9a983b24b59b --- /dev/null +++ b/test/sendable/builtins/Map/prototype/entries/returns-iterator-empty.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.entries +description: > + Returns an iterator on an empty SendableMap object. +info: | + SendableMap.prototype.entries ( ) + + ... + 2. Return CreateSendableMapIterator(M, "key+value"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var map = new SendableMap(); +var iterator = map.entries(); +var result = iterator.next(); + +assert.sameValue( + result.value, undefined, + 'The value of `result.value` is `undefined`' +); +assert.sameValue(result.done, true, 'The value of `result.done` is `true`'); diff --git a/test/sendable/builtins/Map/prototype/entries/returns-iterator.js b/test/sendable/builtins/Map/prototype/entries/returns-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..43a6908737ed0a4c5f4b328fad2563af6755f1b4 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/entries/returns-iterator.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.entries +description: > + Returns an iterator. +info: | + SendableMap.prototype.entries ( ) + + ... + 2. Return CreateSendableMapIterator(M, "key+value"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var map = new SendableMap(); +map.set('a',1); +map.set('b',2); +map.set('c',3); + +var iterator = map.entries(); +var result; + +result = iterator.next(); +assert.sameValue(result.value[0], 'a', 'First result `value` ("key")'); +assert.sameValue(result.value[1], 1, 'First result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'First result `value` (length)'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value[0], 'b', 'Second result `value` ("key")'); +assert.sameValue(result.value[1], 2, 'Second result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'Second result `value` (length)'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value[0], 'c', 'Third result `value` ("key")'); +assert.sameValue(result.value[1], 3, 'Third result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'Third result `value` (length)'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); + +result = iterator.next(); +assert.sameValue( + result.value, undefined, 'Exhausted result `value` (repeated request)' +); +assert.sameValue( + result.done, true, 'Exhausted result `done` flag (repeated request)' +); diff --git a/test/sendable/builtins/Map/prototype/entries/this-not-object-throw.js b/test/sendable/builtins/Map/prototype/entries/this-not-object-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..d83fecfa269674b87f948c5fed32d1ad5a0bf420 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/entries/this-not-object-throw.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.entries +description: > + Throws a TypeError if `this` is not an Object. +info: | + SendableMap.prototype.entries ( ) + + ... + 2. Return CreateSetIterator(M, "key+value"). + + 23.1.5.1 CreateSetIterator Abstract Operation + + 1. If Type(map) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.entries.call(false); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.entries.call(1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.entries.call(''); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.entries.call(undefined); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.entries.call(null); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.entries.call(Symbol()); +}); + +assert.throws(TypeError, function() { + var map = new SendableMap(); + map.entries.call(false); +}); diff --git a/test/sendable/builtins/Map/prototype/forEach/callback-parameters.js b/test/sendable/builtins/Map/prototype/forEach/callback-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..d9f3569f4b05d1a03161a3cf8ad98b0cf028e705 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/callback-parameters.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + Verify the parameters order on the given callback. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + 6. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 7. Repeat for each Record {[[key]], [[value]]} e that is an element of + entries, in original key insertion order + a. If e.[[key]] is not empty, then + i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»). + ... +---*/ + +var map = new SendableMap(); +map.set('foo', 42); +map.set('bar', 'baz'); + +var results = []; + +var callback = function(value, key, thisArg) { + results.push({ + value: value, + key: key, + thisArg: thisArg + }); +}; + +map.forEach(callback); + +assert.sameValue(results[0].value, 42); +assert.sameValue(results[0].key, 'foo'); +assert.sameValue(results[0].thisArg, map); + +assert.sameValue(results[1].value, 'baz'); +assert.sameValue(results[1].key, 'bar'); +assert.sameValue(results[1].thisArg, map); + +assert.sameValue(results.length, 2); diff --git a/test/sendable/builtins/Map/prototype/forEach/callback-result-is-abrupt.js b/test/sendable/builtins/Map/prototype/forEach/callback-result-is-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..9d639454dd37a89b50c6b451f8c502dfb04a9300 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/callback-result-is-abrupt.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + Returns error from callback result is abrupt. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + 6. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 7. Repeat for each Record {[[key]], [[value]]} e that is an element of + entries, in original key insertion order + a. If e.[[key]] is not empty, then + i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»). + ii. ReturnIfAbrupt(funcResult). + ... +---*/ + +var map = new SendableMap([[0, 0]]); + +assert.throws(Test262Error, function() { + map.forEach(function() { + throw new Test262Error(); + }); +}); diff --git a/test/sendable/builtins/Map/prototype/forEach/callback-this-non-strict.js b/test/sendable/builtins/Map/prototype/forEach/callback-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..8ce87579bbf62302f9243aba6163ea387947e7a4 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/callback-this-non-strict.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + If a thisArg is not provided, undefined will be used as the this value for + each invocation of callbackfn. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + 6. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 7. Repeat for each Record {[[key]], [[value]]} e that is an element of + entries, in original key insertion order + a. If e.[[key]] is not empty, then + i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»). + ... +flags: [noStrict] +---*/ + +var _this = []; +var map = new SendableMap(); + +map.set(0, 0); +map.set(1, 1); +map.set(2, 2); + +map.forEach(function() { + _this.push(this); +}); + +assert.sameValue(_this[0], this); +assert.sameValue(_this[1], this); +assert.sameValue(_this[2], this); diff --git a/test/sendable/builtins/Map/prototype/forEach/callback-this-strict.js b/test/sendable/builtins/Map/prototype/forEach/callback-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..037108b6508a148b6e8558fedd0f89ed19c8d6de --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/callback-this-strict.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + If a thisArg is not provided, undefined will be used as the this value for + each invocation of callbackfn. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + 6. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 7. Repeat for each Record {[[key]], [[value]]} e that is an element of + entries, in original key insertion order + a. If e.[[key]] is not empty, then + i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»). + ... +flags: [onlyStrict] +---*/ + +var _this = []; +var map = new SendableMap(); + +map.set(0, 0); +map.set(1, 1); +map.set(2, 2); + +map.forEach(function() { + _this.push(this); +}); + +assert.sameValue(_this[0], undefined); +assert.sameValue(_this[1], undefined); +assert.sameValue(_this[2], undefined); diff --git a/test/sendable/builtins/Map/prototype/forEach/deleted-values-during-foreach.js b/test/sendable/builtins/Map/prototype/forEach/deleted-values-during-foreach.js new file mode 100644 index 0000000000000000000000000000000000000000..ebbc30adddbb6c4f92c3fcbfe9a00b4bbaeddb6d --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/deleted-values-during-foreach.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + SendableMap state with deleted values during forEach. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + 6. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 7. Repeat for each Record {[[key]], [[value]]} e that is an element of + entries, in original key insertion order + a. If e.[[key]] is not empty, then + i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»). + ii. ReturnIfAbrupt(funcResult). + ... +---*/ + +var map = new SendableMap(); +map.set('foo', 0); +map.set('bar', 1); + +var count = 0; +var results = []; + +map.forEach(function(value, key) { + if (count === 0) { + map.delete('bar'); + } + results.push({ + value: value, + key: key + }); + count++; +}); + +assert.sameValue(results.length, 1); +assert.sameValue(results[0].key, 'foo'); +assert.sameValue(results[0].value, 0); diff --git a/test/sendable/builtins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-set.js b/test/sendable/builtins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000000000000000000000000000000000..5860757a16921bf9924ee5631bcb1b75f5f59ef6 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + Throws a TypeError if `this` is a Set object. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.forEach.call(new Set(), function() {}); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.forEach.call(new Set(), function() {}); +}); diff --git a/test/sendable/builtins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-weakmap.js b/test/sendable/builtins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000000000000000000000000000000000..bd29975dec719ebed8743bdcad7fa1ba379f8eed --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.forEach.call(new WeakMap(), function() {}); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.forEach.call(new WeakMap(), function() {}); +}); diff --git a/test/sendable/builtins/Map/prototype/forEach/does-not-have-mapdata-internal-slot.js b/test/sendable/builtins/Map/prototype/forEach/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..512307fd099b8db5b6f138401413e59b790dc39e --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + Throws a TypeError if `this` object does not have a [[SendableMapData]] internal slot. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +var m = new SendableMap(); + +assert.throws(TypeError, function() { + SendableMap.prototype.forEach.call([], function() {}); +}); + +assert.throws(TypeError, function() { + m.forEach.call([], function() {}); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.forEach.call({}, function() {}); +}); + +assert.throws(TypeError, function() { + m.forEach.call({}, function() {}); +}); diff --git a/test/sendable/builtins/Map/prototype/forEach/first-argument-is-not-callable.js b/test/sendable/builtins/Map/prototype/forEach/first-argument-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..3c2a3d07b38ce73fec442baaeda1ed827dbf84ed --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/first-argument-is-not-callable.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + Throws a TypeError if first argument is not callable. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +var map = new SendableMap(); + +assert.throws(TypeError, function() { + map.forEach({}); +}); + +assert.throws(TypeError, function() { + map.forEach([]); +}); + +assert.throws(TypeError, function() { + map.forEach(1); +}); + +assert.throws(TypeError, function() { + map.forEach(''); +}); + +assert.throws(TypeError, function() { + map.forEach(null); +}); + +assert.throws(TypeError, function() { + map.forEach(undefined); +}); + +assert.throws(TypeError, function() { + map.forEach(Symbol()); +}); diff --git a/test/sendable/builtins/Map/prototype/forEach/forEach.js b/test/sendable/builtins/Map/prototype/forEach/forEach.js new file mode 100644 index 0000000000000000000000000000000000000000..c7490340294989ef5ab7894ee2ab8bcbe596d7cb --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/forEach.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + Property type and descriptor. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableMap.prototype.forEach, + 'function', + '`typeof SendableMap.prototype.forEach` is `function`' +); + +verifyProperty(SendableMap.prototype, 'forEach', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/prototype/forEach/iterates-in-key-insertion-order.js b/test/sendable/builtins/Map/prototype/forEach/iterates-in-key-insertion-order.js new file mode 100644 index 0000000000000000000000000000000000000000..e8b089677f0c5b4d928c64dd8b5abf4e2c081c8f --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/iterates-in-key-insertion-order.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + Repeats for each non-empty record, in original key insertion order. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + 6. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 7. Repeat for each Record {[[key]], [[value]]} e that is an element of + entries, in original key insertion order + a. If e.[[key]] is not empty, then + i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»). + ... +---*/ + +var map = new SendableMap([ + ['foo', 'valid foo'], + ['bar', false], + ['baz', 'valid baz'] +]); +map.set(0, false); +map.set(1, false); +map.set(2, 'valid 2'); +map.delete(1); +map.delete('bar'); + +// Not setting a new key, just changing the value +map.set(0, 'valid 0'); + +var results = []; +var callback = function(value) { + results.push(value); +}; + +map.forEach(callback); + +assert.sameValue(results[0], 'valid foo'); +assert.sameValue(results[1], 'valid baz'); +assert.sameValue(results[2], 'valid 0'); +assert.sameValue(results[3], 'valid 2'); +assert.sameValue(results.length, 4); + +map.clear(); +results = []; + +map.forEach(callback); +assert.sameValue(results.length, 0); diff --git a/test/sendable/builtins/Map/prototype/forEach/iterates-values-added-after-foreach-begins.js b/test/sendable/builtins/Map/prototype/forEach/iterates-values-added-after-foreach-begins.js new file mode 100644 index 0000000000000000000000000000000000000000..34d52a8c6715145c1397f162f0205b16b0901a49 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/iterates-values-added-after-foreach-begins.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + New keys are visited if created during forEach execution. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + 6. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 7. Repeat for each Record {[[key]], [[value]]} e that is an element of + entries, in original key insertion order + a. If e.[[key]] is not empty, then + i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»). + ii. ReturnIfAbrupt(funcResult). + ... +---*/ + +var map = new SendableMap(); +map.set('foo', 0); +map.set('bar', 1); + +var count = 0; +var results = []; + +map.forEach(function(value, key) { + if (count === 0) { + map.set('baz', 2); + } + results.push({ + value: value, + key: key + }); + count++; +}); + +assert.sameValue(count, 3); +assert.sameValue(map.size, 3); + +assert.sameValue(results[0].key, 'foo'); +assert.sameValue(results[0].value, 0); + +assert.sameValue(results[1].key, 'bar'); +assert.sameValue(results[1].value, 1); + +assert.sameValue(results[2].key, 'baz'); +assert.sameValue(results[2].value, 2); diff --git a/test/sendable/builtins/Map/prototype/forEach/iterates-values-deleted-then-readded.js b/test/sendable/builtins/Map/prototype/forEach/iterates-values-deleted-then-readded.js new file mode 100644 index 0000000000000000000000000000000000000000..0575317c86556966b1b1e1eeded89cc50cc14481 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/iterates-values-deleted-then-readded.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + New keys are visited if created during forEach execution. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + 6. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 7. Repeat for each Record {[[key]], [[value]]} e that is an element of + entries, in original key insertion order + a. If e.[[key]] is not empty, then + i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»). + ii. ReturnIfAbrupt(funcResult). + ... +---*/ + +var map = new SendableMap(); +map.set('foo', 0); +map.set('bar', 1); + +var count = 0; +var results = []; + +map.forEach(function(value, key) { + if (count === 0) { + map.delete('foo'); + map.set('foo', 'baz'); + } + results.push({ + value: value, + key: key + }); + count++; +}); + +assert.sameValue(count, 3); +assert.sameValue(map.size, 2); + +assert.sameValue(results[0].key, 'foo'); +assert.sameValue(results[0].value, 0); + +assert.sameValue(results[1].key, 'bar'); +assert.sameValue(results[1].value, 1); + +assert.sameValue(results[2].key, 'foo'); +assert.sameValue(results[2].value, 'baz'); diff --git a/test/sendable/builtins/Map/prototype/forEach/length.js b/test/sendable/builtins/Map/prototype/forEach/length.js new file mode 100644 index 0000000000000000000000000000000000000000..9b419dafbf8386b86b2d1497302bf20f1ad1857f --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/length.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + SendableMap.prototype.forEach.length value and descriptor. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.forEach, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/forEach/name.js b/test/sendable/builtins/Map/prototype/forEach/name.js new file mode 100644 index 0000000000000000000000000000000000000000..a2872e5a4091628825a546294b980ca9be342fb8 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/name.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + SendableMap.prototype.forEach.name value and descriptor. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.forEach, "name", { + value: "forEach", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/forEach/not-a-constructor.js b/test/sendable/builtins/Map/prototype/forEach/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..cc4437c10e3e538d0eb75d5ff296a96ac962d2db --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableMap.prototype.forEach does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableMap, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableMap.prototype.forEach), + false, + 'isConstructor(SendableMap.prototype.forEach) must return false' +); + +assert.throws(TypeError, () => { + let m = new SendableMap(); new m.forEach(); +}); + diff --git a/test/sendable/builtins/Map/prototype/forEach/return-undefined.js b/test/sendable/builtins/Map/prototype/forEach/return-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..64d78d5fa9e349bbd2655977b5e4443d9d8e07ba --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/return-undefined.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + Returns undefined. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 8. Return undefined. +---*/ + +var map = new SendableMap(); + +var result = map.forEach(function() { + return true; +}); + +assert.sameValue(result, undefined, 'Empty map#forEach returns undefined'); + +map.set(1, 1); +result = map.forEach(function() { + return true; +}); + +assert.sameValue(result, undefined, 'map#forEach returns undefined'); diff --git a/test/sendable/builtins/Map/prototype/forEach/second-parameter-as-callback-context.js b/test/sendable/builtins/Map/prototype/forEach/second-parameter-as-callback-context.js new file mode 100644 index 0000000000000000000000000000000000000000..fa28fa548eebad58c6f99ff6a71ee22169a2f82f --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/second-parameter-as-callback-context.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + If a thisArg parameter is provided, it will be used as the this value for each + invocation of callbackfn. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + 6. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 7. Repeat for each Record {[[key]], [[value]]} e that is an element of + entries, in original key insertion order + a. If e.[[key]] is not empty, then + i. Let funcResult be Call(callbackfn, T, «e.[[value]], e.[[key]], M»). + ... +---*/ + +var expectedThis = {}; +var _this = []; + +var map = new SendableMap(); +map.set(0, 0); +map.set(1, 1); +map.set(2, 2); + +var callback = function() { + _this.push(this); +}; + +map.forEach(callback, expectedThis); + +assert.sameValue(_this[0], expectedThis); +assert.sameValue(_this[1], expectedThis); +assert.sameValue(_this[2], expectedThis); diff --git a/test/sendable/builtins/Map/prototype/forEach/this-not-object-throw.js b/test/sendable/builtins/Map/prototype/forEach/this-not-object-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..e4b8c26bfcc6272780d1699b08128088436ec7b6 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/forEach/this-not-object-throw.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.forEach +description: > + Throws a TypeError if `this` is not an Object. +info: | + SendableMap.prototype.forEach ( callbackfn [ , thisArg ] ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.forEach.call(false, function() {}); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.forEach.call(1, function() {}); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.forEach.call('', function() {}); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.forEach.call(undefined, function() {}); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.forEach.call(null, function() {}); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.forEach.call(Symbol(), function() {}); +}); + +assert.throws(TypeError, function() { + var map = new SendableMap(); + map.forEach.call(false, function() {}); +}); diff --git a/test/sendable/builtins/Map/prototype/get/does-not-have-mapdata-internal-slot-set.js b/test/sendable/builtins/Map/prototype/get/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000000000000000000000000000000000..0e99f0048ac90128d9781105be3f6d86a2949d83 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/get/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.get +description: > + Throws a TypeError if `this` is a Set object. +info: | + SendableMap.prototype.get ( key ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.get.call(new Set(), 1); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.get.call(new Set(), 1); +}); diff --git a/test/sendable/builtins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.js b/test/sendable/builtins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000000000000000000000000000000000..deb286c182f6d477520b876b70e6048bc42d568f --- /dev/null +++ b/test/sendable/builtins/Map/prototype/get/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.get +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + SendableMap.prototype.get ( key ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.get.call(new WeakMap(), 1); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.get.call(new WeakMap(), 1); +}); diff --git a/test/sendable/builtins/Map/prototype/get/does-not-have-mapdata-internal-slot.js b/test/sendable/builtins/Map/prototype/get/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..2c6198e766714385a4c209900ff6c02bc394f4ea --- /dev/null +++ b/test/sendable/builtins/Map/prototype/get/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.get +description: > + Throws a TypeError if `this` object does not have a [[SendableMapData]] internal slot. +info: | + SendableMap.prototype.get ( key ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +var m = new SendableMap(); + +assert.throws(TypeError, function() { + SendableMap.prototype.get.call([], 1); +}); + +assert.throws(TypeError, function() { + m.get.call([], 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.get.call({}, 1); +}); + +assert.throws(TypeError, function() { + m.get.call({}, 1); +}); diff --git a/test/sendable/builtins/Map/prototype/get/get.js b/test/sendable/builtins/Map/prototype/get/get.js new file mode 100644 index 0000000000000000000000000000000000000000..f561273f63e966c06a584b1fd76d559d2d45c8e1 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/get/get.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.get +description: > + Property type and descriptor. +info: | + SendableMap.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableMap.prototype.get, + 'function', + '`typeof SendableMap.prototype.get` is `function`' +); + +verifyProperty(SendableMap.prototype, 'get', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/prototype/get/length.js b/test/sendable/builtins/Map/prototype/get/length.js new file mode 100644 index 0000000000000000000000000000000000000000..7ce377d5d078ec8f5f0168011fe1feba8cb00749 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/get/length.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.get +description: > + SendableMap.prototype.get.length value and descriptor. +info: | + SendableMap.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.get, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/get/name.js b/test/sendable/builtins/Map/prototype/get/name.js new file mode 100644 index 0000000000000000000000000000000000000000..0d4739d6eda662a56ddb0b835eac4fe6e40eb09d --- /dev/null +++ b/test/sendable/builtins/Map/prototype/get/name.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.get +description: > + SendableMap.prototype.get.name value and descriptor. +info: | + SendableMap.prototype.get ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.get, "name", { + value: "get", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/get/not-a-constructor.js b/test/sendable/builtins/Map/prototype/get/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..3d91289b0313a163b9e80479f615cee995f0600b --- /dev/null +++ b/test/sendable/builtins/Map/prototype/get/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableMap.prototype.get does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableMap, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableMap.prototype.get), false, 'isConstructor(SendableMap.prototype.get) must return false'); + +assert.throws(TypeError, () => { + let m = new SendableMap(); new m.get(); +}); + diff --git a/test/sendable/builtins/Map/prototype/get/returns-undefined.js b/test/sendable/builtins/Map/prototype/get/returns-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..9b0532e484a83e83ebb555bfee66e5411a1e7c8a --- /dev/null +++ b/test/sendable/builtins/Map/prototype/get/returns-undefined.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.get +description: > + Returns undefined when key is not on the map. +info: | + SendableMap.prototype.get ( key ) + + 4. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return p.[[value]]. + 6. Return undefined. + ... +---*/ + +var map = new SendableMap(); + +assert.sameValue( + map.get('item'), undefined, + 'returns undefined if key is not on the map' +); + +map.set('item', 1); +map.set('another_item', 2); +map.delete('item'); + +assert.sameValue( + map.get('item'), undefined, + 'returns undefined if key was deleted' +); + +map.set('item', 1); +map.clear(); + +assert.sameValue( + map.get('item'), undefined, + 'returns undefined after map is cleared' +); diff --git a/test/sendable/builtins/Map/prototype/get/returns-value-different-key-types.js b/test/sendable/builtins/Map/prototype/get/returns-value-different-key-types.js new file mode 100644 index 0000000000000000000000000000000000000000..fb3dc179701e704ac0227def7f24d6a6abba1ab8 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/get/returns-value-different-key-types.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.get +description: > + Returns the value from the specified key on different types. +info: | + SendableMap.prototype.get ( key ) + + 4. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return p.[[value]]. + ... +features: [Symbol] +---*/ + +var map = new SendableMap(); + +map.set('bar', 0); +assert.sameValue(map.get('bar'), 0); + +map.set(1, 42); +assert.sameValue(map.get(1), 42); + +map.set(NaN, 1); +assert.sameValue(map.get(NaN), 1); + +var item = {}; +map.set(item, 2); +assert.sameValue(map.get(item), 2); + +item = []; +map.set(item, 3); +assert.sameValue(map.get(item), 3); + +item = Symbol('item'); +map.set(item, 4); +assert.sameValue(map.get(item), 4); + +item = null; +map.set(item, 5); +assert.sameValue(map.get(item), 5); + +item = undefined; +map.set(item, 6); +assert.sameValue(map.get(item), 6); diff --git a/test/sendable/builtins/Map/prototype/get/returns-value-normalized-zero-key.js b/test/sendable/builtins/Map/prototype/get/returns-value-normalized-zero-key.js new file mode 100644 index 0000000000000000000000000000000000000000..7b040b05603ac364b18b2bc061f1d4b2003f7d9b --- /dev/null +++ b/test/sendable/builtins/Map/prototype/get/returns-value-normalized-zero-key.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.get +description: > + -0 and +0 are normalized to +0; +info: | + SendableMap.prototype.get ( key ) + + 4. Let entries be the List that is the value of M’s [[SendableMapData]] internal slot. + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return p.[[value]]. + ... +---*/ + +var map = new SendableMap(); + +map.set(+0, 42); +assert.sameValue(map.get(-0), 42); + +map = new SendableMap(); +map.set(-0, 43); +assert.sameValue(map.get(+0), 43); diff --git a/test/sendable/builtins/Map/prototype/get/this-not-object-throw.js b/test/sendable/builtins/Map/prototype/get/this-not-object-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..6a36c5f479418818529bf49e1e232f169d8d4eae --- /dev/null +++ b/test/sendable/builtins/Map/prototype/get/this-not-object-throw.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.get +description: > + Throws a TypeError if `this` is not an Object. +info: | + SendableMap.prototype.get ( key ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.get.call(false, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.get.call(1, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.get.call('', 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.get.call(undefined, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.get.call(null, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.get.call(Symbol(), 1); +}); + +assert.throws(TypeError, function() { + var map = new SendableMap(); + map.get.call(false, 1); +}); diff --git a/test/sendable/builtins/Map/prototype/has/does-not-have-mapdata-internal-slot-set.js b/test/sendable/builtins/Map/prototype/has/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000000000000000000000000000000000..39f682dcc2d9b605e7db460fa47663377333437f --- /dev/null +++ b/test/sendable/builtins/Map/prototype/has/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.has +description: > + Throws a TypeError if `this` is a Set object. +info: | + SendableMap.prototype.has ( key ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.has.call(new Set(), 1); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.has.call(new Set(), 1); +}); diff --git a/test/sendable/builtins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js b/test/sendable/builtins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000000000000000000000000000000000..0f44a465cdd21e8d1e8c17f574647c72d6f3dc43 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/has/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.has +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + SendableMap.prototype.has ( key ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.has.call(new WeakMap(), 1); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.has.call(new WeakMap(), 1); +}); diff --git a/test/sendable/builtins/Map/prototype/has/does-not-have-mapdata-internal-slot.js b/test/sendable/builtins/Map/prototype/has/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..eae79bad1fcfd4dd03f364e57218a9aaba3ed6f5 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/has/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.has +description: > + Throws a TypeError if `this` object does not have a [[SendableMapData]] internal slot. +info: | + SendableMap.prototype.has ( key ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +var m = new SendableMap(); + +assert.throws(TypeError, function() { + SendableMap.prototype.has.call([], 1); +}); + +assert.throws(TypeError, function() { + m.has.call([], 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.has.call({}, 1); +}); + +assert.throws(TypeError, function() { + m.has.call({}, 1); +}); diff --git a/test/sendable/builtins/Map/prototype/has/has.js b/test/sendable/builtins/Map/prototype/has/has.js new file mode 100644 index 0000000000000000000000000000000000000000..3fe6f98c711f375df7b937f02593014386683718 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/has/has.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.has +description: > + Property type and descriptor. +info: | + SendableMap.prototype.has ( key ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableMap.prototype.has, + 'function', + '`typeof SendableMap.prototype.has` is `function`' +); + +verifyProperty(SendableMap.prototype, 'has', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/prototype/has/length.js b/test/sendable/builtins/Map/prototype/has/length.js new file mode 100644 index 0000000000000000000000000000000000000000..e73df7cf0b7caf995575f00f16ad13726044359d --- /dev/null +++ b/test/sendable/builtins/Map/prototype/has/length.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.has +description: > + SendableMap.prototype.has.length value and descriptor. +info: | + SendableMap.prototype.has ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.has, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/has/name.js b/test/sendable/builtins/Map/prototype/has/name.js new file mode 100644 index 0000000000000000000000000000000000000000..42a50a24716b7d73fca4799dcd8ac38ba4407bc2 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/has/name.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.has +description: > + SendableMap.prototype.has.name value and descriptor. +info: | + SendableMap.prototype.has ( key ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.has, "name", { + value: "has", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/has/normalizes-zero-key.js b/test/sendable/builtins/Map/prototype/has/normalizes-zero-key.js new file mode 100644 index 0000000000000000000000000000000000000000..27049df0c69c2401ea46f86473b60a5a99656b52 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/has/normalizes-zero-key.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.has +description: > + -0 and +0 are normalized to +0; +info: | + SendableMap.prototype.has ( key ) + + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return true. + ... +---*/ + +var map = new SendableMap(); + +assert.sameValue(map.has(-0), false); +assert.sameValue(map.has(+0), false); + +map.set(-0, 42); +assert.sameValue(map.has(-0), true); +assert.sameValue(map.has(+0), true); + +map.clear(); + +map.set(+0, 42); +assert.sameValue(map.has(-0), true); +assert.sameValue(map.has(+0), true); diff --git a/test/sendable/builtins/Map/prototype/has/not-a-constructor.js b/test/sendable/builtins/Map/prototype/has/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..fda1bdb95fd6f861dece3776ac31dd2d8c9f5be1 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/has/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableMap.prototype.has does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableMap, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableMap.prototype.has), false, 'isConstructor(SendableMap.prototype.has) must return false'); + +assert.throws(TypeError, () => { + let m = new SendableMap(); new m.has(); +}); + diff --git a/test/sendable/builtins/Map/prototype/has/return-false-different-key-types.js b/test/sendable/builtins/Map/prototype/has/return-false-different-key-types.js new file mode 100644 index 0000000000000000000000000000000000000000..ab18d649a4a1a5370da917d577617bbe5bf412e4 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/has/return-false-different-key-types.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.has +description: > + Returns true for existing keys, using different key types. +info: | + SendableMap.prototype.has ( key ) + + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + i. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return true. + ... +features: [Symbol] +---*/ + +var map = new SendableMap(); + +assert.sameValue(map.has('str'), false); +assert.sameValue(map.has(1), false); +assert.sameValue(map.has(NaN), false); +assert.sameValue(map.has(true), false); +assert.sameValue(map.has(false), false); +assert.sameValue(map.has({}), false); +assert.sameValue(map.has([]), false); +assert.sameValue(map.has(Symbol()), false); +assert.sameValue(map.has(null), false); +assert.sameValue(map.has(undefined), false); diff --git a/test/sendable/builtins/Map/prototype/has/return-true-different-key-types.js b/test/sendable/builtins/Map/prototype/has/return-true-different-key-types.js new file mode 100644 index 0000000000000000000000000000000000000000..3ac9e7c6550b0219f96ae2500d11bb3313acd887 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/has/return-true-different-key-types.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.has +description: > + Returns true for existing keys, using different key types. +info: | + SendableMap.prototype.has ( key ) + + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + i. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, + return true. + ... +features: [Symbol] +---*/ + +var map = new SendableMap(); + +var obj = {}; +var arr = []; +var symb = Symbol(); + +map.set('str', undefined); +map.set(1, undefined); +map.set(NaN, undefined); +map.set(true, undefined); +map.set(false, undefined); +map.set(obj, undefined); +map.set(arr, undefined); +map.set(symb, undefined); +map.set(null, undefined); +map.set(undefined, undefined); + +assert.sameValue(map.has('str'), true); +assert.sameValue(map.has(1), true); +assert.sameValue(map.has(NaN), true); +assert.sameValue(map.has(true), true); +assert.sameValue(map.has(false), true); +assert.sameValue(map.has(obj), true); +assert.sameValue(map.has(arr), true); +assert.sameValue(map.has(symb), true); +assert.sameValue(map.has(null), true); +assert.sameValue(map.has(undefined), true); diff --git a/test/sendable/builtins/Map/prototype/has/this-not-object-throw.js b/test/sendable/builtins/Map/prototype/has/this-not-object-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..8c1898b75f0b93e197da720471c4bdc86604b076 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/has/this-not-object-throw.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.has +description: > + Throws a TypeError if `this` is not an Object. +info: | + SendableMap.prototype.has ( key ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.has.call(false, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.has.call(1, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.has.call('', 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.has.call(undefined, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.has.call(null, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.has.call(Symbol(), 1); +}); + +assert.throws(TypeError, function() { + var map = new SendableMap(); + map.has.call(false, 1); +}); diff --git a/test/sendable/builtins/Map/prototype/keys/does-not-have-mapdata-internal-slot-set.js b/test/sendable/builtins/Map/prototype/keys/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000000000000000000000000000000000..783e0016ae007930c9891653c8a682e0841ebf30 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/keys/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.keys +description: > + Throws a TypeError if `this` is a Set object. +info: | + SendableMap.prototype.keys () + + 1. Let M be the this value. + 2. Return CreateSendableMapIterator(M, "key"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 2. If map does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.keys.call(new Set()); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.keys.call(new Set()); +}); diff --git a/test/sendable/builtins/Map/prototype/keys/does-not-have-mapdata-internal-slot-weakmap.js b/test/sendable/builtins/Map/prototype/keys/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000000000000000000000000000000000..fbde6bf7d786f417d08a0314d30e2c4d62331ac0 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/keys/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.keys +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + SendableMap.prototype.keys () + + 1. Let M be the this value. + 2. Return CreateSendableMapIterator(M, "key"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 2. If map does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.keys.call(new WeakMap()); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.keys.call(new WeakMap()); +}); diff --git a/test/sendable/builtins/Map/prototype/keys/does-not-have-mapdata-internal-slot.js b/test/sendable/builtins/Map/prototype/keys/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..dbb500104719a911540da4aae9edfb027512f7e3 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/keys/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.keys +description: > + Throws a TypeError if `this` object does not have a [[SendableMapData]] internal slot. +info: | + SendableMap.prototype.keys () + + 1. Let M be the this value. + 2. Return CreateSendableMapIterator(M, "key"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 2. If map does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... + +---*/ + +var m = new SendableMap(); + +assert.throws(TypeError, function() { + SendableMap.prototype.keys.call([]); +}); + +assert.throws(TypeError, function() { + m.keys.call([]); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.keys.call({}); +}); + +assert.throws(TypeError, function() { + m.keys.call({}); +}); diff --git a/test/sendable/builtins/Map/prototype/keys/keys.js b/test/sendable/builtins/Map/prototype/keys/keys.js new file mode 100644 index 0000000000000000000000000000000000000000..c9bdc36447c9e13974a1da37002ad36221ebb24e --- /dev/null +++ b/test/sendable/builtins/Map/prototype/keys/keys.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.keys +description: > + Property type and descriptor. +info: | + SendableMap.prototype.keys () + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableMap.prototype.keys, + 'function', + '`typeof SendableMap.prototype.keys` is `function`' +); + +verifyProperty(SendableMap.prototype, 'keys', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/prototype/keys/length.js b/test/sendable/builtins/Map/prototype/keys/length.js new file mode 100644 index 0000000000000000000000000000000000000000..24749029c9f6fc08be1f7f4db5b824400dc80b25 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/keys/length.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.keys +description: > + SendableMap.prototype.keys.length value and descriptor. +info: | + SendableMap.prototype.keys () + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.keys, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/keys/name.js b/test/sendable/builtins/Map/prototype/keys/name.js new file mode 100644 index 0000000000000000000000000000000000000000..26a1bb618948a6dc62c844b387374a01986ef07b --- /dev/null +++ b/test/sendable/builtins/Map/prototype/keys/name.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.keys +description: > + SendableMap.prototype.keys.name value and descriptor. +info: | + SendableMap.prototype.keys () + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.keys, "name", { + value: "keys", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/keys/not-a-constructor.js b/test/sendable/builtins/Map/prototype/keys/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..bd97eb98248d829ae97115b85a686e792043b796 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/keys/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableMap.prototype.keys does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableMap, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableMap.prototype.keys), false, 'isConstructor(SendableMap.prototype.keys) must return false'); + +assert.throws(TypeError, () => { + let m = new SendableMap(); new m.keys(); +}); + diff --git a/test/sendable/builtins/Map/prototype/keys/returns-iterator-empty.js b/test/sendable/builtins/Map/prototype/keys/returns-iterator-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..2d60bdfe656fc9189beacb542479e283dbfb79af --- /dev/null +++ b/test/sendable/builtins/Map/prototype/keys/returns-iterator-empty.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.keys +description: > + Returns an iterator on an empty SendableMap object. +info: | + SendableMap.prototype.keys () + + ... + 2. Return CreateSendableMapIterator(M, "key"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var map = new SendableMap(); +var iterator = map.keys(); +var result = iterator.next(); + +assert.sameValue( + result.value, undefined, + 'The value of `result.value` is `undefined`' +); +assert.sameValue(result.done, true, 'The value of `result.done` is `true`'); diff --git a/test/sendable/builtins/Map/prototype/keys/returns-iterator.js b/test/sendable/builtins/Map/prototype/keys/returns-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..d8b3b9fde61b258f6e0265e8fa2f2447219aadc8 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/keys/returns-iterator.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.keys +description: > + Returns an iterator. +info: | + SendableMap.prototype.keys ( ) + + ... + 2. Return CreateSendableMapIterator(M, "key"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var obj = {}; +var map = new SendableMap(); +map.set('foo', 1); +map.set(obj, 2); +map.set(map, 3); + +var iterator = map.keys(); +var result; + +result = iterator.next(); +assert.sameValue(result.value, 'foo', 'First result `value` ("key")'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, obj, 'Second result `value` ("key")'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, map, 'Third result `value` ("key")'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); + +result = iterator.next(); +assert.sameValue( + result.value, undefined, 'Exhausted result `value` (repeated request)' +); +assert.sameValue( + result.done, true, 'Exhausted result `done` flag (repeated request)' +); diff --git a/test/sendable/builtins/Map/prototype/keys/this-not-object-throw.js b/test/sendable/builtins/Map/prototype/keys/this-not-object-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..62668bd895b93f1f4b43b3923d361e5f4904085b --- /dev/null +++ b/test/sendable/builtins/Map/prototype/keys/this-not-object-throw.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.keys +description: > + Throws a TypeError if `this` is not an Object. +info: | + SendableMap.prototype.keys () + + ... + 2. Return CreateSendableMapIterator(M, "key"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + 1. If Type(map) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.keys.call(false); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.keys.call(1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.keys.call(''); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.keys.call(undefined); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.keys.call(null); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.keys.call(Symbol()); +}); + +assert.throws(TypeError, function() { + var map = new SendableMap(); + map.keys.call(false); +}); diff --git a/test/sendable/builtins/Map/prototype/set/append-new-values-normalizes-zero-key.js b/test/sendable/builtins/Map/prototype/set/append-new-values-normalizes-zero-key.js new file mode 100644 index 0000000000000000000000000000000000000000..6c3729b3787f516c2487d2fa89b0cdfd0d9e95e9 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/append-new-values-normalizes-zero-key.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + Appends new value in the map normalizing +0 and -0. +info: | + SendableMap.prototype.set ( key , value ) + + ... + 6. If key is −0, let key be +0. + 7. Let p be the Record {[[key]]: key, [[value]]: value}. + 8. Append p as the last element of entries. + 9. Return M. + ... +---*/ + +var map = new SendableMap(); +map.set(-0, 42); + +assert.sameValue(map.get(0), 42); + +map = new SendableMap(); +map.set(+0, 43); +assert.sameValue(map.get(0), 43); diff --git a/test/sendable/builtins/Map/prototype/set/append-new-values-return-map.js b/test/sendable/builtins/Map/prototype/set/append-new-values-return-map.js new file mode 100644 index 0000000000000000000000000000000000000000..205147862e83d15ec22c9571ff07b2c23256c516 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/append-new-values-return-map.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + SendableMap.prototype.set returns the given `this` object. +info: | + SendableMap.prototype.set ( key , value ) + + ... + 6. If key is −0, let key be +0. + 7. Let p be the Record {[[key]]: key, [[value]]: value}. + 8. Append p as the last element of entries. + 9. Return M. + ... +---*/ + +var map = new SendableMap(); +var result = map.set(1, 1); + +assert.sameValue(result, map); + +result = map.set(1,1).set(2,2).set(3,3); + +assert.sameValue(result, map, 'SendableMap.prototype.set is chainable'); + +var map2 = new SendableMap(); +result = map2.set.call(map, 4, 4); + +assert.sameValue(result, map); diff --git a/test/sendable/builtins/Map/prototype/set/append-new-values.js b/test/sendable/builtins/Map/prototype/set/append-new-values.js new file mode 100644 index 0000000000000000000000000000000000000000..36b6531163aab09fa5a8809ac036c1b10604b030 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/append-new-values.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + Append a new value as the last element of entries. +info: | + SendableMap.prototype.set ( key , value ) + + ... + 6. If key is −0, let key be +0. + 7. Let p be the Record {[[key]]: key, [[value]]: value}. + 8. Append p as the last element of entries. + 9. Return M. + ... +features: [Symbol] +---*/ + +var s = Symbol(2); +var map = new SendableMap([[4, 4], ['foo3', 3], [s, 2]]); + +map.set(null, 42); +map.set(1, 'valid'); + +assert.sameValue(map.size, 5); +assert.sameValue(map.get(1), 'valid'); + +var results = []; + +map.forEach(function(value, key) { + results.push({ + value: value, + key: key + }); +}); + +var result = results.pop(); +assert.sameValue(result.value, 'valid'); +assert.sameValue(result.key, 1); + +result = results.pop(); +assert.sameValue(result.value, 42); +assert.sameValue(result.key, null); + +result = results.pop(); +assert.sameValue(result.value, 2); +assert.sameValue(result.key, s); diff --git a/test/sendable/builtins/Map/prototype/set/does-not-have-mapdata-internal-slot-set.js b/test/sendable/builtins/Map/prototype/set/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000000000000000000000000000000000..0d552e5d79c1acb8a5a9b6c5bc4ec4bb9179928d --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + Throws a TypeError if `this` is a Set object. +info: | + SendableMap.prototype.set ( key , value ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.set.call(new Set(), 1, 1); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.set.call(new Set(), 1, 1); +}); diff --git a/test/sendable/builtins/Map/prototype/set/does-not-have-mapdata-internal-slot-weakmap.js b/test/sendable/builtins/Map/prototype/set/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000000000000000000000000000000000..0850f6ef7f3070bfbafdff975d6cf162288484e4 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + SendableMap.prototype.set ( key , value ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.set.call(new WeakMap(), 1, 1); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.set.call(new WeakMap(), 1, 1); +}); diff --git a/test/sendable/builtins/Map/prototype/set/does-not-have-mapdata-internal-slot.js b/test/sendable/builtins/Map/prototype/set/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..1f459791cf14d677a452d67580eca33b03b3ef29 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + Throws a TypeError if `this` object does not have a [[SendableMapData]] internal slot. +info: | + SendableMap.prototype.set ( key , value ) + + ... + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +var m = new SendableMap(); + +assert.throws(TypeError, function() { + SendableMap.prototype.set.call([], 1, 1); +}); + +assert.throws(TypeError, function() { + m.set.call([], 1, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.set.call({}, 1, 1); +}); + +assert.throws(TypeError, function() { + m.set.call({}, 1, 1); +}); diff --git a/test/sendable/builtins/Map/prototype/set/length.js b/test/sendable/builtins/Map/prototype/set/length.js new file mode 100644 index 0000000000000000000000000000000000000000..26c85d5c9d927cab51d9565e649bb3c37fe90324 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/length.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + SendableMap.prototype.set.length value and descriptor. +info: | + SendableMap.prototype.set ( key , value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.set, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/set/name.js b/test/sendable/builtins/Map/prototype/set/name.js new file mode 100644 index 0000000000000000000000000000000000000000..15f44965f1ccdc44cd923ea2daadbc2564f67d34 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/name.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + SendableMap.prototype.set.name value and descriptor. +info: | + SendableMap.prototype.set ( key , value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.set, "name", { + value: "set", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/set/not-a-constructor.js b/test/sendable/builtins/Map/prototype/set/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..bbf5c4b383eeabb2f2eae76068b1541ddf27e52b --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableMap.prototype.set does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableMap, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableMap.prototype.set), false, 'isConstructor(SendableMap.prototype.set) must return false'); + +assert.throws(TypeError, () => { + let m = new SendableMap(); new m.set(); +}); + diff --git a/test/sendable/builtins/Map/prototype/set/replaces-a-value-normalizes-zero-key.js b/test/sendable/builtins/Map/prototype/set/replaces-a-value-normalizes-zero-key.js new file mode 100644 index 0000000000000000000000000000000000000000..4ebf32d5ef88e1d5493356c0da99aff91ee68650 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/replaces-a-value-normalizes-zero-key.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + Replaces a value in the map normalizing +0 and -0. +info: | + SendableMap.prototype.set ( key , value ) + + ... + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + i. Set p.[[value]] to value. + ii. Return M. + ... +---*/ + +var map = new SendableMap([[+0, 1]]); + +map.set(-0, 42); +assert.sameValue(map.get(+0), 42, 'zero key is normalized in SameValueZero'); + +map = new SendableMap([[-0, 1]]); +map.set(+0, 42); +assert.sameValue(map.get(-0), 42, 'zero key is normalized in SameValueZero'); diff --git a/test/sendable/builtins/Map/prototype/set/replaces-a-value-returns-map.js b/test/sendable/builtins/Map/prototype/set/replaces-a-value-returns-map.js new file mode 100644 index 0000000000000000000000000000000000000000..4f478bbefa88a986009610e50fd0c7fc9ff5f2b0 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/replaces-a-value-returns-map.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + SendableMap.prototype.set returns the given `this` map object. +info: | + SendableMap.prototype.set ( key , value ) + + 1. Let M be the this value. + ... + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + i. Set p.[[value]] to value. + ii. Return M. + ... +---*/ + +var map = new SendableMap([['item', 0]]); +var map2 = new SendableMap(); + +var x = map.set('item', 42); +assert.sameValue(x, map); + +x = SendableMap.prototype.set.call(map, 'item', 0); +assert.sameValue(x, map); + +x = map2.set.call(map, 'item', 0); +assert.sameValue(x, map, 'SendableMap#set returns the map `this` value'); diff --git a/test/sendable/builtins/Map/prototype/set/replaces-a-value.js b/test/sendable/builtins/Map/prototype/set/replaces-a-value.js new file mode 100644 index 0000000000000000000000000000000000000000..e4bde7fc47223e34b613a46862de9237bd7d2d98 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/replaces-a-value.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + Replaces a value in the map. +info: | + SendableMap.prototype.set ( key , value ) + + ... + 5. Repeat for each Record {[[key]], [[value]]} p that is an element of + entries, + a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then + i. Set p.[[value]] to value. + ii. Return M. + ... +---*/ + +var m = new SendableMap([['item', 1]]); + +m.set('item', 42); +assert.sameValue(m.get('item'), 42); +assert.sameValue(m.size, 1); diff --git a/test/sendable/builtins/Map/prototype/set/set.js b/test/sendable/builtins/Map/prototype/set/set.js new file mode 100644 index 0000000000000000000000000000000000000000..b709714aa4645a2eafa2cced33453faae477b930 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/set.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + Property type and descriptor. +info: | + SendableMap.prototype.set ( key , value ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableMap.prototype.set, + 'function', + '`typeof SendableMap.prototype.set` is `function`' +); + +verifyProperty(SendableMap.prototype, 'set', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/prototype/set/this-not-object-throw.js b/test/sendable/builtins/Map/prototype/set/this-not-object-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..7f7d698b846770a893508c4daa095f9ea395a420 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/set/this-not-object-throw.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: > + Throws a TypeError if `this` is not an Object. +info: | + SendableMap.prototype.set ( key , value ) + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.set.call(false, 1, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.set.call(1, 1, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.set.call('', 1, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.set.call(undefined, 1, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.set.call(null, 1, 1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.set.call(Symbol(), 1, 1); +}); + +assert.throws(TypeError, function() { + var map = new SendableMap(); + map.set.call(false, 1, 1); +}); diff --git a/test/sendable/builtins/Map/prototype/size/does-not-have-mapdata-internal-slot-set.js b/test/sendable/builtins/Map/prototype/size/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000000000000000000000000000000000..67867be1c8ac384fb65eb5c82b1d5835f0e36642 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/size/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map.prototype.size +description: > + Throws a TypeError if `this` is a Set object. +info: | + ... + If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableMap.prototype, 'size'); + +var map = new SendableMap(); + +// Does not throw +descriptor.get.call(map); + +assert.throws(TypeError, function() { + descriptor.get.call(new Set()); +}); diff --git a/test/sendable/builtins/Map/prototype/size/does-not-have-mapdata-internal-slot-weakmap.js b/test/sendable/builtins/Map/prototype/size/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000000000000000000000000000000000..dcb4f2be24ebc3e5d2865119c13013c3c08b5862 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/size/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map.prototype.size +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + get SendableMap.prototype.size + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableMap.prototype, 'size'); + +var map = new SendableMap(); + +// Does not throw +descriptor.get.call(map); + +assert.throws(TypeError, function() { + descriptor.get.call(new WeakMap()); +}); diff --git a/test/sendable/builtins/Map/prototype/size/does-not-have-mapdata-internal-slot.js b/test/sendable/builtins/Map/prototype/size/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..33bf47297994946c90e7a8e28f185a70a19c2590 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/size/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map.prototype.size +description: > + Throws a TypeError if `this` object does not have a [[SendableMapData]] internal slot. +info: | + get SendableMap.prototype.size + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableMap.prototype, 'size'); + +var map = new SendableMap(); + +// Does not throw +descriptor.get.call(map); + +assert.throws(TypeError, function() { + descriptor.get.call([]); +}); diff --git a/test/sendable/builtins/Map/prototype/size/length.js b/test/sendable/builtins/Map/prototype/size/length.js new file mode 100644 index 0000000000000000000000000000000000000000..2eb39918dea3f113979f0d59e01d926fc1f1c857 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/size/length.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map.prototype.size +description: > + SendableMap.prototype.size.length value and descriptor. +info: | + get SendableMap.prototype.size + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableMap.prototype, 'size'); + +verifyProperty(descriptor.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/size/name.js b/test/sendable/builtins/Map/prototype/size/name.js new file mode 100644 index 0000000000000000000000000000000000000000..997beab4b48ee48ee4f17c45fd22967d301415ac --- /dev/null +++ b/test/sendable/builtins/Map/prototype/size/name.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map.prototype.size +description: > + SendableMap.prototype.size.name value and descriptor. +info: | + get SendableMap.prototype.size + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableMap.prototype, 'size'); + +verifyProperty(descriptor.get, "name", { + value: "get size", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-before-after-set-clear.js b/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-before-after-set-clear.js new file mode 100644 index 0000000000000000000000000000000000000000..bdeecc09abe3cb8783db95c37d40bd39ad2877ac --- /dev/null +++ b/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-before-after-set-clear.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map.prototype.size +description: > + Returns count of present values before and after using `set` and `clear`. +info: | + get SendableMap.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +---*/ + +var map = new SendableMap(); + +assert.sameValue(map.size, 0, 'The value of `map.size` is `0`'); + +map.set(1, 1); +map.set(2, 2); +assert.sameValue( + map.size, 2, + 'The value of `map.size` is `2`' +); + +map.clear(); +assert.sameValue( + map.size, 0, + 'The value of `map.size` is `0`, after executing `map.clear()`' +); diff --git a/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-before-after-set-delete.js b/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-before-after-set-delete.js new file mode 100644 index 0000000000000000000000000000000000000000..48146f9be3094b164bbb45052918ecf4ce453421 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-before-after-set-delete.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map.prototype.size +description: > + Returns count of present values before and after using `set` and `delete`. +info: | + get SendableMap.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +---*/ + +var map = new SendableMap(); + +assert.sameValue(map.size, 0, 'The value of `map.size` is `0`'); + +map.set(1, 1); +assert.sameValue( + map.size, 1, + 'The value of `map.size` is `1`, after executing `map.set(1, 1)`' +); + +map.delete(1); +assert.sameValue( + map.size, 0, + 'The value of `map.size` is `0`, after executing `map.delete(1)`' +); diff --git a/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-by-insertion.js b/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-by-insertion.js new file mode 100644 index 0000000000000000000000000000000000000000..10de04d77183f6aa55ad605397cedc79745ec1b9 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-by-insertion.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map.prototype.size +description: > + Returns count of present values inserted with set. +info: | + get SendableMap.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +features: [Symbol] +---*/ + +var map = new SendableMap(); + +map.set(0, undefined); +map.set(undefined, undefined); +map.set(false, undefined); +map.set(NaN, undefined); +map.set(null, undefined); +map.set('', undefined); +map.set(Symbol(), undefined); + +assert.sameValue(map.size, 7, 'The value of `map.size` is `7`'); diff --git a/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-by-iterable.js b/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-by-iterable.js new file mode 100644 index 0000000000000000000000000000000000000000..2babd5c5c8da7801a46c6e3b6d673f103872c8c4 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/size/returns-count-of-present-values-by-iterable.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map.prototype.size +description: > + Returns count of present values inserted via iterable argument. +info: | + get SendableMap.prototype.size + + 5. Let count be 0. + 6. For each Record {[[key]], [[value]]} p that is an element of entries + a. If p.[[key]] is not empty, set count to count+1. +features: [Symbol] +---*/ + +var map = new SendableMap([ + [0, undefined], + [undefined, undefined], + [false, undefined], + [NaN, undefined], + [null, undefined], + ['', undefined], + [Symbol(), undefined], +]); + +assert.sameValue(map.size, 7, 'The value of `map.size` is `7`'); diff --git a/test/sendable/builtins/Map/prototype/size/size.js b/test/sendable/builtins/Map/prototype/size/size.js new file mode 100644 index 0000000000000000000000000000000000000000..87364b92895059945b25e86d09157997ae9613b5 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/size/size.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map.prototype.size +description: > + Property type and descriptor. +info: | + get SendableMap.prototype.size + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableMap.prototype, 'size'); + +assert.sameValue( + typeof descriptor.get, + 'function', + 'typeof descriptor.get is function' +); +assert.sameValue( + typeof descriptor.set, + 'undefined', + 'typeof descriptor.set is undefined' +); + +verifyNotEnumerable(SendableMap.prototype, 'size'); +verifyConfigurable(SendableMap.prototype, 'size'); diff --git a/test/sendable/builtins/Map/prototype/size/this-not-object-throw.js b/test/sendable/builtins/Map/prototype/size/this-not-object-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..4328211821a9784cbffc735b4d50a966404c3457 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/size/this-not-object-throw.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-map.prototype.size +description: > + Throws a TypeError if `this` is not an Object. +info: | + get SendableMap.prototype.size + + 1. Let M be the this value. + 2. If Type(M) is not Object, throw a TypeError exception. + 3. If M does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... + +features: [Symbol] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableMap.prototype, 'size'); + +assert.throws(TypeError, function() { + descriptor.get.call(1); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(false); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(1); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(''); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(undefined); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(null); +}); + +assert.throws(TypeError, function() { + descriptor.get.call(Symbol()); +}); diff --git a/test/sendable/builtins/Map/prototype/values/does-not-have-mapdata-internal-slot-set.js b/test/sendable/builtins/Map/prototype/values/does-not-have-mapdata-internal-slot-set.js new file mode 100644 index 0000000000000000000000000000000000000000..a9011bd191d500b8e49bbb7352eacd0f017ce2c4 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/values/does-not-have-mapdata-internal-slot-set.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.values +description: > + Throws a TypeError if `this` is a Set object. +info: | + SendableMap.prototype.values () + + 1. Let M be the this value. + 2. Return CreateSendableMapIterator(M, "value"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 2. If map does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [Set] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.values.call(new Set()); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.values.call(new Set()); +}); diff --git a/test/sendable/builtins/Map/prototype/values/does-not-have-mapdata-internal-slot-weakmap.js b/test/sendable/builtins/Map/prototype/values/does-not-have-mapdata-internal-slot-weakmap.js new file mode 100644 index 0000000000000000000000000000000000000000..58f030e93752d36436a7b00df64a20986bfd9036 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/values/does-not-have-mapdata-internal-slot-weakmap.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.values +description: > + Throws a TypeError if `this` is a WeakMap object. +info: | + SendableMap.prototype.values () + + 1. Let M be the this value. + 2. Return CreateSendableMapIterator(M, "value"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 2. If map does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... +features: [WeakMap] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.values.call(new WeakMap()); +}); + +assert.throws(TypeError, function() { + var m = new SendableMap(); + m.values.call(new WeakMap()); +}); diff --git a/test/sendable/builtins/Map/prototype/values/does-not-have-mapdata-internal-slot.js b/test/sendable/builtins/Map/prototype/values/does-not-have-mapdata-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..5c313fc3a12519267b2eb9f782701d57641ca2f8 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/values/does-not-have-mapdata-internal-slot.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.values +description: > + Throws a TypeError if `this` object does not have a [[SendableMapData]] internal slot. +info: | + SendableMap.prototype.values () + + 1. Let M be the this value. + 2. Return CreateSendableMapIterator(M, "value"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 2. If map does not have a [[SendableMapData]] internal slot, throw a TypeError + exception. + ... + +---*/ + +var m = new SendableMap(); + +assert.throws(TypeError, function() { + SendableMap.prototype.values.call([]); +}); + +assert.throws(TypeError, function() { + m.values.call([]); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.values.call({}); +}); + +assert.throws(TypeError, function() { + m.values.call({}); +}); diff --git a/test/sendable/builtins/Map/prototype/values/length.js b/test/sendable/builtins/Map/prototype/values/length.js new file mode 100644 index 0000000000000000000000000000000000000000..751ddcbfb134cfa2a6b9918dfdd251d0b3b547f8 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/values/length.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.values +description: > + SendableMap.prototype.values.length value and descriptor. +info: | + SendableMap.prototype.values () + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.values, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/values/name.js b/test/sendable/builtins/Map/prototype/values/name.js new file mode 100644 index 0000000000000000000000000000000000000000..a5b90a5f9b1a70529193565c5395a68c756ce1d5 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/values/name.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.values +description: > + SendableMap.prototype.values.name value and descriptor. +info: | + SendableMap.prototype.values () + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableMap.prototype.values, "name", { + value: "values", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Map/prototype/values/not-a-constructor.js b/test/sendable/builtins/Map/prototype/values/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..9a07dcacfec2a511aec9f73819ad3b39e43c5842 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/values/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableMap.prototype.values does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableMap, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableMap.prototype.values), false, 'isConstructor(SendableMap.prototype.values) must return false'); + +assert.throws(TypeError, () => { + let m = new SendableMap(); new m.values(); +}); + diff --git a/test/sendable/builtins/Map/prototype/values/returns-iterator-empty.js b/test/sendable/builtins/Map/prototype/values/returns-iterator-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..4c5fc2efa81c4e207cc5bd7881e8c60119565b3d --- /dev/null +++ b/test/sendable/builtins/Map/prototype/values/returns-iterator-empty.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.values +description: > + Returns an iterator on an empty SendableMap object. +info: | + SendableMap.prototype.values () + + ... + 2. Return CreateSendableMapIterator(M, "value"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var map = new SendableMap(); +var iterator = map.values(); +var result = iterator.next(); + +assert.sameValue( + result.value, undefined, + 'The value of `result.value` is `undefined`' +); +assert.sameValue(result.done, true, 'The value of `result.done` is `true`'); diff --git a/test/sendable/builtins/Map/prototype/values/returns-iterator.js b/test/sendable/builtins/Map/prototype/values/returns-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..f6797acc54dfaeb320f3ac0f099dbb5bc42c4453 --- /dev/null +++ b/test/sendable/builtins/Map/prototype/values/returns-iterator.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.values +description: > + Returns an iterator. +info: | + SendableMap.prototype.values ( ) + + ... + 2. Return CreateSendableMapIterator(M, "value"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + ... + 7. Return iterator. +---*/ + +var obj = {}; +var map = new SendableMap(); +map.set(1, 'foo'); +map.set(2, obj); +map.set(3, map); + +var iterator = map.values(); +var result; + +result = iterator.next(); +assert.sameValue(result.value, 'foo', 'First result `value` ("value")'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, obj, 'Second result `value` ("value")'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, map, 'Third result `value` ("value")'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); + +result = iterator.next(); +assert.sameValue( + result.value, undefined, 'Exhausted result `value` (repeated request)' +); +assert.sameValue( + result.done, true, 'Exhausted result `done` flag (repeated request)' +); diff --git a/test/sendable/builtins/Map/prototype/values/this-not-object-throw.js b/test/sendable/builtins/Map/prototype/values/this-not-object-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..114688ec056c95cb287c7cea108ac24a9dd3582f --- /dev/null +++ b/test/sendable/builtins/Map/prototype/values/this-not-object-throw.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.values +description: > + Throws a TypeError if `this` is not an Object. +info: | + SendableMap.prototype.values () + + ... + 2. Return CreateSendableMapIterator(M, "values"). + + 23.1.5.1 CreateSendableMapIterator Abstract Operation + + 1. If Type(map) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableMap.prototype.values.call(false); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.values.call(1); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.values.call(''); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.values.call(undefined); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.values.call(null); +}); + +assert.throws(TypeError, function() { + SendableMap.prototype.values.call(Symbol()); +}); + +assert.throws(TypeError, function() { + var map = new SendableMap(); + map.values.call(false); +}); diff --git a/test/sendable/builtins/Map/prototype/values/values.js b/test/sendable/builtins/Map/prototype/values/values.js new file mode 100644 index 0000000000000000000000000000000000000000..722459650eb2630bdac19b8fa9a4bfbf27dae91e --- /dev/null +++ b/test/sendable/builtins/Map/prototype/values/values.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.values +description: > + Property type and descriptor. +info: | + SendableMap.prototype.values () + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableMap.prototype.values, + 'function', + '`typeof SendableMap.prototype.values` is `function`' +); + +verifyProperty(SendableMap.prototype, 'values', { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Map/undefined-newtarget.js b/test/sendable/builtins/Map/undefined-newtarget.js new file mode 100644 index 0000000000000000000000000000000000000000..581cba4cc416a90d7850e78d1c25cf4bfb6bc9db --- /dev/null +++ b/test/sendable/builtins/Map/undefined-newtarget.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map-iterable +description: > + Throws a TypeError if SendableMap is called without a newTarget. +info: | + SendableMap ( [ iterable ] ) + + When the SendableMap function is called with optional argument the following steps + are taken: + + 1. If NewTarget is undefined, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableMap(); +}); + +assert.throws(TypeError, function() { + SendableMap([]); +}); diff --git a/test/sendable/builtins/Map/valid-keys.js b/test/sendable/builtins/Map/valid-keys.js new file mode 100644 index 0000000000000000000000000000000000000000..db513bc7726c5972241d0fc414b8137fde7afa23 --- /dev/null +++ b/test/sendable/builtins/Map/valid-keys.js @@ -0,0 +1,496 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-map.prototype.set +description: Observing the expected behavior of valid keys +info: | + SendableMap.prototype.set ( key , value ) + + ... + Let p be the Record {[[key]]: key, [[value]]: value}. + Append p as the last element of entries. + ... + +features: [BigInt, Symbol, TypedArray, WeakRef, exponentiation] +---*/ + + +const negativeZero = -0; +const positiveZero = +0; +const zero = 0; +const one = 1; +const twoRaisedToFiftyThreeMinusOne = 2 ** 53 - 1; +const int32Array = new Int32Array([zero, one]); +const uint32Array = new Uint32Array([zero, one]); +const n = 100000000000000000000000000000000000000000000000000000000000000000000000000000000001n; +const bigInt = BigInt('100000000000000000000000000000000000000000000000000000000000000000000000000000000001'); +const n1 = 1n; +const n53 = 9007199254740991n; +const fiftyThree = BigInt('9007199254740991'); +const bigInt64Array = new BigInt64Array([n1, n53]); +const bigUint64Array = new BigUint64Array([n1, n53]); +const symbol = Symbol(''); +const object = {}; +const array = []; +const string = ''; +const booleanTrue = true; +const booleanFalse = true; +const functionExprValue = function() {}; +const arrowFunctionValue = () => {}; +const classValue = class {}; +const map = new SendableMap(); +const set = new Set(); +const weakMap = new WeakMap(); +const weakRef = new WeakRef({}); +const weakSet = new WeakSet(); +const nullValue = null; +const undefinedValue = undefined; +let unassigned; + +{ + const m = new SendableMap([[negativeZero, negativeZero]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(negativeZero), true); + assert.sameValue(m.get(negativeZero), negativeZero); + m.delete(negativeZero); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(negativeZero), false); + m.set(negativeZero, negativeZero); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(negativeZero), true); + assert.sameValue(m.get(negativeZero), negativeZero); +}; + +{ + const m = new SendableMap([[positiveZero, positiveZero]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(positiveZero), true); + assert.sameValue(m.get(positiveZero), positiveZero); + m.delete(positiveZero); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(positiveZero), false); + m.set(positiveZero, positiveZero); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(positiveZero), true); + assert.sameValue(m.get(positiveZero), positiveZero); +}; + +{ + const m = new SendableMap([[zero, zero]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(zero), true); + assert.sameValue(m.get(zero), zero); + m.delete(zero); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(zero), false); + m.set(zero, zero); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(zero), true); + assert.sameValue(m.get(zero), zero); +}; + +{ + const m = new SendableMap([[one, one]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(one), true); + assert.sameValue(m.get(one), one); + m.delete(one); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(one), false); + m.set(one, one); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(one), true); + assert.sameValue(m.get(one), one); +}; + +{ + const m = new SendableMap([[twoRaisedToFiftyThreeMinusOne, twoRaisedToFiftyThreeMinusOne]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(twoRaisedToFiftyThreeMinusOne), true); + assert.sameValue(m.get(twoRaisedToFiftyThreeMinusOne), twoRaisedToFiftyThreeMinusOne); + m.delete(twoRaisedToFiftyThreeMinusOne); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(twoRaisedToFiftyThreeMinusOne), false); + m.set(twoRaisedToFiftyThreeMinusOne, twoRaisedToFiftyThreeMinusOne); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(twoRaisedToFiftyThreeMinusOne), true); + assert.sameValue(m.get(twoRaisedToFiftyThreeMinusOne), twoRaisedToFiftyThreeMinusOne); +}; + +{ + const m = new SendableMap([[int32Array, int32Array]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(int32Array), true); + assert.sameValue(m.get(int32Array), int32Array); + m.delete(int32Array); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(int32Array), false); + m.set(int32Array, int32Array); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(int32Array), true); + assert.sameValue(m.get(int32Array), int32Array); +}; + +{ + const m = new SendableMap([[uint32Array, uint32Array]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(uint32Array), true); + assert.sameValue(m.get(uint32Array), uint32Array); + m.delete(uint32Array); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(uint32Array), false); + m.set(uint32Array, uint32Array); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(uint32Array), true); + assert.sameValue(m.get(uint32Array), uint32Array); +}; + +{ + const m = new SendableMap([[n, n]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n), true); + assert.sameValue(m.get(n), n); + m.delete(n); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(n), false); + m.set(n, n); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n), true); + assert.sameValue(m.get(n), n); +}; + +{ + const m = new SendableMap([[bigInt, bigInt]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigInt), true); + assert.sameValue(m.get(bigInt), bigInt); + m.delete(bigInt); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(bigInt), false); + m.set(bigInt, bigInt); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigInt), true); + assert.sameValue(m.get(bigInt), bigInt); +}; + +{ + const m = new SendableMap([[n1, n1]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n1), true); + assert.sameValue(m.get(n1), n1); + m.delete(n1); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(n1), false); + m.set(n1, n1); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n1), true); + assert.sameValue(m.get(n1), n1); +}; + +{ + const m = new SendableMap([[n53, n53]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n53), true); + assert.sameValue(m.get(n53), n53); + m.delete(n53); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(n53), false); + m.set(n53, n53); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(n53), true); + assert.sameValue(m.get(n53), n53); +}; + +{ + const m = new SendableMap([[fiftyThree, fiftyThree]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(fiftyThree), true); + assert.sameValue(m.get(fiftyThree), fiftyThree); + m.delete(fiftyThree); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(fiftyThree), false); + m.set(fiftyThree, fiftyThree); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(fiftyThree), true); + assert.sameValue(m.get(fiftyThree), fiftyThree); +}; + +{ + const m = new SendableMap([[bigInt64Array, bigInt64Array]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigInt64Array), true); + assert.sameValue(m.get(bigInt64Array), bigInt64Array); + m.delete(bigInt64Array); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(bigInt64Array), false); + m.set(bigInt64Array, bigInt64Array); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigInt64Array), true); + assert.sameValue(m.get(bigInt64Array), bigInt64Array); +}; + +{ + const m = new SendableMap([[bigUint64Array, bigUint64Array]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigUint64Array), true); + assert.sameValue(m.get(bigUint64Array), bigUint64Array); + m.delete(bigUint64Array); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(bigUint64Array), false); + m.set(bigUint64Array, bigUint64Array); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(bigUint64Array), true); + assert.sameValue(m.get(bigUint64Array), bigUint64Array); +}; + +{ + const m = new SendableMap([[symbol, symbol]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(symbol), true); + assert.sameValue(m.get(symbol), symbol); + m.delete(symbol); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(symbol), false); + m.set(symbol, symbol); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(symbol), true); + assert.sameValue(m.get(symbol), symbol); +}; + +{ + const m = new SendableMap([[object, object]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(object), true); + assert.sameValue(m.get(object), object); + m.delete(object); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(object), false); + m.set(object, object); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(object), true); + assert.sameValue(m.get(object), object); +}; + +{ + const m = new SendableMap([[array, array]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(array), true); + assert.sameValue(m.get(array), array); + m.delete(array); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(array), false); + m.set(array, array); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(array), true); + assert.sameValue(m.get(array), array); +}; + +{ + const m = new SendableMap([[string, string]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(string), true); + assert.sameValue(m.get(string), string); + m.delete(string); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(string), false); + m.set(string, string); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(string), true); + assert.sameValue(m.get(string), string); +}; + +{ + const m = new SendableMap([[booleanTrue, booleanTrue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(booleanTrue), true); + assert.sameValue(m.get(booleanTrue), booleanTrue); + m.delete(booleanTrue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(booleanTrue), false); + m.set(booleanTrue, booleanTrue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(booleanTrue), true); + assert.sameValue(m.get(booleanTrue), booleanTrue); +}; + +{ + const m = new SendableMap([[booleanFalse, booleanFalse]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(booleanFalse), true); + assert.sameValue(m.get(booleanFalse), booleanFalse); + m.delete(booleanFalse); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(booleanFalse), false); + m.set(booleanFalse, booleanFalse); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(booleanFalse), true); + assert.sameValue(m.get(booleanFalse), booleanFalse); +}; + +{ + const m = new SendableMap([[functionExprValue, functionExprValue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(functionExprValue), true); + assert.sameValue(m.get(functionExprValue), functionExprValue); + m.delete(functionExprValue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(functionExprValue), false); + m.set(functionExprValue, functionExprValue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(functionExprValue), true); + assert.sameValue(m.get(functionExprValue), functionExprValue); +}; + +{ + const m = new SendableMap([[arrowFunctionValue, arrowFunctionValue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(arrowFunctionValue), true); + assert.sameValue(m.get(arrowFunctionValue), arrowFunctionValue); + m.delete(arrowFunctionValue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(arrowFunctionValue), false); + m.set(arrowFunctionValue, arrowFunctionValue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(arrowFunctionValue), true); + assert.sameValue(m.get(arrowFunctionValue), arrowFunctionValue); +}; + +{ + const m = new SendableMap([[classValue, classValue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(classValue), true); + assert.sameValue(m.get(classValue), classValue); + m.delete(classValue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(classValue), false); + m.set(classValue, classValue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(classValue), true); + assert.sameValue(m.get(classValue), classValue); +}; + +{ + const m = new SendableMap([[map, map]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(map), true); + assert.sameValue(m.get(map), map); + m.delete(map); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(map), false); + m.set(map, map); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(map), true); + assert.sameValue(m.get(map), map); +}; + +{ + const m = new SendableMap([[set, set]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(set), true); + assert.sameValue(m.get(set), set); + m.delete(set); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(set), false); + m.set(set, set); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(set), true); + assert.sameValue(m.get(set), set); +}; + +{ + const m = new SendableMap([[weakMap, weakMap]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakMap), true); + assert.sameValue(m.get(weakMap), weakMap); + m.delete(weakMap); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(weakMap), false); + m.set(weakMap, weakMap); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakMap), true); + assert.sameValue(m.get(weakMap), weakMap); +}; + +{ + const m = new SendableMap([[weakRef, weakRef]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakRef), true); + assert.sameValue(m.get(weakRef), weakRef); + m.delete(weakRef); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(weakRef), false); + m.set(weakRef, weakRef); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakRef), true); + assert.sameValue(m.get(weakRef), weakRef); +}; + +{ + const m = new SendableMap([[weakSet, weakSet]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakSet), true); + assert.sameValue(m.get(weakSet), weakSet); + m.delete(weakSet); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(weakSet), false); + m.set(weakSet, weakSet); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(weakSet), true); + assert.sameValue(m.get(weakSet), weakSet); +}; + +{ + const m = new SendableMap([[nullValue, nullValue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(nullValue), true); + assert.sameValue(m.get(nullValue), nullValue); + m.delete(nullValue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(nullValue), false); + m.set(nullValue, nullValue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(nullValue), true); + assert.sameValue(m.get(nullValue), nullValue); +}; + +{ + const m = new SendableMap([[undefinedValue, undefinedValue]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(undefinedValue), true); + assert.sameValue(m.get(undefinedValue), undefinedValue); + m.delete(undefinedValue); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(undefinedValue), false); + m.set(undefinedValue, undefinedValue); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(undefinedValue), true); + assert.sameValue(m.get(undefinedValue), undefinedValue); +}; + +{ + const m = new SendableMap([[unassigned, unassigned]]); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(unassigned), true); + assert.sameValue(m.get(unassigned), unassigned); + m.delete(unassigned); + assert.sameValue(m.size, 0); + assert.sameValue(m.has(unassigned), false); + m.set(unassigned, unassigned); + assert.sameValue(m.size, 1); + assert.sameValue(m.has(unassigned), true); + assert.sameValue(m.get(unassigned), unassigned); +}; + diff --git a/test/sendable/builtins/Set/Symbol.species/length.js b/test/sendable/builtins/Set/Symbol.species/length.js new file mode 100644 index 0000000000000000000000000000000000000000..f08cd5e3fe7aa23027ddd574261aaa0265ce3971 --- /dev/null +++ b/test/sendable/builtins/Set/Symbol.species/length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-set-@@species +description: > + get SendableSet [ @@species ].length is 0. +info: | + get SendableSet [ @@species ] + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.species] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableSet, Symbol.species); + +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/Symbol.species/return-value.js b/test/sendable/builtins/Set/Symbol.species/return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..71778bb8e80457f0018867e24a2ecf1c93b56784 --- /dev/null +++ b/test/sendable/builtins/Set/Symbol.species/return-value.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-set-@@species +description: Return value of @@species accessor method +info: | + 1. Return the this value. +features: [Symbol.species] +---*/ + +var thisVal = {}; +var accessor = Object.getOwnPropertyDescriptor(SendableSet, Symbol.species).get; + +assert.sameValue(accessor.call(thisVal), thisVal); diff --git a/test/sendable/builtins/Set/Symbol.species/symbol-species-name.js b/test/sendable/builtins/Set/Symbol.species/symbol-species-name.js new file mode 100644 index 0000000000000000000000000000000000000000..daae0593b48a22a85298cd95f7cab34c43c9cd08 --- /dev/null +++ b/test/sendable/builtins/Set/Symbol.species/symbol-species-name.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-set-@@species +description: > + SendableSet[Symbol.species] accessor property get name +info: | + 23.2.2.2 get SendableSet [ @@species ] + + ... + The value of the name property of this function is "get [Symbol.species]". +features: [Symbol.species] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableSet, Symbol.species); + +assert.sameValue( + descriptor.get.name, + 'get [Symbol.species]' +); diff --git a/test/sendable/builtins/Set/Symbol.species/symbol-species.js b/test/sendable/builtins/Set/Symbol.species/symbol-species.js new file mode 100644 index 0000000000000000000000000000000000000000..efa092c9d313435cfeedf618af68fa875be4062a --- /dev/null +++ b/test/sendable/builtins/Set/Symbol.species/symbol-species.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-set-@@species +description: SendableSet[Symbol.species] exists per spec +info: | + SendableSet has a property at `Symbol.species` +author: Sam Mikes +includes: [propertyHelper.js] +features: [Symbol.species] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableSet, Symbol.species); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +verifyNotWritable(SendableSet, Symbol.species, Symbol.species); +verifyNotEnumerable(SendableSet, Symbol.species); +verifyConfigurable(SendableSet, Symbol.species); diff --git a/test/sendable/builtins/Set/bigint-number-same-value.js b/test/sendable/builtins/Set/bigint-number-same-value.js new file mode 100644 index 0000000000000000000000000000000000000000..bffbb9e403f33f6b0a47f4b9ac109a077e3077dc --- /dev/null +++ b/test/sendable/builtins/Set/bigint-number-same-value.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + Observing the expected behavior of keys when a BigInt and Number have + the same value. +info: | + SendableSet.prototype.add ( value ) + + ... + For each element e of entries, do + If e is not empty and SameValueZero(e, value) is true, then + Return S. + If value is -0, set value to +0. + Append value as the last element of entries. + ... + +features: [BigInt] +---*/ + +const number = 9007199254740991; +const bigint = 9007199254740991n; + +const s = new SendableSet([ + number, + bigint, +]); + +assert.sameValue(s.size, 2); +assert.sameValue(s.has(number), true); +assert.sameValue(s.has(bigint), true); + +s.delete(number); +assert.sameValue(s.size, 1); +assert.sameValue(s.has(number), false); +s.delete(bigint); +assert.sameValue(s.size, 0); +assert.sameValue(s.has(bigint), false); + +s.add(number); +assert.sameValue(s.size, 1); +s.add(bigint); +assert.sameValue(s.size, 2); diff --git a/test/sendable/builtins/Set/constructor.js b/test/sendable/builtins/Set/constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..f13db4ac767a2d68c9dde863cd6c7484d53104f7 --- /dev/null +++ b/test/sendable/builtins/Set/constructor.js @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + The SendableSet constructor is the %SendableSet% intrinsic object and the + initial value of the SendableSet property of the global object. +---*/ + +assert.sameValue(typeof SendableSet, "function", "`typeof SendableSet` is `'function'`"); diff --git a/test/sendable/builtins/Set/is-a-constructor.js b/test/sendable/builtins/Set/is-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..fd89d61735025902a67454642ded7e63fd8dfb6d --- /dev/null +++ b/test/sendable/builtins/Set/is-a-constructor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The SendableSet constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, SendableSet] +---*/ + +assert.sameValue(isConstructor(SendableSet), true, 'isConstructor(SendableSet) must return true'); +new SendableSet(); + diff --git a/test/sendable/builtins/Set/length.js b/test/sendable/builtins/Set/length.js new file mode 100644 index 0000000000000000000000000000000000000000..bc82180910cc70c2cdadc1022080d3dfb97aed31 --- /dev/null +++ b/test/sendable/builtins/Set/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + Properties of the SendableSet Constructor + + Besides the length property (whose value is 0) + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/name.js b/test/sendable/builtins/Set/name.js new file mode 100644 index 0000000000000000000000000000000000000000..b3f9f9e0209dc4534b270f03b71b99281a0b1d6c --- /dev/null +++ b/test/sendable/builtins/Set/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet, "name", { + value: "SendableSet", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/properties-of-the-set-prototype-object.js b/test/sendable/builtins/Set/properties-of-the-set-prototype-object.js new file mode 100644 index 0000000000000000000000000000000000000000..355c8f2e14ec9c45d7cc47941264b7ee1b9a7c1c --- /dev/null +++ b/test/sendable/builtins/Set/properties-of-the-set-prototype-object.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-properties-of-the-set-prototype-object +description: > + The SendableSet prototype object is the intrinsic object %SendableSetPrototype%. + The value of the [[Prototype]] internal slot of the SendableSet prototype + object is the intrinsic object %ObjectPrototype% (19.1.3). The SendableSet + prototype object is an ordinary object. It does not have a + [[SendableSetData]] internal slot. +---*/ + +assert.sameValue( + Object.getPrototypeOf(SendableSet.prototype), + Object.prototype, + "`Object.getPrototypeOf(SendableSet.prototype)` returns `Object.prototype`" +); diff --git a/test/sendable/builtins/Set/proto-from-ctor-realm.js b/test/sendable/builtins/Set/proto-from-ctor-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..3039823332e80e2b80fb89bb54637e003893484f --- /dev/null +++ b/test/sendable/builtins/Set/proto-from-ctor-realm.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-iterable +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 2. Let set be ? OrdinaryCreateFromConstructor(NewTarget, "%SendableSetPrototype%", + « [[SendableSetData]] »). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [cross-realm, Reflect] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +var o = Reflect.construct(SendableSet, [], C); + +assert.sameValue(Object.getPrototypeOf(o), other.SendableSet.prototype); diff --git a/test/sendable/builtins/Set/prototype-of-set.js b/test/sendable/builtins/Set/prototype-of-set.js new file mode 100644 index 0000000000000000000000000000000000000000..5b44a0d2d7327393afa33e287a0280bddd67fdac --- /dev/null +++ b/test/sendable/builtins/Set/prototype-of-set.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-properties-of-the-set-constructor +description: > + The value of the [[Prototype]] internal slot of the SendableSet constructor + is the intrinsic object %FunctionPrototype% (19.2.3). +---*/ + +assert.sameValue( + Object.getPrototypeOf(SendableSet), + Function.prototype, + "`Object.getPrototypeOf(SendableSet)` returns `Function.prototype`" +); diff --git a/test/sendable/builtins/Set/prototype/Symbol.iterator.js b/test/sendable/builtins/Set/prototype/Symbol.iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..4495d2b6d3902be4c892600b84ddf956f6643df1 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/Symbol.iterator.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype-@@iterator +description: Initial state of the Symbol.iterator property +info: | + The initial value of the @@iterator property is the same function object as + the initial value of the values property. + + Per ES6 section 17, the method should exist on the SendableSet prototype, and it + should be writable and configurable, but not enumerable. +includes: [propertyHelper.js] +features: [Symbol.iterator] +---*/ + +assert.sameValue(SendableSet.prototype[Symbol.iterator], SendableSet.prototype.values); +verifyProperty(SendableSet.prototype, Symbol.iterator, { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/Symbol.iterator/not-a-constructor.js b/test/sendable/builtins/Set/prototype/Symbol.iterator/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..86941c16a31b23beb64600cb6d081b1c6f837b02 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/Symbol.iterator/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableSet.prototype[Symbol.iterator] does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Symbol, Symbol.iterator, SendableSet, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableSet.prototype[Symbol.iterator]), + false, + 'isConstructor(SendableSet.prototype[Symbol.iterator]) must return false' +); + +assert.throws(TypeError, () => { + let s = new SendableSet([]); new s[Symbol.iterator](); +}); + diff --git a/test/sendable/builtins/Set/prototype/Symbol.toStringTag.js b/test/sendable/builtins/Set/prototype/Symbol.toStringTag.js new file mode 100644 index 0000000000000000000000000000000000000000..c806d93247586eb2896c1bb0fcc8f8fda5b16dd8 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/Symbol.toStringTag.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype-@@tostringtag +description: > + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the String value + "SendableSet". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.toStringTag] +---*/ + +assert.sameValue(SendableSet.prototype[Symbol.toStringTag], 'SendableSet'); + +verifyProperty(SendableSet.prototype, Symbol.toStringTag, { + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/Symbol.toStringTag/property-descriptor.js b/test/sendable/builtins/Set/prototype/Symbol.toStringTag/property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..9e067128d069f4b12933938f4ec0997c2cba08bf --- /dev/null +++ b/test/sendable/builtins/Set/prototype/Symbol.toStringTag/property-descriptor.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype-@@tostringtag +description: > + `Object.prototype.getOwnPropertyDescriptor` should reflect the value and + writability of the @@toStringTag attribute. +includes: [propertyHelper.js] +features: [Symbol.toStringTag] +---*/ + +var SendableSetProto = Object.getPrototypeOf(new SendableSet()); + +assert.sameValue( + SendableSetProto[Symbol.toStringTag], + 'SendableSet', + "The value of `SendableSetProto[Symbol.toStringTag]` is `'SendableSet'`" +); + +verifyProperty(SendableSetProto, Symbol.toStringTag, { + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/add/add.js b/test/sendable/builtins/Set/prototype/add/add.js new file mode 100644 index 0000000000000000000000000000000000000000..1c76772546a726b666558824b28da42741020333 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/add.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.add, + "function", + "`typeof SendableSet.prototype.add` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "add", { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-array.js b/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-array.js new file mode 100644 index 0000000000000000000000000000000000000000..2e1a313119abd7eef9db68c6df3f638a4a3d58ab --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-array.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.add.call([], 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.add.call([], 1); +}); diff --git a/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-map.js b/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-map.js new file mode 100644 index 0000000000000000000000000000000000000000..2bee729625b36914441a19d37e7bb8aa31105b1c --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-map.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.add.call(new Map(), 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.add.call(new Map(), 1); +}); diff --git a/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-object.js b/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-object.js new file mode 100644 index 0000000000000000000000000000000000000000..50a95db2be47601ea86574be63912ba510a0b3d3 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-object.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.add.call({}, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.add.call({}, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-set-prototype.js b/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-set-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..96ba1e15536205b4986693ccce62a61a24a9d429 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-set-prototype.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.add.call(SendableSet.prototype, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.add.call(SendableSet.prototype, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-weakset.js b/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-weakset.js new file mode 100644 index 0000000000000000000000000000000000000000..8b5dbfe514f8aa0b6fdd905642e3935332c702c8 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/does-not-have-setdata-internal-slot-weakset.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +features: [WeakSet] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.add.call(new WeakSet(), 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.add.call(new WeakSet(), 1); +}); diff --git a/test/sendable/builtins/Set/prototype/add/length.js b/test/sendable/builtins/Set/prototype/add/length.js new file mode 100644 index 0000000000000000000000000000000000000000..1814ffd6d4c49cec05f4053186e5524d421285ce --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.add, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/add/name.js b/test/sendable/builtins/Set/prototype/add/name.js new file mode 100644 index 0000000000000000000000000000000000000000..d87d840e2835f9d6b64022d8ef838c70a248a1ed --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.add, "name", { + value: "add", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/add/not-a-constructor.js b/test/sendable/builtins/Set/prototype/add/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..3c836157ff51837a74983aba723249056ab1c286 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableSet.prototype.add does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableSet, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableSet.prototype.add), false, 'isConstructor(SendableSet.prototype.add) must return false'); + +assert.throws(TypeError, () => { + let s = new SendableSet([]); new s.add(); +}); + diff --git a/test/sendable/builtins/Set/prototype/add/preserves-insertion-order.js b/test/sendable/builtins/Set/prototype/add/preserves-insertion-order.js new file mode 100644 index 0000000000000000000000000000000000000000..540854783fc5febb4003a390919a87dd0903790b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/preserves-insertion-order.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + ... + 7. Append value as the last element of entries. + ... +---*/ + +var s = new SendableSet(); +var expects = [1, 2, 3]; + +s.add(1).add(2).add(3); + +s.forEach(function(value) { + assert.sameValue(value, expects.shift()); +}); + +assert.sameValue(expects.length, 0, "The value of `expects.length` is `0`"); diff --git a/test/sendable/builtins/Set/prototype/add/returns-this-when-ignoring-duplicate.js b/test/sendable/builtins/Set/prototype/add/returns-this-when-ignoring-duplicate.js new file mode 100644 index 0000000000000000000000000000000000000000..f010fe2b0aa05dfb6604de9f2d5b876be2a1f9fc --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/returns-this-when-ignoring-duplicate.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + 1. Let S be this value. + ... + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, then + i. Return S. + ... + +---*/ + +var s = new SendableSet([1]); + +assert.sameValue(s.add(1), s, "`s.add(1)` returns `s`"); diff --git a/test/sendable/builtins/Set/prototype/add/returns-this.js b/test/sendable/builtins/Set/prototype/add/returns-this.js new file mode 100644 index 0000000000000000000000000000000000000000..7ea874e2d9dd6dd1b1ec61bfd18e977a0393074d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/returns-this.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + 1. Let S be this value. + ... + 8. Return S. + +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.add(1), s, "`s.add(1)` returns `s`"); diff --git a/test/sendable/builtins/Set/prototype/add/this-not-object-throw-boolean.js b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..a00790891172d0e6ba5c4831dc6c6721b4b24b3a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-boolean.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.add.call(false, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.add.call(false, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/add/this-not-object-throw-null.js b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-null.js new file mode 100644 index 0000000000000000000000000000000000000000..e11aa8e4e94d86a5596b6bd6da0b23bc6c351532 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-null.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.add.call(null, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.add.call(null, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/add/this-not-object-throw-number.js b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-number.js new file mode 100644 index 0000000000000000000000000000000000000000..dc0e270e21b70fc277d09cafba3a59369e9d66f0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-number.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.add.call(0, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.add.call(0, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/add/this-not-object-throw-string.js b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-string.js new file mode 100644 index 0000000000000000000000000000000000000000..08c535cbf8f84084374245a012df9bf0c5698aaf --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-string.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.add.call("", 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.add.call("", 1); +}); diff --git a/test/sendable/builtins/Set/prototype/add/this-not-object-throw-symbol.js b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..2719d227ab78d65e2979026a9f3f12ad9639302f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-symbol.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.add.call(Symbol(), 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.add.call(Symbol(), 1); +}); diff --git a/test/sendable/builtins/Set/prototype/add/this-not-object-throw-undefined.js b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..7c5e1de48bbec1dfff76c58f0ebfe771613dc258 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/this-not-object-throw-undefined.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.add.call(undefined, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.add.call(undefined, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/add/will-not-add-duplicate-entry-initial-iterable.js b/test/sendable/builtins/Set/prototype/add/will-not-add-duplicate-entry-initial-iterable.js new file mode 100644 index 0000000000000000000000000000000000000000..5d5e4ceb7f0d03c6c6e979516f42da1fe4690a76 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/will-not-add-duplicate-entry-initial-iterable.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + ... + 4. Let entries be the List that is the value of S’s [[SendableSetData]] internal slot. + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, then + i. Return S. + 6. If value is −0, let value be +0. + 7. Append value as the last element of entries. + ... + +---*/ + +var s = new SendableSet([1]); + +assert.sameValue(s.size, 1, "The value of `s.size` is `1`"); + +s.add(1); + +assert.sameValue(s.size, 1, "The value of `s.size` is `1`"); diff --git a/test/sendable/builtins/Set/prototype/add/will-not-add-duplicate-entry-normalizes-zero.js b/test/sendable/builtins/Set/prototype/add/will-not-add-duplicate-entry-normalizes-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..fd07635924fc2d4cb4b597d4bb213298521515a8 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/will-not-add-duplicate-entry-normalizes-zero.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + ... + 4. Let entries be the List that is the value of S’s [[SendableSetData]] internal slot. + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, then + i. Return S. + 6. If value is −0, let value be +0. + 7. Append value as the last element of entries. + ... + +---*/ + +var s = new SendableSet([-0]); + +assert.sameValue(s.size, 1, "The value of `s.size` is `1`"); + +s.add(-0); + +assert.sameValue(s.size, 1, "The value of `s.size` is `1`, after executing `s.add(-0)`"); + +s.add(0); + +assert.sameValue(s.size, 1, "The value of `s.size` is `1`, after executing `s.add(0)`"); diff --git a/test/sendable/builtins/Set/prototype/add/will-not-add-duplicate-entry.js b/test/sendable/builtins/Set/prototype/add/will-not-add-duplicate-entry.js new file mode 100644 index 0000000000000000000000000000000000000000..0d794adbaef46a0b75ec582f2b0274fe0c66fcdf --- /dev/null +++ b/test/sendable/builtins/Set/prototype/add/will-not-add-duplicate-entry.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: > + SendableSet.prototype.add ( value ) + + ... + 4. Let entries be the List that is the value of S’s [[SendableSetData]] internal slot. + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, then + i. Return S. + 6. If value is −0, let value be +0. + 7. Append value as the last element of entries. + ... + +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.size, 0, "The value of `s.size` is `0`"); + +s.add(1); +s.add(1); + +assert.sameValue(s.size, 1, "The value of `s.size` is `1`, after executing `s.add(1); s.add(1);`"); diff --git a/test/sendable/builtins/Set/prototype/clear/clear.js b/test/sendable/builtins/Set/prototype/clear/clear.js new file mode 100644 index 0000000000000000000000000000000000000000..57eff4d063ce2161612ba62cb2b562e1d5c1fed5 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/clear.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.clear, + "function", + "`typeof SendableSet.prototype.clear` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "clear", { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/clear/clears-all-contents-from-iterable.js b/test/sendable/builtins/Set/prototype/clear/clears-all-contents-from-iterable.js new file mode 100644 index 0000000000000000000000000000000000000000..5f64a910796e48493f7dc6382d9068761875b624 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/clears-all-contents-from-iterable.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + ... + 4. Let entries be the List that is the value of S’s [[SendableSetData]] internal slot. + 5. Repeat for each e that is an element of entries, + a. Replace the element of entries whose value is e with an element whose value is empty. + ... + +---*/ + +var s = new SendableSet([1, 2, 3]); + +assert.sameValue(s.size, 3, "The value of `s.size` is `3`"); + +var result = s.clear(); + +assert.sameValue(s.size, 0, "The value of `s.size` is `0`, after executing `s.clear()`"); +assert.sameValue(s.has(1), false, "`s.has(1)` returns `false`"); +assert.sameValue(s.has(2), false, "`s.has(2)` returns `false`"); +assert.sameValue(s.has(3), false, "`s.has(3)` returns `false`"); +assert.sameValue(result, undefined, "The result of `s.clear()` is `undefined`"); diff --git a/test/sendable/builtins/Set/prototype/clear/clears-all-contents.js b/test/sendable/builtins/Set/prototype/clear/clears-all-contents.js new file mode 100644 index 0000000000000000000000000000000000000000..aeaa384a4fc9dc2ed6309653962a0d024fa96ecd --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/clears-all-contents.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + ... + 4. Let entries be the List that is the value of S’s [[SendableSetData]] internal slot. + 5. Repeat for each e that is an element of entries, + a. Replace the element of entries whose value is e with an element whose value is empty. + ... + +---*/ + +var s = new SendableSet(); + +s.add(1).add(2).add(3); + +assert.sameValue(s.size, 3, "The value of `s.size` is `3`"); + +var result = s.clear(); + +assert.sameValue(s.size, 0, "The value of `s.size` is `0`, after executing `s.clear()`"); +assert.sameValue(s.has(1), false, "`s.has(1)` returns `false`"); +assert.sameValue(s.has(2), false, "`s.has(2)` returns `false`"); +assert.sameValue(s.has(3), false, "`s.has(3)` returns `false`"); +assert.sameValue(result, undefined, "The result of `s.clear()` is `undefined`"); diff --git a/test/sendable/builtins/Set/prototype/clear/clears-an-empty-set.js b/test/sendable/builtins/Set/prototype/clear/clears-an-empty-set.js new file mode 100644 index 0000000000000000000000000000000000000000..dd10b7dd4c31f220a654e2db0463240918af43e9 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/clears-an-empty-set.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + ... + 4. Let entries be the List that is the value of S’s [[SendableSetData]] internal slot. + 5. Repeat for each e that is an element of entries, + a. Replace the element of entries whose value is e with an element whose value is empty. + ... + +---*/ + +var s = new SendableSet(); + +var result = s.clear(); + +assert.sameValue(s.size, 0, "The value of `s.size` is `0`"); +assert.sameValue(result, undefined, "The result of `s.clear()` is `undefined`"); diff --git a/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-array.js b/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-array.js new file mode 100644 index 0000000000000000000000000000000000000000..b6a87f4046c7252fcc6cc5836c517c689fc2b6f9 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-array.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.clear.call([]); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.clear.call([]); +}); diff --git a/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-map.js b/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-map.js new file mode 100644 index 0000000000000000000000000000000000000000..3d2218e04dead1a062fa06bf50a208c8940031a2 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-map.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.clear.call(new Map()); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.clear.call(new Map()); +}); diff --git a/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-object.js b/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-object.js new file mode 100644 index 0000000000000000000000000000000000000000..a9e16f9740bfde38d3154e3c583f7f7d6e0be532 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-object.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.clear.call({}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.clear.call({}); +}); diff --git a/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-set.prototype.js b/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-set.prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..45d1886cd56233ea7075c13aa53b2f17ef665150 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-set.prototype.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.clear.call(SendableSet.prototype); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.clear.call(SendableSet.prototype); +}); diff --git a/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-weakset.js b/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-weakset.js new file mode 100644 index 0000000000000000000000000000000000000000..1a78dd40f5e816426612d160ad431f55a426929e --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/does-not-have-setdata-internal-slot-weakset.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +features: [WeakSet] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.clear.call(new WeakSet()); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.clear.call(new WeakSet()); +}); diff --git a/test/sendable/builtins/Set/prototype/clear/length.js b/test/sendable/builtins/Set/prototype/clear/length.js new file mode 100644 index 0000000000000000000000000000000000000000..08586731ae642d906e1d6236d8b5e0191c9e86ad --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.clear, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/clear/name.js b/test/sendable/builtins/Set/prototype/clear/name.js new file mode 100644 index 0000000000000000000000000000000000000000..05bb398f8589c2fe5483fb57c5a34363a08e307e --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.clear, "name", { + value: "clear", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/clear/not-a-constructor.js b/test/sendable/builtins/Set/prototype/clear/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..87e3ec626b81ae40fea8178a290ff8a81ff79e5d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableSet.prototype.clear does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableSet, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableSet.prototype.clear), false, 'isConstructor(SendableSet.prototype.clear) must return false'); + +assert.throws(TypeError, () => { + let s = new SendableSet([]); new s.clear(); +}); + diff --git a/test/sendable/builtins/Set/prototype/clear/returns-undefined.js b/test/sendable/builtins/Set/prototype/clear/returns-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..ee4082cca44bcfaf9c3461b949226d27f18d563d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/returns-undefined.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + ... + 6. Return undefined. + +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.clear(), undefined, "`s.clear()` returns `undefined`"); diff --git a/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-boolean.js b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..c4f8cf85cc9f960eb9e8002369006476d02237b4 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-boolean.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.clear.call(false); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.clear.call(false); +}); diff --git a/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-null.js b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-null.js new file mode 100644 index 0000000000000000000000000000000000000000..384d65228f5ac76c283dbef651aca6b52ec48c85 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-null.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.clear.call(null); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.clear.call(null); +}); diff --git a/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-number.js b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-number.js new file mode 100644 index 0000000000000000000000000000000000000000..913c69dca02a43d4afc2734a1237859819a198b6 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-number.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.clear.call(0); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.clear.call(0); +}); diff --git a/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-string.js b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-string.js new file mode 100644 index 0000000000000000000000000000000000000000..4cc4310037e3d4de9d8e7e8864de7d130bc1db39 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-string.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.clear.call(""); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.clear.call(""); +}); diff --git a/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-symbol.js b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..4de0afcabcc69cf27133348ba48724bb35c62d1d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-symbol.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.clear.call(Symbol()); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.clear.call(Symbol()); +}); diff --git a/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-undefined.js b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..8501eb0116542fe282b7bb5c2445ae1b14b553db --- /dev/null +++ b/test/sendable/builtins/Set/prototype/clear/this-not-object-throw-undefined.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.clear +description: > + SendableSet.prototype.clear ( ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.clear.call(undefined); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.clear.call(undefined); +}); diff --git a/test/sendable/builtins/Set/prototype/constructor/set-prototype-constructor-intrinsic.js b/test/sendable/builtins/Set/prototype/constructor/set-prototype-constructor-intrinsic.js new file mode 100644 index 0000000000000000000000000000000000000000..c6193dc0b98948f8ce6070eace06b1f7a9a0c600 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/constructor/set-prototype-constructor-intrinsic.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableSet.prototype.constructor + + The initial value of SendableSet.prototype.constructor is the intrinsic object %SendableSet%. + +---*/ + +assert.sameValue( + SendableSet.prototype.constructor, + SendableSet, + "The value of `SendableSet.prototype.constructor` is `SendableSet`" +); diff --git a/test/sendable/builtins/Set/prototype/constructor/set-prototype-constructor.js b/test/sendable/builtins/Set/prototype/constructor/set-prototype-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..672e8815d31470cd470cb9b99c046cfeca691572 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/constructor/set-prototype-constructor.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableSet ( [ iterable ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype, "constructor", { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/delete/delete-entry-initial-iterable.js b/test/sendable/builtins/Set/prototype/delete/delete-entry-initial-iterable.js new file mode 100644 index 0000000000000000000000000000000000000000..97fdcebb3d8e3d705d64506e15021e1684e30e8f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/delete-entry-initial-iterable.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + ... + 4. Let entries be the List that is the value of S’s [[SendableSetData]] internal slot. + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, then + b. Replace the element of entries whose value is e with an element whose value is empty. + c. Return true. + ... + + +---*/ + +var s = new SendableSet([1]); + +assert.sameValue(s.size, 1, "The value of `s.size` is `1`"); + +var result = s.delete(1); + +assert.sameValue(s.size, 0, "The value of `s.size` is `0`, after executing `s.delete(1)`"); +assert.sameValue(result, true, "The result of `s.delete(1)` is `true`"); diff --git a/test/sendable/builtins/Set/prototype/delete/delete-entry-normalizes-zero.js b/test/sendable/builtins/Set/prototype/delete/delete-entry-normalizes-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..727efb276b1292062d3fba73d1b0f21c618138b9 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/delete-entry-normalizes-zero.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + ... + 4. Let entries be the List that is the value of S’s [[SendableSetData]] internal slot. + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, then + b. Replace the element of entries whose value is e with an element whose value is empty. + c. Return true. + ... + +---*/ + +var s = new SendableSet([-0]); + +assert.sameValue(s.size, 1, "The value of `s.size` is `1`"); + +var result = s.delete(+0); + +assert.sameValue(s.size, 0, "The value of `s.size` is `0`, after executing `s.delete(-0)`"); +assert.sameValue(result, true, "The result of `s.delete(+0)` is `true`"); diff --git a/test/sendable/builtins/Set/prototype/delete/delete-entry.js b/test/sendable/builtins/Set/prototype/delete/delete-entry.js new file mode 100644 index 0000000000000000000000000000000000000000..895e8cf32c6eb975ae12b9edf454e9de0b9ec981 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/delete-entry.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + ... + 4. Let entries be the List that is the value of S’s [[SendableSetData]] internal slot. + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, then + i. Return S. + 6. If value is −0, let value be +0. + 7. Append value as the last element of entries. + ... + +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.size, 0, "The value of `s.size` is `0`"); + +s.add(1); + +assert.sameValue(s.size, 1, "The value of `s.size` is `1`, after executing `s.add(1)`"); + +var result = s.delete(1); + +assert.sameValue(s.size, 0, "The value of `s.size` is `0`, after executing `s.delete(1)`"); +assert.sameValue(result, true, "The result of `s.delete(1)` is `true`"); diff --git a/test/sendable/builtins/Set/prototype/delete/delete.js b/test/sendable/builtins/Set/prototype/delete/delete.js new file mode 100644 index 0000000000000000000000000000000000000000..bc8602ae55aba1f93c2bd659d80a94075cc24c1e --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/delete.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.delete, + "function", + "`typeof SendableSet.prototype.delete` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "delete", { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-array.js b/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-array.js new file mode 100644 index 0000000000000000000000000000000000000000..a200e687da828cee277afaeae9be44f602bfbeb1 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-array.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.delete.call([], 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.delete.call([], 1); +}); diff --git a/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-map.js b/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-map.js new file mode 100644 index 0000000000000000000000000000000000000000..e429e6c7ac37577ea58f4d3d4a532081a31f69a5 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-map.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.delete.call(new Map(), 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.delete.call(new Map(), 1); +}); diff --git a/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-object.js b/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-object.js new file mode 100644 index 0000000000000000000000000000000000000000..aa5f7032bb426aae3439443bc2a64a7831bb2642 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-object.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.delete.call({}, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.delete.call({}, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-set-prototype.js b/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-set-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..85819bf5b0b9e3084cfe3458f2017e175b5adb60 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-set-prototype.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.delete.call(SendableSet.prototype, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.delete.call(SendableSet.prototype, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-weakset.js b/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-weakset.js new file mode 100644 index 0000000000000000000000000000000000000000..0b0992731a9a0430c2c411b0252c1e8a3ba98795 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/does-not-have-setdata-internal-slot-weakset.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +features: [WeakSet] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.delete.call(new WeakSet(), 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.delete.call(new WeakSet(), 1); +}); diff --git a/test/sendable/builtins/Set/prototype/delete/length.js b/test/sendable/builtins/Set/prototype/delete/length.js new file mode 100644 index 0000000000000000000000000000000000000000..4bdf2f50794f33a1dfd01f093d390c8ed057b808 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.delete, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/delete/name.js b/test/sendable/builtins/Set/prototype/delete/name.js new file mode 100644 index 0000000000000000000000000000000000000000..851b4bf71d981c48417eac77f6f445ecfb1b2e1c --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.delete, "name", { + value: "delete", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/delete/not-a-constructor.js b/test/sendable/builtins/Set/prototype/delete/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..2cc09403734ccc8bfe8800d1ecb61b3a61f4381b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableSet.prototype.delete does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableSet, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableSet.prototype.delete), false, 'isConstructor(SendableSet.prototype.delete) must return false'); + +assert.throws(TypeError, () => { + let s = new SendableSet([]); new s.delete(); +}); + diff --git a/test/sendable/builtins/Set/prototype/delete/returns-false-when-delete-is-noop.js b/test/sendable/builtins/Set/prototype/delete/returns-false-when-delete-is-noop.js new file mode 100644 index 0000000000000000000000000000000000000000..411530e0945fc029d99c7bb2ff71892fc4ffc3ea --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/returns-false-when-delete-is-noop.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + ... + 6. Return false. + +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.delete(1), false, "`s.delete(1)` returns `false`"); diff --git a/test/sendable/builtins/Set/prototype/delete/returns-true-when-delete-operation-occurs.js b/test/sendable/builtins/Set/prototype/delete/returns-true-when-delete-operation-occurs.js new file mode 100644 index 0000000000000000000000000000000000000000..650346293ec25a30ce4f5b544123309e07b8f59d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/returns-true-when-delete-operation-occurs.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + ... + 4. Let entries be the List that is the value of S’s [[SendableSetData]] internal slot. + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, then + b. Replace the element of entries whose value is e with an element whose value is empty. + c. Return true. + ... + +---*/ + +var s = new SendableSet(); + +s.add(1); + +assert.sameValue(s.delete(1), true, "`s.delete(1)` returns `true`"); diff --git a/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-boolean.js b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..acd462a2e6f407696bfffaf4d90ceaebdd5c6085 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-boolean.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.delete.call(false, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.delete.call(false, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-null.js b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-null.js new file mode 100644 index 0000000000000000000000000000000000000000..179b36110b8d2222cd6dabcfb8b35bb903e7bb97 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-null.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.delete.call(null, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.delete.call(null, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-number.js b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-number.js new file mode 100644 index 0000000000000000000000000000000000000000..fd00dedd788019fd18843d4ca38e76e92a4f5c40 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-number.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.delete.call(0, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.delete.call(0, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-string.js b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-string.js new file mode 100644 index 0000000000000000000000000000000000000000..cba49f02a30402ca3985593e0bc56cfacf420985 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-string.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.delete.call("", 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.delete.call("", 1); +}); diff --git a/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-symbol.js b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..94cbd19e650cd161883e3b71bc1a301ed47b68f0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-symbol.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.delete.call(Symbol(), 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.delete.call(Symbol(), 1); +}); diff --git a/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-undefined.js b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..5cd6365e807d43c6f7656934c91e198e7eeb29e6 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/delete/this-not-object-throw-undefined.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.delete +description: > + SendableSet.prototype.delete ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.delete.call(undefined, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.delete.call(undefined, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/difference/add-not-called.js b/test/sendable/builtins/Set/prototype/difference/add-not-called.js new file mode 100644 index 0000000000000000000000000000000000000000..6a4c27636c3d58fec225f84838252fb95a1fd36e --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/add-not-called.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference should not call SendableSet.prototype.add +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1]; + +const originalAdd = SendableSet.prototype.add; +let count = 0; +SendableSet.prototype.add = function (...rest) { + count++; + return originalAdd.apply(this, rest); +}; + +const combined = s1.difference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(count, 0, "Add is never called"); + +SendableSet.prototype.add = originalAdd; diff --git a/test/sendable/builtins/Set/prototype/difference/allows-set-like-class.js b/test/sendable/builtins/Set/prototype/difference/allows-set-like-class.js new file mode 100644 index 0000000000000000000000000000000000000000..24518f454db308a7d420ee153531b8e6263259ed --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/allows-set-like-class.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: GetSendableSetRecord allows instances of SendableSet-like classes +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new class { + get size() { + return 2; + } + has(v) { + if (v === 1) return false; + if (v === 2) return true; + throw new Test262Error("SendableSet.prototype.difference should only call its argument's has method with contents of this"); + } + * keys() { + throw new Test262Error("SendableSet.prototype.difference should not call its argument's keys iterator when this.size ≤ arg.size"); + } +}; +const expected = [1]; +const combined = s1.difference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/difference/allows-set-like-object.js b/test/sendable/builtins/Set/prototype/difference/allows-set-like-object.js new file mode 100644 index 0000000000000000000000000000000000000000..5ffc80009410c39e29c335be95135020a6c30e7f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/allows-set-like-object.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: GetSendableSetRecord allows SendableSet-like objects +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: (v) => { + if (v === 1) return false; + if (v === 2) return true; + throw new Test262Error("SendableSet.prototype.difference should only call its argument's has method with contents of this"); + }, + keys: function* keys() { + throw new Test262Error("SendableSet.prototype.difference should not call its argument's keys iterator when this.size ≤ arg.size"); + }, +}; +const expected = [1]; +const combined = s1.difference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/difference/array-throws.js b/test/sendable/builtins/Set/prototype/difference/array-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..396fa8526e109bc53b1c10be9daaf7ec9e8e11ed --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/array-throws.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference doesn't work with arrays +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [3]; +assert.throws( + TypeError, + function () { + s1.difference(s2); + }, + "Throws an error when an array is used" +); diff --git a/test/sendable/builtins/Set/prototype/difference/builtins.js b/test/sendable/builtins/Set/prototype/difference/builtins.js new file mode 100644 index 0000000000000000000000000000000000000000..fdae2112d715e850867bd4a912018bf129993f76 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/builtins.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: Tests that SendableSet.prototype.difference meets the requirements for built-in objects +features: [set-methods] +---*/ + +assert.sameValue( + Object.isExtensible(SendableSet.prototype.difference), + true, + "Built-in objects must be extensible." +); + +assert.sameValue( + Object.prototype.toString.call(SendableSet.prototype.difference), + "[object Function]", + "Object.prototype.toString" +); + +assert.sameValue( + Object.getPrototypeOf(SendableSet.prototype.difference), + Function.prototype, + "prototype" +); diff --git a/test/sendable/builtins/Set/prototype/difference/called-with-object.js b/test/sendable/builtins/Set/prototype/difference/called-with-object.js new file mode 100644 index 0000000000000000000000000000000000000000..9cacb497ada4ad6d45daa1c0741fb55ae6753b12 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/called-with-object.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws if obj is not an object +info: | + 1. If obj is not an Object, throw a TypeError exception. +features: [set-methods] +---*/ + +let s1 = new SendableSet([1]); +assert.throws( + TypeError, + function () { + s1.difference(1); + }, + "number" +); + +assert.throws( + TypeError, + function () { + s1.difference(""); + }, + "string" +); + +assert.throws( + TypeError, + function () { + s1.difference(1n); + }, + "bigint" +); + +assert.throws( + TypeError, + function () { + s1.difference(false); + }, + "boolean" +); + +assert.throws( + TypeError, + function () { + s1.difference(undefined); + }, + "undefined" +); + +assert.throws( + TypeError, + function () { + s1.difference(null); + }, + "null" +); + +assert.throws( + TypeError, + function () { + s1.difference(Symbol("test")); + }, + "symbol" +); diff --git a/test/sendable/builtins/Set/prototype/difference/combines-Map.js b/test/sendable/builtins/Set/prototype/difference/combines-Map.js new file mode 100644 index 0000000000000000000000000000000000000000..3efdb8ecd63f6224ee634c01eb7962dccd70f0a7 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/combines-Map.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference combines with Map +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const m1 = new Map([ + [2, "two"], + [3, "three"], +]); +const expected = [1]; +const combined = s1.difference(m1); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/difference/combines-empty-sets.js b/test/sendable/builtins/Set/prototype/difference/combines-empty-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..a996ced8dd09358a3d89c9eec3df8f9ee70215b6 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/combines-empty-sets.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference can combine empty SendableSets +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([]); +const s2 = new SendableSet([1, 2]); +let expected = []; +let combined = s1.difference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); + +const s3 = new SendableSet([1, 2]); +const s4 = new SendableSet([]); +expected = [1, 2]; +combined = s3.difference(s4); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); + +const s5 = new SendableSet([]); +const s6 = new SendableSet([]); +expected = []; +combined = s5.difference(s6); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/difference/combines-itself.js b/test/sendable/builtins/Set/prototype/difference/combines-itself.js new file mode 100644 index 0000000000000000000000000000000000000000..f301a6a7b01b4d5ccbc08577773f16909e87b9b7 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/combines-itself.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference is successful when called on itself +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const expected = []; +const combined = s1.difference(s1); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(combined === s1, false, "The returned object is a new object"); diff --git a/test/sendable/builtins/Set/prototype/difference/combines-same-sets.js b/test/sendable/builtins/Set/prototype/difference/combines-same-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..1821fe3613484dd7943ce759a7adb2df503a097d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/combines-same-sets.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference can combine SendableSets that have the same content +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([1, 2]); +const expected = []; +const combined = s1.difference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(combined === s1, false, "The returned object is a new object"); +assert.sameValue(combined === s2, false, "The returned object is a new object"); diff --git a/test/sendable/builtins/Set/prototype/difference/combines-sets.js b/test/sendable/builtins/Set/prototype/difference/combines-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..6c2d6941823ddef3386ab5b4d10267c9c4f0687f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/combines-sets.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference combines SendableSets +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1]; +const combined = s1.difference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/difference/converts-negative-zero.js b/test/sendable/builtins/Set/prototype/difference/converts-negative-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..247bb6f81ac12bc4c09a6ebd5c8c893b258d3ccf --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/converts-negative-zero.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference converts -0𝔽 to +0𝔽 +info: | + 7.b.ii If nextValue is -0𝔽, set nextValue to +0𝔽. +features: [set-methods] +includes: [compareArray.js] +---*/ + +const setlikeWithMinusZero = { + size: 1, + has: function () { + throw new Test262Error("SendableSet.prototype.difference should not call its argument's has method when this.size > arg.size"); + }, + keys: function () { + // we use an array here because the SendableSet constructor would normalize away -0 + return [-0].values(); + }, +}; + +const s1 = new SendableSet([+0, 1]); +let expected = [1]; +let combined = s1.difference(setlikeWithMinusZero); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/difference/difference.js b/test/sendable/builtins/Set/prototype/difference/difference.js new file mode 100644 index 0000000000000000000000000000000000000000..017602a9a49999527338f48792a050c68177f914 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/difference.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference properties +includes: [propertyHelper.js] +features: [set-methods] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.difference, + "function", + "`typeof SendableSet.prototype.difference` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "difference", { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/difference/has-is-callable.js b/test/sendable/builtins/Set/prototype/difference/has-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..43e12d530108a1beeb3f0a553bd87e73146238dc --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/has-is-callable.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'has' property is not callable +info: | + 7. Let has be ? Get(obj, "has"). + 8. If IsCallable(has) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: undefined, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.difference(s2); + }, + "GetSendableSetRecord throws an error when has is undefined" +); + +s2.has = {}; +assert.throws( + TypeError, + function () { + s1.difference(s2); + }, + "GetSendableSetRecord throws an error when has is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/difference/keys-is-callable.js b/test/sendable/builtins/Set/prototype/difference/keys-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..ab27cc75899b637c582eace3f4f8979a55629f6c --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/keys-is-callable.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'keys' property is not callable +info: | + 9. Let keys be ? Get(obj, "keys"). + 10. If IsCallable(keys) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: () => {}, + keys: undefined, +}; +assert.throws( + TypeError, + function () { + s1.difference(s2); + }, + "GetSendableSetRecord throws an error when keys is undefined" +); + +s2.keys = {}; +assert.throws( + TypeError, + function () { + s1.difference(s2); + }, + "GetSendableSetRecord throws an error when keys is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/difference/length.js b/test/sendable/builtins/Set/prototype/difference/length.js new file mode 100644 index 0000000000000000000000000000000000000000..f6e078301f238be31c4f66e3bdf8077eed997607 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference length property +info: | + SendableSet.prototype.difference ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.difference, "function"); + +verifyProperty(SendableSet.prototype.difference, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1, +}); diff --git a/test/sendable/builtins/Set/prototype/difference/name.js b/test/sendable/builtins/Set/prototype/difference/name.js new file mode 100644 index 0000000000000000000000000000000000000000..459eb5bec64ccd7b333714078f023772efaeed99 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference name property +info: | + SendableSet.prototype.difference ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.difference, "function"); + +verifyProperty(SendableSet.prototype.difference, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "difference", +}); diff --git a/test/sendable/builtins/Set/prototype/difference/not-a-constructor.js b/test/sendable/builtins/Set/prototype/difference/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..4b229908785caf22f64842837811d60bb1eddcab --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/not-a-constructor.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference does not implement [[Construct]], is not new-able +includes: [isConstructor.js] +features: [Reflect.construct, set-methods] +---*/ + +assert.sameValue( + isConstructor(SendableSet.prototype.difference), + false, + "isConstructor(SendableSet.prototype.difference) must return false" +); + +assert.throws( + TypeError, + () => { + new SendableSet.prototype.difference(); + }); diff --git a/test/sendable/builtins/Set/prototype/difference/receiver-not-set.js b/test/sendable/builtins/Set/prototype/difference/receiver-not-set.js new file mode 100644 index 0000000000000000000000000000000000000000..293c8311c47979ad7210fa9b28851fb6ae625f28 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/receiver-not-set.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference throws when receiver is not a SendableSet +features: [set-methods] +---*/ + +class MySendableSetLike { + constructor() { + this.size = 2; + this.has = () => {}; + this.keys = function* keys() { + yield 2; + yield 3; + }; + } +} + +const s1 = new MySendableSetLike(); +const s2 = new SendableSet(); +assert.throws( + TypeError, + () => { + SendableSet.prototype.difference.call(s1, s2); + }, + "SendableSet-like class" +); + +const s3 = { + size: 2, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + () => { + SendableSet.prototype.difference.call(s3, s2); + }, + "SendableSet-like object" +); diff --git a/test/sendable/builtins/Set/prototype/difference/require-internal-slot.js b/test/sendable/builtins/Set/prototype/difference/require-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..9ee5fbc1f2729f1aa45ddff05a0175e1df9bb633 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/require-internal-slot.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference RequireInternalSlot +info: | + 2. Perform ? RequireInternalSlot(O, [[SendableSetData]]) +features: [set-methods] +---*/ + +const difference = SendableSet.prototype.difference; + +assert.sameValue(typeof difference, "function"); + +const realSendableSet = new SendableSet([]); + +assert.throws(TypeError, () => difference.call(undefined, realSendableSet), "undefined"); +assert.throws(TypeError, () => difference.call(null, realSendableSet), "null"); +assert.throws(TypeError, () => difference.call(true, realSendableSet), "true"); +assert.throws(TypeError, () => difference.call("", realSendableSet), "empty string"); +assert.throws(TypeError, () => difference.call(Symbol(), realSendableSet), "symbol"); +assert.throws(TypeError, () => difference.call(1, realSendableSet), "1"); +assert.throws(TypeError, () => difference.call(1n, realSendableSet), "1n"); +assert.throws(TypeError, () => difference.call({}, realSendableSet), "plain object"); +assert.throws(TypeError, () => difference.call([], realSendableSet), "array"); +assert.throws(TypeError, () => difference.call(new Map(), realSendableSet), "map"); +assert.throws(TypeError, () => difference.call(SendableSet.prototype, realSendableSet), "SendableSet.prototype"); diff --git a/test/sendable/builtins/Set/prototype/difference/result-order.js b/test/sendable/builtins/Set/prototype/difference/result-order.js new file mode 100644 index 0000000000000000000000000000000000000000..789a1ddf8e7dc13b104925263bcb7aed5ae5e034 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/result-order.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference orders results as in this, regardless of sizes +features: [set-methods] +includes: [compareArray.js] +---*/ + +{ + const s1 = new SendableSet([1, 2, 3, 4]); + const s2 = new SendableSet([6, 5, 3, 2]); + + assert.compareArray([...s1.difference(s2)], [1, 4]); +} + +{ + const s1 = new SendableSet([6, 5, 3, 2]); + const s2 = new SendableSet([1, 2, 3, 4]); + + assert.compareArray([...s1.difference(s2)], [6, 5]); +} + +{ + const s1 = new SendableSet([1, 2, 3, 4]); + const s2 = new SendableSet([7, 6, 5, 3, 2]); + + assert.compareArray([...s1.difference(s2)], [1, 4]); +} + +{ + const s1 = new SendableSet([7, 6, 5, 3, 2]); + const s2 = new SendableSet([1, 2, 3, 4]); + + assert.compareArray([...s1.difference(s2)], [7, 6, 5]); +} + diff --git a/test/sendable/builtins/Set/prototype/difference/set-like-array.js b/test/sendable/builtins/Set/prototype/difference/set-like-array.js new file mode 100644 index 0000000000000000000000000000000000000000..9da2fd7448a4ab21cfea200f65c3972db0c663e6 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/set-like-array.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference consumes a set-like array as a set-like, not an array +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [5, 6]; +s2.size = 3; +s2.has = function (v) { + if (v === 1) return false; + if (v === 2) return true; + throw new Test262Error("SendableSet.prototype.difference should only call its argument's has method with contents of this"); +}; +s2.keys = function () { + throw new Test262Error("SendableSet.prototype.difference should not call its argument's keys iterator when this.size ≤ arg.size"); +}; + +const expected = [1]; +const combined = s1.difference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/difference/set-like-class-mutation.js b/test/sendable/builtins/Set/prototype/difference/set-like-class-mutation.js new file mode 100644 index 0000000000000000000000000000000000000000..fb839765ffacac773aa74f858334a53d36614479 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/set-like-class-mutation.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference maintains values even when a custom SendableSet-like class mutates the receiver +features: [set-methods] +includes: [compareArray.js] +---*/ + +const baseSendableSet = new SendableSet(["a", "b", "c", "d", "e"]); + +function mutatingIterator() { + let index = 0; + let values = ["x", "b", "b"]; + return { + next() { + if (index === 0) { + baseSendableSet.delete("b"); + baseSendableSet.delete("c"); + baseSendableSet.add("b"); + baseSendableSet.add("d"); + } + return { + done: index >= values.length, + value: values[index++], + }; + }, + }; +} + +const evilSendableSetLike = { + size: 3, + get has() { + baseSendableSet.add("q"); + return function () { + throw new Test262Error("SendableSet.prototype.difference should not invoke .has on its argument when this.size > other.size"); + }; + }, + keys() { + return mutatingIterator(); + }, +}; + +const combined = baseSendableSet.difference(evilSendableSetLike); +const expectedCombined = ["a", "c", "d", "e", "q"]; +assert.compareArray([...combined], expectedCombined); + +const expectedNewBase = ["a", "d", "e", "q", "b"]; +assert.compareArray([...baseSendableSet], expectedNewBase); diff --git a/test/sendable/builtins/Set/prototype/difference/set-like-class-order.js b/test/sendable/builtins/Set/prototype/difference/set-like-class-order.js new file mode 100644 index 0000000000000000000000000000000000000000..2f627ff61ab4315c65b9ab2e8e87af38a80233d9 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/set-like-class-order.js @@ -0,0 +1,153 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference calls a SendableSet-like class's methods in order +features: [set-methods] +includes: [compareArray.js] +---*/ + +let observedOrder = []; + +function observableIterator() { + let values = ["a", "b", "c"]; + let index = 0; + return { + get next() { + observedOrder.push("getting next"); + return function () { + observedOrder.push("calling next"); + return { + get done() { + observedOrder.push("getting done"); + return index >= values.length; + }, + get value() { + observedOrder.push("getting value"); + return values[index++]; + }, + }; + }; + }, + }; +} + +class MySendableSetLike { + get size() { + observedOrder.push("getting size"); + return { + valueOf: function () { + observedOrder.push("ToNumber(size)"); + return 3; + }, + }; + } + get has() { + observedOrder.push("getting has"); + return function (v) { + observedOrder.push("calling has"); + return ["a", "b", "c"].indexOf(v) !== -1; + }; + } + get keys() { + observedOrder.push("getting keys"); + return function () { + observedOrder.push("calling keys"); + return observableIterator(); + }; + } +} + +// this is smaller than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "d"]); + const s2 = new MySendableSetLike(); + const combined = s1.difference(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // two calls to has + "calling has", + "calling has", + ]; + + assert.compareArray([...combined], ["d"]); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is same size as argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "d"]); + const s2 = new MySendableSetLike(); + const combined = s1.difference(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // three calls to has + "calling has", + "calling has", + "calling has", + ]; + + assert.compareArray([...combined], ["d"]); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is larger than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "c", "d"]); + const s2 = new MySendableSetLike(); + const combined = s1.difference(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + "calling keys", + "getting next", + // first iteration, has value + "calling next", + "getting done", + "getting value", + // second iteration, has value + "calling next", + "getting done", + "getting value", + // third iteration, has value + "calling next", + "getting done", + "getting value", + // fourth iteration, no value; ends + "calling next", + "getting done", + ]; + + assert.compareArray([...combined], ["d"]); + assert.compareArray(observedOrder, expectedOrder); +} diff --git a/test/sendable/builtins/Set/prototype/difference/size-is-a-number.js b/test/sendable/builtins/Set/prototype/difference/size-is-a-number.js new file mode 100644 index 0000000000000000000000000000000000000000..df5704bbec971bb629a687432d4aad654e0844c3 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/size-is-a-number.js @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object has a size that is coerced to NaN +info: | + 2. Let rawSize be ? Get(obj, "size"). + 3. Let numSize be ? ToNumber(rawSize). + 4. NOTE: If rawSize is undefined, then numSize will be NaN. + 5. If numSize is NaN, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: undefined, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.difference(s2); + }, + "GetSendableSetRecord throws an error when size is undefined" +); + +s2.size = NaN; +assert.throws( + TypeError, + function () { + s1.difference(s2); + }, + "GetSendableSetRecord throws an error when size is NaN" +); + +let coercionCalls = 0; +s2.size = { + valueOf: function() { + ++coercionCalls; + return NaN; + }, +}; +assert.throws( + TypeError, + function () { + s1.difference(s2); + }, + "GetSendableSetRecord throws an error when size coerces to NaN" +); +assert.sameValue(coercionCalls, 1, "GetSendableSetRecord coerces size"); + +s2.size = 0n; +assert.throws( + TypeError, + function () { + s1.difference(s2); + }, + "GetSendableSetRecord throws an error when size is a BigInt" +); + +s2.size = "string"; +assert.throws( + TypeError, + function () { + s1.difference(s2); + }, + "GetSendableSetRecord throws an error when size is a non-numeric string" +); diff --git a/test/sendable/builtins/Set/prototype/difference/subclass-receiver-methods.js b/test/sendable/builtins/Set/prototype/difference/subclass-receiver-methods.js new file mode 100644 index 0000000000000000000000000000000000000000..6278f67a96f5cc219791e738a15ef75c4db3968a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/subclass-receiver-methods.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference works on subclasses of SendableSet, but never calls the receiver's size/has/keys methods +features: [set-methods] +includes: [compareArray.js] +---*/ + +let sizeCount = 0; +let hasCount = 0; +let keysCount = 0; + +class MySendableSet extends SendableSet { + size(...rest) { + sizeCount++; + return super.size(...rest); + } + + has(...rest) { + hasCount++; + return super.has(...rest); + } + + keys(...rest) { + keysCount++; + return super.keys(...rest); + } +} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1]; +const combined = s1.difference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); +assert.sameValue(sizeCount, 0, "size should not be called on the receiver"); +assert.sameValue(hasCount, 0, "has should not be called on the receiver"); +assert.sameValue(keysCount, 0, "keys should not be called on the receiver"); diff --git a/test/sendable/builtins/Set/prototype/difference/subclass-symbol-species.js b/test/sendable/builtins/Set/prototype/difference/subclass-symbol-species.js new file mode 100644 index 0000000000000000000000000000000000000000..bb37e12b7128382b8c4c2b44ecdfe2363aaa47ae --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/subclass-symbol-species.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference works on subclasses of SendableSet, but returns an instance of SendableSet even when Symbol.species is overridden. +features: [set-methods] +includes: [compareArray.js] +---*/ +var count = 0; +class MySendableSet extends SendableSet { + static get [Symbol.species]() { + count++; + return SendableSet; + } +} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1]; +const combined = s1.difference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(count, 0, "Symbol.species is never called"); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); diff --git a/test/sendable/builtins/Set/prototype/difference/subclass.js b/test/sendable/builtins/Set/prototype/difference/subclass.js new file mode 100644 index 0000000000000000000000000000000000000000..dc5668b91b3f5f1698ff9f24c276ab34f807401b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/difference/subclass.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.difference +description: SendableSet.prototype.difference works on subclasses of SendableSet, but returns an instance of SendableSet +features: [set-methods] +includes: [compareArray.js] +---*/ + +class MySendableSet extends SendableSet {} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1]; +const combined = s1.difference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); diff --git a/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-array.js b/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-array.js new file mode 100644 index 0000000000000000000000000000000000000000..531bfa35fd6758a0b0c5ac313fef7b971464050b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-array.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 2. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.entries.call([]); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.entries.call([]); +}); diff --git a/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-map.js b/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-map.js new file mode 100644 index 0000000000000000000000000000000000000000..6bae5c7e99df81f5095e1ff0ad9342dab7fbdde6 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-map.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 2. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.entries.call(new Map()); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.entries.call(new Map()); +}); diff --git a/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-object.js b/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-object.js new file mode 100644 index 0000000000000000000000000000000000000000..2129bf806a33ef2e84a6908617d5eb7c528284a0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-object.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 2. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.entries.call({}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.entries.call({}); +}); diff --git a/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-set-prototype.js b/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-set-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..0d7815b25b56b05c554b4994ee187242cc3be6e5 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-set-prototype.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 2. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.entries.call(SendableSet.prototype); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.entries.call(SendableSet.prototype); +}); diff --git a/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-weakset.js b/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-weakset.js new file mode 100644 index 0000000000000000000000000000000000000000..f7503407f44bf95524f9e416467957922f97d0ff --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/does-not-have-setdata-internal-slot-weakset.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 2. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +features: [WeakSet] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.entries.call(new WeakSet()); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.entries.call(new WeakSet()); +}); diff --git a/test/sendable/builtins/Set/prototype/entries/entries.js b/test/sendable/builtins/Set/prototype/entries/entries.js new file mode 100644 index 0000000000000000000000000000000000000000..708e89de5399437eee98ec935cbc246f9ac8b0b0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/entries.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.entries, + "function", + "`typeof SendableSet.prototype.entries` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "entries", { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/entries/length.js b/test/sendable/builtins/Set/prototype/entries/length.js new file mode 100644 index 0000000000000000000000000000000000000000..6632bb6805ed84ba978b5de7b6f5f6df54eb26e3 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.entries, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/entries/name.js b/test/sendable/builtins/Set/prototype/entries/name.js new file mode 100644 index 0000000000000000000000000000000000000000..4578beae6c1479dd48f340472e33773b49558d35 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.entries, "name", { + value: "entries", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/entries/not-a-constructor.js b/test/sendable/builtins/Set/prototype/entries/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..3c5fd807125347c2ba99a348b8ca2ea7b3ab0e51 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableSet.prototype.entries does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableSet, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableSet.prototype.entries), + false, + 'isConstructor(SendableSet.prototype.entries) must return false' +); + +assert.throws(TypeError, () => { + let s = new SendableSet([]); new s.entries(); +}); + diff --git a/test/sendable/builtins/Set/prototype/entries/returns-iterator-empty.js b/test/sendable/builtins/Set/prototype/entries/returns-iterator-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..57c0c891479b652a7e86df9948003cdf1742487d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/returns-iterator-empty.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 7. Return iterator. + + +---*/ + +var set = new SendableSet(); +var iterator = set.entries(); +var result = iterator.next(); + +assert.sameValue(result.value, undefined, "The value of `result.value` is `undefined`"); +assert.sameValue(result.done, true, "The value of `result.done` is `true`"); diff --git a/test/sendable/builtins/Set/prototype/entries/returns-iterator.js b/test/sendable/builtins/Set/prototype/entries/returns-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..2e7724b7e05aec073e7d6557731859b34cf123f2 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/returns-iterator.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 7. Return iterator. + + +---*/ + +var set = new SendableSet(); +set.add(1); +set.add(2); +set.add(3); + +var iterator = set.entries(); +var result; + +result = iterator.next(); +assert.sameValue(result.value[0], 1, 'First result `value` ("key")'); +assert.sameValue(result.value[1], 1, 'First result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'First result `value` (length)'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value[0], 2, 'Second result `value` ("key")'); +assert.sameValue(result.value[1], 2, 'Second result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'Second result `value` (length)'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value[0], 3, 'Third result `value` ("key")'); +assert.sameValue(result.value[1], 3, 'Third result `value` ("value")'); +assert.sameValue(result.value.length, 2, 'Third result `value` (length)'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); + +result = iterator.next(); +assert.sameValue( + result.value, undefined, 'Exhausted result `value` (repeated request)' +); +assert.sameValue( + result.done, true, 'Exhausted result `done` flag (repeated request)' +); diff --git a/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-boolean.js b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..54a92290cda44521a9895e6b6b012a669521233a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-boolean.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.entries.call(false); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.entries.call(false); +}); diff --git a/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-null.js b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-null.js new file mode 100644 index 0000000000000000000000000000000000000000..07bb3542cb070a4c5e725b2501caa53604766a88 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-null.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.entries.call(null); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.entries.call(null); +}); diff --git a/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-number.js b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-number.js new file mode 100644 index 0000000000000000000000000000000000000000..1534f1bb98f92e655129745c6837b9f10ee66503 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-number.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.entries.call(0); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.entries.call(0); +}); diff --git a/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-string.js b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-string.js new file mode 100644 index 0000000000000000000000000000000000000000..19b9030428534e605f9963738439cdb6897decce --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-string.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.entries.call(""); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.entries.call(""); +}); diff --git a/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-symbol.js b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..2c0989f1f577cb8ec40a5fd9659f1bfc83bfb991 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-symbol.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.entries.call(Symbol()); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.entries.call(Symbol()); +}); diff --git a/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-undefined.js b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..f6f06c62b7d787d9ac0dd873d813512c012333b9 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/entries/this-not-object-throw-undefined.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.entries +description: > + SendableSet.prototype.entries ( ) + + ... + 2. Return CreateSendableSetIterator(S, "key+value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.entries.call(undefined); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.entries.call(undefined); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-boolean.js b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..2cc150d88809b3923d383539d33f0e9c30c44718 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-boolean.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... + + Passing `false` as callback + +---*/ + +var s = new SendableSet([1]); + +assert.throws(TypeError, function() { + s.forEach(false); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-null.js b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-null.js new file mode 100644 index 0000000000000000000000000000000000000000..06bcfa4a59a2be316cbf0f0997799f9ad53b0ae6 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-null.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... + + Passing `null` as callback + +---*/ + +var s = new SendableSet([1]); + +assert.throws(TypeError, function() { + s.forEach(null); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-number.js b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-number.js new file mode 100644 index 0000000000000000000000000000000000000000..869213fc0c8b38cf6d09c3d81bf8fe84fe189f49 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-number.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... + + Passing `number` as callback + +---*/ + +var s = new SendableSet([1]); + +assert.throws(TypeError, function() { + s.forEach(0); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-string.js b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-string.js new file mode 100644 index 0000000000000000000000000000000000000000..d2cbfc1714744e3096898942addc6fc2a8cc0a80 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-string.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... + + Passing `string` as callback + +---*/ + +var s = new SendableSet([1]); + +assert.throws(TypeError, function() { + s.forEach(""); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-symbol.js b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..32f51e5a38e623dc0e9c203bc45502c2e8e29c5a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-symbol.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... + + Passing `symbol` as callback + +features: [Symbol] +---*/ + +var s = new SendableSet([1]); + +assert.throws(TypeError, function() { + s.forEach(Symbol()); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-undefined.js b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..1ff798bf033abaff96f47b9af7d9a1123b9b3c1f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/callback-not-callable-undefined.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... + + Passing `undefined` as callback + +---*/ + +var s = new SendableSet([1]); + +assert.throws(TypeError, function() { + s.forEach(undefined); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-array.js b/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-array.js new file mode 100644 index 0000000000000000000000000000000000000000..3c6c1d8fddccc220abc439f8295c00c396517693 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-array.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.forEach.call([], function() {}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.forEach.call([], function() {}); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-map.js b/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-map.js new file mode 100644 index 0000000000000000000000000000000000000000..69c5ac5ecaabb6e44bd7137b0b7254c2c4c41092 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-map.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.forEach.call(new Map(), function() {}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.forEach.call(new Map(), function() {}); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-object.js b/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-object.js new file mode 100644 index 0000000000000000000000000000000000000000..621904c043d9e3bb0e8653a75061687170141244 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-object.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.forEach.call({}, function() {}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.forEach.call({}, function() {}); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-set-prototype.js b/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-set-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..ce4ed46ecb10cec3cb1ff2aceef126bfa8431d19 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-set-prototype.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.forEach.call(SendableSet.prototype, function() {}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.forEach.call(SendableSet.prototype, function() {}); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-weakset.js b/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-weakset.js new file mode 100644 index 0000000000000000000000000000000000000000..e974585e9d49c6cd98dfc6e7cd8bb187dd0c1d80 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/does-not-have-setdata-internal-slot-weakset.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +features: [WeakSet] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.forEach.call(new WeakSet(), function() {}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.forEach.call(new WeakSet(), function() {}); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/forEach.js b/test/sendable/builtins/Set/prototype/forEach/forEach.js new file mode 100644 index 0000000000000000000000000000000000000000..ae24cc2d67b0c523b17982431e50a3e6b1b01a1f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/forEach.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.forEach, + "function", + "`typeof SendableSet.prototype.forEach` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "forEach", { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/iterates-in-insertion-order.js b/test/sendable/builtins/Set/prototype/forEach/iterates-in-insertion-order.js new file mode 100644 index 0000000000000000000000000000000000000000..1c5e39d34245762109d34be71797c76ce8956cfe --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/iterates-in-insertion-order.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 7. Repeat for each e that is an element of entries, in original insertion order + a. If e is not empty, then + i. Let funcResult be Call(callbackfn, T, «e, e, S»). + ii. ReturnIfAbrupt(funcResult). + ... +---*/ + +var s = new SendableSet(); +var expects = [1, 2, 3]; + +s.add(1).add(2).add(3); + +s.forEach(function(value, entry, set) { + var expect = expects.shift(); + + assert.sameValue(value, expect); + assert.sameValue(entry, expect); + assert.sameValue(set, s); +}); + +assert.sameValue(expects.length, 0, "The value of `expects.length` is `0`"); diff --git a/test/sendable/builtins/Set/prototype/forEach/iterates-in-iterable-entry-order.js b/test/sendable/builtins/Set/prototype/forEach/iterates-in-iterable-entry-order.js new file mode 100644 index 0000000000000000000000000000000000000000..0fa445eed174893a9f31a9fdddc2ad353a09c130 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/iterates-in-iterable-entry-order.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 7. Repeat for each e that is an element of entries, in original insertion order + a. If e is not empty, then + i. Let funcResult be Call(callbackfn, T, «e, e, S»). + ii. ReturnIfAbrupt(funcResult). + ... +---*/ + +var expects = [1, 2, 3]; +var s = new SendableSet(expects); + +s.forEach(function(value, entry, set) { + var expect = expects.shift(); + + assert.sameValue(value, expect); + assert.sameValue(entry, expect); + assert.sameValue(set, s); +}); + +assert.sameValue(expects.length, 0, "The value of `expects.length` is `0`"); diff --git a/test/sendable/builtins/Set/prototype/forEach/iterates-values-added-after-foreach-begins.js b/test/sendable/builtins/Set/prototype/forEach/iterates-values-added-after-foreach-begins.js new file mode 100644 index 0000000000000000000000000000000000000000..fa7b446dbc9b2cb3ca8eb45c771c1091fe7abed9 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/iterates-values-added-after-foreach-begins.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 7. Repeat for each e that is an element of entries, in original insertion order + a. If e is not empty, then + i. Let funcResult be Call(callbackfn, T, «e, e, S»). + ii. ReturnIfAbrupt(funcResult). + ... + + NOTE: + + ... + New values added after the call to forEach begins are visited. + +---*/ + + +var s = new SendableSet([1]); +var expects = [1, 2, 3]; + +s.forEach(function(value, entry, set) { + var expect = expects.shift(); + + if (value === 1) { + set.add(2); + } + + if (value === 2) { + set.add(3); + } + + assert.sameValue(value, expect); + assert.sameValue(entry, expect); + assert.sameValue(set, s); +}); + +assert.sameValue(expects.length, 0, "The value of `expects.length` is `0`"); diff --git a/test/sendable/builtins/Set/prototype/forEach/iterates-values-deleted-then-readded.js b/test/sendable/builtins/Set/prototype/forEach/iterates-values-deleted-then-readded.js new file mode 100644 index 0000000000000000000000000000000000000000..4ccca0f109b7420131f695179c8ac593704f25a6 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/iterates-values-deleted-then-readded.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 7. Repeat for each e that is an element of entries, in original insertion order + a. If e is not empty, then + i. Let funcResult be Call(callbackfn, T, «e, e, S»). + ii. ReturnIfAbrupt(funcResult). + ... + + NOTE: + + ... + Values that are deleted after the call to forEach begins and before being visited are not visited unless the value is added again before the forEach call completes. + ... + +---*/ + + +var s = new SendableSet([1, 2, 3]); +var expects = [1, 3, 2]; + +s.forEach(function(value, entry, set) { + var expect = expects.shift(); + + // Delete `2` before being visited + if (value === 1) { + set.delete(2); + } + + // Re-add `2` before forEach call completes + if (value === 3) { + set.add(2); + } + + assert.sameValue(value, expect); + assert.sameValue(entry, expect); + assert.sameValue(set, s); +}); + +assert.sameValue(expects.length, 0, "The value of `expects.length` is `0`"); diff --git a/test/sendable/builtins/Set/prototype/forEach/iterates-values-not-deleted.js b/test/sendable/builtins/Set/prototype/forEach/iterates-values-not-deleted.js new file mode 100644 index 0000000000000000000000000000000000000000..2767432cfcdc3823f10934b2835fbc2e3237f60b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/iterates-values-not-deleted.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 7. Repeat for each e that is an element of entries, in original insertion order + a. If e is not empty, then + i. Let funcResult be Call(callbackfn, T, «e, e, S»). + ii. ReturnIfAbrupt(funcResult). + ... + + NOTE: + + callbackfn should be a function that accepts three arguments. forEach calls callbackfn once for each value present in the set object, in value insertion order. callbackfn is called only for values of the SendableSet which actually exist; it is not called for keys that have been deleted from the set. + +---*/ + +var expects = [1, 3]; +var s = new SendableSet([1, 2, 3]); + +s.delete(2); + +s.forEach(function(value, entry, set) { + var expect = expects.shift(); + + assert.sameValue(value, expect); + assert.sameValue(entry, expect); + assert.sameValue(set, s); +}); + +assert.sameValue(expects.length, 0, "`forEach` is not a no-op"); diff --git a/test/sendable/builtins/Set/prototype/forEach/iterates-values-revisits-after-delete-re-add.js b/test/sendable/builtins/Set/prototype/forEach/iterates-values-revisits-after-delete-re-add.js new file mode 100644 index 0000000000000000000000000000000000000000..daa7c929a958973511180f416751bcb4fa8fc0b5 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/iterates-values-revisits-after-delete-re-add.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 7. Repeat for each e that is an element of entries, in original insertion order + a. If e is not empty, then + i. Let funcResult be Call(callbackfn, T, «e, e, S»). + ii. ReturnIfAbrupt(funcResult). + ... + + NOTE: + + ... + a value will be revisited if it is deleted after it has been visited and then re-added before the forEach call completes. + ... + +---*/ + + +var s = new SendableSet([1, 2, 3]); +var expects = [1, 2, 3, 1]; + +s.forEach(function(value, entry, set) { + var expect = expects.shift(); + + // Delete `1` after visit + if (value === 2) { + set.delete(1); + } + + // Re-add `1` + if (value === 3) { + set.add(1); + } + + assert.sameValue(value, expect); + assert.sameValue(entry, expect); + assert.sameValue(set, s); +}); + +assert.sameValue(expects.length, 0, "The value of `expects.length` is `0`"); diff --git a/test/sendable/builtins/Set/prototype/forEach/length.js b/test/sendable/builtins/Set/prototype/forEach/length.js new file mode 100644 index 0000000000000000000000000000000000000000..f7b8588716cbf47b92a3780a625830eff0a4a1e2 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + The length property of the forEach method is 1. + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.forEach, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/name.js b/test/sendable/builtins/Set/prototype/forEach/name.js new file mode 100644 index 0000000000000000000000000000000000000000..03403b140235a40730557f509560baab7b608c1f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.forEach, "name", { + value: "forEach", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/not-a-constructor.js b/test/sendable/builtins/Set/prototype/forEach/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..6f8fc4228db5a6fe669e401a688b1c3b199afbf4 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableSet.prototype.forEach does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableSet, arrow-function] +---*/ + +assert.sameValue( + isConstructor(SendableSet.prototype.forEach), + false, + 'isConstructor(SendableSet.prototype.forEach) must return false' +); + +assert.throws(TypeError, () => { + let s = new SendableSet([]); new s.forEach(() => {}); +}); + diff --git a/test/sendable/builtins/Set/prototype/forEach/returns-undefined.js b/test/sendable/builtins/Set/prototype/forEach/returns-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..5a1576f4c7b76c9e8a4ee18f6f9b80b2df527350 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/returns-undefined.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 8. Return undefined. + +---*/ + +var s = new SendableSet([1]); + +assert.sameValue( + s.forEach(function() {}), + undefined, + "`s.forEach(function() {})` returns `undefined`" +); diff --git a/test/sendable/builtins/Set/prototype/forEach/this-arg-explicit-cannot-override-lexical-this-arrow.js b/test/sendable/builtins/Set/prototype/forEach/this-arg-explicit-cannot-override-lexical-this-arrow.js new file mode 100644 index 0000000000000000000000000000000000000000..08282ffb96ee54cb0586dda3cf2ab21f433a29b2 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/this-arg-explicit-cannot-override-lexical-this-arrow.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + + An arrow function will ignore an explicit thisArg + +features: [arrow-function] +---*/ + +var s = new SendableSet([1]); +var usurper = {}; +var counter = 0; + +s.forEach(_ => { + assert.notSameValue(this, usurper, "`this` is not `usurper`"); + counter++; +}, usurper); + +assert.sameValue(counter, 1, "`forEach` is not a no-op"); diff --git a/test/sendable/builtins/Set/prototype/forEach/this-arg-explicit.js b/test/sendable/builtins/Set/prototype/forEach/this-arg-explicit.js new file mode 100644 index 0000000000000000000000000000000000000000..43ce1da84f4f87fbea7fff759c7368c023f95c57 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/this-arg-explicit.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... +---*/ + +var s = new SendableSet([1]); +var thisArg = {}; +var counter = 0; + +s.forEach(function() { + assert.sameValue(this, thisArg, "`this` is `thisArg`"); + counter++; +}, thisArg); + +assert.sameValue(counter, 1, "`forEach` is not a no-op"); diff --git a/test/sendable/builtins/Set/prototype/forEach/this-non-strict.js b/test/sendable/builtins/Set/prototype/forEach/this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..dde323167ebc6a8515dc715330d37c7c6148f7d0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/this-non-strict.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + +flags: [noStrict] +---*/ + +var s = new SendableSet([1]); +var counter = 0; +var globalObject = this; + +s.forEach(function() { + assert.sameValue(this, globalObject, "`this` is the global object in non-strict mode code"); + counter++; +}); + +assert.sameValue(counter, 1, "`forEach` is not a no-op"); diff --git a/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-boolean.js b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..940b55d236ac001c589f219fb6a6f3e1faae715c --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-boolean.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.forEach.call(false, function() {}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.forEach.call(false, function() {}); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-null.js b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-null.js new file mode 100644 index 0000000000000000000000000000000000000000..a950acb119a022356f4fea4dbf3bd341056646f5 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-null.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.forEach.call(null, function() {}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.forEach.call(null, function() {}); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-number.js b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-number.js new file mode 100644 index 0000000000000000000000000000000000000000..e01b1678e0d7c00fc45cad4a1c8d8361176fc842 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-number.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.forEach.call(0, function() {}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.forEach.call(0, function() {}); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-string.js b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-string.js new file mode 100644 index 0000000000000000000000000000000000000000..ae9fcaf44ea8f8356ad4905da7d04d0685fa5d3e --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-string.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.forEach.call("", function() {}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.forEach.call("", function() {}); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-symbol.js b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..5753fcfbfec0c7446b90dbcf8b3780edec741531 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-symbol.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.forEach.call(Symbol(), function() {}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.forEach.call(Symbol(), function() {}); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-undefined.js b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..fe6984b13cec59daa149997bd4525a2b07491243 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/this-not-object-throw-undefined.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.forEach.call(undefined, function() {}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.forEach.call(undefined, function() {}); +}); diff --git a/test/sendable/builtins/Set/prototype/forEach/this-strict.js b/test/sendable/builtins/Set/prototype/forEach/this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..9d582c84281ea6b327c2f9447213edaf50e2fb64 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/this-strict.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + +flags: [onlyStrict] +---*/ + +var s = new SendableSet([1]); +var counter = 0; + +s.forEach(function() { + assert.sameValue(this, undefined, "`this` is `undefined` in strict mode code"); + counter++; +}); + +assert.sameValue(counter, 1, "`forEach` is not a no-op"); diff --git a/test/sendable/builtins/Set/prototype/forEach/throws-when-callback-throws.js b/test/sendable/builtins/Set/prototype/forEach/throws-when-callback-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..86154b336ab7081226624d97c916f5c1a374b18c --- /dev/null +++ b/test/sendable/builtins/Set/prototype/forEach/throws-when-callback-throws.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.forEach +description: > + SendableSet.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 7. Repeat for each e that is an element of entries, in original insertion order + a. If e is not empty, then + i. Let funcResult be Call(callbackfn, T, «e, e, S»). + ii. ReturnIfAbrupt(funcResult). + ... +---*/ + +var s = new SendableSet([1]); +var counter = 0; + +assert.throws(Error, function() { + s.forEach(function() { + counter++; + throw new Error(); + }); +}); + +assert.sameValue(counter, 1, "`forEach` is not a no-op"); diff --git a/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-array.js b/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-array.js new file mode 100644 index 0000000000000000000000000000000000000000..87c7d0efbf62592800695cb9a78922532818906b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-array.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.has.call([], 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.has.call([], 1); +}); diff --git a/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-map.js b/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-map.js new file mode 100644 index 0000000000000000000000000000000000000000..c1073821814d386beb20b68c9ff2d7ad667e0523 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-map.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.has.call(new Map(), 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.has.call(new Map(), 1); +}); diff --git a/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-object.js b/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-object.js new file mode 100644 index 0000000000000000000000000000000000000000..5fba9aa1c7f2f40b704587067225acb12968ebea --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-object.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.has.call({}, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.has.call({}, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-set-prototype.js b/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-set-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..d8f2c393de195556e93613bb2fd347ba36a639e0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-set-prototype.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.has.call(SendableSet.prototype, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.has.call(SendableSet.prototype, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-weakset.js b/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-weakset.js new file mode 100644 index 0000000000000000000000000000000000000000..6bc5aa4f9d2e936ae43e5d51256c28ca4a5c8d00 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/does-not-have-setdata-internal-slot-weakset.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 3. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +features: [WeakSet] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.has.call(new WeakSet(), 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.has.call(new WeakSet(), 1); +}); diff --git a/test/sendable/builtins/Set/prototype/has/has.js b/test/sendable/builtins/Set/prototype/has/has.js new file mode 100644 index 0000000000000000000000000000000000000000..46f8bec3e07ddc10b6ddeebeba6fdd61e4c96200 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/has.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.has, + "function", + "`typeof SendableSet.prototype.has` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "has", { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/has/length.js b/test/sendable/builtins/Set/prototype/has/length.js new file mode 100644 index 0000000000000000000000000000000000000000..9e09aa7437b61e4fa41f0f2676caa4cb6de0ded3 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.has, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/has/name.js b/test/sendable/builtins/Set/prototype/has/name.js new file mode 100644 index 0000000000000000000000000000000000000000..9e74f521fc80918570b0e274c55d1807c9e945cd --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.has, "name", { + value: "has", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/has/not-a-constructor.js b/test/sendable/builtins/Set/prototype/has/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..2f31c55be188da724d8bfdbda22a8e2b821a6253 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableSet.prototype.has does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableSet, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableSet.prototype.has), false, 'isConstructor(SendableSet.prototype.has) must return false'); + +assert.throws(TypeError, () => { + let s = new SendableSet([]); new s.has(); +}); + diff --git a/test/sendable/builtins/Set/prototype/has/returns-false-when-undefined-added-deleted-not-present-undefined.js b/test/sendable/builtins/Set/prototype/has/returns-false-when-undefined-added-deleted-not-present-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..5a0820b39b8d31596a8b2085f2b50fe1d4704514 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-false-when-undefined-added-deleted-not-present-undefined.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 6. Return false. + +---*/ + +var s = new SendableSet(); + +s.add(undefined); +assert.sameValue(s.has(undefined), true, "`s.has(undefined)` returns `true`"); + +var result = s.delete(undefined); + +assert.sameValue(s.has(undefined), false, "`s.has(undefined)` returns `false`"); +assert.sameValue(result, true, "The result of `s.delete(undefined)` is `true`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-boolean.js b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..98f86b93646cd8b86cca781fc068cd0a26322693 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-boolean.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 6. Return false. + +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.has(false), false, "`s.has(false)` returns `false`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-nan.js b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-nan.js new file mode 100644 index 0000000000000000000000000000000000000000..1470a16acd939207f2877aef8f7c39b1c24b05b0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-nan.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 6. Return false. + +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.has(NaN), false, "`s.has(NaN)` returns `false`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-null.js b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-null.js new file mode 100644 index 0000000000000000000000000000000000000000..d02f56130137f1944270a3bf5c7dc5418f34d637 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-null.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 6. Return false. + +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.has(null), false, "`s.has(null)` returns `false`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-number.js b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-number.js new file mode 100644 index 0000000000000000000000000000000000000000..d66e1209ddfed39bc8ae0f8ca06b67980f99f56b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-number.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 6. Return false. + +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.has(0), false, "`s.has(0)` returns `false`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-string.js b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-string.js new file mode 100644 index 0000000000000000000000000000000000000000..9f58e14d8c2e4efeda6de4bc6b82b58d1ee121ff --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-string.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 6. Return false. + +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.has(""), false, "`s.has('')` returns `false`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-symbol.js b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..787a0c9f9910e3759f1737c25e515f0190f54262 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-symbol.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 6. Return false. + +features: [Symbol] +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.has(Symbol()), false, "`s.has(Symbol())` returns `false`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-undefined.js b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..f1478c7e1056bc1846475617dcab7913f577f43a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-false-when-value-not-present-undefined.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 6. Return false. + +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.has(undefined), false, "`s.has(undefined)` returns `false`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-boolean.js b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..50ad841e00b418fce38749a02c1a44e7b3560f5c --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-boolean.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, return true. + ... + +---*/ + +var s = new SendableSet(); + +s.add(false) + +assert.sameValue(s.has(false), true, "`s.has(false)` returns `true`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-nan.js b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-nan.js new file mode 100644 index 0000000000000000000000000000000000000000..a9c3fe13fd4679af71d8a7aece2999e5266be456 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-nan.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, return true. + ... + +---*/ + +var s = new SendableSet(); + +s.add(NaN) + +assert.sameValue(s.has(NaN), true, "`s.has(NaN)` returns `true`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-null.js b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-null.js new file mode 100644 index 0000000000000000000000000000000000000000..78b5b18b9e07d2b648badbc7b033dc977ae6ff83 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-null.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, return true. + ... + +---*/ + +var s = new SendableSet(); + +s.add(null) + +assert.sameValue(s.has(null), true, "`s.has(null)` returns `true`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-number.js b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-number.js new file mode 100644 index 0000000000000000000000000000000000000000..8f8538d0d1e5f35ecaa287c8e1da8aa46820d3a3 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-number.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, return true. + ... + +---*/ + +var s = new SendableSet(); + +s.add(0) + +assert.sameValue(s.has(0), true, "`s.has(0)` returns `true`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-string.js b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-string.js new file mode 100644 index 0000000000000000000000000000000000000000..84a5aa32c623ab42f9f4525cf8acf385ff2b24d4 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-string.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, return true. + ... + +---*/ + +var s = new SendableSet(); + +s.add("") + +assert.sameValue(s.has(""), true, "`s.has('')` returns `true`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-symbol.js b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..9cdae26056c6e0f84055176330e955ccba8f4580 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-symbol.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, return true. + ... + +features: [Symbol] +---*/ + +var s = new SendableSet(); +var a = Symbol(); + +s.add(a) + +assert.sameValue(s.has(a), true, "`s.has(a)` returns `true`"); diff --git a/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-undefined.js b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..8b2c4212f509802ea9bada71358c35602a9a1476 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/returns-true-when-value-present-undefined.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + ... + 5. Repeat for each e that is an element of entries, + a. If e is not empty and SameValueZero(e, value) is true, return true. + ... + +---*/ + +var s = new SendableSet(); + +s.add(undefined) + +assert.sameValue(s.has(undefined), true, "`s.has(undefined)` returns `true`"); diff --git a/test/sendable/builtins/Set/prototype/has/this-not-object-throw-boolean.js b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..d608b2adf6162d8c73f395d69745c06e26e35f56 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-boolean.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.has.call(false, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.has.call(false, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/has/this-not-object-throw-null.js b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-null.js new file mode 100644 index 0000000000000000000000000000000000000000..5fb249b0c495284c3b015bd98ed7380ec3dbe165 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-null.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.has.call(null, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.has.call(null, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/has/this-not-object-throw-number.js b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-number.js new file mode 100644 index 0000000000000000000000000000000000000000..75415ba482c4eeb33e7a43efe81708af689ff419 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-number.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.has.call(0, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.has.call(0, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/has/this-not-object-throw-string.js b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-string.js new file mode 100644 index 0000000000000000000000000000000000000000..0f1f25e7603b05fe2480a7e23a9c32f73b7608eb --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-string.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.has.call("", 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.has.call("", 1); +}); diff --git a/test/sendable/builtins/Set/prototype/has/this-not-object-throw-symbol.js b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..6917d6a2c70b775fe45c71e63cf1dccfd39f70ea --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-symbol.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.has.call(Symbol(), 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.has.call(Symbol(), 1); +}); diff --git a/test/sendable/builtins/Set/prototype/has/this-not-object-throw-undefined.js b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..0fef31de421314eb409003e34870f9f81e30e137 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/has/this-not-object-throw-undefined.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.has +description: > + SendableSet.prototype.has ( value ) + + 1. Let S be the this value. + 2. If Type(S) is not Object, throw a TypeError exception. + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.has.call(undefined, 1); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.has.call(undefined, 1); +}); diff --git a/test/sendable/builtins/Set/prototype/intersection/add-not-called.js b/test/sendable/builtins/Set/prototype/intersection/add-not-called.js new file mode 100644 index 0000000000000000000000000000000000000000..386b0bb2f7074190bd5944e24efabb5e09dd7cb7 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/add-not-called.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection should not call SendableSet.prototype.add +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [2]; + +const originalAdd = SendableSet.prototype.add; +let count = 0; +SendableSet.prototype.add = function (...rest) { + count++; + return originalAdd.apply(this, rest); +}; + +const combined = s1.intersection(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(count, 0, "Add is never called"); + +SendableSet.prototype.add = originalAdd; diff --git a/test/sendable/builtins/Set/prototype/intersection/allows-set-like-class.js b/test/sendable/builtins/Set/prototype/intersection/allows-set-like-class.js new file mode 100644 index 0000000000000000000000000000000000000000..b82cf713e207d9e9cbf8679755616b67632293a4 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/allows-set-like-class.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: GetSendableSetRecord allows instances of SendableSet-like classes +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new class { + get size() { + return 2; + } + has(v) { + if (v === 1) return false; + if (v === 2) return true; + throw new Test262Error("SendableSet.prototype.intersection should only call its argument's has method with contents of this"); + } + * keys() { + throw new Test262Error("SendableSet.prototype.intersection should not call its argument's keys iterator when this.size ≤ arg.size"); + } +}; +const expected = [2]; +const combined = s1.intersection(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/intersection/allows-set-like-object.js b/test/sendable/builtins/Set/prototype/intersection/allows-set-like-object.js new file mode 100644 index 0000000000000000000000000000000000000000..0fd6e9161b30c3ee364a8cda1dfaef487da349e2 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/allows-set-like-object.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: GetSendableSetRecord allows SendableSet-like objects +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: (v) => { + if (v === 1) return false; + if (v === 2) return true; + throw new Test262Error("SendableSet.prototype.intersection should only call its argument's has method with contents of this"); + }, + keys: function* keys() { + throw new Test262Error("SendableSet.prototype.intersection should not call its argument's keys iterator when this.size ≤ arg.size"); + }, +}; +const expected = [2]; +const combined = s1.intersection(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/intersection/array-throws.js b/test/sendable/builtins/Set/prototype/intersection/array-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..5230342676f9a5ecec998e6675d9b422818dbfa5 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/array-throws.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection doesn't work with arrays +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [3]; +assert.throws( + TypeError, + function () { + s1.intersection(s2); + }, + "Throws an error when an array is used" +); diff --git a/test/sendable/builtins/Set/prototype/intersection/builtins.js b/test/sendable/builtins/Set/prototype/intersection/builtins.js new file mode 100644 index 0000000000000000000000000000000000000000..6bc43c900d993116db51000f46115674754a080f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/builtins.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: Tests that SendableSet.prototype.intersection meets the requirements for built-in objects +features: [set-methods] +---*/ + +assert.sameValue( + Object.isExtensible(SendableSet.prototype.intersection), + true, + "Built-in objects must be extensible." +); + +assert.sameValue( + Object.prototype.toString.call(SendableSet.prototype.intersection), + "[object Function]", + "Object.prototype.toString" +); + +assert.sameValue( + Object.getPrototypeOf(SendableSet.prototype.intersection), + Function.prototype, + "prototype" +); diff --git a/test/sendable/builtins/Set/prototype/intersection/called-with-object.js b/test/sendable/builtins/Set/prototype/intersection/called-with-object.js new file mode 100644 index 0000000000000000000000000000000000000000..ee028f9b999e0dc8c05a84eec18ae7a2967339f5 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/called-with-object.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws if obj is not an object +info: | + 1. If obj is not an Object, throw a TypeError exception. +features: [set-methods] +---*/ + +let s1 = new SendableSet([1]); +assert.throws( + TypeError, + function () { + s1.intersection(1); + }, + "number" +); + +assert.throws( + TypeError, + function () { + s1.intersection(""); + }, + "string" +); + +assert.throws( + TypeError, + function () { + s1.intersection(1n); + }, + "bigint" +); + +assert.throws( + TypeError, + function () { + s1.intersection(false); + }, + "boolean" +); + +assert.throws( + TypeError, + function () { + s1.intersection(undefined); + }, + "undefined" +); + +assert.throws( + TypeError, + function () { + s1.intersection(null); + }, + "null" +); + +assert.throws( + TypeError, + function () { + s1.intersection(Symbol("test")); + }, + "symbol" +); diff --git a/test/sendable/builtins/Set/prototype/intersection/combines-Map.js b/test/sendable/builtins/Set/prototype/intersection/combines-Map.js new file mode 100644 index 0000000000000000000000000000000000000000..4342019e76d7ff68053048e96b486ebf578d43bb --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/combines-Map.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection combines with Map +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const m1 = new Map([ + [2, "two"], + [3, "three"], +]); +const expected = [2]; +const combined = s1.intersection(m1); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/intersection/combines-empty-sets.js b/test/sendable/builtins/Set/prototype/intersection/combines-empty-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..1ce0361fbc3b19ef72517e7d7e352867eac5e0ed --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/combines-empty-sets.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection can combine empty SendableSets +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([]); +const s2 = new SendableSet([1, 2]); +let expected = []; +let combined = s1.intersection(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); + +const s3 = new SendableSet([1, 2]); +const s4 = new SendableSet([]); +expected = []; +combined = s3.intersection(s4); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); + +const s5 = new SendableSet([]); +const s6 = new SendableSet([]); +expected = []; +combined = s5.intersection(s6); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/intersection/combines-itself.js b/test/sendable/builtins/Set/prototype/intersection/combines-itself.js new file mode 100644 index 0000000000000000000000000000000000000000..7a8bdec212fc2a0ee4f033083b371205503fd4a0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/combines-itself.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection is successful when called on itself +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const expected = [1, 2]; +const combined = s1.intersection(s1); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(combined === s1, false, "The returned object is a new object"); diff --git a/test/sendable/builtins/Set/prototype/intersection/combines-same-sets.js b/test/sendable/builtins/Set/prototype/intersection/combines-same-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..f0f4f5abed6182fb93546c0bcd5079a976d1d777 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/combines-same-sets.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection can combine SendableSets that have the same content +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([1, 2]); +const expected = [1, 2]; +const combined = s1.intersection(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(combined === s1, false, "The returned object is a new object"); +assert.sameValue(combined === s2, false, "The returned object is a new object"); diff --git a/test/sendable/builtins/Set/prototype/intersection/combines-sets.js b/test/sendable/builtins/Set/prototype/intersection/combines-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..e4812f82d1d30fe702e497343af8526497fda27d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/combines-sets.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection combines SendableSets +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [2]; +const combined = s1.intersection(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/intersection/converts-negative-zero.js b/test/sendable/builtins/Set/prototype/intersection/converts-negative-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..b26d07f881d34c6973480336e948a1b285471cdc --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/converts-negative-zero.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection converts -0𝔽 to +0𝔽 +info: | + 7.c.ii.2 If nextValue is -0𝔽, set nextValue to +0𝔽. +features: [set-methods] +includes: [compareArray.js] +---*/ + +const setlikeWithMinusZero = { + size: 1, + has: function () { + throw new Test262Error("SendableSet.prototype.intersection should not invoke .has on its argument when this.size > arg.size"); + }, + keys: function () { + // we use an array here because the SendableSet constructor would normalize away -0 + return [-0].values(); + }, +}; + +const s1 = new SendableSet([0, 1, 2]); +let expected = [+0]; +let combined = s1.intersection(setlikeWithMinusZero); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/intersection/has-is-callable.js b/test/sendable/builtins/Set/prototype/intersection/has-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..85fa2085efc0724e8802bbdb8df87c801579f8b0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/has-is-callable.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'has' property is not callable +info: | + 7. Let has be ? Get(obj, "has"). + 8. If IsCallable(has) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: undefined, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.intersection(s2); + }, + "GetSendableSetRecord throws an error when has is undefined" +); + +s2.has = {}; +assert.throws( + TypeError, + function () { + s1.intersection(s2); + }, + "GetSendableSetRecord throws an error when has is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/intersection/intersection.js b/test/sendable/builtins/Set/prototype/intersection/intersection.js new file mode 100644 index 0000000000000000000000000000000000000000..d9016d3b6d10f8afe9f051b1f39ebbe48d7d222c --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/intersection.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection properties +includes: [propertyHelper.js] +features: [set-methods] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.intersection, + "function", + "`typeof SendableSet.prototype.intersection` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "intersection", { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/intersection/keys-is-callable.js b/test/sendable/builtins/Set/prototype/intersection/keys-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..09dcf0cfc523ef4a543cacc4584c2c7e3df2cfbe --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/keys-is-callable.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'keys' property is not callable +info: | + 9. Let keys be ? Get(obj, "keys"). + 10. If IsCallable(keys) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: () => {}, + keys: undefined, +}; +assert.throws( + TypeError, + function () { + s1.intersection(s2); + }, + "GetSendableSetRecord throws an error when keys is undefined" +); + +s2.keys = {}; +assert.throws( + TypeError, + function () { + s1.intersection(s2); + }, + "GetSendableSetRecord throws an error when keys is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/intersection/length.js b/test/sendable/builtins/Set/prototype/intersection/length.js new file mode 100644 index 0000000000000000000000000000000000000000..987980e623f3be8d62394f8e0939258b85f1eb26 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection length property +info: | + SendableSet.prototype.intersection ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.intersection, "function"); + +verifyProperty(SendableSet.prototype.intersection, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1, +}); diff --git a/test/sendable/builtins/Set/prototype/intersection/name.js b/test/sendable/builtins/Set/prototype/intersection/name.js new file mode 100644 index 0000000000000000000000000000000000000000..fafb674c2eefec444cd3fa1e778ca0d6fa3481e0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection name property +info: | + SendableSet.prototype.intersection ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.intersection, "function"); + +verifyProperty(SendableSet.prototype.intersection, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "intersection", +}); diff --git a/test/sendable/builtins/Set/prototype/intersection/not-a-constructor.js b/test/sendable/builtins/Set/prototype/intersection/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..71b0351bbe09c575b03c404caaacbcaf6d3b00c9 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/not-a-constructor.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection does not implement [[Construct]], is not new-able +includes: [isConstructor.js] +features: [Reflect.construct, set-methods] +---*/ + +assert.sameValue( + isConstructor(SendableSet.prototype.intersection), + false, + "isConstructor(SendableSet.prototype.intersection) must return false" +); + +assert.throws( + TypeError, + () => { + new SendableSet.prototype.intersection(); + }); diff --git a/test/sendable/builtins/Set/prototype/intersection/receiver-not-set.js b/test/sendable/builtins/Set/prototype/intersection/receiver-not-set.js new file mode 100644 index 0000000000000000000000000000000000000000..fbd7d8116c5db6ee2a7e3120a02b0b5fdb07c623 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/receiver-not-set.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection throws when receiver is not a SendableSet +features: [set-methods] +---*/ + +class MySendableSetLike { + constructor() { + this.size = 2; + this.has = () => {}; + this.keys = function* keys() { + yield 2; + yield 3; + }; + } +} + +const s1 = new MySendableSetLike(); +const s2 = new SendableSet(); +assert.throws( + TypeError, + () => { + SendableSet.prototype.intersection.call(s1, s2); + }, + "SendableSet-like class" +); + +const s3 = { + size: 2, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + () => { + SendableSet.prototype.intersection.call(s3, s2); + }, + "SendableSet-like object" +); diff --git a/test/sendable/builtins/Set/prototype/intersection/require-internal-slot.js b/test/sendable/builtins/Set/prototype/intersection/require-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..1567f753e30d5b24ff8515ef0e3e71c7b8499f6e --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/require-internal-slot.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection RequireInternalSlot +info: | + 2. Perform ? RequireInternalSlot(O, [[SendableSetData]]) +features: [set-methods] +---*/ + +const intersection = SendableSet.prototype.intersection; + +assert.sameValue(typeof intersection, "function"); + +const realSendableSet = new SendableSet([]); + +assert.throws(TypeError, () => intersection.call(undefined, realSendableSet), "undefined"); +assert.throws(TypeError, () => intersection.call(null, realSendableSet), "null"); +assert.throws(TypeError, () => intersection.call(true, realSendableSet), "true"); +assert.throws(TypeError, () => intersection.call("", realSendableSet), "empty string"); +assert.throws(TypeError, () => intersection.call(Symbol(), realSendableSet), "symbol"); +assert.throws(TypeError, () => intersection.call(1, realSendableSet), "1"); +assert.throws(TypeError, () => intersection.call(1n, realSendableSet), "1n"); +assert.throws(TypeError, () => intersection.call({}, realSendableSet), "plain object"); +assert.throws(TypeError, () => intersection.call([], realSendableSet), "array"); +assert.throws(TypeError, () => intersection.call(new Map(), realSendableSet), "map"); +assert.throws(TypeError, () => intersection.call(SendableSet.prototype, realSendableSet), "SendableSet.prototype"); diff --git a/test/sendable/builtins/Set/prototype/intersection/result-order.js b/test/sendable/builtins/Set/prototype/intersection/result-order.js new file mode 100644 index 0000000000000000000000000000000000000000..49af585cab46310abf20093d19a4da7a240f18c9 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/result-order.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection result ordering +features: [set-methods] +includes: [compareArray.js] +---*/ + +// when this.size ≤ other.size, results are ordered as in this +{ + const s1 = new SendableSet([1, 3, 5]); + const s2 = new SendableSet([3, 2, 1]); + + assert.compareArray([...s1.intersection(s2)], [1, 3]); +} + +{ + const s1 = new SendableSet([3, 2, 1]); + const s2 = new SendableSet([1, 3, 5]); + + assert.compareArray([...s1.intersection(s2)], [3, 1]); +} + +{ + const s1 = new SendableSet([1, 3, 5]); + const s2 = new SendableSet([3, 2, 1, 0]); + + assert.compareArray([...s1.intersection(s2)], [1, 3]); +} + +{ + const s1 = new SendableSet([3, 2, 1]); + const s2 = new SendableSet([1, 3, 5, 7]); + + assert.compareArray([...s1.intersection(s2)], [3, 1]); +} + + +// when this.size > other.size, results are ordered as in other +{ + const s1 = new SendableSet([3, 2, 1, 0]); + const s2 = new SendableSet([1, 3, 5]); + + assert.compareArray([...s1.intersection(s2)], [1, 3]); +} + +{ + const s1 = new SendableSet([1, 3, 5, 7]); + const s2 = new SendableSet([3, 2, 1]); + + assert.compareArray([...s1.intersection(s2)], [3, 1]); +} diff --git a/test/sendable/builtins/Set/prototype/intersection/set-like-array.js b/test/sendable/builtins/Set/prototype/intersection/set-like-array.js new file mode 100644 index 0000000000000000000000000000000000000000..656e161295a66ba6721ee72ed8562119df8c311a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/set-like-array.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection consumes a set-like array as a set-like, not an array +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [5, 6]; +s2.size = 3; +s2.has = function (v) { + if (v === 1) return false; + if (v === 2) return true; + throw new Test262Error("SendableSet.prototype.intersection should only call its argument's has method with contents of this"); +}; +s2.keys = function () { + throw new Test262Error("SendableSet.prototype.intersection should not call its argument's keys iterator when this.size ≤ arg.size"); +}; + +const expected = [2]; +const combined = s1.intersection(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/intersection/set-like-class-mutation.js b/test/sendable/builtins/Set/prototype/intersection/set-like-class-mutation.js new file mode 100644 index 0000000000000000000000000000000000000000..491405f6f038452f9ee3f71c525e831ce8ee65a4 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/set-like-class-mutation.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection maintains values even when a custom SendableSet-like class mutates the receiver +features: [set-methods] +includes: [compareArray.js] +---*/ + +const baseSendableSet = new SendableSet(["a", "b", "c", "d", "e"]); + +function mutatingIterator() { + let index = 0; + let values = ["x", "b", "b"]; + return { + next() { + if (index === 0) { + baseSendableSet.delete("b"); + baseSendableSet.delete("c"); + baseSendableSet.add("b"); + baseSendableSet.add("d"); + } + return { + done: index >= values.length, + value: values[index++], + }; + }, + }; +} + +const evilSendableSetLike = { + size: 3, + get has() { + baseSendableSet.add("q"); + return function () { + throw new Test262Error("SendableSet.prototype.intersection should not invoke .has on its argument when this.size > other.size"); + }; + }, + keys() { + return mutatingIterator(); + }, +}; + +const combined = baseSendableSet.intersection(evilSendableSetLike); +const expectedCombined = ["b"]; +assert.compareArray([...combined], expectedCombined); + +const expectedNewBase = ["a", "d", "e", "q", "b"]; +assert.compareArray([...baseSendableSet], expectedNewBase); diff --git a/test/sendable/builtins/Set/prototype/intersection/set-like-class-order.js b/test/sendable/builtins/Set/prototype/intersection/set-like-class-order.js new file mode 100644 index 0000000000000000000000000000000000000000..b2237ee3bb6addcf54bb6aaa0f7ddecbb6fe9238 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/set-like-class-order.js @@ -0,0 +1,153 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection calls a SendableSet-like class's methods in order +features: [set-methods] +includes: [compareArray.js] +---*/ + +let observedOrder = []; + +function observableIterator() { + let values = ["a", "b", "c"]; + let index = 0; + return { + get next() { + observedOrder.push("getting next"); + return function () { + observedOrder.push("calling next"); + return { + get done() { + observedOrder.push("getting done"); + return index >= values.length; + }, + get value() { + observedOrder.push("getting value"); + return values[index++]; + }, + }; + }; + }, + }; +} + +class MySendableSetLike { + get size() { + observedOrder.push("getting size"); + return { + valueOf: function () { + observedOrder.push("ToNumber(size)"); + return 3; + }, + }; + } + get has() { + observedOrder.push("getting has"); + return function (v) { + observedOrder.push("calling has"); + return ["a", "b", "c"].indexOf(v) !== -1; + }; + } + get keys() { + observedOrder.push("getting keys"); + return function () { + observedOrder.push("calling keys"); + return observableIterator(); + }; + } +} + +// this is smaller than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "d"]); + const s2 = new MySendableSetLike(); + const combined = s1.intersection(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // two calls to has + "calling has", + "calling has", + ]; + + assert.compareArray([...combined], ["a"]); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is same size as argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "d"]); + const s2 = new MySendableSetLike(); + const combined = s1.intersection(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // three calls to has + "calling has", + "calling has", + "calling has", + ]; + + assert.compareArray([...combined], ["a", "b"]); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is larger than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "c", "d"]); + const s2 = new MySendableSetLike(); + const combined = s1.intersection(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + "calling keys", + "getting next", + // first iteration, has value + "calling next", + "getting done", + "getting value", + // second iteration, has value + "calling next", + "getting done", + "getting value", + // third iteration, has value + "calling next", + "getting done", + "getting value", + // fourth iteration, no value; ends + "calling next", + "getting done", + ]; + + assert.compareArray([...combined], ["a", "b", "c"]); + assert.compareArray(observedOrder, expectedOrder); +} diff --git a/test/sendable/builtins/Set/prototype/intersection/size-is-a-number.js b/test/sendable/builtins/Set/prototype/intersection/size-is-a-number.js new file mode 100644 index 0000000000000000000000000000000000000000..950d3a32bb3a8e062d8b78e983d0cc361b1fc030 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/size-is-a-number.js @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object has a size that is coerced to NaN +info: | + 2. Let rawSize be ? Get(obj, "size"). + 3. Let numSize be ? ToNumber(rawSize). + 4. NOTE: If rawSize is undefined, then numSize will be NaN. + 5. If numSize is NaN, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: undefined, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.intersection(s2); + }, + "GetSendableSetRecord throws an error when size is undefined" +); + +s2.size = NaN; +assert.throws( + TypeError, + function () { + s1.intersection(s2); + }, + "GetSendableSetRecord throws an error when size is NaN" +); + +let coercionCalls = 0; +s2.size = { + valueOf: function() { + ++coercionCalls; + return NaN; + }, +}; +assert.throws( + TypeError, + function () { + s1.intersection(s2); + }, + "GetSendableSetRecord throws an error when size coerces to NaN" +); +assert.sameValue(coercionCalls, 1, "GetSendableSetRecord coerces size"); + +s2.size = 0n; +assert.throws( + TypeError, + function () { + s1.intersection(s2); + }, + "GetSendableSetRecord throws an error when size is a BigInt" +); + +s2.size = "string"; +assert.throws( + TypeError, + function () { + s1.intersection(s2); + }, + "GetSendableSetRecord throws an error when size is a non-numeric string" +); diff --git a/test/sendable/builtins/Set/prototype/intersection/subclass-receiver-methods.js b/test/sendable/builtins/Set/prototype/intersection/subclass-receiver-methods.js new file mode 100644 index 0000000000000000000000000000000000000000..d1075476a5f3306dccc3a6dbe9369c29885f4411 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/subclass-receiver-methods.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection works on subclasses of SendableSet, but never calls the receiver's size/has/keys methods +features: [set-methods] +includes: [compareArray.js] +---*/ + +let sizeCount = 0; +let hasCount = 0; +let keysCount = 0; + +class MySendableSet extends SendableSet { + size(...rest) { + sizeCount++; + return super.size(...rest); + } + + has(...rest) { + hasCount++; + return super.has(...rest); + } + + keys(...rest) { + keysCount++; + return super.keys(...rest); + } +} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [2]; +const combined = s1.intersection(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); +assert.sameValue(sizeCount, 0, "size should not be called on the receiver"); +assert.sameValue(hasCount, 0, "has should not be called on the receiver"); +assert.sameValue(keysCount, 0, "keys should not be called on the receiver"); diff --git a/test/sendable/builtins/Set/prototype/intersection/subclass-symbol-species.js b/test/sendable/builtins/Set/prototype/intersection/subclass-symbol-species.js new file mode 100644 index 0000000000000000000000000000000000000000..03d69853298c97eaa757dfe0932c09d3e9031233 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/subclass-symbol-species.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection works on subclasses of SendableSet, but returns an instance of SendableSet even when Symbol.species is overridden. +features: [set-methods] +includes: [compareArray.js] +---*/ +var count = 0; +class MySendableSet extends SendableSet { + static get [Symbol.species]() { + count++; + return SendableSet; + } +} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [2]; +const combined = s1.intersection(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(count, 0, "Symbol.species is never called"); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); diff --git a/test/sendable/builtins/Set/prototype/intersection/subclass.js b/test/sendable/builtins/Set/prototype/intersection/subclass.js new file mode 100644 index 0000000000000000000000000000000000000000..e21c936458efa22027fd567b61a0468bb1f90586 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/intersection/subclass.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.intersection +description: SendableSet.prototype.intersection works on subclasses of SendableSet, but returns an instance of SendableSet +features: [set-methods] +includes: [compareArray.js] +---*/ + +class MySendableSet extends SendableSet {} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [2]; +const combined = s1.intersection(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/allows-set-like-class.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/allows-set-like-class.js new file mode 100644 index 0000000000000000000000000000000000000000..000b817a4acdc24109495d1055fae38f1917e5c0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/allows-set-like-class.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: GetSendableSetRecord allows instances of SendableSet-like classes +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new class { + get size() { + return 2; + } + has(v) { + if (v === 1 || v === 2) return false; + throw new Test262Error("SendableSet.prototype.isDisjointFrom should only call its argument's has method with contents of this"); + } + * keys() { + throw new Test262Error("SendableSet.prototype.isDisjointFrom should not call its argument's keys iterator when this.size ≤ arg.size"); + } +}; + +assert.sameValue(s1.isDisjointFrom(s2), true); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/allows-set-like-object.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/allows-set-like-object.js new file mode 100644 index 0000000000000000000000000000000000000000..04e96a602fd12f59e12646b377cba816045b7fff --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/allows-set-like-object.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: GetSendableSetRecord allows SendableSet-like objects +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: (v) => { + if (v === 1 || v === 2) return false; + throw new Test262Error("SendableSet.prototype.isDisjointFrom should only call its argument's has method with contents of this"); + }, + keys: function* keys() { + throw new Test262Error("SendableSet.prototype.isDisjointFrom should not call its argument's keys iterator when this.size ≤ arg.size"); + }, +}; + +assert.sameValue(s1.isDisjointFrom(s2), true); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/array-throws.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/array-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..ce6007e486bdaadd10ad7a5e03b5ebbb739ae5f4 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/array-throws.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom doesn't work with arrays +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [3]; +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(s2); + }, + "Throws an error when an array is used" +); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/builtins.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/builtins.js new file mode 100644 index 0000000000000000000000000000000000000000..c272fb6cb269d24fe3d3825f54fa71c0b562671f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/builtins.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: Tests that SendableSet.prototype.isDisjointFrom meets the requirements for built-in objects +features: [set-methods] +---*/ + +assert.sameValue( + Object.isExtensible(SendableSet.prototype.isDisjointFrom), + true, + "Built-in objects must be extensible." +); + +assert.sameValue( + Object.prototype.toString.call(SendableSet.prototype.isDisjointFrom), + "[object Function]", + "Object.prototype.toString" +); + +assert.sameValue( + Object.getPrototypeOf(SendableSet.prototype.isDisjointFrom), + Function.prototype, + "prototype" +); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/called-with-object.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/called-with-object.js new file mode 100644 index 0000000000000000000000000000000000000000..f817779c09854ba7290789dbfe8a3a6cdbef2761 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/called-with-object.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws if obj is not an object +info: | + 1. If obj is not an Object, throw a TypeError exception. +features: [set-methods] +---*/ + +let s1 = new SendableSet([1]); +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(1); + }, + "number" +); + +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(""); + }, + "string" +); + +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(1n); + }, + "bigint" +); + +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(false); + }, + "boolean" +); + +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(undefined); + }, + "undefined" +); + +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(null); + }, + "null" +); + +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(Symbol("test")); + }, + "symbol" +); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-Map.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-Map.js new file mode 100644 index 0000000000000000000000000000000000000000..7e3d339cc225e91123f1532cc463f229b36d4b22 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-Map.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom compares with Map +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const m1 = new Map([ + [2, "two"], + [3, "three"], +]); + +assert.sameValue(s1.isDisjointFrom(m1), false); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-empty-sets.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-empty-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..817c07b5f4bf2c8a7df95b87883d91000fcc672e --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-empty-sets.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom can compare empty SendableSets +features: [set-methods] +---*/ + +const s1 = new SendableSet([]); +const s2 = new SendableSet([1, 2]); + +assert.sameValue(s1.isDisjointFrom(s2), true); + +const s3 = new SendableSet([1, 2]); +const s4 = new SendableSet([]); + +assert.sameValue(s3.isDisjointFrom(s4), true); + +const s5 = new SendableSet([]); +const s6 = new SendableSet([]); + +assert.sameValue(s5.isDisjointFrom(s6), true); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-itself.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-itself.js new file mode 100644 index 0000000000000000000000000000000000000000..2d1f8945635a7f31d6932940d34492d3f1345f89 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-itself.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom is successful when called on itself +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); + +assert.sameValue(s1.isDisjointFrom(s1), false); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-same-sets.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-same-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..d3b66578526d5fcd10b90572548df9a38eabe616 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-same-sets.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom can compare SendableSets that have the same content +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([1, 2]); + +assert.sameValue(s1.isDisjointFrom(s2), false); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-sets.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..f03fb689d73b4f6b6b7566c2dff3bafa9a7c1dc9 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/compares-sets.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom compares SendableSets +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); + +assert.sameValue(s1.isDisjointFrom(s2), false); + +const s3 = new SendableSet([3]); + +assert.sameValue(s1.isDisjointFrom(s3), true); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/converts-negative-zero.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/converts-negative-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..8c65df4615d10d442023fa07c9171c554bbe1262 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/converts-negative-zero.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom converts -0𝔽 to +0𝔽 +features: [set-methods] +---*/ + +const setlikeWithMinusZero = { + size: 1, + has: function () { + throw new Test262Error("SendableSet.prototype.isDisjointFrom should not call its argument's has method when this.size > arg.size"); + }, + keys: function () { + // we use an array here because the SendableSet constructor would normalize away -0 + return [-0].values(); + }, +}; + +const s1 = new SendableSet([+0, 1]); + +assert.sameValue(s1.isDisjointFrom(setlikeWithMinusZero), false); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/has-is-callable.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/has-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..53409059e758c5e26f84883f44066726802adb5a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/has-is-callable.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'has' property is not callable +info: | + 7. Let has be ? Get(obj, "has"). + 8. If IsCallable(has) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: undefined, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(s2); + }, + "GetSendableSetRecord throws an error when has is undefined" +); + +s2.has = {}; +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(s2); + }, + "GetSendableSetRecord throws an error when has is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/isDisjointFrom.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/isDisjointFrom.js new file mode 100644 index 0000000000000000000000000000000000000000..4e0b549d1ed1f3ad4f2f41741b78a277d130538b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/isDisjointFrom.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom properties +includes: [propertyHelper.js] +features: [set-methods] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.isDisjointFrom, + "function", + "`typeof SendableSet.prototype.isDisjointFrom` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "isDisjointFrom", { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/keys-is-callable.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/keys-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..b12490826d0e255269b5fc04b108b6ba87ae6069 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/keys-is-callable.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'keys' property is not callable +info: | + 9. Let keys be ? Get(obj, "keys"). + 10. If IsCallable(keys) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: () => {}, + keys: undefined, +}; +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(s2); + }, + "GetSendableSetRecord throws an error when keys is undefined" +); + +s2.keys = {}; +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(s2); + }, + "GetSendableSetRecord throws an error when keys is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/length.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/length.js new file mode 100644 index 0000000000000000000000000000000000000000..76988dbb41251b6d5e808cd0c625893fd8809ba0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom length property +info: | + SendableSet.prototype.isDisjointFrom ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.isDisjointFrom, "function"); + +verifyProperty(SendableSet.prototype.isDisjointFrom, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1, +}); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/name.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/name.js new file mode 100644 index 0000000000000000000000000000000000000000..ed0b3fc9dc057b765802c56462a4317b2ed9c92c --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom name property +info: | + SendableSet.prototype.isDisjointFrom ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.isDisjointFrom, "function"); + +verifyProperty(SendableSet.prototype.isDisjointFrom, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "isDisjointFrom", +}); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/not-a-constructor.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..74938ee800388a5823ed2a1b19c065b1dfdfa342 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/not-a-constructor.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom does not implement [[Construct]], is not new-able +includes: [isConstructor.js] +features: [Reflect.construct, set-methods] +---*/ + +assert.sameValue( + isConstructor(SendableSet.prototype.isDisjointFrom), + false, + "isConstructor(SendableSet.prototype.isDisjointFrom) must return false" +); + +assert.throws( + TypeError, + () => { + new SendableSet.prototype.isDisjointFrom(); + }); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/receiver-not-set.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/receiver-not-set.js new file mode 100644 index 0000000000000000000000000000000000000000..7671303e5278c59c918febac2a03e2be2c363c0b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/receiver-not-set.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom throws when receiver is not a SendableSet +features: [set-methods] +---*/ + +class MySendableSetLike { + constructor() { + this.size = 2; + this.has = () => {}; + this.keys = function* keys() { + yield 2; + yield 3; + }; + } +} + +const s1 = new MySendableSetLike(); +const s2 = new SendableSet(); +assert.throws( + TypeError, + () => { + SendableSet.prototype.isDisjointFrom.call(s1, s2); + }, + "SendableSet-like class" +); + +const s3 = { + size: 2, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + () => { + SendableSet.prototype.isDisjointFrom.call(s3, s2); + }, + "SendableSet-like object" +); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/require-internal-slot.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/require-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..574bd92a120d54fa40df29a8c73fa78db3e59593 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/require-internal-slot.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom RequireInternalSlot +info: | + 2. Perform ? RequireInternalSlot(O, [[SendableSetData]]) +features: [set-methods] +---*/ + +const isDisjointFrom = SendableSet.prototype.isDisjointFrom; + +assert.sameValue(typeof isDisjointFrom, "function"); + +const realSendableSet = new SendableSet([]); + +assert.throws(TypeError, () => isDisjointFrom.call(undefined, realSendableSet), "undefined"); +assert.throws(TypeError, () => isDisjointFrom.call(null, realSendableSet), "null"); +assert.throws(TypeError, () => isDisjointFrom.call(true, realSendableSet), "true"); +assert.throws(TypeError, () => isDisjointFrom.call("", realSendableSet), "empty string"); +assert.throws(TypeError, () => isDisjointFrom.call(Symbol(), realSendableSet), "symbol"); +assert.throws(TypeError, () => isDisjointFrom.call(1, realSendableSet), "1"); +assert.throws(TypeError, () => isDisjointFrom.call(1n, realSendableSet), "1n"); +assert.throws(TypeError, () => isDisjointFrom.call({}, realSendableSet), "plain object"); +assert.throws(TypeError, () => isDisjointFrom.call([], realSendableSet), "array"); +assert.throws(TypeError, () => isDisjointFrom.call(new Map(), realSendableSet), "map"); +assert.throws(TypeError, () => isDisjointFrom.call(SendableSet.prototype, realSendableSet), "SendableSet.prototype"); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/set-like-array.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/set-like-array.js new file mode 100644 index 0000000000000000000000000000000000000000..4356dd5ed9ff4331041980161460da94036b3574 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/set-like-array.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom consumes a set-like array as a set-like, not an array +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [5, 6]; +s2.size = 3; +s2.has = function (v) { + if (v === 1 || v === 2) return true; + throw new Test262Error("SendableSet.prototype.isDisjointFrom should only call its argument's has method with contents of this"); +}; +s2.keys = function () { + throw new Test262Error("SendableSet.prototype.isDisjointFrom should not call its argument's keys iterator when this.size ≤ arg.size"); +}; + +assert.sameValue(s1.isDisjointFrom(s2), false); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/set-like-class-mutation.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/set-like-class-mutation.js new file mode 100644 index 0000000000000000000000000000000000000000..7b13bc5442a3a28ff870b145d46a4d0c0d66ac4c --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/set-like-class-mutation.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom behavior when a custom SendableSet-like class mutates the receiver +features: [set-methods] +includes: [compareArray.js] +---*/ + +const baseSendableSet = new SendableSet(["a", "b", "c"]); + +const evilSendableSetLike = { + size: 3, + has(v) { + if (v === "a") { + baseSendableSet.delete("b"); + baseSendableSet.delete("c"); + baseSendableSet.add("b"); + return false; + } + if (v === "b") { + return false; + } + if (v === "c") { + throw new Test262Error("SendableSet.prototype.isDisjointFrom should not call its argument's has method with values from this which have been deleted before visiting"); + } + throw new Test262Error("SendableSet.prototype.isDisjointFrom should only call its argument's has method with contents of this"); + }, + * keys() { + throw new Test262Error("SendableSet.prototype.isDisjointFrom should not call its argument's keys iterator when this.size ≤ arg.size"); + }, +}; + +const result = baseSendableSet.isDisjointFrom(evilSendableSetLike); +assert.sameValue(result, true); + +const expectedNewBase = ["a", "b"]; +assert.compareArray([...baseSendableSet], expectedNewBase); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/set-like-class-order.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/set-like-class-order.js new file mode 100644 index 0000000000000000000000000000000000000000..c72eea0f64398f782bc2938dd99e004e1bec7d6f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/set-like-class-order.js @@ -0,0 +1,204 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom calls a SendableSet-like class's methods in order +features: [set-methods] +includes: [compareArray.js] +---*/ + +let observedOrder = []; + +function observableIterator() { + let values = ["a", "b", "c"]; + let index = 0; + return { + get next() { + observedOrder.push("getting next"); + return function () { + observedOrder.push("calling next"); + return { + get done() { + observedOrder.push("getting done"); + return index >= values.length; + }, + get value() { + observedOrder.push("getting value"); + return values[index++]; + }, + }; + }; + }, + }; +} + +class MySendableSetLike { + get size() { + observedOrder.push("getting size"); + return { + valueOf: function () { + observedOrder.push("ToNumber(size)"); + return 3; + }, + }; + } + get has() { + observedOrder.push("getting has"); + return function (v) { + observedOrder.push("calling has"); + return ["a", "b", "c"].indexOf(v) !== -1; + }; + } + get keys() { + observedOrder.push("getting keys"); + return function () { + observedOrder.push("calling keys"); + return observableIterator(); + }; + } +} + +// this is smaller than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["x", "b"]); + const s2 = new MySendableSetLike(); + const result = s1.isDisjointFrom(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // two calls to has + "calling has", + "calling has", + ]; + + assert.sameValue(result, false); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is same size as argument - stops eagerly +{ + observedOrder = []; + + const s1 = new SendableSet(["x", "b", "y"]); + const s2 = new MySendableSetLike(); + const result = s1.isDisjointFrom(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // two calls to has + "calling has", + "calling has", + ]; + + assert.sameValue(result, false); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is same size as argument - full run +{ + observedOrder = []; + + const s1 = new SendableSet(["x", "y", "z"]); + const s2 = new MySendableSetLike(); + const result = s1.isDisjointFrom(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // three calls to has + "calling has", + "calling has", + "calling has", + ]; + + assert.sameValue(result, true); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is larger than argument - stops eagerly +{ + observedOrder = []; + + const s1 = new SendableSet(["x", "b", "y", "z"]); + const s2 = new MySendableSetLike(); + const result = s1.isDisjointFrom(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + "calling keys", + "getting next", + // first iteration, has value + "calling next", + "getting done", + "getting value", + // second iteration, has value + "calling next", + "getting done", + "getting value", + ]; + + assert.sameValue(result, false); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is larger than argument - full run +{ + observedOrder = []; + + const s1 = new SendableSet(["x", "y", "z", "w"]); + const s2 = new MySendableSetLike(); + const result = s1.isDisjointFrom(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + "calling keys", + "getting next", + // first iteration, has value + "calling next", + "getting done", + "getting value", + // second iteration, has value + "calling next", + "getting done", + "getting value", + // third iteration, has value + "calling next", + "getting done", + "getting value", + // fourth iteration, done + "calling next", + "getting done", + ]; + + assert.sameValue(result, true); + assert.compareArray(observedOrder, expectedOrder); +} diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/size-is-a-number.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/size-is-a-number.js new file mode 100644 index 0000000000000000000000000000000000000000..1de5b1141371bfdb16d5a327e71dfa38626c2fca --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/size-is-a-number.js @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object has a size that is coerced to NaN +info: | + 2. Let rawSize be ? Get(obj, "size"). + 3. Let numSize be ? ToNumber(rawSize). + 4. NOTE: If rawSize is undefined, then numSize will be NaN. + 5. If numSize is NaN, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: undefined, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(s2); + }, + "GetSendableSetRecord throws an error when size is undefined" +); + +s2.size = NaN; +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(s2); + }, + "GetSendableSetRecord throws an error when size is NaN" +); + +let coercionCalls = 0; +s2.size = { + valueOf: function() { + ++coercionCalls; + return NaN; + }, +}; +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(s2); + }, + "GetSendableSetRecord throws an error when size coerces to NaN" +); +assert.sameValue(coercionCalls, 1, "GetSendableSetRecord coerces size"); + +s2.size = 0n; +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(s2); + }, + "GetSendableSetRecord throws an error when size is a BigInt" +); + +s2.size = "string"; +assert.throws( + TypeError, + function () { + s1.isDisjointFrom(s2); + }, + "GetSendableSetRecord throws an error when size is a non-numeric string" +); diff --git a/test/sendable/builtins/Set/prototype/isDisjointFrom/subclass-receiver-methods.js b/test/sendable/builtins/Set/prototype/isDisjointFrom/subclass-receiver-methods.js new file mode 100644 index 0000000000000000000000000000000000000000..aa5160181a77bf150cc7527f50d1d237e357bae1 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isDisjointFrom/subclass-receiver-methods.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.isdisjointfrom +description: SendableSet.prototype.isDisjointFrom works on subclasses of SendableSet, but never calls the receiver's size/has/keys methods +features: [set-methods] +---*/ + +let sizeCount = 0; +let hasCount = 0; +let keysCount = 0; + +class MySendableSet extends SendableSet { + size(...rest) { + sizeCount++; + return super.size(...rest); + } + + has(...rest) { + hasCount++; + return super.has(...rest); + } + + keys(...rest) { + keysCount++; + return super.keys(...rest); + } +} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const result = s1.isDisjointFrom(s2); +assert.sameValue(result, false); + +assert.sameValue(sizeCount, 0, "size should not be called on the receiver"); +assert.sameValue(hasCount, 0, "has should not be called on the receiver"); +assert.sameValue(keysCount, 0, "keys should not be called on the receiver"); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/allows-set-like-class.js b/test/sendable/builtins/Set/prototype/isSubsetOf/allows-set-like-class.js new file mode 100644 index 0000000000000000000000000000000000000000..e458f9f0ca19e486696752db4724401e7c08e713 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/allows-set-like-class.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: GetSendableSetRecord allows instances of SendableSet-like classes +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new class { + get size() { + return 3; + } + has(v) { + if (v === 1) return false; + if (v === 2) return true; + throw new Test262Error("SendableSet.prototype.isSubsetOf should only call its argument's has method with contents of this"); + } + * keys() { + throw new Test262Error("SendableSet.prototype.isSubsetOf should not call its argument's keys iterator"); + } +}; + +assert.sameValue(s1.isSubsetOf(s2), false); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/allows-set-like-object.js b/test/sendable/builtins/Set/prototype/isSubsetOf/allows-set-like-object.js new file mode 100644 index 0000000000000000000000000000000000000000..4fe659afcaca0d81ff859574fc9563f703f15d0b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/allows-set-like-object.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: GetSendableSetRecord allows SendableSet-like objects +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: (v) => { + if (v === 1) return false; + if (v === 2) return true; + throw new Test262Error("SendableSet.prototype.isSubsetOf should only call its argument's has method with contents of this"); + }, + keys: function* keys() { + throw new Test262Error("SendableSet.prototype.isSubsetOf should not call its argument's keys iterator"); + }, +}; + +assert.sameValue(s1.isSubsetOf(s2), false); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/array-throws.js b/test/sendable/builtins/Set/prototype/isSubsetOf/array-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..85fdeee8f1ea92e222bcf2a1f5012e40a587e782 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/array-throws.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf doesn't work with arrays +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [3]; +assert.throws( + TypeError, + function () { + s1.isSubsetOf(s2); + }, + "Throws an error when an array is used" +); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/builtins.js b/test/sendable/builtins/Set/prototype/isSubsetOf/builtins.js new file mode 100644 index 0000000000000000000000000000000000000000..51a27424e63129ac962177158687a56a978ef2f9 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/builtins.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: Tests that SendableSet.prototype.isSubsetOf meets the requirements for built-in objects +features: [set-methods] +---*/ + +assert.sameValue( + Object.isExtensible(SendableSet.prototype.isSubsetOf), + true, + "Built-in objects must be extensible." +); + +assert.sameValue( + Object.prototype.toString.call(SendableSet.prototype.isSubsetOf), + "[object Function]", + "Object.prototype.toString" +); + +assert.sameValue( + Object.getPrototypeOf(SendableSet.prototype.isSubsetOf), + Function.prototype, + "prototype" +); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/called-with-object.js b/test/sendable/builtins/Set/prototype/isSubsetOf/called-with-object.js new file mode 100644 index 0000000000000000000000000000000000000000..74cff4ca1c85a6f6898284823bfd625c0af76b7f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/called-with-object.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws if obj is not an object +info: | + 1. If obj is not an Object, throw a TypeError exception. +features: [set-methods] +---*/ + +let s1 = new SendableSet([1]); +assert.throws( + TypeError, + function () { + s1.isSubsetOf(1); + }, + "number" +); + +assert.throws( + TypeError, + function () { + s1.isSubsetOf(""); + }, + "string" +); + +assert.throws( + TypeError, + function () { + s1.isSubsetOf(1n); + }, + "bigint" +); + +assert.throws( + TypeError, + function () { + s1.isSubsetOf(false); + }, + "boolean" +); + +assert.throws( + TypeError, + function () { + s1.isSubsetOf(undefined); + }, + "undefined" +); + +assert.throws( + TypeError, + function () { + s1.isSubsetOf(null); + }, + "null" +); + +assert.throws( + TypeError, + function () { + s1.isSubsetOf(Symbol("test")); + }, + "symbol" +); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/compares-Map.js b/test/sendable/builtins/Set/prototype/isSubsetOf/compares-Map.js new file mode 100644 index 0000000000000000000000000000000000000000..5a6a2189556f6a545ca1650053306640fa748032 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/compares-Map.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf compares with Map +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const m1 = new Map([ + [2, "two"], + [3, "three"], +]); + +assert.sameValue(s1.isSubsetOf(m1), false); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/compares-empty-sets.js b/test/sendable/builtins/Set/prototype/isSubsetOf/compares-empty-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..dea8c5772e689d599953fb8a6bc8ec971664da68 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/compares-empty-sets.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf can compare empty SendableSets +features: [set-methods] +---*/ + +const s1 = new SendableSet([]); +const s2 = new SendableSet([1, 2]); + +assert.sameValue(s1.isSubsetOf(s2), true); + +const s3 = new SendableSet([1, 2]); +const s4 = new SendableSet([]); + +assert.sameValue(s3.isSubsetOf(s4), false); + +const s5 = new SendableSet([]); +const s6 = new SendableSet([]); + +assert.sameValue(s5.isSubsetOf(s6), true); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/compares-itself.js b/test/sendable/builtins/Set/prototype/isSubsetOf/compares-itself.js new file mode 100644 index 0000000000000000000000000000000000000000..e0d7d8be93691184f91fa166b1466f8fd6c622a8 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/compares-itself.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf is successful when called on itself +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); + +assert.sameValue(s1.isSubsetOf(s1), true); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/compares-same-sets.js b/test/sendable/builtins/Set/prototype/isSubsetOf/compares-same-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..b4c33d59f9eefd8499d114ff433a6e752a5535be --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/compares-same-sets.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf can compare SendableSets that have the same content +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([1, 2]); + +assert.sameValue(s1.isSubsetOf(s2), true); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/compares-sets.js b/test/sendable/builtins/Set/prototype/isSubsetOf/compares-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..d30799efb22ea7238feee672e5aa7b1421b0ef8b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/compares-sets.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf compares SendableSets +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); + +assert.sameValue(s1.isSubsetOf(s2), false); + +const s3 = new SendableSet([1, 2, 3]); + +assert.sameValue(s1.isSubsetOf(s3), true); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/has-is-callable.js b/test/sendable/builtins/Set/prototype/isSubsetOf/has-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..2a46129717f0b69eaea3032a51a1e157aa3932ba --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/has-is-callable.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'has' property is not callable +info: | + 7. Let has be ? Get(obj, "has"). + 8. If IsCallable(has) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: undefined, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.isSubsetOf(s2); + }, + "GetSendableSetRecord throws an error when has is undefined" +); + +s2.has = {}; +assert.throws( + TypeError, + function () { + s1.isSubsetOf(s2); + }, + "GetSendableSetRecord throws an error when has is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/isSubsetOf.js b/test/sendable/builtins/Set/prototype/isSubsetOf/isSubsetOf.js new file mode 100644 index 0000000000000000000000000000000000000000..fd7c6eca970501c1b9f2efc1aa26c44c3c3ad53b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/isSubsetOf.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf properties +includes: [propertyHelper.js] +features: [set-methods] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.isSubsetOf, + "function", + "`typeof SendableSet.prototype.isSubsetOf` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "isSubsetOf", { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/keys-is-callable.js b/test/sendable/builtins/Set/prototype/isSubsetOf/keys-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..969408af3cfaa53d7d193ce6ead8b0e68319543d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/keys-is-callable.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'keys' property is not callable +info: | + 9. Let keys be ? Get(obj, "keys"). + 10. If IsCallable(keys) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: () => {}, + keys: undefined, +}; +assert.throws( + TypeError, + function () { + s1.isSubsetOf(s2); + }, + "GetSendableSetRecord throws an error when keys is undefined" +); + +s2.keys = {}; +assert.throws( + TypeError, + function () { + s1.isSubsetOf(s2); + }, + "GetSendableSetRecord throws an error when keys is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/length.js b/test/sendable/builtins/Set/prototype/isSubsetOf/length.js new file mode 100644 index 0000000000000000000000000000000000000000..24bde29e7e2e3afef8e81ad8a9b72bec3dd823fd --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf length property +info: | + SendableSet.prototype.isSubsetOf ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.isSubsetOf, "function"); + +verifyProperty(SendableSet.prototype.isSubsetOf, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1, +}); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/name.js b/test/sendable/builtins/Set/prototype/isSubsetOf/name.js new file mode 100644 index 0000000000000000000000000000000000000000..f376efd900a1eaf53efa9a969e87eedc8b3f8d81 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf name property +info: | + SendableSet.prototype.isSubsetOf ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.isSubsetOf, "function"); + +verifyProperty(SendableSet.prototype.isSubsetOf, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "isSubsetOf", +}); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/not-a-constructor.js b/test/sendable/builtins/Set/prototype/isSubsetOf/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..d73d1aa1ba4e3f09a447eaf0d1bb5cee9d879366 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/not-a-constructor.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf does not implement [[Construct]], is not new-able +includes: [isConstructor.js] +features: [Reflect.construct, set-methods] +---*/ + +assert.sameValue( + isConstructor(SendableSet.prototype.isSubsetOf), + false, + "isConstructor(SendableSet.prototype.isSubsetOf) must return false" +); + +assert.throws( + TypeError, + () => { + new SendableSet.prototype.isSubsetOf(); + }); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/receiver-not-set.js b/test/sendable/builtins/Set/prototype/isSubsetOf/receiver-not-set.js new file mode 100644 index 0000000000000000000000000000000000000000..d81f171330d8f2049d776b924769f444c2bea79a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/receiver-not-set.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf throws when receiver is not a SendableSet +features: [set-methods] +---*/ + +class MySendableSetLike { + constructor() { + this.size = 2; + this.has = () => {}; + this.keys = function* keys() { + yield 2; + yield 3; + }; + } +} + +const s1 = new MySendableSetLike(); +const s2 = new SendableSet(); +assert.throws( + TypeError, + () => { + SendableSet.prototype.isSubsetOf.call(s1, s2); + }, + "SendableSet-like class" +); + +const s3 = { + size: 2, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + () => { + SendableSet.prototype.isSubsetOf.call(s3, s2); + }, + "SendableSet-like object" +); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/require-internal-slot.js b/test/sendable/builtins/Set/prototype/isSubsetOf/require-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..4c108e51076e048ce79612782b5c043b21688b6f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/require-internal-slot.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf RequireInternalSlot +info: | + 2. Perform ? RequireInternalSlot(O, [[SendableSetData]]) +features: [set-methods] +---*/ + +const isSubsetOf = SendableSet.prototype.isSubsetOf; + +assert.sameValue(typeof isSubsetOf, "function"); + +const realSendableSet = new SendableSet([]); + +assert.throws(TypeError, () => isSubsetOf.call(undefined, realSendableSet), "undefined"); +assert.throws(TypeError, () => isSubsetOf.call(null, realSendableSet), "null"); +assert.throws(TypeError, () => isSubsetOf.call(true, realSendableSet), "true"); +assert.throws(TypeError, () => isSubsetOf.call("", realSendableSet), "empty string"); +assert.throws(TypeError, () => isSubsetOf.call(Symbol(), realSendableSet), "symbol"); +assert.throws(TypeError, () => isSubsetOf.call(1, realSendableSet), "1"); +assert.throws(TypeError, () => isSubsetOf.call(1n, realSendableSet), "1n"); +assert.throws(TypeError, () => isSubsetOf.call({}, realSendableSet), "plain object"); +assert.throws(TypeError, () => isSubsetOf.call([], realSendableSet), "array"); +assert.throws(TypeError, () => isSubsetOf.call(new Map(), realSendableSet), "map"); +assert.throws(TypeError, () => isSubsetOf.call(SendableSet.prototype, realSendableSet), "SendableSet.prototype"); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/set-like-array.js b/test/sendable/builtins/Set/prototype/isSubsetOf/set-like-array.js new file mode 100644 index 0000000000000000000000000000000000000000..cec1e8f6ed1d6be003d84ca92182ced9ef95b72d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/set-like-array.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf consumes a set-like array as a set-like, not an array +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [5, 6]; +s2.size = 3; +s2.has = function (v) { + if (v === 1) return true; + if (v === 2) return true; + throw new Test262Error("SendableSet.prototype.isSubsetOf should only call its argument's has method with contents of this"); +}; +s2.keys = function () { + throw new Test262Error("SendableSet.prototype.isSubsetOf should not call its argument's keys iterator when this.size ≤ arg.size"); +}; + +assert.sameValue(s1.isSubsetOf(s2), true); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/set-like-class-mutation.js b/test/sendable/builtins/Set/prototype/isSubsetOf/set-like-class-mutation.js new file mode 100644 index 0000000000000000000000000000000000000000..62b003bb446c41386b9ff1bc431887adb1d3fce3 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/set-like-class-mutation.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf behavior when a custom SendableSet-like class mutates the receiver +features: [set-methods] +includes: [compareArray.js] +---*/ + +const baseSendableSet = new SendableSet(["a", "b", "c"]); + +const evilSendableSetLike = { + size: 3, + has(v) { + if (v === "a") { + baseSendableSet.delete("c"); + } + return ["x", "a", "b"].includes(v); + }, + * keys() { + throw new Test262Error("SendableSet.prototype.isSubsetOf should not call its argument's keys iterator"); + }, +}; + +const result = baseSendableSet.isSubsetOf(evilSendableSetLike); +assert.sameValue(result, true); + +const expectedNewBase = ["a", "b"]; +assert.compareArray([...baseSendableSet], expectedNewBase); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/set-like-class-order.js b/test/sendable/builtins/Set/prototype/isSubsetOf/set-like-class-order.js new file mode 100644 index 0000000000000000000000000000000000000000..8dfcfbf4605110228598efeffd24cad3e216a379 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/set-like-class-order.js @@ -0,0 +1,134 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf calls a SendableSet-like class's methods in order +features: [set-methods] +includes: [compareArray.js] +---*/ + +let observedOrder = []; + +class MySendableSetLike { + get size() { + observedOrder.push("getting size"); + return { + valueOf: function () { + observedOrder.push("ToNumber(size)"); + return 3; + }, + }; + } + get has() { + observedOrder.push("getting has"); + return function (v) { + observedOrder.push("calling has"); + return ["a", "b", "c"].indexOf(v) !== -1; + }; + } + get keys() { + observedOrder.push("getting keys"); + return function () { + throw new Test262Error("SendableSet.prototype.isSubsetOf should not call its argument's keys iterator"); + }; + } +} + +// this is smaller than argument - stops eagerly +{ + observedOrder = []; + + const s1 = new SendableSet(["d", "a"]); + const s2 = new MySendableSetLike(); + const result = s1.isSubsetOf(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // one call to has + "calling has", + ]; + + assert.sameValue(result, false); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is smaller than argument - full run +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b"]); + const s2 = new MySendableSetLike(); + const result = s1.isSubsetOf(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // two calls to has + "calling has", + "calling has", + ]; + + assert.sameValue(result, true); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is same size as argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "c"]); + const s2 = new MySendableSetLike(); + const result = s1.isSubsetOf(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // three calls to has + "calling has", + "calling has", + "calling has", + ]; + + assert.sameValue(result, true); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is larger than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "c", "d"]); + const s2 = new MySendableSetLike(); + const result = s1.isSubsetOf(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // no calls to has + ]; + + assert.sameValue(result, false); + assert.compareArray(observedOrder, expectedOrder); +} diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/size-is-a-number.js b/test/sendable/builtins/Set/prototype/isSubsetOf/size-is-a-number.js new file mode 100644 index 0000000000000000000000000000000000000000..5394b6999186572df43c2f8882967e8fe8546ab8 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/size-is-a-number.js @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object has a size that is coerced to NaN +info: | + 2. Let rawSize be ? Get(obj, "size"). + 3. Let numSize be ? ToNumber(rawSize). + 4. NOTE: If rawSize is undefined, then numSize will be NaN. + 5. If numSize is NaN, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: undefined, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.isSubsetOf(s2); + }, + "GetSendableSetRecord throws an error when size is undefined" +); + +s2.size = NaN; +assert.throws( + TypeError, + function () { + s1.isSubsetOf(s2); + }, + "GetSendableSetRecord throws an error when size is NaN" +); + +let coercionCalls = 0; +s2.size = { + valueOf: function() { + ++coercionCalls; + return NaN; + }, +}; +assert.throws( + TypeError, + function () { + s1.isSubsetOf(s2); + }, + "GetSendableSetRecord throws an error when size coerces to NaN" +); +assert.sameValue(coercionCalls, 1, "GetSendableSetRecord coerces size"); + +s2.size = 0n; +assert.throws( + TypeError, + function () { + s1.isSubsetOf(s2); + }, + "GetSendableSetRecord throws an error when size is a BigInt" +); + +s2.size = "string"; +assert.throws( + TypeError, + function () { + s1.isSubsetOf(s2); + }, + "GetSendableSetRecord throws an error when size is a non-numeric string" +); diff --git a/test/sendable/builtins/Set/prototype/isSubsetOf/subclass-receiver-methods.js b/test/sendable/builtins/Set/prototype/isSubsetOf/subclass-receiver-methods.js new file mode 100644 index 0000000000000000000000000000000000000000..42af3fdb337fd5bfd9050c7d57ce0f701926fedf --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSubsetOf/subclass-receiver-methods.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issubsetof +description: SendableSet.prototype.isSubsetOf works on subclasses of SendableSet, but never calls the receiver's size/has/keys methods +features: [set-methods] +---*/ + +let sizeCount = 0; +let hasCount = 0; +let keysCount = 0; + +class MySendableSet extends SendableSet { + size(...rest) { + sizeCount++; + return super.size(...rest); + } + + has(...rest) { + hasCount++; + return super.has(...rest); + } + + keys(...rest) { + keysCount++; + return super.keys(...rest); + } +} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const result = s1.isSubsetOf(s2); +assert.sameValue(result, false); + +assert.sameValue(sizeCount, 0, "size should not be called on the receiver"); +assert.sameValue(hasCount, 0, "has should not be called on the receiver"); +assert.sameValue(keysCount, 0, "keys should not be called on the receiver"); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/allows-set-like-class.js b/test/sendable/builtins/Set/prototype/isSupersetOf/allows-set-like-class.js new file mode 100644 index 0000000000000000000000000000000000000000..542ffd00339cd14f8a53e99e2f9dbed9b5567992 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/allows-set-like-class.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: GetSendableSetRecord allows instances of SendableSet-like classes +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new class { + get size() { + return 1; + } + has(v) { + throw new Test262Error("SendableSet.prototype.isSupersetOf should not call its argument's has method"); + } + * keys() { + yield 1; + } +}; + +assert.sameValue(s1.isSupersetOf(s2), true); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/allows-set-like-object.js b/test/sendable/builtins/Set/prototype/isSupersetOf/allows-set-like-object.js new file mode 100644 index 0000000000000000000000000000000000000000..fbbf225a82057753f40843378231dd5be059615a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/allows-set-like-object.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: GetSendableSetRecord allows SendableSet-like objects +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 1, + has: (v) => { + throw new Test262Error("SendableSet.prototype.isSupersetOf should not call its argument's has method"); + }, + keys: function* keys() { + yield 1; + }, +}; + +assert.sameValue(s1.isSupersetOf(s2), true); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/array-throws.js b/test/sendable/builtins/Set/prototype/isSupersetOf/array-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..bee793c59442bc805a73a97488b6fb7e04115173 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/array-throws.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf doesn't work with arrays +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [3]; +assert.throws( + TypeError, + function () { + s1.isSupersetOf(s2); + }, + "Throws an error when an array is used" +); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/builtins.js b/test/sendable/builtins/Set/prototype/isSupersetOf/builtins.js new file mode 100644 index 0000000000000000000000000000000000000000..13e7229f83c39f35019084f383c42f7c17f25563 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/builtins.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: Tests that SendableSet.prototype.isSupersetOf meets the requirements for built-in objects +features: [set-methods] +---*/ + +assert.sameValue( + Object.isExtensible(SendableSet.prototype.isSupersetOf), + true, + "Built-in objects must be extensible." +); + +assert.sameValue( + Object.prototype.toString.call(SendableSet.prototype.isSupersetOf), + "[object Function]", + "Object.prototype.toString" +); + +assert.sameValue( + Object.getPrototypeOf(SendableSet.prototype.isSupersetOf), + Function.prototype, + "prototype" +); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/called-with-object.js b/test/sendable/builtins/Set/prototype/isSupersetOf/called-with-object.js new file mode 100644 index 0000000000000000000000000000000000000000..157aaf8db34e1045b70a0c9d3a974e4d794e2d0f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/called-with-object.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws if obj is not an object +info: | + 1. If obj is not an Object, throw a TypeError exception. +features: [set-methods] +---*/ + +let s1 = new SendableSet([1]); +assert.throws( + TypeError, + function () { + s1.isSupersetOf(1); + }, + "number" +); + +assert.throws( + TypeError, + function () { + s1.isSupersetOf(""); + }, + "string" +); + +assert.throws( + TypeError, + function () { + s1.isSupersetOf(1n); + }, + "bigint" +); + +assert.throws( + TypeError, + function () { + s1.isSupersetOf(false); + }, + "boolean" +); + +assert.throws( + TypeError, + function () { + s1.isSupersetOf(undefined); + }, + "undefined" +); + +assert.throws( + TypeError, + function () { + s1.isSupersetOf(null); + }, + "null" +); + +assert.throws( + TypeError, + function () { + s1.isSupersetOf(Symbol("test")); + }, + "symbol" +); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/compares-Map.js b/test/sendable/builtins/Set/prototype/isSupersetOf/compares-Map.js new file mode 100644 index 0000000000000000000000000000000000000000..834b7fe079a6f2673040c2329158fec58ed38131 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/compares-Map.js @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf compares with Map +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const m1 = new Map([ + [2, "two"], + [3, "three"], +]); + +assert.sameValue(s1.isSupersetOf(m1), false); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/compares-empty-sets.js b/test/sendable/builtins/Set/prototype/isSupersetOf/compares-empty-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..98bf65f4c29303ea5ddeeb466fe4ff5b23022502 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/compares-empty-sets.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf can compare empty SendableSets +features: [set-methods] +---*/ + +const s1 = new SendableSet([]); +const s2 = new SendableSet([1, 2]); + +assert.sameValue(s1.isSupersetOf(s2), false); + +const s3 = new SendableSet([1, 2]); +const s4 = new SendableSet([]); + +assert.sameValue(s3.isSupersetOf(s4), true); + +const s5 = new SendableSet([]); +const s6 = new SendableSet([]); + +assert.sameValue(s5.isSupersetOf(s6), true); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/compares-itself.js b/test/sendable/builtins/Set/prototype/isSupersetOf/compares-itself.js new file mode 100644 index 0000000000000000000000000000000000000000..80e5104fb6f71fb6e2264cc5ebcf8d8b8262ab70 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/compares-itself.js @@ -0,0 +1,24 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf is successful when called on itself +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); + +assert.sameValue(s1.isSupersetOf(s1), true); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/compares-same-sets.js b/test/sendable/builtins/Set/prototype/isSupersetOf/compares-same-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..4ad98819ab4dbdc2b0594faea9c62060fbd2a6e2 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/compares-same-sets.js @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf can compare SendableSets that have the same content +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([1, 2]); + +assert.sameValue(s1.isSupersetOf(s2), true); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/compares-sets.js b/test/sendable/builtins/Set/prototype/isSupersetOf/compares-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..ffeeae1a3934fb07d721ce9aa6e7501f354c4787 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/compares-sets.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf compares SendableSets +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); + +assert.sameValue(s1.isSupersetOf(s2), false); + +const s3 = new SendableSet([1]); + +assert.sameValue(s1.isSupersetOf(s3), true); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/converts-negative-zero.js b/test/sendable/builtins/Set/prototype/isSupersetOf/converts-negative-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..a5a17656590a01c13f966d48f2065359825ac742 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/converts-negative-zero.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf converts -0𝔽 to +0𝔽 +features: [set-methods] +---*/ + +const setlikeWithMinusZero = { + size: 1, + has: function () { + throw new Test262Error("SendableSet.prototype.isSupersetOf should not call its argument's has method"); + }, + keys: function () { + // we use an array here because the SendableSet constructor would normalize away -0 + return [-0].values(); + }, +}; + +const s1 = new SendableSet([+0, 1]); + +assert.sameValue(s1.isSupersetOf(setlikeWithMinusZero), true); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/has-is-callable.js b/test/sendable/builtins/Set/prototype/isSupersetOf/has-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..442b8bacae0647168df3f1484721301b348b44d5 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/has-is-callable.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'has' property is not callable +info: | + 7. Let has be ? Get(obj, "has"). + 8. If IsCallable(has) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: undefined, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.isSupersetOf(s2); + }, + "GetSendableSetRecord throws an error when has is undefined" +); + +s2.has = {}; +assert.throws( + TypeError, + function () { + s1.isSupersetOf(s2); + }, + "GetSendableSetRecord throws an error when has is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/isSupersetOf.js b/test/sendable/builtins/Set/prototype/isSupersetOf/isSupersetOf.js new file mode 100644 index 0000000000000000000000000000000000000000..2a2b8dff98431962f2a8fe764f420e9c00c98e37 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/isSupersetOf.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf properties +includes: [propertyHelper.js] +features: [set-methods] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.isSupersetOf, + "function", + "`typeof SendableSet.prototype.isSupersetOf` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "isSupersetOf", { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/keys-is-callable.js b/test/sendable/builtins/Set/prototype/isSupersetOf/keys-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..547f3174439b7ca6913fbefff710fdfeff6fc273 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/keys-is-callable.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'keys' property is not callable +info: | + 9. Let keys be ? Get(obj, "keys"). + 10. If IsCallable(keys) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: () => {}, + keys: undefined, +}; +assert.throws( + TypeError, + function () { + s1.isSupersetOf(s2); + }, + "GetSendableSetRecord throws an error when keys is undefined" +); + +s2.keys = {}; +assert.throws( + TypeError, + function () { + s1.isSupersetOf(s2); + }, + "GetSendableSetRecord throws an error when keys is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/length.js b/test/sendable/builtins/Set/prototype/isSupersetOf/length.js new file mode 100644 index 0000000000000000000000000000000000000000..d815fbde54f5f0e5b1b8f06068b05da3a9c1687f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf length property +info: | + SendableSet.prototype.isSupersetOf ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.isSupersetOf, "function"); + +verifyProperty(SendableSet.prototype.isSupersetOf, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1, +}); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/name.js b/test/sendable/builtins/Set/prototype/isSupersetOf/name.js new file mode 100644 index 0000000000000000000000000000000000000000..d63fa32f3dfe33cdd4f02bc4dbec4bd315ebb5e9 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf name property +info: | + SendableSet.prototype.isSupersetOf ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.isSupersetOf, "function"); + +verifyProperty(SendableSet.prototype.isSupersetOf, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "isSupersetOf", +}); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/not-a-constructor.js b/test/sendable/builtins/Set/prototype/isSupersetOf/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..64352fdaf369f8496dc1f628f5b22e8680dd367c --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/not-a-constructor.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf does not implement [[Construct]], is not new-able +includes: [isConstructor.js] +features: [Reflect.construct, set-methods] +---*/ + +assert.sameValue( + isConstructor(SendableSet.prototype.isSupersetOf), + false, + "isConstructor(SendableSet.prototype.isSupersetOf) must return false" +); + +assert.throws( + TypeError, + () => { + new SendableSet.prototype.isSupersetOf(); + }); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/receiver-not-set.js b/test/sendable/builtins/Set/prototype/isSupersetOf/receiver-not-set.js new file mode 100644 index 0000000000000000000000000000000000000000..af3ff6dd524aded1142fb529dde05416582fcb81 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/receiver-not-set.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf throws when receiver is not a SendableSet +features: [set-methods] +---*/ + +class MySendableSetLike { + constructor() { + this.size = 2; + this.has = () => {}; + this.keys = function* keys() { + yield 2; + yield 3; + }; + } +} + +const s1 = new MySendableSetLike(); +const s2 = new SendableSet(); +assert.throws( + TypeError, + () => { + SendableSet.prototype.isSupersetOf.call(s1, s2); + }, + "SendableSet-like class" +); + +const s3 = { + size: 2, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + () => { + SendableSet.prototype.isSupersetOf.call(s3, s2); + }, + "SendableSet-like object" +); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/require-internal-slot.js b/test/sendable/builtins/Set/prototype/isSupersetOf/require-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..f36bae9d221ea8dd0ee548b5a46cba8268db722f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/require-internal-slot.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf RequireInternalSlot +info: | + 2. Perform ? RequireInternalSlot(O, [[SendableSetData]]) +features: [set-methods] +---*/ + +const isSupersetOf = SendableSet.prototype.isSupersetOf; + +assert.sameValue(typeof isSupersetOf, "function"); + +const realSendableSet = new SendableSet([]); + +assert.throws(TypeError, () => isSupersetOf.call(undefined, realSendableSet), "undefined"); +assert.throws(TypeError, () => isSupersetOf.call(null, realSendableSet), "null"); +assert.throws(TypeError, () => isSupersetOf.call(true, realSendableSet), "true"); +assert.throws(TypeError, () => isSupersetOf.call("", realSendableSet), "empty string"); +assert.throws(TypeError, () => isSupersetOf.call(Symbol(), realSendableSet), "symbol"); +assert.throws(TypeError, () => isSupersetOf.call(1, realSendableSet), "1"); +assert.throws(TypeError, () => isSupersetOf.call(1n, realSendableSet), "1n"); +assert.throws(TypeError, () => isSupersetOf.call({}, realSendableSet), "plain object"); +assert.throws(TypeError, () => isSupersetOf.call([], realSendableSet), "array"); +assert.throws(TypeError, () => isSupersetOf.call(new Map(), realSendableSet), "map"); +assert.throws(TypeError, () => isSupersetOf.call(SendableSet.prototype, realSendableSet), "SendableSet.prototype"); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/set-like-array.js b/test/sendable/builtins/Set/prototype/isSupersetOf/set-like-array.js new file mode 100644 index 0000000000000000000000000000000000000000..fa4205130573941c2180e7bc3e4ddf15c7daa556 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/set-like-array.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf consumes a set-like array as a set-like, not an array +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [1]; +s2.size = 3; +s2.has = function (v) { + if (v === 1) return true; + if (v === 2) return true; + throw new Test262Error("SendableSet.prototype.isSupersetOf should only call its argument's has method with contents of this"); +}; +s2.keys = function () { + throw new Test262Error("SendableSet.prototype.isSupersetOf should not call its argument's keys iterator when this.size ≤ arg.size"); +}; + +assert.sameValue(s1.isSupersetOf(s2), false); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/set-like-class-mutation.js b/test/sendable/builtins/Set/prototype/isSupersetOf/set-like-class-mutation.js new file mode 100644 index 0000000000000000000000000000000000000000..960e91f2235b06b9f727381e0d925728f3016770 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/set-like-class-mutation.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf behavior when a custom SendableSet-like class mutates the receiver +features: [set-methods] +includes: [compareArray.js] +---*/ + +const baseSendableSet = new SendableSet(["a", "b", "c"]); + +const evilSendableSetLike = { + size: 3, + has(v) { + throw new Test262Error("SendableSet.prototype.isSupersetOf should not call its argument's has method"); + }, + * keys() { + yield "a"; + baseSendableSet.delete("b"); + baseSendableSet.delete("c"); + baseSendableSet.add("b"); + yield "b"; + }, +}; + +const result = baseSendableSet.isSupersetOf(evilSendableSetLike); +assert.sameValue(result, true); + +const expectedNewBase = ["a", "b"]; +assert.compareArray([...baseSendableSet], expectedNewBase); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/set-like-class-order.js b/test/sendable/builtins/Set/prototype/isSupersetOf/set-like-class-order.js new file mode 100644 index 0000000000000000000000000000000000000000..0b39e4fcbf162c7839ed34527de042c78cd9ac64 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/set-like-class-order.js @@ -0,0 +1,192 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf calls a SendableSet-like class's methods in order +features: [set-methods] +includes: [compareArray.js] +---*/ + +let observedOrder = []; + +function observableIterator() { + let values = ["a", "b", "c"]; + let index = 0; + return { + get next() { + observedOrder.push("getting next"); + return function () { + observedOrder.push("calling next"); + return { + get done() { + observedOrder.push("getting done"); + return index >= values.length; + }, + get value() { + observedOrder.push("getting value"); + return values[index++]; + }, + }; + }; + }, + }; +} + +class MySendableSetLike { + get size() { + observedOrder.push("getting size"); + return { + valueOf: function () { + observedOrder.push("ToNumber(size)"); + return 3; + }, + }; + } + get has() { + observedOrder.push("getting has"); + return function (v) { + throw new Test262Error("SendableSet.prototype.isSupersetOf should not call its argument's has method"); + }; + } + get keys() { + observedOrder.push("getting keys"); + return function () { + observedOrder.push("calling keys"); + return observableIterator(); + }; + } +} + +// this is smaller than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b"]); + const s2 = new MySendableSetLike(); + const result = s1.isSupersetOf(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + // no iteration + ]; + + assert.sameValue(result, false); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is same size as argument - stops eagerly +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "x", "c"]); + const s2 = new MySendableSetLike(); + const result = s1.isSupersetOf(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + "calling keys", + "getting next", + // first iteration, has value + "calling next", + "getting done", + "getting value", + // second iteration, has value + "calling next", + "getting done", + "getting value", + ]; + + assert.sameValue(result, false); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is same size as argument - full run +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "c"]); + const s2 = new MySendableSetLike(); + const result = s1.isSupersetOf(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + "calling keys", + "getting next", + // first iteration, has value + "calling next", + "getting done", + "getting value", + // second iteration, has value + "calling next", + "getting done", + "getting value", + // third iteration, has value + "calling next", + "getting done", + "getting value", + // fourth iteration, no value; ends + "calling next", + "getting done", + ]; + + assert.sameValue(result, true); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is larger than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "c", "d"]); + const s2 = new MySendableSetLike(); + const result = s1.isSupersetOf(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + "calling keys", + "getting next", + // first iteration, has value + "calling next", + "getting done", + "getting value", + // second iteration, has value + "calling next", + "getting done", + "getting value", + // third iteration, has value + "calling next", + "getting done", + "getting value", + // fourth iteration, no value; ends + "calling next", + "getting done", + ]; + + assert.sameValue(result, true); + assert.compareArray(observedOrder, expectedOrder); +} diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/size-is-a-number.js b/test/sendable/builtins/Set/prototype/isSupersetOf/size-is-a-number.js new file mode 100644 index 0000000000000000000000000000000000000000..ae9531b7b9fc56491b0a461750e26474fb30b09a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/size-is-a-number.js @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object has a size that is coerced to NaN +info: | + 2. Let rawSize be ? Get(obj, "size"). + 3. Let numSize be ? ToNumber(rawSize). + 4. NOTE: If rawSize is undefined, then numSize will be NaN. + 5. If numSize is NaN, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: undefined, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.isSupersetOf(s2); + }, + "GetSendableSetRecord throws an error when size is undefined" +); + +s2.size = NaN; +assert.throws( + TypeError, + function () { + s1.isSupersetOf(s2); + }, + "GetSendableSetRecord throws an error when size is NaN" +); + +let coercionCalls = 0; +s2.size = { + valueOf: function() { + ++coercionCalls; + return NaN; + }, +}; +assert.throws( + TypeError, + function () { + s1.isSupersetOf(s2); + }, + "GetSendableSetRecord throws an error when size coerces to NaN" +); +assert.sameValue(coercionCalls, 1, "GetSendableSetRecord coerces size"); + +s2.size = 0n; +assert.throws( + TypeError, + function () { + s1.isSupersetOf(s2); + }, + "GetSendableSetRecord throws an error when size is a BigInt" +); + +s2.size = "string"; +assert.throws( + TypeError, + function () { + s1.isSupersetOf(s2); + }, + "GetSendableSetRecord throws an error when size is a non-numeric string" +); diff --git a/test/sendable/builtins/Set/prototype/isSupersetOf/subclass-receiver-methods.js b/test/sendable/builtins/Set/prototype/isSupersetOf/subclass-receiver-methods.js new file mode 100644 index 0000000000000000000000000000000000000000..c74f685864855241f739216dc203fe451dc0aa0b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/isSupersetOf/subclass-receiver-methods.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.issupersetof +description: SendableSet.prototype.isSupersetOf works on subclasses of SendableSet, but never calls the receiver's size/has/keys methods +features: [set-methods] +---*/ + +let sizeCount = 0; +let hasCount = 0; +let keysCount = 0; + +class MySendableSet extends SendableSet { + size(...rest) { + sizeCount++; + return super.size(...rest); + } + + has(...rest) { + hasCount++; + return super.has(...rest); + } + + keys(...rest) { + keysCount++; + return super.keys(...rest); + } +} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const result = s1.isSupersetOf(s2); +assert.sameValue(result, false); + +assert.sameValue(sizeCount, 0, "size should not be called on the receiver"); +assert.sameValue(hasCount, 0, "has should not be called on the receiver"); +assert.sameValue(keysCount, 0, "keys should not be called on the receiver"); diff --git a/test/sendable/builtins/Set/prototype/keys/keys.js b/test/sendable/builtins/Set/prototype/keys/keys.js new file mode 100644 index 0000000000000000000000000000000000000000..6bce48dc71459ec81e43fa552b7cbd246059463d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/keys/keys.js @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.keys +description: > + The initial value of the keys property is the same function object as the + initial value of the values property. +---*/ + +assert.sameValue( + SendableSet.prototype.keys, + SendableSet.prototype.values, + "The value of `SendableSet.prototype.keys` is `SendableSet.prototype.values`" +); diff --git a/test/sendable/builtins/Set/prototype/size/length.js b/test/sendable/builtins/Set/prototype/size/length.js new file mode 100644 index 0000000000000000000000000000000000000000..6e946e444bda238a989180a57295a1b1191e2c43 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/size/length.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-set.prototype.size +description: > + get SendableSet.prototype.size + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableSet.prototype, "size"); + + +verifyProperty(descriptor.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/size/name.js b/test/sendable/builtins/Set/prototype/size/name.js new file mode 100644 index 0000000000000000000000000000000000000000..2e586d78d1d9cfa6064c24c907db750e9333f4d8 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/size/name.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-set.prototype.size +description: > + get SendableSet.prototype.size + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableSet.prototype, "size"); + + +verifyProperty(descriptor.get, "name", { + value: "get size", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/size/returns-count-of-present-values-before-after-add-delete.js b/test/sendable/builtins/Set/prototype/size/returns-count-of-present-values-before-after-add-delete.js new file mode 100644 index 0000000000000000000000000000000000000000..9b29073cebc9cd9b603b49392074ee5f09859f86 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/size/returns-count-of-present-values-before-after-add-delete.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-set.prototype.size +description: > + get SendableSet.prototype.size + + 5. Let count be 0. + 6. For each e that is an element of entries + a. If e is not empty, set count to count+1. + + Before and after add(), delete() +---*/ + +var s = new SendableSet(); + +assert.sameValue(s.size, 0, "The value of `s.size` is `0`"); + +s.add(0); + +assert.sameValue(s.size, 1, "The value of `s.size` is `1`, after executing `s.add(0)`"); + +s.delete(0); + +assert.sameValue(s.size, 0, "The value of `s.size` is `0`, after executing `s.delete(0)`"); diff --git a/test/sendable/builtins/Set/prototype/size/returns-count-of-present-values-by-insertion.js b/test/sendable/builtins/Set/prototype/size/returns-count-of-present-values-by-insertion.js new file mode 100644 index 0000000000000000000000000000000000000000..ad97cdd0112733467cd08a36490610c6d7dda157 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/size/returns-count-of-present-values-by-insertion.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-set.prototype.size +description: > + get SendableSet.prototype.size + + 5. Let count be 0. + 6. For each e that is an element of entries + a. If e is not empty, set count to count+1. + +features: [Symbol] +---*/ + +var s = new SendableSet(); + +s.add(0); +s.add(undefined); +s.add(false); +s.add(NaN); +s.add(null); +s.add(""); +s.add(Symbol()); + +assert.sameValue(s.size, 7, "The value of `s.size` is `7`"); diff --git a/test/sendable/builtins/Set/prototype/size/returns-count-of-present-values-by-iterable.js b/test/sendable/builtins/Set/prototype/size/returns-count-of-present-values-by-iterable.js new file mode 100644 index 0000000000000000000000000000000000000000..a5f1fe9c3247d169d7e77d6ec3e3300415d425eb --- /dev/null +++ b/test/sendable/builtins/Set/prototype/size/returns-count-of-present-values-by-iterable.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-set.prototype.size +description: > + get SendableSet.prototype.size + + 5. Let count be 0. + 6. For each e that is an element of entries + a. If e is not empty, set count to count+1. + +features: [Symbol] +---*/ + +var s = new SendableSet([0, undefined, false, NaN, null, "", Symbol()]); + +assert.sameValue(s.size, 7, "The value of `s.size` is `7`"); diff --git a/test/sendable/builtins/Set/prototype/size/size.js b/test/sendable/builtins/Set/prototype/size/size.js new file mode 100644 index 0000000000000000000000000000000000000000..4103ae9ccd0d98957be07563d86866a6a72752b0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/size/size.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-set.prototype.size +description: > + get SendableSet.prototype.size + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(SendableSet.prototype, "size"); + +assert.sameValue( + typeof descriptor.get, + "function", + "`typeof descriptor.get` is `'function'`" +); +assert.sameValue( + typeof descriptor.set, + "undefined", + "`typeof descriptor.set` is `\"undefined\"`" +); + +verifyNotEnumerable(SendableSet.prototype, "size"); +verifyConfigurable(SendableSet.prototype, "size"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/add-not-called.js b/test/sendable/builtins/Set/prototype/symmetricDifference/add-not-called.js new file mode 100644 index 0000000000000000000000000000000000000000..58bf9b46e6f49feaabb67f7c1da57e40fc37eab5 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/add-not-called.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference should not call SendableSet.prototype.add +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1, 3]; + +const originalAdd = SendableSet.prototype.add; +let count = 0; +SendableSet.prototype.add = function (...rest) { + count++; + return originalAdd.apply(this, rest); +}; + +const combined = s1.symmetricDifference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(count, 0, "Add is never called"); + +SendableSet.prototype.add = originalAdd; diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/allows-set-like-class.js b/test/sendable/builtins/Set/prototype/symmetricDifference/allows-set-like-class.js new file mode 100644 index 0000000000000000000000000000000000000000..253b006e10309a365baa204627b5b756befbc1bf --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/allows-set-like-class.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: GetSendableSetRecord allows instances of SendableSet-like classes +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new class { + get size() { + return 2; + } + has(v) { + throw new Test262Error("SendableSet.prototype.symmetricDifference should not invoke .has on its argument"); + } + * keys() { + yield 2; + yield 3; + } +}; +const expected = [1, 3]; +const combined = s1.symmetricDifference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/allows-set-like-object.js b/test/sendable/builtins/Set/prototype/symmetricDifference/allows-set-like-object.js new file mode 100644 index 0000000000000000000000000000000000000000..60d2d38bc689b79cf704797eab5a396672dbd059 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/allows-set-like-object.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: GetSendableSetRecord allows SendableSet-like objects +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: (v) => { + throw new Test262Error("SendableSet.prototype.symmetricDifference should not invoke .has on its argument"); + }, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +const expected = [1, 3]; +const combined = s1.symmetricDifference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/array-throws.js b/test/sendable/builtins/Set/prototype/symmetricDifference/array-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..31e6dcd1cf089a874cecd662cc13db3675877197 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/array-throws.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference doesn't work with arrays +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [3]; +assert.throws( + TypeError, + function () { + s1.symmetricDifference(s2); + }, + "Throws an error when an array is used" +); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/builtins.js b/test/sendable/builtins/Set/prototype/symmetricDifference/builtins.js new file mode 100644 index 0000000000000000000000000000000000000000..3635fe64c9bc2fa2f32ca9ff55d7c1d5c60cafb8 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/builtins.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: Tests that SendableSet.prototype.symmetricDifference meets the requirements for built-in objects +features: [set-methods] +---*/ + +assert.sameValue( + Object.isExtensible(SendableSet.prototype.symmetricDifference), + true, + "Built-in objects must be extensible." +); + +assert.sameValue( + Object.prototype.toString.call(SendableSet.prototype.symmetricDifference), + "[object Function]", + "Object.prototype.toString" +); + +assert.sameValue( + Object.getPrototypeOf(SendableSet.prototype.symmetricDifference), + Function.prototype, + "prototype" +); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/called-with-object.js b/test/sendable/builtins/Set/prototype/symmetricDifference/called-with-object.js new file mode 100644 index 0000000000000000000000000000000000000000..0931ce98cd6d88fbe68b29509f60cdff737845c2 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/called-with-object.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws if obj is not an object +info: | + 1. If obj is not an Object, throw a TypeError exception. +features: [set-methods] +---*/ + +let s1 = new SendableSet([1]); +assert.throws( + TypeError, + function () { + s1.symmetricDifference(1); + }, + "number" +); + +assert.throws( + TypeError, + function () { + s1.symmetricDifference(""); + }, + "string" +); + +assert.throws( + TypeError, + function () { + s1.symmetricDifference(1n); + }, + "bigint" +); + +assert.throws( + TypeError, + function () { + s1.symmetricDifference(false); + }, + "boolean" +); + +assert.throws( + TypeError, + function () { + s1.symmetricDifference(undefined); + }, + "undefined" +); + +assert.throws( + TypeError, + function () { + s1.symmetricDifference(null); + }, + "null" +); + +assert.throws( + TypeError, + function () { + s1.symmetricDifference(Symbol("test")); + }, + "symbol" +); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/combines-Map.js b/test/sendable/builtins/Set/prototype/symmetricDifference/combines-Map.js new file mode 100644 index 0000000000000000000000000000000000000000..39c474cdbb520b387ecd96c2435c8c89d69ed2f0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/combines-Map.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference combines with Map +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const m1 = new Map([ + [2, "two"], + [3, "three"], +]); +const expected = [1, 3]; +const combined = s1.symmetricDifference(m1); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/combines-empty-sets.js b/test/sendable/builtins/Set/prototype/symmetricDifference/combines-empty-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..5af303f8afa31fb701f5cbe9d72869ce670b324f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/combines-empty-sets.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference can combine empty SendableSets +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([]); +const s2 = new SendableSet([1, 2]); +let expected = [1, 2]; +let combined = s1.symmetricDifference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); + +const s3 = new SendableSet([1, 2]); +const s4 = new SendableSet([]); +expected = [1, 2]; +combined = s3.symmetricDifference(s4); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); + +const s5 = new SendableSet([]); +const s6 = new SendableSet([]); +expected = []; +combined = s5.symmetricDifference(s6); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/combines-itself.js b/test/sendable/builtins/Set/prototype/symmetricDifference/combines-itself.js new file mode 100644 index 0000000000000000000000000000000000000000..01d2174a6df1e8f185e6033fb705322f61308d05 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/combines-itself.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference is successful when called on itself +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const expected = []; +const combined = s1.symmetricDifference(s1); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(combined === s1, false, "The returned object is a new object"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/combines-same-sets.js b/test/sendable/builtins/Set/prototype/symmetricDifference/combines-same-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..cf72cc72587c01312abf6445633b470b0b524f18 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/combines-same-sets.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference can combine SendableSets that have the same content +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([1, 2]); +const expected = []; +const combined = s1.symmetricDifference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(combined === s1, false, "The returned object is a new object"); +assert.sameValue(combined === s2, false, "The returned object is a new object"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/combines-sets.js b/test/sendable/builtins/Set/prototype/symmetricDifference/combines-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..a4de65645a5368ee31ddde3d18e9e8c09a752f11 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/combines-sets.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference combines SendableSets +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1, 3]; +const combined = s1.symmetricDifference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/converts-negative-zero.js b/test/sendable/builtins/Set/prototype/symmetricDifference/converts-negative-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..37f81eb46a7e084694279759fb4313620c0f329a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/converts-negative-zero.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference converts -0𝔽 to +0𝔽 +info: | + 7.b.ii If nextValue is -0𝔽, set nextValue to +0𝔽. +features: [set-methods] +includes: [compareArray.js] +---*/ + +const setlikeWithMinusZero = { + size: 1, + has: function () { + throw new Test262Error("SendableSet.prototype.symmetricDifference should not invoke .has on its argument"); + }, + keys: function () { + // we use an array here because the SendableSet constructor would normalize away -0 + return [-0].values(); + }, +}; + +const s1 = new SendableSet([1, 2]); +let expected = [1, 2, +0]; +let combined = s1.symmetricDifference(setlikeWithMinusZero); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/has-is-callable.js b/test/sendable/builtins/Set/prototype/symmetricDifference/has-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..3263508ca48cb499dd853de4f0c2101c77f8b7e7 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/has-is-callable.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'has' property is not callable +info: | + 7. Let has be ? Get(obj, "has"). + 8. If IsCallable(has) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: undefined, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.symmetricDifference(s2); + }, + "GetSendableSetRecord throws an error when has is undefined" +); + +s2.has = {}; +assert.throws( + TypeError, + function () { + s1.symmetricDifference(s2); + }, + "GetSendableSetRecord throws an error when has is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/keys-is-callable.js b/test/sendable/builtins/Set/prototype/symmetricDifference/keys-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..0b982462614e2e721e06adb15f1664fca7fb7707 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/keys-is-callable.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'keys' property is not callable +info: | + 9. Let keys be ? Get(obj, "keys"). + 10. If IsCallable(keys) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: () => {}, + keys: undefined, +}; +assert.throws( + TypeError, + function () { + s1.symmetricDifference(s2); + }, + "GetSendableSetRecord throws an error when keys is undefined" +); + +s2.keys = {}; +assert.throws( + TypeError, + function () { + s1.symmetricDifference(s2); + }, + "GetSendableSetRecord throws an error when keys is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/length.js b/test/sendable/builtins/Set/prototype/symmetricDifference/length.js new file mode 100644 index 0000000000000000000000000000000000000000..55b64ef64fd3900288682c284c75a683ffe94423 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference length property +info: | + SendableSet.prototype.symmetricDifference ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.symmetricDifference, "function"); + +verifyProperty(SendableSet.prototype.symmetricDifference, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1, +}); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/name.js b/test/sendable/builtins/Set/prototype/symmetricDifference/name.js new file mode 100644 index 0000000000000000000000000000000000000000..a8844759fad4d012b098836ce5cee289c158d734 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference name property +info: | + SendableSet.prototype.symmetricDifference ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.symmetricDifference, "function"); + +verifyProperty(SendableSet.prototype.symmetricDifference, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "symmetricDifference", +}); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/not-a-constructor.js b/test/sendable/builtins/Set/prototype/symmetricDifference/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..b30ae7d49a7081f9b0b56fb88f161a62b874bfc4 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/not-a-constructor.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference does not implement [[Construct]], is not new-able +includes: [isConstructor.js] +features: [Reflect.construct, set-methods] +---*/ + +assert.sameValue( + isConstructor(SendableSet.prototype.symmetricDifference), + false, + "isConstructor(SendableSet.prototype.symmetricDifference) must return false" +); + +assert.throws( + TypeError, + () => { + new SendableSet.prototype.symmetricDifference(); + }); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/receiver-not-set.js b/test/sendable/builtins/Set/prototype/symmetricDifference/receiver-not-set.js new file mode 100644 index 0000000000000000000000000000000000000000..a2d9aff20e0f0b0012def5308c63e6cb26c16df8 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/receiver-not-set.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference throws when receiver is not a SendableSet +features: [set-methods] +---*/ + +class MySendableSetLike { + constructor() { + this.size = 2; + this.has = () => {}; + this.keys = function* keys() { + yield 2; + yield 3; + }; + } +} + +const s1 = new MySendableSetLike(); +const s2 = new SendableSet(); +assert.throws( + TypeError, + () => { + SendableSet.prototype.symmetricDifference.call(s1, s2); + }, + "SendableSet-like class" +); + +const s3 = { + size: 2, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + () => { + SendableSet.prototype.symmetricDifference.call(s3, s2); + }, + "SendableSet-like object" +); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/require-internal-slot.js b/test/sendable/builtins/Set/prototype/symmetricDifference/require-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..92a73e82d3a7e212c571ab80886d9d31d6f843af --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/require-internal-slot.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference RequireInternalSlot +info: | + 2. Perform ? RequireInternalSlot(O, [[SendableSetData]]) +features: [set-methods] +---*/ + +const symmetricDifference = SendableSet.prototype.symmetricDifference; + +assert.sameValue(typeof symmetricDifference, "function"); + +const realSendableSet = new SendableSet([]); + +assert.throws(TypeError, () => symmetricDifference.call(undefined, realSendableSet), "undefined"); +assert.throws(TypeError, () => symmetricDifference.call(null, realSendableSet), "null"); +assert.throws(TypeError, () => symmetricDifference.call(true, realSendableSet), "true"); +assert.throws(TypeError, () => symmetricDifference.call("", realSendableSet), "empty string"); +assert.throws(TypeError, () => symmetricDifference.call(Symbol(), realSendableSet), "symbol"); +assert.throws(TypeError, () => symmetricDifference.call(1, realSendableSet), "1"); +assert.throws(TypeError, () => symmetricDifference.call(1n, realSendableSet), "1n"); +assert.throws(TypeError, () => symmetricDifference.call({}, realSendableSet), "plain object"); +assert.throws(TypeError, () => symmetricDifference.call([], realSendableSet), "array"); +assert.throws(TypeError, () => symmetricDifference.call(new Map(), realSendableSet), "map"); +assert.throws(TypeError, () => symmetricDifference.call(SendableSet.prototype, realSendableSet), "SendableSet.prototype"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/result-order.js b/test/sendable/builtins/Set/prototype/symmetricDifference/result-order.js new file mode 100644 index 0000000000000000000000000000000000000000..fa2d55ea72e1897637e00178797f7362a0ba6cc0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/result-order.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference result ordering +features: [set-methods] +includes: [compareArray.js] +---*/ + +// results are ordered as in this, then as in other +{ + const s1 = new SendableSet([1, 2, 3, 4]); + const s2 = new SendableSet([6, 5, 4, 3]); + + assert.compareArray([...s1.symmetricDifference(s2)], [1, 2, 6, 5]); +} + +{ + const s1 = new SendableSet([6, 5, 4, 3]); + const s2 = new SendableSet([1, 2, 3, 4]); + + assert.compareArray([...s1.symmetricDifference(s2)], [6, 5, 1, 2]); +} diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/set-like-array.js b/test/sendable/builtins/Set/prototype/symmetricDifference/set-like-array.js new file mode 100644 index 0000000000000000000000000000000000000000..a7f561cfc224e3e979dbefbcb45959717423106d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/set-like-array.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference consumes a set-like array as a set-like, not an array +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [5]; +s2.size = 3; +s2.has = function (v) { + throw new Test262Error("SendableSet.prototype.symmetricDifference should not invoke .has on its argument"); +}; +s2.keys = function () { + return [2, 3, 4].values(); +}; + +const expected = [1, 3, 4]; +const combined = s1.symmetricDifference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/set-like-class-mutation.js b/test/sendable/builtins/Set/prototype/symmetricDifference/set-like-class-mutation.js new file mode 100644 index 0000000000000000000000000000000000000000..cb32a2647cd155cd36c2555983b5ead45e1aef8f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/set-like-class-mutation.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference maintains values even when a custom SendableSet-like class mutates the receiver +features: [set-methods] +includes: [compareArray.js] +---*/ + +const baseSendableSet = new SendableSet(["a", "b", "c", "d", "e"]); + +function mutatingIterator() { + let index = 0; + let values = ["x", "b", "c", "c"]; + return { + next() { + if (index === 0) { + baseSendableSet.delete("b"); + baseSendableSet.delete("c"); + baseSendableSet.add("b"); + baseSendableSet.add("d"); + } + return { + done: index >= values.length, + value: values[index++], + }; + }, + }; +} + +const evilSendableSetLike = { + size: 4, + get has() { + baseSendableSet.add("q"); + return function () { + throw new Test262Error("SendableSet.prototype.symmetricDifference should not invoke .has on its argument"); + }; + }, + keys() { + return mutatingIterator(); + }, +}; + +const combined = baseSendableSet.symmetricDifference(evilSendableSetLike); +const expectedCombined = ["a", "c", "d", "e", "q", "x"]; +assert.compareArray([...combined], expectedCombined); + +const expectedNewBase = ["a", "d", "e", "q", "b"]; +assert.compareArray([...baseSendableSet], expectedNewBase); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/set-like-class-order.js b/test/sendable/builtins/Set/prototype/symmetricDifference/set-like-class-order.js new file mode 100644 index 0000000000000000000000000000000000000000..170190f603716b0eededd6c607e00081660afad0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/set-like-class-order.js @@ -0,0 +1,179 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference calls a SendableSet-like class's methods in order +features: [set-methods] +includes: [compareArray.js] +---*/ + +let observedOrder = []; + +function observableIterator() { + let values = ["a", "b", "c"]; + let index = 0; + return { + get next() { + observedOrder.push("getting next"); + return function () { + observedOrder.push("calling next"); + return { + get done() { + observedOrder.push("getting done"); + return index >= values.length; + }, + get value() { + observedOrder.push("getting value"); + return values[index++]; + }, + }; + }; + }, + }; +} + +class MySendableSetLike { + get size() { + observedOrder.push("getting size"); + return { + valueOf: function () { + observedOrder.push("ToNumber(size)"); + return 2; + }, + }; + } + get has() { + observedOrder.push("getting has"); + return function () { + throw new Test262Error("SendableSet.prototype.symmetricDifference should not invoke .has on its argument"); + }; + } + get keys() { + observedOrder.push("getting keys"); + return function () { + observedOrder.push("calling keys"); + return observableIterator(); + }; + } +} + +// this is smaller than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "d"]); + const s2 = new MySendableSetLike(); + const combined = s1.symmetricDifference(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + "calling keys", + "getting next", + // first iteration, has value + "calling next", + "getting done", + "getting value", + // second iteration, has value + "calling next", + "getting done", + "getting value", + // third iteration, has value + "calling next", + "getting done", + "getting value", + // fourth iteration, no value; ends + "calling next", + "getting done", + ]; + + assert.compareArray([...combined], ["d", "b", "c"]); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is same size as argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "d"]); + const s2 = new MySendableSetLike(); + const combined = s1.symmetricDifference(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + "calling keys", + "getting next", + // first iteration, has value + "calling next", + "getting done", + "getting value", + // second iteration, has value + "calling next", + "getting done", + "getting value", + // third iteration, has value + "calling next", + "getting done", + "getting value", + // fourth iteration, no value; ends + "calling next", + "getting done", + ]; + + assert.compareArray([...combined], ["d", "c"]); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is larger than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "d", "e"]); + const s2 = new MySendableSetLike(); + const combined = s1.symmetricDifference(s2); + + const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + "calling keys", + "getting next", + // first iteration, has value + "calling next", + "getting done", + "getting value", + // second iteration, has value + "calling next", + "getting done", + "getting value", + // third iteration, has value + "calling next", + "getting done", + "getting value", + // fourth iteration, no value; ends + "calling next", + "getting done", + ]; + + assert.compareArray([...combined], ["d", "e", "c"]); + assert.compareArray(observedOrder, expectedOrder); +} diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/size-is-a-number.js b/test/sendable/builtins/Set/prototype/symmetricDifference/size-is-a-number.js new file mode 100644 index 0000000000000000000000000000000000000000..c30184f3354922ce7cfb1aa9d01abbcd2a198ca0 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/size-is-a-number.js @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object has a size that is coerced to NaN +info: | + 2. Let rawSize be ? Get(obj, "size"). + 3. Let numSize be ? ToNumber(rawSize). + 4. NOTE: If rawSize is undefined, then numSize will be NaN. + 5. If numSize is NaN, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: undefined, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.symmetricDifference(s2); + }, + "GetSendableSetRecord throws an error when size is undefined" +); + +s2.size = NaN; +assert.throws( + TypeError, + function () { + s1.symmetricDifference(s2); + }, + "GetSendableSetRecord throws an error when size is NaN" +); + +let coercionCalls = 0; +s2.size = { + valueOf: function() { + ++coercionCalls; + return NaN; + }, +}; +assert.throws( + TypeError, + function () { + s1.symmetricDifference(s2); + }, + "GetSendableSetRecord throws an error when size coerces to NaN" +); +assert.sameValue(coercionCalls, 1, "GetSendableSetRecord coerces size"); + +s2.size = 0n; +assert.throws( + TypeError, + function () { + s1.symmetricDifference(s2); + }, + "GetSendableSetRecord throws an error when size is a BigInt" +); + +s2.size = "string"; +assert.throws( + TypeError, + function () { + s1.symmetricDifference(s2); + }, + "GetSendableSetRecord throws an error when size is a non-numeric string" +); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/subclass-receiver-methods.js b/test/sendable/builtins/Set/prototype/symmetricDifference/subclass-receiver-methods.js new file mode 100644 index 0000000000000000000000000000000000000000..a3c5634317c1b557a55d2f0b63058a677da7a766 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/subclass-receiver-methods.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference works on subclasses of SendableSet, but never calls the receiver's size/has/keys methods +features: [set-methods] +includes: [compareArray.js] +---*/ + +let sizeCount = 0; +let hasCount = 0; +let keysCount = 0; + +class MySendableSet extends SendableSet { + size(...rest) { + sizeCount++; + return super.size(...rest); + } + + has(...rest) { + hasCount++; + return super.has(...rest); + } + + keys(...rest) { + keysCount++; + return super.keys(...rest); + } +} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1, 3]; +const combined = s1.symmetricDifference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); +assert.sameValue(sizeCount, 0, "size should not be called on the receiver"); +assert.sameValue(hasCount, 0, "has should not be called on the receiver"); +assert.sameValue(keysCount, 0, "keys should not be called on the receiver"); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/subclass-symbol-species.js b/test/sendable/builtins/Set/prototype/symmetricDifference/subclass-symbol-species.js new file mode 100644 index 0000000000000000000000000000000000000000..cccd545939b9cac95e459acad7ef4fbfbedbe757 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/subclass-symbol-species.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference works on subclasses of SendableSet, but returns an instance of SendableSet even when Symbol.species is overridden. +features: [set-methods] +includes: [compareArray.js] +---*/ +var count = 0; +class MySendableSet extends SendableSet { + static get [Symbol.species]() { + count++; + return SendableSet; + } +} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1, 3]; +const combined = s1.symmetricDifference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(count, 0, "Symbol.species is never called"); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/subclass.js b/test/sendable/builtins/Set/prototype/symmetricDifference/subclass.js new file mode 100644 index 0000000000000000000000000000000000000000..b16754b727a809035b43aae68a28e03ec3e20f24 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/subclass.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference works on subclasses of SendableSet, but returns an instance of SendableSet +features: [set-methods] +includes: [compareArray.js] +---*/ + +class MySendableSet extends SendableSet {} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1, 3]; +const combined = s1.symmetricDifference(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); diff --git a/test/sendable/builtins/Set/prototype/symmetricDifference/symmetricDifference.js b/test/sendable/builtins/Set/prototype/symmetricDifference/symmetricDifference.js new file mode 100644 index 0000000000000000000000000000000000000000..00df85146d2ead1ee8a5ebcd9749a79d0b9a87f1 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/symmetricDifference/symmetricDifference.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.symmetricdifference +description: SendableSet.prototype.symmetricDifference properties +includes: [propertyHelper.js] +features: [set-methods] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.symmetricDifference, + "function", + "`typeof SendableSet.prototype.symmetricDifference` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "symmetricDifference", { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/union/add-not-called.js b/test/sendable/builtins/Set/prototype/union/add-not-called.js new file mode 100644 index 0000000000000000000000000000000000000000..a34fef110d7c865a0de2e1b6ad5cfadf0e5ac399 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/add-not-called.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union should not call SendableSet.prototype.add +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1, 2, 3]; + +const originalAdd = SendableSet.prototype.add; +let count = 0; +SendableSet.prototype.add = function (...rest) { + count++; + return originalAdd.apply(this, rest); +}; + +const combined = s1.union(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(count, 0, "Add is never called"); + +SendableSet.prototype.add = originalAdd; diff --git a/test/sendable/builtins/Set/prototype/union/allows-set-like-class.js b/test/sendable/builtins/Set/prototype/union/allows-set-like-class.js new file mode 100644 index 0000000000000000000000000000000000000000..e2c6cd398c08dbaafa5cdf565960414fe1da308d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/allows-set-like-class.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: GetSendableSetRecord allows instances of SendableSet-like classes +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new class { + get size() { + return 2; + } + has() { + throw new Test262Error("SendableSet.prototype.union should not invoke .has on its argument"); + } + * keys() { + yield 2; + yield 3; + } +}; +const expected = [1, 2, 3]; +const combined = s1.union(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/union/allows-set-like-object.js b/test/sendable/builtins/Set/prototype/union/allows-set-like-object.js new file mode 100644 index 0000000000000000000000000000000000000000..80de6c3ec9701a5c3e9c4ada2c5616693110ac46 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/allows-set-like-object.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: GetSendableSetRecord allows SendableSet-like objects +info: | + 1. If obj is not an Object, throw a TypeError exception. + 2. Let rawSize be ? Get(obj, "size"). + ... + 7. Let has be ? Get(obj, "has"). + ... + 9. Let keys be ? Get(obj, "keys"). +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: () => { + throw new Test262Error("SendableSet.prototype.union should not invoke .has on its argument"); + }, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +const expected = [1, 2, 3]; +const combined = s1.union(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/union/appends-new-values.js b/test/sendable/builtins/Set/prototype/union/appends-new-values.js new file mode 100644 index 0000000000000000000000000000000000000000..c240914f29a1c1fbe79b96a9ec3efaa7d1797be8 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/appends-new-values.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union appends new values to a copy of the original SendableSet +info: | + 7.b.iii.1 Append nextValue to resultSendableSetData. +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([-1, 0, 3]); +const expected = [1, 2, -1, 0, 3]; +const combined = s1.union(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); + +const s3 = new SendableSet([1, 2, -3]); +const s4 = new SendableSet([-1, 0]); +const expected2 = [1, 2, -3, -1, 0]; +const combined2 = s3.union(s4); + +assert.compareArray([...combined2], expected2); +assert.sameValue( + combined2 instanceof SendableSet, + true, + "The returned object is a SendableSet" +); diff --git a/test/sendable/builtins/Set/prototype/union/array-throws.js b/test/sendable/builtins/Set/prototype/union/array-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..0e55d13d24b57a2e3a9056cd11c0859d82397a41 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/array-throws.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union doesn't work with arrays +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [3]; +assert.throws( + TypeError, + function () { + s1.union(s2); + }, + "Throws an error when an array is used" +); diff --git a/test/sendable/builtins/Set/prototype/union/builtins.js b/test/sendable/builtins/Set/prototype/union/builtins.js new file mode 100644 index 0000000000000000000000000000000000000000..5f75fc8d490465edeec89d50a736096d287ab087 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/builtins.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: Tests that SendableSet.prototype.union meets the requirements for built-in objects +features: [set-methods] +---*/ + +assert.sameValue( + Object.isExtensible(SendableSet.prototype.union), + true, + "Built-in objects must be extensible." +); + +assert.sameValue( + Object.prototype.toString.call(SendableSet.prototype.union), + "[object Function]", + "Object.prototype.toString" +); + +assert.sameValue( + Object.getPrototypeOf(SendableSet.prototype.union), + Function.prototype, + "prototype" +); diff --git a/test/sendable/builtins/Set/prototype/union/called-with-object.js b/test/sendable/builtins/Set/prototype/union/called-with-object.js new file mode 100644 index 0000000000000000000000000000000000000000..a419b323d95f482a652bd579d1dc16ced359aec1 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/called-with-object.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws if obj is not an object +info: | + 1. If obj is not an Object, throw a TypeError exception. +features: [set-methods] +---*/ + +let s1 = new SendableSet([1]); +assert.throws( + TypeError, + function () { + s1.union(1); + }, + "number" +); + +assert.throws( + TypeError, + function () { + s1.union(""); + }, + "string" +); + +assert.throws( + TypeError, + function () { + s1.union(1n); + }, + "bigint" +); + +assert.throws( + TypeError, + function () { + s1.union(false); + }, + "boolean" +); + +assert.throws( + TypeError, + function () { + s1.union(undefined); + }, + "undefined" +); + +assert.throws( + TypeError, + function () { + s1.union(null); + }, + "null" +); + +assert.throws( + TypeError, + function () { + s1.union(Symbol("test")); + }, + "symbol" +); diff --git a/test/sendable/builtins/Set/prototype/union/combines-Map.js b/test/sendable/builtins/Set/prototype/union/combines-Map.js new file mode 100644 index 0000000000000000000000000000000000000000..6f421a4bdeb22b612dcdf658b03dc999f4bb433f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/combines-Map.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union combines with Map +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const m1 = new Map([ + [2, "two"], + [3, "three"], +]); +const expected = [1, 2, 3]; +const combined = s1.union(m1); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/union/combines-empty-sets.js b/test/sendable/builtins/Set/prototype/union/combines-empty-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..ebf46bf7cc57322478aab07d908a5a9759b33431 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/combines-empty-sets.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union can combine empty SendableSets +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([]); +const s2 = new SendableSet([1, 2]); +let expected = [1, 2]; +let combined = s1.union(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); + +const s3 = new SendableSet([1, 2]); +const s4 = new SendableSet([]); +expected = [1, 2]; +combined = s3.union(s4); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); + +const s5 = new SendableSet([]); +const s6 = new SendableSet([]); +expected = []; +combined = s5.union(s6); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/union/combines-itself.js b/test/sendable/builtins/Set/prototype/union/combines-itself.js new file mode 100644 index 0000000000000000000000000000000000000000..b59b3944e5be9f1ee5d98d440fd0c16883bbb081 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/combines-itself.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union is successful when called on itself +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const expected = [1, 2]; +const combined = s1.union(s1); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(combined === s1, false, "The returned object is a new object"); diff --git a/test/sendable/builtins/Set/prototype/union/combines-same-sets.js b/test/sendable/builtins/Set/prototype/union/combines-same-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..665d2ea47112311becea5fb41e8abeba70aed5af --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/combines-same-sets.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union can combine SendableSets that have the same content +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([1, 2]); +const expected = [1, 2]; +const combined = s1.union(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue(combined === s1, false, "The returned object is a new object"); +assert.sameValue(combined === s2, false, "The returned object is a new object"); diff --git a/test/sendable/builtins/Set/prototype/union/combines-sets.js b/test/sendable/builtins/Set/prototype/union/combines-sets.js new file mode 100644 index 0000000000000000000000000000000000000000..9b48eec3bd942f89069c6f4da5203a7b1b6c7188 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/combines-sets.js @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union combines SendableSets +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1, 2, 3]; +const combined = s1.union(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/union/converts-negative-zero.js b/test/sendable/builtins/Set/prototype/union/converts-negative-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..b4060f27b573554578245bde901be4219f151373 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/converts-negative-zero.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union converts -0𝔽 to +0𝔽 +info: | + 7.b.ii. If nextValue is -0𝔽, set nextValue to +0𝔽. +features: [set-methods] +includes: [compareArray.js] +---*/ + +const setlikeWithMinusZero = { + size: 1, + has: function () { + throw new Test262Error("SendableSet.prototype.union should not invoke .has on its argument"); + }, + keys: function () { + // we use an array here because the SendableSet constructor would normalize away -0 + return [-0].values(); + }, +}; + +const s1 = new SendableSet([1]); +let expected = [1, +0]; +let combined = s1.union(setlikeWithMinusZero); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); + +const s2 = new SendableSet([+0]); +expected = [+0]; +combined = s2.union(setlikeWithMinusZero); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/union/has-is-callable.js b/test/sendable/builtins/Set/prototype/union/has-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..e0f871060be8f36fb5c4874b9d127b328ada9f9a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/has-is-callable.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'has' property is not callable +info: | + 7. Let has be ? Get(obj, "has"). + 8. If IsCallable(has) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: undefined, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.union(s2); + }, + "GetSendableSetRecord throws an error when has is undefined" +); + +s2.has = {}; +assert.throws( + TypeError, + function () { + s1.union(s2); + }, + "GetSendableSetRecord throws an error when has is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/union/keys-is-callable.js b/test/sendable/builtins/Set/prototype/union/keys-is-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..834a85f12a92dc8c0a1de5c2a0b892a9ef764382 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/keys-is-callable.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object's 'keys' property is not callable +info: | + 9. Let keys be ? Get(obj, "keys"). + 10. If IsCallable(keys) is false, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: 2, + has: () => {}, + keys: undefined, +}; +assert.throws( + TypeError, + function () { + s1.union(s2); + }, + "GetSendableSetRecord throws an error when keys is undefined" +); + +s2.keys = {}; +assert.throws( + TypeError, + function () { + s1.union(s2); + }, + "GetSendableSetRecord throws an error when keys is not callable" +); diff --git a/test/sendable/builtins/Set/prototype/union/length.js b/test/sendable/builtins/Set/prototype/union/length.js new file mode 100644 index 0000000000000000000000000000000000000000..16ad84e42f84670b1bd5c3ec4cf81d9586c87df4 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union length property +info: | + SendableSet.prototype.union ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.union, "function"); + +verifyProperty(SendableSet.prototype.union, "length", { + enumerable: false, + writable: false, + configurable: true, + value: 1, +}); diff --git a/test/sendable/builtins/Set/prototype/union/name.js b/test/sendable/builtins/Set/prototype/union/name.js new file mode 100644 index 0000000000000000000000000000000000000000..688702085e95082a8e8519fa736ca183085395bf --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union name property +info: | + SendableSet.prototype.union ( other ) +includes: [propertyHelper.js] +features: [set-methods] +---*/ +assert.sameValue(typeof SendableSet.prototype.union, "function"); + +verifyProperty(SendableSet.prototype.union, "name", { + enumerable: false, + writable: false, + configurable: true, + value: "union", +}); diff --git a/test/sendable/builtins/Set/prototype/union/not-a-constructor.js b/test/sendable/builtins/Set/prototype/union/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..debfbf3b9cf990d2b7102ef1d45af5a7c41a50a1 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/not-a-constructor.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union does not implement [[Construct]], is not new-able +includes: [isConstructor.js] +features: [Reflect.construct, set-methods] +---*/ + +assert.sameValue( + isConstructor(SendableSet.prototype.union), + false, + "isConstructor(SendableSet.prototype.union) must return false" +); + +assert.throws( + TypeError, + () => { + new SendableSet.prototype.union(); + }); diff --git a/test/sendable/builtins/Set/prototype/union/receiver-not-set.js b/test/sendable/builtins/Set/prototype/union/receiver-not-set.js new file mode 100644 index 0000000000000000000000000000000000000000..a4f194c449e51db979c5981fcfbea7c2eff89180 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/receiver-not-set.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union throws when receiver is not a SendableSet +features: [set-methods] +---*/ + +class MySendableSetLike { + constructor() { + this.size = 2; + this.has = () => {}; + this.keys = function* keys() { + yield 2; + yield 3; + }; + } +} + +const s1 = new MySendableSetLike(); +const s2 = new SendableSet(); +assert.throws( + TypeError, + () => { + SendableSet.prototype.union.call(s1, s2); + }, + "SendableSet-like class" +); + +const s3 = { + size: 2, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + () => { + SendableSet.prototype.union.call(s3, s2); + }, + "SendableSet-like object" +); diff --git a/test/sendable/builtins/Set/prototype/union/require-internal-slot.js b/test/sendable/builtins/Set/prototype/union/require-internal-slot.js new file mode 100644 index 0000000000000000000000000000000000000000..9179ae5a1cf772cb42a849ca1da4fe727272c6dc --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/require-internal-slot.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union RequireInternalSlot +info: | + 2. Perform ? RequireInternalSlot(O, [[SendableSetData]]) +features: [set-methods] +---*/ + +const union = SendableSet.prototype.union; + +assert.sameValue(typeof union, "function"); + +const realSendableSet = new SendableSet([]); + +assert.throws(TypeError, () => union.call(undefined, realSendableSet), "undefined"); +assert.throws(TypeError, () => union.call(null, realSendableSet), "null"); +assert.throws(TypeError, () => union.call(true, realSendableSet), "true"); +assert.throws(TypeError, () => union.call("", realSendableSet), "empty string"); +assert.throws(TypeError, () => union.call(Symbol(), realSendableSet), "symbol"); +assert.throws(TypeError, () => union.call(1, realSendableSet), "1"); +assert.throws(TypeError, () => union.call(1n, realSendableSet), "1n"); +assert.throws(TypeError, () => union.call({}, realSendableSet), "plain object"); +assert.throws(TypeError, () => union.call([], realSendableSet), "array"); +assert.throws(TypeError, () => union.call(new Map(), realSendableSet), "map"); +assert.throws(TypeError, () => union.call(SendableSet.prototype, realSendableSet), "SendableSet.prototype"); diff --git a/test/sendable/builtins/Set/prototype/union/result-order.js b/test/sendable/builtins/Set/prototype/union/result-order.js new file mode 100644 index 0000000000000000000000000000000000000000..2f10ca00c9ef819425181893b769680ce5b2999d --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/result-order.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union result ordering +features: [set-methods] +includes: [compareArray.js] +---*/ + +{ + const s1 = new SendableSet([1, 2]); + const s2 = new SendableSet([2, 3]); + + assert.compareArray([...s1.union(s2)], [1, 2, 3]); +} + +{ + const s1 = new SendableSet([2, 3]); + const s2 = new SendableSet([1, 2]); + + assert.compareArray([...s1.union(s2)], [2, 3, 1]); +} + +{ + const s1 = new SendableSet([1, 2]); + const s2 = new SendableSet([3]); + + assert.compareArray([...s1.union(s2)], [1, 2, 3]); +} + +{ + const s1 = new SendableSet([3]); + const s2 = new SendableSet([1, 2]); + + assert.compareArray([...s1.union(s2)], [3, 1, 2]); +} diff --git a/test/sendable/builtins/Set/prototype/union/set-like-array.js b/test/sendable/builtins/Set/prototype/union/set-like-array.js new file mode 100644 index 0000000000000000000000000000000000000000..3e46470e75ab0f1c25be4c817f818e3952d93a81 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/set-like-array.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union consumes a set-like array as a set-like, not an array +features: [set-methods] +includes: [compareArray.js] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = [5, 6]; +s2.size = 3; +s2.has = function () { + throw new Test262Error("SendableSet.prototype.union should not invoke .has on its argument"); +}; +s2.keys = function () { + return [2, 3, 4].values(); +}; + +const expected = [1, 2, 3, 4]; +const combined = s1.union(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); diff --git a/test/sendable/builtins/Set/prototype/union/set-like-class-mutation.js b/test/sendable/builtins/Set/prototype/union/set-like-class-mutation.js new file mode 100644 index 0000000000000000000000000000000000000000..6b00e5395a6d6fff5967eb2c3ef81a145a1e1a01 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/set-like-class-mutation.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union maintains values even when a custom SendableSet-like class mutates the receiver +features: [set-methods] +includes: [compareArray.js] +---*/ + +const baseSendableSet = new SendableSet(["a", "b", "c", "d", "e"]); + +function mutatingIterator() { + let index = 0; + let values = ["x", "y"]; + return { + next() { + baseSendableSet.delete("b"); + baseSendableSet.delete("c"); + baseSendableSet.add("b"); + baseSendableSet.add("d"); + return { + done: index >= 2, + value: values[index++], + }; + }, + }; +} + +const evilSendableSetLike = { + size: 2, + get has() { + baseSendableSet.add("q"); + return function () { + throw new Test262Error("SendableSet.prototype.union should not invoke .has on its argument"); + }; + }, + keys() { + return mutatingIterator(); + }, +}; + +const combined = baseSendableSet.union(evilSendableSetLike); +const expectedCombined = ["a", "b", "c", "d", "e", "q", "x", "y"]; +assert.compareArray([...combined], expectedCombined); + +const expectedNewBase = ["a", "d", "e", "q", "b"]; +assert.compareArray([...baseSendableSet], expectedNewBase); diff --git a/test/sendable/builtins/Set/prototype/union/set-like-class-order.js b/test/sendable/builtins/Set/prototype/union/set-like-class-order.js new file mode 100644 index 0000000000000000000000000000000000000000..a8ae6086902a4efd4eb6ad329c0ced56f6f813a4 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/set-like-class-order.js @@ -0,0 +1,131 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union calls a SendableSet-like class's methods in order +features: [set-methods] +includes: [compareArray.js] +---*/ + +let observedOrder = []; + +function observableIterator() { + let values = ["a", "b", "c"]; + let index = 0; + return { + get next() { + observedOrder.push("getting next"); + return function () { + observedOrder.push("calling next"); + return { + get done() { + observedOrder.push("getting done"); + return index >= values.length; + }, + get value() { + observedOrder.push("getting value"); + return values[index++]; + }, + }; + }; + }, + }; +} + +class MySendableSetLike { + get size() { + observedOrder.push("getting size"); + return { + valueOf: function () { + observedOrder.push("ToNumber(size)"); + return 2; + }, + }; + } + get has() { + observedOrder.push("getting has"); + return function () { + throw new Test262Error("SendableSet.prototype.union should not invoke .has on its argument"); + }; + } + get keys() { + observedOrder.push("getting keys"); + return function () { + observedOrder.push("calling keys"); + return observableIterator(); + }; + } +} + +const expectedOrder = [ + "getting size", + "ToNumber(size)", + "getting has", + "getting keys", + "calling keys", + "getting next", + // first iteration, has value + "calling next", + "getting done", + "getting value", + // second iteration, has value + "calling next", + "getting done", + "getting value", + // third iteration, has value + "calling next", + "getting done", + "getting value", + // fourth iteration, no value; ends + "calling next", + "getting done", +]; + +// this is smaller than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "d"]); + const s2 = new MySendableSetLike(); + const combined = s1.union(s2); + + assert.compareArray([...combined], ["a", "d", "b", "c"]); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is same size as argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "d"]); + const s2 = new MySendableSetLike(); + const combined = s1.union(s2); + + assert.compareArray([...combined], ["a", "b", "d", "c"]); + assert.compareArray(observedOrder, expectedOrder); +} + +// this is larger than argument +{ + observedOrder = []; + + const s1 = new SendableSet(["a", "b", "d", "e"]); + const s2 = new MySendableSetLike(); + const combined = s1.union(s2); + + assert.compareArray([...combined], ["a", "b", "d", "e", "c"]); + assert.compareArray(observedOrder, expectedOrder); +} diff --git a/test/sendable/builtins/Set/prototype/union/size-is-a-number.js b/test/sendable/builtins/Set/prototype/union/size-is-a-number.js new file mode 100644 index 0000000000000000000000000000000000000000..78c6ffeb56d1282b73016c5a39406699e49d7ed4 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/size-is-a-number.js @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-getsetrecord +description: GetSendableSetRecord throws an exception if the SendableSet-like object has a size that is coerced to NaN +info: | + 2. Let rawSize be ? Get(obj, "size"). + 3. Let numSize be ? ToNumber(rawSize). + 4. NOTE: If rawSize is undefined, then numSize will be NaN. + 5. If numSize is NaN, throw a TypeError exception. +features: [set-methods] +---*/ + +const s1 = new SendableSet([1, 2]); +const s2 = { + size: undefined, + has: () => {}, + keys: function* keys() { + yield 2; + yield 3; + }, +}; +assert.throws( + TypeError, + function () { + s1.union(s2); + }, + "GetSendableSetRecord throws an error when size is undefined" +); + +s2.size = NaN; +assert.throws( + TypeError, + function () { + s1.union(s2); + }, + "GetSendableSetRecord throws an error when size is NaN" +); + +let coercionCalls = 0; +s2.size = { + valueOf: function() { + ++coercionCalls; + return NaN; + }, +}; +assert.throws( + TypeError, + function () { + s1.union(s2); + }, + "GetSendableSetRecord throws an error when size coerces to NaN" +); +assert.sameValue(coercionCalls, 1, "GetSendableSetRecord coerces size"); + +s2.size = 0n; +assert.throws( + TypeError, + function () { + s1.union(s2); + }, + "GetSendableSetRecord throws an error when size is a BigInt" +); + +s2.size = "string"; +assert.throws( + TypeError, + function () { + s1.union(s2); + }, + "GetSendableSetRecord throws an error when size is a non-numeric string" +); diff --git a/test/sendable/builtins/Set/prototype/union/subclass-receiver-methods.js b/test/sendable/builtins/Set/prototype/union/subclass-receiver-methods.js new file mode 100644 index 0000000000000000000000000000000000000000..ea853bade169575d02bbdcc71020f0929d6c6b27 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/subclass-receiver-methods.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union works on subclasses of SendableSet, but never calls the receiver's size/has/keys methods +features: [set-methods] +includes: [compareArray.js] +---*/ + +let sizeCount = 0; +let hasCount = 0; +let keysCount = 0; + +class MySendableSet extends SendableSet { + size(...rest) { + sizeCount++; + return super.size(...rest); + } + + has(...rest) { + hasCount++; + return super.has(...rest); + } + + keys(...rest) { + keysCount++; + return super.keys(...rest); + } +} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1, 2, 3]; +const combined = s1.union(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); +assert.sameValue(sizeCount, 0, "size should not be called on the receiver"); +assert.sameValue(hasCount, 0, "has should not be called on the receiver"); +assert.sameValue(keysCount, 0, "keys should not be called on the receiver"); diff --git a/test/sendable/builtins/Set/prototype/union/subclass-symbol-species.js b/test/sendable/builtins/Set/prototype/union/subclass-symbol-species.js new file mode 100644 index 0000000000000000000000000000000000000000..f3ffc4f72b50a478a15718e4728af4e43b19a2a2 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/subclass-symbol-species.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union works on subclasses of SendableSet, but returns an instance of SendableSet even when Symbol.species is overridden. +features: [set-methods] +includes: [compareArray.js] +---*/ +var count = 0; +class MySendableSet extends SendableSet { + static get [Symbol.species]() { + count++; + return SendableSet; + } +} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1, 2, 3]; +const combined = s1.union(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(count, 0, "Symbol.species is never called"); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); diff --git a/test/sendable/builtins/Set/prototype/union/subclass.js b/test/sendable/builtins/Set/prototype/union/subclass.js new file mode 100644 index 0000000000000000000000000000000000000000..6ec7f440586da357bb7f28ffb5ac159c9b55534b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/subclass.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union works on subclasses of SendableSet, but returns an instance of SendableSet +features: [set-methods] +includes: [compareArray.js] +---*/ + +class MySendableSet extends SendableSet {} + +const s1 = new MySendableSet([1, 2]); +const s2 = new SendableSet([2, 3]); +const expected = [1, 2, 3]; +const combined = s1.union(s2); + +assert.compareArray([...combined], expected); +assert.sameValue(combined instanceof SendableSet, true, "The returned object is a SendableSet"); +assert.sameValue( + combined instanceof MySendableSet, + false, + "The returned object is a SendableSet, not a subclass" +); diff --git a/test/sendable/builtins/Set/prototype/union/union.js b/test/sendable/builtins/Set/prototype/union/union.js new file mode 100644 index 0000000000000000000000000000000000000000..7fb114c99a46418660fb1991b96c70a24c20a445 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/union/union.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.union +description: SendableSet.prototype.union properties +includes: [propertyHelper.js] +features: [set-methods] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.union, + "function", + "`typeof SendableSet.prototype.union` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "union", { + enumerable: false, + writable: true, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-array.js b/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-array.js new file mode 100644 index 0000000000000000000000000000000000000000..006d5b665bc66ba0aec5db5b1157a749ff3c9b2b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-array.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + ... + 2. Return CreateSendableSetIterator(S, "value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 2. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.values.call([]); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.values.call([]); +}); diff --git a/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-map.js b/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-map.js new file mode 100644 index 0000000000000000000000000000000000000000..a67b0068a214312826ba8e025c5d3683e68fa20a --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-map.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + ... + 2. Return CreateSendableSetIterator(S, "value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 2. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.values.call(new Map()); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.values.call(new Map()); +}); diff --git a/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-object.js b/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-object.js new file mode 100644 index 0000000000000000000000000000000000000000..4749467bdaa435cdf2c308f7256d47cf82ca3161 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-object.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + ... + 2. Return CreateSendableSetIterator(S, "value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 2. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.values.call({}); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.values.call({}); +}); diff --git a/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-set-prototype.js b/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-set-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..9f86e8b3af25ffd5bd32ff0792e1725f9d5b4d57 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-set-prototype.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + ... + 2. Return CreateSendableSetIterator(S, "value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 2. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.values.call(SendableSet.prototype); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.values.call(SendableSet.prototype); +}); diff --git a/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-weakset.js b/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-weakset.js new file mode 100644 index 0000000000000000000000000000000000000000..ed00c00983eda66c8aeebfedbbb82f98bb6ef9bf --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/does-not-have-setdata-internal-slot-weakset.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + ... + 2. Return CreateSendableSetIterator(S, "value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + ... + 2. If S does not have a [[SendableSetData]] internal slot, throw a TypeError exception. + ... +features: [WeakSet] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.values.call(new WeakSet()); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.values.call(new WeakSet()); +}); diff --git a/test/sendable/builtins/Set/prototype/values/length.js b/test/sendable/builtins/Set/prototype/values/length.js new file mode 100644 index 0000000000000000000000000000000000000000..fc0ebbd388530c760c5e611746a95fc4d2d0cbc4 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/length.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.values, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/values/name.js b/test/sendable/builtins/Set/prototype/values/name.js new file mode 100644 index 0000000000000000000000000000000000000000..2d1a6dc6522f493b95372960a277cf0c58edbacb --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/name.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(SendableSet.prototype.values, "name", { + value: "values", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/prototype/values/not-a-constructor.js b/test/sendable/builtins/Set/prototype/values/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..e59149a44debb4583d4866dfacb27485ae02c081 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableSet.prototype.values does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, SendableSet, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableSet.prototype.values), false, 'isConstructor(SendableSet.prototype.values) must return false'); + +assert.throws(TypeError, () => { + let s = new SendableSet([]); new s.values(); +}); + diff --git a/test/sendable/builtins/Set/prototype/values/returns-iterator-empty.js b/test/sendable/builtins/Set/prototype/values/returns-iterator-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..0128c08fa3ec49d42b66be6551999db1cd9648a6 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/returns-iterator-empty.js @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + Returns an iterator that's already done if SendableSet is empty. +---*/ + +var set = new SendableSet(); +var iterator = set.values(); +var result = iterator.next(); +assert.sameValue(result.value, undefined, "The value of `result.value` is `undefined`"); +assert.sameValue(result.done, true, "The value of `result.done` is `true`"); diff --git a/test/sendable/builtins/Set/prototype/values/returns-iterator.js b/test/sendable/builtins/Set/prototype/values/returns-iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..38d8b5d2d1edeeac74805046bccbf4fdbd23a37f --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/returns-iterator.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + The method should return a valid iterator with the context as the + IteratedObject. +---*/ + +var set = new SendableSet(); +set.add(1); +set.add(2); +set.add(3); + +var iterator = set.values(); +var result; + +result = iterator.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, 2, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, 3, 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); + +result = iterator.next(); +assert.sameValue( + result.value, undefined, 'Exhausted result `value` (repeated request)' +); +assert.sameValue( + result.done, true, 'Exhausted result `done` flag (repeated request)' +); diff --git a/test/sendable/builtins/Set/prototype/values/this-not-object-throw-boolean.js b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-boolean.js new file mode 100644 index 0000000000000000000000000000000000000000..61a2d60da9c60b75ba0074f0ce5950784ae68286 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-boolean.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + ... + 2. Return CreateSendableSetIterator(S, "value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.values.call(false); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.values.call(false); +}); diff --git a/test/sendable/builtins/Set/prototype/values/this-not-object-throw-null.js b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-null.js new file mode 100644 index 0000000000000000000000000000000000000000..986be99fe2b88e2a2b0ada48a7203bda7f182c19 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-null.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + ... + 2. Return CreateSendableSetIterator(S, "value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.values.call(null); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.values.call(null); +}); diff --git a/test/sendable/builtins/Set/prototype/values/this-not-object-throw-number.js b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-number.js new file mode 100644 index 0000000000000000000000000000000000000000..304c454ab19fe1cfc1fdff404fe3e6645e1b9163 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-number.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + ... + 2. Return CreateSendableSetIterator(S, "value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.values.call(0); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.values.call(0); +}); diff --git a/test/sendable/builtins/Set/prototype/values/this-not-object-throw-string.js b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-string.js new file mode 100644 index 0000000000000000000000000000000000000000..a105abd1e3821b11b2c6f0ec89a6c2ce6a1ef581 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-string.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + ... + 2. Return CreateSendableSetIterator(S, "value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.values.call(""); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.values.call(""); +}); diff --git a/test/sendable/builtins/Set/prototype/values/this-not-object-throw-symbol.js b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..0a14a5cc1946e7f924c475861069bc847021709b --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-symbol.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + ... + 2. Return CreateSendableSetIterator(S, "value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.values.call(Symbol()); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.values.call(Symbol()); +}); diff --git a/test/sendable/builtins/Set/prototype/values/this-not-object-throw-undefined.js b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..dea7182780ae1e828ada9bb02243efce09a3190c --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/this-not-object-throw-undefined.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + ... + 2. Return CreateSendableSetIterator(S, "value"). + + + 23.2.5.1 CreateSendableSetIterator Abstract Operation + + 1. If Type(set) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SendableSet.prototype.values.call(undefined); +}); + +assert.throws(TypeError, function() { + var s = new SendableSet(); + s.values.call(undefined); +}); diff --git a/test/sendable/builtins/Set/prototype/values/values-iteration-mutable.js b/test/sendable/builtins/Set/prototype/values/values-iteration-mutable.js new file mode 100644 index 0000000000000000000000000000000000000000..1e737efb8b1375bffda8c22bb82ec63de07d4c68 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/values-iteration-mutable.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + When an item is added to the set after the iterator is created but before + the iterator is "done" (as defined by 23.2.5.2.1), the new item should be + accessible via iteration. When an item is added to the set after the + iterator is "done", the new item should not be accessible via iteration. +---*/ + +var set = new SendableSet(); +set.add(1); +set.add(2); + +var iterator = set.values(); +var result; + +result = iterator.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +set.add(3); + +result = iterator.next(); +assert.sameValue(result.value, 2, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, 3, 'Third result `value`'); +assert.sameValue(result.done, false, 'Third result `done` flag'); + +result = iterator.next(); +assert.sameValue(result.value, undefined, 'Exhausted result `value`'); +assert.sameValue(result.done, true, 'Exhausted result `done` flag'); + +set.add(4); + +result = iterator.next(); +assert.sameValue( + result.value, undefined, 'Exhausted result `value` (repeated request)' +); +assert.sameValue( + result.done, true, 'Exhausted result `done` flag (repeated request)' +); diff --git a/test/sendable/builtins/Set/prototype/values/values.js b/test/sendable/builtins/Set/prototype/values/values.js new file mode 100644 index 0000000000000000000000000000000000000000..a0dd25d801b609efcf8ef72f7c83e6ad597be007 --- /dev/null +++ b/test/sendable/builtins/Set/prototype/values/values.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.values +description: > + SendableSet.prototype.values ( ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof SendableSet.prototype.values, + "function", + "`typeof SendableSet.prototype.values` is `'function'`" +); + +verifyProperty(SendableSet.prototype, "values", { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/Set/set-does-not-throw-when-add-is-not-callable.js b/test/sendable/builtins/Set/set-does-not-throw-when-add-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..f5a6145f7293ea9757eb350f484cf1c3c51f1130 --- /dev/null +++ b/test/sendable/builtins/Set/set-does-not-throw-when-add-is-not-callable.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + ... + 7. Else, + a. Let adder be Get(set, "add"). + b. ReturnIfAbrupt(adder). + c. If IsCallable(adder) is false, throw a TypeError exception. + d. Let iter be GetIterator(iterable). + e. ReturnIfAbrupt(iter). + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). + c. If next is false, return set. + d. Let nextValue be IteratorValue(next). + e. ReturnIfAbrupt(nextValue). + f. Let status be Call(adder, set, «nextValue.[[value]]»). + g. If status is an abrupt completion, return IteratorClose(iter, status). + +---*/ + +SendableSet.prototype.add = null; + +var s = new SendableSet(); + +assert.sameValue(s.size, 0, "The value of `s.size` is `0`"); diff --git a/test/sendable/builtins/Set/set-get-add-method-failure.js b/test/sendable/builtins/Set/set-get-add-method-failure.js new file mode 100644 index 0000000000000000000000000000000000000000..8b6497faf4c26e2e9d1031994ceff8b68b62a941 --- /dev/null +++ b/test/sendable/builtins/Set/set-get-add-method-failure.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + ... + 6. If iterable is either undefined or null, let iter be undefined. + 7. Else, + a. Let adder be Get(set, "add"). + b. ReturnIfAbrupt(adder). +---*/ + +function MyError() {} +Object.defineProperty(SendableSet.prototype, 'add', { + get: function() { + throw new MyError(); + } +}); + +new SendableSet(); + +assert.throws(MyError, function() { + new SendableSet([]); +}); diff --git a/test/sendable/builtins/Set/set-iterable-calls-add.js b/test/sendable/builtins/Set/set-iterable-calls-add.js new file mode 100644 index 0000000000000000000000000000000000000000..56d21e4c4905e9e72937cfaa50af5d6f9ecf0609 --- /dev/null +++ b/test/sendable/builtins/Set/set-iterable-calls-add.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + ... + 7. Else, + a. Let adder be Get(set, "add"). + b. ReturnIfAbrupt(adder). + c. If IsCallable(adder) is false, throw a TypeError exception. + d. Let iter be GetIterator(iterable). + e. ReturnIfAbrupt(iter). + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). + c. If next is false, return set. + d. Let nextValue be IteratorValue(next). + e. ReturnIfAbrupt(nextValue). + f. Let status be Call(adder, set, «nextValue.[[value]]»). + g. If status is an abrupt completion, return IteratorClose(iter, status). + +---*/ + +var setAdd = SendableSet.prototype.add; +var counter = 0; + +SendableSet.prototype.add = function(value) { + counter++; + setAdd.call(this, value); +}; + +var s = new SendableSet([1, 2]); + +assert.sameValue(counter, 2, "`SendableSet.prototype.add` called twice."); diff --git a/test/sendable/builtins/Set/set-iterable-empty-does-not-call-add.js b/test/sendable/builtins/Set/set-iterable-empty-does-not-call-add.js new file mode 100644 index 0000000000000000000000000000000000000000..0dd5edd27d1eb766058b3b65f2a9db6a3268b173 --- /dev/null +++ b/test/sendable/builtins/Set/set-iterable-empty-does-not-call-add.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + ... + 7. Else, + a. Let adder be Get(set, "add"). + b. ReturnIfAbrupt(adder). + c. If IsCallable(adder) is false, throw a TypeError exception. + d. Let iter be GetIterator(iterable). + e. ReturnIfAbrupt(iter). + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). + c. If next is false, return set. + d. Let nextValue be IteratorValue(next). + e. ReturnIfAbrupt(nextValue). + f. Let status be Call(adder, set, «nextValue.[[value]]»). + g. If status is an abrupt completion, return IteratorClose(iter, status). + +---*/ + +var setAdd = SendableSet.prototype.add; +var counter = 0; + +SendableSet.prototype.add = function(value) { + counter++; + setAdd.call(this, value); +}; + +var s = new SendableSet([]); + +assert.sameValue(counter, 0, "`SendableSet.prototype.add` was not called."); diff --git a/test/sendable/builtins/Set/set-iterable-throws-when-add-is-not-callable.js b/test/sendable/builtins/Set/set-iterable-throws-when-add-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..f5f72cbbd1e9d0947480ce77ae288e1d780d739f --- /dev/null +++ b/test/sendable/builtins/Set/set-iterable-throws-when-add-is-not-callable.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + ... + 7. Else, + a. Let adder be Get(set, "add"). + b. ReturnIfAbrupt(adder). + c. If IsCallable(adder) is false, throw a TypeError exception. + d. Let iter be GetIterator(iterable). + e. ReturnIfAbrupt(iter). + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). + c. If next is false, return set. + d. Let nextValue be IteratorValue(next). + e. ReturnIfAbrupt(nextValue). + f. Let status be Call(adder, set, «nextValue.[[value]]»). + g. If status is an abrupt completion, return IteratorClose(iter, status). + +---*/ + + +SendableSet.prototype.add = null; + +assert.throws(TypeError, function() { + new SendableSet([1, 2]); +}); diff --git a/test/sendable/builtins/Set/set-iterable.js b/test/sendable/builtins/Set/set-iterable.js new file mode 100644 index 0000000000000000000000000000000000000000..30ede9ad6275518be34c8c79bcfa63a52f8be55c --- /dev/null +++ b/test/sendable/builtins/Set/set-iterable.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + ... + 7. Else, + a. Let adder be Get(set, "add"). + b. ReturnIfAbrupt(adder). + c. If IsCallable(adder) is false, throw a TypeError exception. + d. Let iter be GetIterator(iterable). + e. ReturnIfAbrupt(iter). + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). + c. If next is false, return set. + d. Let nextValue be IteratorValue(next). + e. ReturnIfAbrupt(nextValue). + f. Let status be Call(adder, set, «nextValue.[[value]]»). + g. If status is an abrupt completion, return IteratorClose(iter, status). + +---*/ + +var s = new SendableSet([1, 2]); + +assert.sameValue(s.size, 2, "The value of `s.size` is `2`"); diff --git a/test/sendable/builtins/Set/set-iterator-close-after-add-failure.js b/test/sendable/builtins/Set/set-iterator-close-after-add-failure.js new file mode 100644 index 0000000000000000000000000000000000000000..d43968ea5f9c238f7424b880c7715d1240190f49 --- /dev/null +++ b/test/sendable/builtins/Set/set-iterator-close-after-add-failure.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). + c. If next is false, return set. + d. Let nextValue be IteratorValue(next). + e. ReturnIfAbrupt(nextValue). + f. Let status be Call(adder, set, «nextValue.[[value]]»). + g. If status is an abrupt completion, return IteratorClose(iter, status). + +features: [Symbol.iterator] +---*/ + +var count = 0; +var iterable = {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + value: null, + done: false + }; + }, + return: function() { + count += 1; + } + }; +}; +SendableSet.prototype.add = function() { + throw new Error(); +} + +assert.throws(Error, function() { + new SendableSet(iterable); +}); + +assert.sameValue( + count, 1, "The iterator is closed when `SendableSet.prototype.add` throws an error." +); diff --git a/test/sendable/builtins/Set/set-iterator-next-failure.js b/test/sendable/builtins/Set/set-iterator-next-failure.js new file mode 100644 index 0000000000000000000000000000000000000000..eb3c3f3034d36a76dfd1daa9f602db84dc4d6e29 --- /dev/null +++ b/test/sendable/builtins/Set/set-iterator-next-failure.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + ... + 9. Repeat + a. Let next be IteratorStep(iter). + b. ReturnIfAbrupt(next). +features: [Symbol.iterator] +---*/ + +var iterable = {}; + +function MyError() {}; +iterable[Symbol.iterator] = function() { + return { + next: function() { + throw new MyError(); + } + }; +}; + +assert.throws(MyError, function() { + new SendableSet(iterable); +}); diff --git a/test/sendable/builtins/Set/set-iterator-value-failure.js b/test/sendable/builtins/Set/set-iterator-value-failure.js new file mode 100644 index 0000000000000000000000000000000000000000..562459f552b48e4ef225c0b4223da4475c44c57b --- /dev/null +++ b/test/sendable/builtins/Set/set-iterator-value-failure.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + ... + 9. Repeat + ... + d. Let nextValue be IteratorValue(next). + e. ReturnIfAbrupt(nextValue). +features: [Symbol.iterator] +---*/ + +var count = 0; +var iterable = {}; + +function MyError() {} +iterable[Symbol.iterator] = function() { + return { + next: function() { + return { + get value() { + throw new MyError(); + }, + done: false + }; + } + }; +}; + +assert.throws(MyError, function() { + new SendableSet(iterable); +}); diff --git a/test/sendable/builtins/Set/set-newtarget.js b/test/sendable/builtins/Set/set-newtarget.js new file mode 100644 index 0000000000000000000000000000000000000000..9cfcfeb9b3f4f5ad367b9bf3182d4afae8069948 --- /dev/null +++ b/test/sendable/builtins/Set/set-newtarget.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + ... + 2. Let set be OrdinaryCreateFromConstructor(NewTarget, "%SendableSetPrototype%", «‍[[SendableSetData]]» ). + ... + +---*/ + +var s1 = new SendableSet(); + +assert.sameValue( + Object.getPrototypeOf(s1), + SendableSet.prototype, + "`Object.getPrototypeOf(s1)` returns `SendableSet.prototype`" +); + +var s2 = new SendableSet([1, 2]); + +assert.sameValue( + Object.getPrototypeOf(s2), + SendableSet.prototype, + "`Object.getPrototypeOf(s2)` returns `SendableSet.prototype`" +); diff --git a/test/sendable/builtins/Set/set-no-iterable.js b/test/sendable/builtins/Set/set-no-iterable.js new file mode 100644 index 0000000000000000000000000000000000000000..91cd4e3a5990517a3b337d21f0ee98a52d54cee9 --- /dev/null +++ b/test/sendable/builtins/Set/set-no-iterable.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + ... + 5. If iterable is not present, let iterable be undefined. + 6. If iterable is either undefined or null, let iter be undefined. + ... + 8. If iter is undefined, return set. + +---*/ + + +assert.sameValue(new SendableSet().size, 0, "The value of `new SendableSet().size` is `0`"); +assert.sameValue(new SendableSet(undefined).size, 0, "The value of `new SendableSet(undefined).size` is `0`"); +assert.sameValue(new SendableSet(null).size, 0, "The value of `new SendableSet(null).size` is `0`"); diff --git a/test/sendable/builtins/Set/set-undefined-newtarget.js b/test/sendable/builtins/Set/set-undefined-newtarget.js new file mode 100644 index 0000000000000000000000000000000000000000..010c56fd475b5b2db13f1ab99c30b2643e3ee276 --- /dev/null +++ b/test/sendable/builtins/Set/set-undefined-newtarget.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + When the SendableSet function is called with optional argument iterable the following steps are taken: + + 1. If NewTarget is undefined, throw a TypeError exception. + ... + +---*/ + +assert.throws(TypeError, function() { + SendableSet(); +}); + +assert.throws(TypeError, function() { + SendableSet([]); +}); diff --git a/test/sendable/builtins/Set/set.js b/test/sendable/builtins/Set/set.js new file mode 100644 index 0000000000000000000000000000000000000000..02133513692546261145b0b59ff44cc81d882070 --- /dev/null +++ b/test/sendable/builtins/Set/set.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set-constructor +description: > + SendableSet ( [ iterable ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyProperty(this, "SendableSet", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/Set/valid-values.js b/test/sendable/builtins/Set/valid-values.js new file mode 100644 index 0000000000000000000000000000000000000000..af9fc60462ef576acc0ce0d07f213850eb97f4ef --- /dev/null +++ b/test/sendable/builtins/Set/valid-values.js @@ -0,0 +1,400 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-set.prototype.add +description: Observing the expected behavior of valid values +info: | + SendableSet.prototype.add ( value ) + + ... + For each element e of entries, do + If e is not empty and SameValueZero(e, value) is true, then + Return S. + If value is -0, set value to +0. + Append value as the last element of entries. + ... + +features: [BigInt, Symbol, TypedArray, WeakRef, exponentiation] +---*/ + + +const negativeZero = -0; +const positiveZero = +0; +const zero = 0; +const one = 1; +const twoRaisedToFiftyThreeMinusOne = 2 ** 53 - 1; +const int32Array = new Int32Array([zero, one]); +const uint32Array = new Uint32Array([zero, one]); +const n = 100000000000000000000000000000000000000000000000000000000000000000000000000000000001n; +const bigInt = BigInt('100000000000000000000000000000000000000000000000000000000000000000000000000000000001'); +const n1 = 1n; +const n53 = 9007199254740991n; +const fiftyThree = BigInt('9007199254740991'); +const bigInt64Array = new BigInt64Array([n1, n53]); +const bigUint64Array = new BigUint64Array([n1, n53]); +const symbol = Symbol(''); +const object = {}; +const array = []; +const string = ''; +const booleanTrue = true; +const booleanFalse = true; +const functionExprValue = function() {}; +const arrowFunctionValue = () => {}; +const classValue = class {}; +const map = new Map(); +const set = new SendableSet(); +const weakMap = new WeakMap(); +const weakRef = new WeakRef({}); +const weakSet = new WeakSet(); +const nullValue = null; +const undefinedValue = undefined; +let unassigned; + +{ + const s = new SendableSet([negativeZero, negativeZero]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(negativeZero), true); + s.delete(negativeZero); + assert.sameValue(s.size, 0); + s.add(negativeZero); + assert.sameValue(s.has(negativeZero), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([positiveZero, positiveZero]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(positiveZero), true); + s.delete(positiveZero); + assert.sameValue(s.size, 0); + s.add(positiveZero); + assert.sameValue(s.has(positiveZero), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([zero, zero]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(zero), true); + s.delete(zero); + assert.sameValue(s.size, 0); + s.add(zero); + assert.sameValue(s.has(zero), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([one, one]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(one), true); + s.delete(one); + assert.sameValue(s.size, 0); + s.add(one); + assert.sameValue(s.has(one), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([twoRaisedToFiftyThreeMinusOne, twoRaisedToFiftyThreeMinusOne]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(twoRaisedToFiftyThreeMinusOne), true); + s.delete(twoRaisedToFiftyThreeMinusOne); + assert.sameValue(s.size, 0); + s.add(twoRaisedToFiftyThreeMinusOne); assert.sameValue(s.has(twoRaisedToFiftyThreeMinusOne), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([int32Array, int32Array]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(int32Array), true); + s.delete(int32Array); + assert.sameValue(s.size, 0); + s.add(int32Array); + assert.sameValue(s.has(int32Array), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([uint32Array, uint32Array]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(uint32Array), true); + s.delete(uint32Array); + assert.sameValue(s.size, 0); + s.add(uint32Array); + assert.sameValue(s.has(uint32Array), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([n, n]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(n), true); + s.delete(n); + assert.sameValue(s.size, 0); + s.add(n); + assert.sameValue(s.has(n), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([bigInt, bigInt]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(bigInt), true); + s.delete(bigInt); + assert.sameValue(s.size, 0); + s.add(bigInt); + assert.sameValue(s.has(bigInt), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([n1, n1]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(n1), true); + s.delete(n1); + assert.sameValue(s.size, 0); + s.add(n1); + assert.sameValue(s.has(n1), true); +} +{ const s = new SendableSet([n53, n53]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(n53), true); + s.delete(n53); + assert.sameValue(s.size, 0); + s.add(n53); + assert.sameValue(s.has(n53), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([fiftyThree, fiftyThree]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(fiftyThree), true); + s.delete(fiftyThree); + assert.sameValue(s.size, 0); + s.add(fiftyThree); + assert.sameValue(s.has(fiftyThree), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([bigInt64Array, bigInt64Array]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(bigInt64Array), true); + s.delete(bigInt64Array); + assert.sameValue(s.size, 0); + s.add(bigInt64Array); + assert.sameValue(s.has(bigInt64Array), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([bigUint64Array, bigUint64Array]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(bigUint64Array), true); + s.delete(bigUint64Array); + assert.sameValue(s.size, 0); + s.add(bigUint64Array); + assert.sameValue(s.has(bigUint64Array), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([symbol, symbol]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(symbol), true); + s.delete(symbol); + assert.sameValue(s.size, 0); + s.add(symbol); + assert.sameValue(s.has(symbol), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([object, object]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(object), true); + s.delete(object); + assert.sameValue(s.size, 0); + s.add(object); + assert.sameValue(s.has(object), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([array, array]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(array), true); + s.delete(array); + assert.sameValue(s.size, 0); + s.add(array); + assert.sameValue(s.has(array), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([string, string]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(string), true); + s.delete(string); + assert.sameValue(s.size, 0); + s.add(string); + assert.sameValue(s.has(string), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([booleanTrue, booleanTrue]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(booleanTrue), true); + s.delete(booleanTrue); + assert.sameValue(s.size, 0); + s.add(booleanTrue); + assert.sameValue(s.has(booleanTrue), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([booleanFalse, booleanFalse]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(booleanFalse), true); + s.delete(booleanFalse); + assert.sameValue(s.size, 0); + s.add(booleanFalse); + assert.sameValue(s.has(booleanFalse), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([functionExprValue, functionExprValue]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(functionExprValue), true); + s.delete(functionExprValue); + assert.sameValue(s.size, 0); + s.add(functionExprValue); assert.sameValue(s.has(functionExprValue), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([arrowFunctionValue, arrowFunctionValue]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(arrowFunctionValue), true); + s.delete(arrowFunctionValue); + assert.sameValue(s.size, 0); + s.add(arrowFunctionValue); assert.sameValue(s.has(arrowFunctionValue), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([classValue, classValue]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(classValue), true); + s.delete(classValue); + assert.sameValue(s.size, 0); + s.add(classValue); + assert.sameValue(s.has(classValue), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([map, map]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(map), true); + s.delete(map); + assert.sameValue(s.size, 0); + s.add(map); + assert.sameValue(s.has(map), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([set, set]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(set), true); + s.delete(set); + assert.sameValue(s.size, 0); + s.add(set); + assert.sameValue(s.has(set), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([weakMap, weakMap]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(weakMap), true); + s.delete(weakMap); + assert.sameValue(s.size, 0); + s.add(weakMap); + assert.sameValue(s.has(weakMap), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([weakRef, weakRef]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(weakRef), true); + s.delete(weakRef); + assert.sameValue(s.size, 0); + s.add(weakRef); + assert.sameValue(s.has(weakRef), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([weakSet, weakSet]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(weakSet), true); + s.delete(weakSet); + assert.sameValue(s.size, 0); + s.add(weakSet); + assert.sameValue(s.has(weakSet), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([nullValue, nullValue]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(nullValue), true); + s.delete(nullValue); + assert.sameValue(s.size, 0); + s.add(nullValue); + assert.sameValue(s.has(nullValue), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([undefinedValue, undefinedValue]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(undefinedValue), true); + s.delete(undefinedValue); + assert.sameValue(s.size, 0); + s.add(undefinedValue); + assert.sameValue(s.has(undefinedValue), true); + assert.sameValue(s.size, 1); +}; + +{ + const s = new SendableSet([unassigned, unassigned]); + assert.sameValue(s.size, 1); + assert.sameValue(s.has(unassigned), true); + s.delete(unassigned); + assert.sameValue(s.size, 0); + s.add(unassigned); + assert.sameValue(s.has(unassigned), true); + assert.sameValue(s.size, 1); +}; + diff --git a/test/sendable/builtins/TypedArray/Symbol.species/length.js b/test/sendable/builtins/TypedArray/Symbol.species/length.js new file mode 100644 index 0000000000000000000000000000000000000000..8a453388da768f36d7c9dd0abff4ae0206203369 --- /dev/null +++ b/test/sendable/builtins/TypedArray/Symbol.species/length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 22.2.2.4 +description: > + get %SendableTypedArray% [ @@species ].length is 0. +info: | + get %SendableTypedArray% [ @@species ] + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [Symbol.species] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray, Symbol.species); + +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/Symbol.species/name.js b/test/sendable/builtins/TypedArray/Symbol.species/name.js new file mode 100644 index 0000000000000000000000000000000000000000..68290c66f9661472bd37c636e4166bfaf97b37cb --- /dev/null +++ b/test/sendable/builtins/TypedArray/Symbol.species/name.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 22.2.2.4 +description: > + get %SendableTypedArray% [ @@species ].name is "get [Symbol.species]". +info: | + get %SendableTypedArray% [ @@species ] + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [Symbol.species] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray, Symbol.species); + +verifyProperty(desc.get, "name", { + value: "get [Symbol.species]", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/Symbol.species/prop-desc.js b/test/sendable/builtins/TypedArray/Symbol.species/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..494c4ffa40d89af4c5f79f622e4d520509223036 --- /dev/null +++ b/test/sendable/builtins/TypedArray/Symbol.species/prop-desc.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 22.2.2.4 +description: > + @@species property of SendableTypedArray +info: | + 22.2.2.4 get %SendableTypedArray% [ @@species ] + + %SendableTypedArray%[@@species] is an accessor property whose set accessor function + is undefined. +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray, Symbol.species); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); diff --git a/test/sendable/builtins/TypedArray/Symbol.species/result.js b/test/sendable/builtins/TypedArray/Symbol.species/result.js new file mode 100644 index 0000000000000000000000000000000000000000..064cf7e190ac83bd1e12e1a8890f0b61c6994910 --- /dev/null +++ b/test/sendable/builtins/TypedArray/Symbol.species/result.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 22.2.2.4 +description: > + @@species property returns the `this` value +info: | + 22.2.2.4 get %SendableTypedArray% [ @@species ] + + 1. Return the this value. +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +var value = {}; +var getter = Object.getOwnPropertyDescriptor(SendableTypedArray, Symbol.species).get; + +assert.sameValue(getter.call(value), value); diff --git a/test/sendable/builtins/TypedArray/from/arylk-get-length-error.js b/test/sendable/builtins/TypedArray/from/arylk-get-length-error.js new file mode 100644 index 0000000000000000000000000000000000000000..0eaf6889b2c243734aab86b744f93e89ed646894 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/arylk-get-length-error.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: Returns error produced by accessing array-like's length +info: | + 22.2.2.1 %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 7. Let len be ? ToLength(? Get(arrayLike, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var arrayLike = {}; + +Object.defineProperty(arrayLike, "length", { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + SendableTypedArray.from(arrayLike); +}); diff --git a/test/sendable/builtins/TypedArray/from/arylk-to-length-error.js b/test/sendable/builtins/TypedArray/from/arylk-to-length-error.js new file mode 100644 index 0000000000000000000000000000000000000000..26834fbef6fac5c04273e9eac2c8aaeaba15bf8e --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/arylk-to-length-error.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: Returns error produced by interpreting length property as a length +info: | + 22.2.2.1 %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 7. Let len be ? ToLength(? Get(arrayLike, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var arrayLike = { length: {} }; + +arrayLike.length = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + SendableTypedArray.from(arrayLike); +}); diff --git a/test/sendable/builtins/TypedArray/from/from-array-mapper-detaches-result.js b/test/sendable/builtins/TypedArray/from/from-array-mapper-detaches-result.js new file mode 100644 index 0000000000000000000000000000000000000000..6052231533a1f20e239453b8c9d772cb0a2901e9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/from-array-mapper-detaches-result.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: > + If the mapper function detaches the result typed array, .from performs Set operation which ignores out-of-bounds indices. +info: | + %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +includes: [detachArrayBuffer.js] +features: [TypedArray] +---*/ + +let ab = new ArrayBuffer(3); +let target = new Int8Array(ab); +let values = [0, 1, 2]; + +let result = Int32Array.from.call(function() { + return target; +}, values, v => { + if (v === 1) { + $DETACHBUFFER(ab); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 0); diff --git a/test/sendable/builtins/TypedArray/from/from-array-mapper-makes-result-out-of-bounds.js b/test/sendable/builtins/TypedArray/from/from-array-mapper-makes-result-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..f0497ed23dcffa1c0672715407be5baa01d3fcce --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/from-array-mapper-makes-result-out-of-bounds.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: > + If the mapper function makes result typed array out-of-bounds, .from performs Set operation which ignores out-of-bounds indices. +info: | + %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(3, {maxByteLength: 5}); +let target = new Int8Array(rab); +let values = [0, 1, 2]; + +let result = Int32Array.from.call(function() { + return target; +}, values, v => { + if (v === 1) { + rab.resize(1); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], 10); diff --git a/test/sendable/builtins/TypedArray/from/from-typedarray-into-itself-mapper-detaches-result.js b/test/sendable/builtins/TypedArray/from/from-typedarray-into-itself-mapper-detaches-result.js new file mode 100644 index 0000000000000000000000000000000000000000..44e056dc96867a381fe32697c6b9b2027cd48ba2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/from-typedarray-into-itself-mapper-detaches-result.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: > + If the mapper function detaches the result typed array, .from performs Set operation which ignores out-of-bounds indices. +info: | + %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +includes: [detachArrayBuffer.js] +features: [TypedArray] +---*/ + +let ab = new ArrayBuffer(3); +let target = new Int8Array(ab); +target.set([0, 1, 2]); + +let result = Int32Array.from.call(function() { + return target; +}, target, v => { + if (v === 1) { + $DETACHBUFFER(ab); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 0); diff --git a/test/sendable/builtins/TypedArray/from/from-typedarray-into-itself-mapper-makes-result-out-of-bounds.js b/test/sendable/builtins/TypedArray/from/from-typedarray-into-itself-mapper-makes-result-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..614ad6bcbda84c991690564a00821c4f4499d70d --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/from-typedarray-into-itself-mapper-makes-result-out-of-bounds.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: > + If the mapper function makes result typed array out-of-bounds, .from performs Set operation which ignores out-of-bounds indices. +info: | + %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(3, {maxByteLength: 5}); +let target = new Int8Array(rab); +target.set([0, 1, 2]); + +let result = Int32Array.from.call(function() { + return target; +}, target, v => { + if (v === 1) { + rab.resize(1); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], 10); diff --git a/test/sendable/builtins/TypedArray/from/from-typedarray-mapper-detaches-result.js b/test/sendable/builtins/TypedArray/from/from-typedarray-mapper-detaches-result.js new file mode 100644 index 0000000000000000000000000000000000000000..51ff48e918038c46042340e60a0f74e65af01cd6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/from-typedarray-mapper-detaches-result.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: > + If the mapper function detaches the result typed array, .from performs Set operation which ignores out-of-bounds indices. +info: | + %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +includes: [detachArrayBuffer.js] +features: [TypedArray] +---*/ + +let ab = new ArrayBuffer(3); +let target = new Int8Array(ab); +let values = new Int8Array([0, 1, 2]); + +let result = Int32Array.from.call(function() { + return target; +}, values, v => { + if (v === 1) { + $DETACHBUFFER(ab); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 0); diff --git a/test/sendable/builtins/TypedArray/from/from-typedarray-mapper-makes-result-out-of-bounds.js b/test/sendable/builtins/TypedArray/from/from-typedarray-mapper-makes-result-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..a874ab3e2f09a4dfaf1f4f77c6829997f9b11382 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/from-typedarray-mapper-makes-result-out-of-bounds.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: > + If the mapper function makes result typed array out-of-bounds, .from performs Set operation which ignores out-of-bounds indices. +info: | + %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 12. Repeat, while k < len, + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, thisArg, « kValue, 𝔽(k) »). + ... + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(3, {maxByteLength: 5}); +let target = new Int8Array(rab); +let values = new Int8Array([0, 1, 2]); + +let result = Int32Array.from.call(function() { + return target; +}, values, v => { + if (v === 1) { + rab.resize(1); + } + return v + 10; +}); + +assert.sameValue(result, target); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], 10); diff --git a/test/sendable/builtins/TypedArray/from/invoked-as-func.js b/test/sendable/builtins/TypedArray/from/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..70255415c59d3cc61001ec36b1a2d1675ce2bb96 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/invoked-as-func.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: > + "from" cannot be invoked as a function +info: | + 22.2.2.1 %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + 1. Let C be the this value. + 2. If IsConstructor(C) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var from = SendableTypedArray.from; + +assert.throws(TypeError, function() { + from([]); +}); diff --git a/test/sendable/builtins/TypedArray/from/invoked-as-method.js b/test/sendable/builtins/TypedArray/from/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..f581fbb0ae82bdaeca807c01f836b494e7e75072 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/invoked-as-method.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: > + "from" cannot be invoked as a method of %SendableTypedArray% +info: | + 22.2.2.1 %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 8. Let targetObj be ? SendableTypedArrayCreate(C, «len»). + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + SendableTypedArray.from([]); +}); diff --git a/test/sendable/builtins/TypedArray/from/iter-access-error.js b/test/sendable/builtins/TypedArray/from/iter-access-error.js new file mode 100644 index 0000000000000000000000000000000000000000..5cecfc2eb2c8b65d4dd4cc3f9050c2fe9903ccc5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/iter-access-error.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: Returns error produced by accessing @@iterator +info: | + 22.2.2.1 %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 6. Let arrayLike be ? IterableToArrayLike(source). + ... + + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 1. Let usingIterator be ? GetMethod(items, @@iterator). + ... +includes: [sendableTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +Object.defineProperty(iter, Symbol.iterator, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + SendableTypedArray.from(iter); +}); diff --git a/test/sendable/builtins/TypedArray/from/iter-invoke-error.js b/test/sendable/builtins/TypedArray/from/iter-invoke-error.js new file mode 100644 index 0000000000000000000000000000000000000000..02bfc0613179eb9c40dd01ac1c60b73b0a74f724 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/iter-invoke-error.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: Returns error produced by invoking @@iterator +info: | + 22.2.2.1 %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 6. Let arrayLike be ? IterableToArrayLike(source). + ... + + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 1. Let usingIterator be ? GetMethod(items, @@iterator). + 2. If usingIterator is not undefined, then + a. Let iterator be ? GetIterator(items, usingIterator). + ... +includes: [sendableTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + SendableTypedArray.from(iter); +}); diff --git a/test/sendable/builtins/TypedArray/from/iter-next-error.js b/test/sendable/builtins/TypedArray/from/iter-next-error.js new file mode 100644 index 0000000000000000000000000000000000000000..bab5d92291272aeb6261cd77e9d5aaa35df1945e --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/iter-next-error.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: Returns error produced by advancing the iterator +info: | + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 2. If usingIterator is not undefined, then + ... + d. Repeat, while next is not false + i. Let next be ? IteratorStep(iterator). + ... +includes: [sendableTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +assert.throws(Test262Error, function() { + SendableTypedArray.from(iter); +}); diff --git a/test/sendable/builtins/TypedArray/from/iter-next-value-error.js b/test/sendable/builtins/TypedArray/from/iter-next-value-error.js new file mode 100644 index 0000000000000000000000000000000000000000..3e1bc4adf5f4b1079d85953e42a0b5639b4c4992 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/iter-next-value-error.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: Returns error produced by accessing iterated value +info: | + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 2. If usingIterator is not undefined, then + ... + d. Repeat, while next is not false + ... + ii. If next is not false, then + 1. Let nextValue be ? IteratorValue(next). + ... +includes: [sendableTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + var result = {}; + Object.defineProperty(result, 'value', { + get: function() { + throw new Test262Error(); + } + }); + + return result; + } + }; +}; + +assert.throws(Test262Error, function() { + SendableTypedArray.from(iter); +}); diff --git a/test/sendable/builtins/TypedArray/from/iterated-array-changed-by-tonumber.js b/test/sendable/builtins/TypedArray/from/iterated-array-changed-by-tonumber.js new file mode 100644 index 0000000000000000000000000000000000000000..6eddef139ed4023baa6149a7b7e9d90c09779901 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/iterated-array-changed-by-tonumber.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: > + Modifications to input array after iteration are handled correctly. +info: | + %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 6. If usingIterator is not undefined, then + a. Let values be ? IteratorToList(? GetIteratorFromMethod(source, usingIterator)). + b. Let len be the number of elements in values. + ... + e. Repeat, while k < len, + ... + vi. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +features: [TypedArray] +---*/ + +let values = [0, { + valueOf() { + // Removes all array elements. Caller must have saved all elements. + values.length = 0; + return 100; + } +}, 2]; + +// `from` called with array which uses the built-in array iterator. +let ta = Int32Array.from(values); + +assert.sameValue(ta.length, 3); +assert.sameValue(ta[0], 0); +assert.sameValue(ta[1], 100); +assert.sameValue(ta[2], 2); diff --git a/test/sendable/builtins/TypedArray/from/length.js b/test/sendable/builtins/TypedArray/from/length.js new file mode 100644 index 0000000000000000000000000000000000000000..856c81f042a05eec1d5a9b595a4e1df9d9baa417 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/length.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: > + %SendableTypedArray%.from.length is 1. +info: | + %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + 17 ECMAScript Standard Built-in Objects: + + Every built-in Function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.from, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/from/mapfn-is-not-callable.js b/test/sendable/builtins/TypedArray/from/mapfn-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..4cf4cf64d6e160924259d1ab621d5c8379687ff4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/mapfn-is-not-callable.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: Throw a TypeError exception is mapfn is not callable +info: | + 22.2.2.1 %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 3. If mapfn was supplied and mapfn is not undefined, then + a. If IsCallable(mapfn) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, Symbol.iterator, TypedArray] +---*/ + +var getIterator = 0; +var arrayLike = {}; +Object.defineProperty(arrayLike, Symbol.iterator, { + get: function() { + getIterator++; + } +}); + +assert.throws(TypeError, function() { + SendableTypedArray.from(arrayLike, null); +}, "mapfn is null"); + +assert.throws(TypeError, function() { + SendableTypedArray.from(arrayLike, 42); +}, "mapfn is a number"); + +assert.throws(TypeError, function() { + SendableTypedArray.from(arrayLike, ""); +}, "mapfn is a string"); + +assert.throws(TypeError, function() { + SendableTypedArray.from(arrayLike, {}); +}, "mapfn is an ordinary object"); + +assert.throws(TypeError, function() { + SendableTypedArray.from(arrayLike, []); +}, "mapfn is an array"); + +assert.throws(TypeError, function() { + SendableTypedArray.from(arrayLike, true); +}, "mapfn is a boolean"); + +var s = Symbol("1"); +assert.throws(TypeError, function() { + SendableTypedArray.from(arrayLike, s); +}, "mapfn is a symbol"); + +assert.sameValue( + getIterator, 0, + "IsCallable(mapfn) check occurs before getting source[@@iterator]" +); diff --git a/test/sendable/builtins/TypedArray/from/name.js b/test/sendable/builtins/TypedArray/from/name.js new file mode 100644 index 0000000000000000000000000000000000000000..7285ff08bfd56a378dc8606dd73a4f6577b667d0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 22.2.2.1 +description: > + %SendableTypedArray%.from.name is "from". +info: | + %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.from, "name", { + value: "from", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/from/not-a-constructor.js b/test/sendable/builtins/TypedArray/from/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..1f6244cfc4a43b505510253dcba822f50e694872 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.from does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, SendableTypedArray, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableTypedArray.from), false, 'isConstructor(SendableTypedArray.from) must return false'); + +assert.throws(TypeError, () => { + new SendableTypedArray.from([]); +}); + diff --git a/test/sendable/builtins/TypedArray/from/prop-desc.js b/test/sendable/builtins/TypedArray/from/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..dc94166160451b99c7df5766c3caabbe95a637d9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/prop-desc.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 22.2.2.1 +description: > + "from" property of SendableTypedArray +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray, 'from', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/from/this-is-not-constructor.js b/test/sendable/builtins/TypedArray/from/this-is-not-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..24209f7969c0d8167ec1c6dcea1d1b9a50a71f1f --- /dev/null +++ b/test/sendable/builtins/TypedArray/from/this-is-not-constructor.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.from +description: > + Throws a TypeError exception if this is not a constructor +info: | + 22.2.2.1 %SendableTypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + 1. Let C be the this value. + 2. If IsConstructor(C) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var from = SendableTypedArray.from; +var m = { m() {} }.m; + +assert.throws(TypeError, function() { + from.call(m, []); +}); diff --git a/test/sendable/builtins/TypedArray/invoked.js b/test/sendable/builtins/TypedArray/invoked.js new file mode 100644 index 0000000000000000000000000000000000000000..05bf7355e476320e13c658d76bbe290bde852b57 --- /dev/null +++ b/test/sendable/builtins/TypedArray/invoked.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray% +description: Throw a TypeError exception if directly invoked. +info: | + 22.2.1.1 %SendableTypedArray% ( ) + + 1. Throw a TypeError Exception + ... + + Note: ES2016 replaces all the references for the %SendableTypedArray% constructor to a + single chapter covering all arguments cases. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + SendableTypedArray(); +}); + +assert.throws(TypeError, function() { + new SendableTypedArray(); +}); + +assert.throws(TypeError, function() { + SendableTypedArray(1); +}); + +assert.throws(TypeError, function() { + new SendableTypedArray(1); +}); + +assert.throws(TypeError, function() { + SendableTypedArray(1.1); +}); + +assert.throws(TypeError, function() { + new SendableTypedArray(1.1); +}); + +assert.throws(TypeError, function() { + SendableTypedArray({}); +}); + +assert.throws(TypeError, function() { + new SendableTypedArray({}); +}); + +var typedArray = new Int8Array(4); +assert.throws(TypeError, function() { + SendableTypedArray(typedArray); +}); + +assert.throws(TypeError, function() { + new SendableTypedArray(typedArray); +}); + +var buffer = new ArrayBuffer(4); +assert.throws(TypeError, function() { + SendableTypedArray(buffer); +}); + +assert.throws(TypeError, function() { + new SendableTypedArray(buffer); +}); diff --git a/test/sendable/builtins/TypedArray/length.js b/test/sendable/builtins/TypedArray/length.js new file mode 100644 index 0000000000000000000000000000000000000000..fe5a78e2514eeb3a8645176d5c301686a2803711 --- /dev/null +++ b/test/sendable/builtins/TypedArray/length.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray% +description: > + SendableTypedArray has a "length" property whose value is 0. +info: | + %SendableTypedArray% ( ) + + The length property of the %SendableTypedArray% constructor function is 0. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/name.js b/test/sendable/builtins/TypedArray/name.js new file mode 100644 index 0000000000000000000000000000000000000000..2f326dc9f66a2dd61462e7e5f82348447e7ab33b --- /dev/null +++ b/test/sendable/builtins/TypedArray/name.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray% +description: > + SendableTypedArray has a 'name' property whose value is "SendableTypedArray". +info: | + 22.2.2 Properties of the %SendableTypedArray% Intrinsic Object + + Besides a length property whose value is 3 and a name property whose value is + "SendableTypedArray", %SendableTypedArray% has the following properties: + ... + + ES6 section 17: Unless otherwise specified, the name property of a built-in + Function object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray, "name", { + value: "SendableTypedArray", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/of/invoked-as-func.js b/test/sendable/builtins/TypedArray/of/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..9df788439183e24f72bc6ff4e9c2bb594b5a366c --- /dev/null +++ b/test/sendable/builtins/TypedArray/of/invoked-as-func.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 22.2.2.2 +description: > + "of" cannot be invoked as a function +info: | + 22.2.2.2 %SendableTypedArray%.of ( ...items ) + + ... + 3. Let C be the this value. + 4. If IsConstructor(C) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var of = SendableTypedArray.of; + +assert.throws(TypeError, function() { + of(); +}); diff --git a/test/sendable/builtins/TypedArray/of/invoked-as-method.js b/test/sendable/builtins/TypedArray/of/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..e51444ff6b7f0a2519682a293cf47a57fab5faee --- /dev/null +++ b/test/sendable/builtins/TypedArray/of/invoked-as-method.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.of +description: > + "of" cannot be invoked as a method of %SendableTypedArray% +info: | + 22.2.2.2 %SendableTypedArray%.of ( ...items ) + + ... + 5. Let newObj be ? SendableTypedArrayCreate(C, «len»). + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + SendableTypedArray.of(); +}); diff --git a/test/sendable/builtins/TypedArray/of/length.js b/test/sendable/builtins/TypedArray/of/length.js new file mode 100644 index 0000000000000000000000000000000000000000..1987cae7c067fd38bbffc7a28aebfd1128f140b5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/of/length.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%-of +description: > + %SendableTypedArray%.of.length is 0. +info: | + %SendableTypedArray%.of ( ...items ) + + 17 ECMAScript Standard Built-in Objects: + + Every built-in Function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.of, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/of/name.js b/test/sendable/builtins/TypedArray/of/name.js new file mode 100644 index 0000000000000000000000000000000000000000..5563b2b942d5a792538b37365b0c0f08f2b2c455 --- /dev/null +++ b/test/sendable/builtins/TypedArray/of/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 22.2.2.2 +description: > + %SendableTypedArray%.of.name is "of". +info: | + %SendableTypedArray%.of ( ...items ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.of, "name", { + value: "of", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/of/not-a-constructor.js b/test/sendable/builtins/TypedArray/of/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..127215ebcc902a03f9002e0ddd9de278cf4a8ef1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/of/not-a-constructor.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.of does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, SendableTypedArray, arrow-function] +---*/ + +assert.sameValue(isConstructor(SendableTypedArray.of), false, 'isConstructor(SendableTypedArray.of) must return false'); + +assert.throws(TypeError, () => { + new SendableTypedArray.of(1, 2, 3, 4); +}); + diff --git a/test/sendable/builtins/TypedArray/of/prop-desc.js b/test/sendable/builtins/TypedArray/of/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..c1496005d593e8fbfbed761f9a6dedf61263eff2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/of/prop-desc.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +es6id: 22.2.2.2 +description: > + "of" property of SendableTypedArray +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray, 'of', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/of/resized-with-out-of-bounds-and-in-bounds-indices.js b/test/sendable/builtins/TypedArray/of/resized-with-out-of-bounds-and-in-bounds-indices.js new file mode 100644 index 0000000000000000000000000000000000000000..223b88d4a58a3a0ecdd4d6c1cb0756bfc5bfec75 --- /dev/null +++ b/test/sendable/builtins/TypedArray/of/resized-with-out-of-bounds-and-in-bounds-indices.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.of +description: > + Performs Set operation which ignores out-of-bounds indices. +info: | + %SendableTypedArray%.of ( ...items ) + + ... + 6. Repeat, while k < len, + ... + c. Perform ? Set(newObj, Pk, kValue, true). + ... + +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(3, {maxByteLength: 4}); +let ta = new Int8Array(rab); + +let one = { + valueOf() { + // Shrink buffer. Assignment to `ta[0]` should be ignored. + rab.resize(0); + return 1; + } +}; + +let two = { + valueOf() { + // Grow buffer. All following assignment should succeed. + rab.resize(4); + return 2; + } +}; + +// Typed array is correctly zero initialised. +assert.sameValue(ta.length, 3); +assert.sameValue(ta[0], 0); +assert.sameValue(ta[1], 0); +assert.sameValue(ta[2], 0); + +let result = Int8Array.of.call(function() { + return ta; +}, one, two, 3); + +// Correct result value. +assert.sameValue(result, ta); + +// Values are correctly set. +assert.sameValue(ta.length, 4); +assert.sameValue(ta[0], 0); +assert.sameValue(ta[1], 2); +assert.sameValue(ta[2], 3); +assert.sameValue(ta[3], 0); diff --git a/test/sendable/builtins/TypedArray/of/this-is-not-constructor.js b/test/sendable/builtins/TypedArray/of/this-is-not-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..db5193716c879239dca369a9f37da0096d9eb951 --- /dev/null +++ b/test/sendable/builtins/TypedArray/of/this-is-not-constructor.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray%.of +description: > + Throws a TypeError exception if this is not a constructor +info: | + 22.2.2.2 %SendableTypedArray%.of ( ...items ) + + ... + 3. Let C be the this value. + 4. If IsConstructor(C) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var m = { m() {} }.m; + +assert.throws(TypeError, function() { + SendableTypedArray.of.call(m, []); +}); diff --git a/test/sendable/builtins/TypedArray/out-of-bounds-behaves-like-detached.js b/test/sendable/builtins/TypedArray/out-of-bounds-behaves-like-detached.js new file mode 100644 index 0000000000000000000000000000000000000000..9997bf55059683d8706ae5c6d6de405170867aa3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/out-of-bounds-behaves-like-detached.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-isvalidintegerindex +description: > + SendableTypedArrays backed by resizable buffers that are out-of-bounds behave + as if they were detached +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const rab = CreateResizableArrayBuffer(16, 40); +const i8a = new Int8Array(rab, 0, 4); +i8a.__proto__ = { 2: 'wrong value' }; +i8a[2] = 10; +assert.sameValue(i8a[2], 10); +assert(2 in i8a); +rab.resize(0); +assert.sameValue(i8a[2], undefined); +assert(!(2 in i8a)); diff --git a/test/sendable/builtins/TypedArray/out-of-bounds-get-and-set.js b/test/sendable/builtins/TypedArray/out-of-bounds-get-and-set.js new file mode 100644 index 0000000000000000000000000000000000000000..88ccef49bfa4487db81221463b3136d90ffcf7ee --- /dev/null +++ b/test/sendable/builtins/TypedArray/out-of-bounds-get-and-set.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-isvalidintegerindex +description: > + Getting and setting in-bounds and out-of-bounds indices on SendableTypedArrays backed + by resizable buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 40 * ctor.BYTES_PER_ELEMENT); + const array = new ctor(rab, 0, 4); + // Initial values + for (let i = 0; i < 4; ++i) { + assert.sameValue(Convert(array[i]), 0); + } + // Within-bounds write + for (let i = 0; i < 4; ++i) { + array[i] = MayNeedBigInt(array, i); + } + // Within-bounds read + for (let i = 0; i < 4; ++i) { + assert.sameValue(Convert(array[i]), i, `${ctor} array fails within-bounds read`); + } + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + // OOB read. If the RAB isn't large enough to fit the entire SendableTypedArray, + // the length of the SendableTypedArray is treated as 0. + for (let i = 0; i < 4; ++i) { + assert.sameValue(array[i], undefined); + } + // OOB write (has no effect) + for (let i = 0; i < 4; ++i) { + array[i] = MayNeedBigInt(array, 10); + } + rab.resize(4 * ctor.BYTES_PER_ELEMENT); + // Within-bounds read + for (let i = 0; i < 2; ++i) { + assert.sameValue(array[i], MayNeedBigInt(array, i)); + } + // The shrunk-and-regrown part got zeroed. + for (let i = 2; i < 4; ++i) { + assert.sameValue(array[i], MayNeedBigInt(array, 0)); + } + rab.resize(40 * ctor.BYTES_PER_ELEMENT); + // Within-bounds read + for (let i = 0; i < 2; ++i) { + assert.sameValue(array[i], MayNeedBigInt(array, i)); + } + for (let i = 2; i < 4; ++i) { + assert.sameValue(array[i], MayNeedBigInt(array, 0)); + } +} diff --git a/test/sendable/builtins/TypedArray/out-of-bounds-has.js b/test/sendable/builtins/TypedArray/out-of-bounds-has.js new file mode 100644 index 0000000000000000000000000000000000000000..f72d12ddbedf095e5f7be7614ed6c005fe1b6d15 --- /dev/null +++ b/test/sendable/builtins/TypedArray/out-of-bounds-has.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-isvalidintegerindex +description: > + In-bound indices are testable with `in` on SendableTypedArrays backed by resizable buffers. +info: | + IsValidIntegerIndex ( O, index ) + ... + 6. Let length be IntegerIndexedObjectLength(O, getBufferByteLength). + 7. If length is out-of-bounds or ℝ(index) < 0 or ℝ(index) ≥ length, return false. + ... +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 40 * ctor.BYTES_PER_ELEMENT); + const array = new ctor(rab, 0, 4); + // Within-bounds read + for (let i = 0; i < 4; ++i) { + assert(i in array); + } + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + // OOB read. If the RAB isn't large enough to fit the entire SendableTypedArray, + // the length of the SendableTypedArray is treated as 0. + for (let i = 0; i < 4; ++i) { + assert(!(i in array)); + } + rab.resize(4 * ctor.BYTES_PER_ELEMENT); + // Within-bounds read + for (let i = 0; i < 4; ++i) { + assert(i in array); + } + rab.resize(40 * ctor.BYTES_PER_ELEMENT); + // Within-bounds read + for (let i = 0; i < 4; ++i) { + assert(i in array); + } +} diff --git a/test/sendable/builtins/TypedArray/prototype.js b/test/sendable/builtins/TypedArray/prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..c0debbc32f9a6c7e4e4716e1cd6aeb475a336a2a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendabletypedarray% +description: > + "prototype" property of SendableTypedArray +info: | + 22.2.2.3 %SendableTypedArray%.prototype + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: false }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray, 'prototype', { + writable: false, + enumerable: false, + configurable: false, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.iterator.js b/test/sendable/builtins/TypedArray/prototype/Symbol.iterator.js new file mode 100644 index 0000000000000000000000000000000000000000..a187d4187053a2cdc0d9cf593e1bd937112d6b1e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.iterator.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype-@@iterator +description: > + Initial state of the Symbol.iterator property +info: | + The initial value of the @@iterator property is the same function object + as the initial value of the %SendableTypedArray%.prototype.values property. + + Per ES6 section 17, the method should exist on the %SendableTypedArray% prototype, and it + should be writable and configurable, but not enumerable. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [Symbol.iterator] +---*/ + +assert.sameValue(SendableTypedArray.prototype[Symbol.iterator], SendableTypedArray.prototype.values); + +verifyProperty(SendableTypedArray.prototype, Symbol.iterator, { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.iterator/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/Symbol.iterator/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..8456e5cb0a5e514a0c7e675f28f7129fba437721 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.iterator/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype[Symbol.iterator] does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, Symbol, Symbol.iterator, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype[Symbol.iterator]), + false, + 'isConstructor(SendableTypedArray.prototype[Symbol.iterator]) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8[Symbol.iterator](); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..763f61f2d424b9b13b6672505927255522756750 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/detached-buffer.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: The getter method does not throw with a detached buffer +info: | + 22.2.3.32 get %SendableTypedArray%.prototype [ @@toStringTag ] + + ... + 4. Let name be the value of O's [[TypedArrayName]] internal slot. + 5. Assert: name is a String value. + 6. Return name. +includes: [sendableBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol.toStringTag, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample[Symbol.toStringTag], TA.name); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-accessor.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..31e9597abbc3b977af5fc49793beb446aef8d0d6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-accessor.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + Return undefined if this value does not have a [[TypedArrayName]] internal slot +info: | + 22.2.3.31 get %SendableTypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + ... + 3. If O does not have a [[TypedArrayName]] internal slot, return undefined. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(SendableTypedArrayPrototype[Symbol.toStringTag], undefined); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..2a2774008763490500e21cfe5e0dad4725cdd064 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-func.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: If this value is not Object, return undefined. +info: | + 22.2.3.31 get %SendableTypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + 2. If Type(O) is not Object, return undefined. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, Symbol.toStringTag +).get; + +assert.sameValue(getter(), undefined); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/length.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/length.js new file mode 100644 index 0000000000000000000000000000000000000000..d6d2fb6e6ba5c3a035b43324130b7df32d0acfcb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + get %SendableTypedArray%.prototype [ @@toStringTag ].length is 0. +info: | + get %SendableTypedArray%.prototype [ @@toStringTag ] + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, Symbol.toStringTag); + +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/name.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/name.js new file mode 100644 index 0000000000000000000000000000000000000000..45e4da17b1d4ee27561f7263bab08d775b522a08 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/name.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + get %SendableTypedArray%.prototype [ @@toStringTag ].name is "get [Symbol.toStringTag]". +info: | + get %SendableTypedArray%.prototype [ @@toStringTag ] + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, Symbol.toStringTag); + +verifyProperty(desc.get, "name", { + value: "get [Symbol.toStringTag]", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..7c972c15849cea1093af0e48013da3561982115a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/prop-desc.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + "@@toStringTag" property of SendableTypedArrayPrototype +info: | + 22.2.3.31 get %SendableTypedArray%.prototype [ @@toStringTag ] + + %SendableTypedArray%.prototype[@@toStringTag] is an accessor property whose set + accessor function is undefined. + ... + + This property has the attributes { [[Enumerable]]: false, [[Configurable]]: + true }. +includes: [propertyHelper.js, sendableBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var desc = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, Symbol.toStringTag +); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); +verifyNotEnumerable(SendableTypedArrayPrototype, Symbol.toStringTag); +verifyConfigurable(SendableTypedArrayPrototype, Symbol.toStringTag); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/return-typedarrayname.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/return-typedarrayname.js new file mode 100644 index 0000000000000000000000000000000000000000..d5f2be6adaa56a2a40f2bea0db35fdb3e6dc7100 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/return-typedarrayname.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + Return value from the [[TypedArrayName]] internal slot +info: | + 22.2.3.32 get %SendableTypedArray%.prototype [ @@toStringTag ] + + ... + 4. Let name be the value of O's [[TypedArrayName]] internal slot. + 5. Assert: name is a String value. + 6. Return name. +includes: [sendableBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = new TA(); + assert.sameValue(ta[Symbol.toStringTag], TA.name, "property value"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-has-no-typedarrayname-internal.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-has-no-typedarrayname-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..3f3ae7c1563b5dd57d70698544f044efe43cb7ac --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-has-no-typedarrayname-internal.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + Return undefined when `this` does not have a [[TypedArrayName]] internal slot +info: | + 22.2.3.32 get %SendableTypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + ... + 3. If O does not have a [[TypedArrayName]] internal slot, return undefined. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag, DataView, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, Symbol.toStringTag +).get; + +assert.sameValue(getter.call({}), undefined); +assert.sameValue(getter.call([]), undefined); +assert.sameValue(getter.call(new ArrayBuffer(8)), undefined); + +var ab = new ArrayBuffer(8); +var dv = new DataView(ab, 0, 1); +assert.sameValue(getter.call(dv), undefined); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..c27c5fad4047b2c2cc46e3255c3116c76ef8f2c6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-is-not-object.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: Return undefined when `this` is not Object +info: | + 22.2.3.32 get %SendableTypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + 2. If Type(O) is not Object, return undefined. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, Symbol, Symbol.toStringTag, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, Symbol.toStringTag +).get; + +assert.sameValue(getter.call(undefined), undefined, "this is undefined"); +assert.sameValue(getter.call(42), undefined, "this is 42"); +assert.sameValue(getter.call("foo"), undefined, "this is a string"); +assert.sameValue(getter.call(true), undefined, "this is true"); +assert.sameValue(getter.call(false), undefined, "this is false"); +assert.sameValue(getter.call(Symbol("s")), undefined, "this is a Symbol"); +assert.sameValue(getter.call(null), undefined, "this is null"); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..984843b63566a6ce8fbac6f9eb9679dc856bd348 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/detached-buffer.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: The getter method does not throw with a detached buffer +info: | + 22.2.3.32 get %SendableTypedArray%.prototype [ @@toStringTag ] + + ... + 4. Let name be the value of O's [[TypedArrayName]] internal slot. + 5. Assert: name is a String value. + 6. Return name. +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [Symbol.toStringTag, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample[Symbol.toStringTag], TA.name); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/invoked-as-accessor.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/invoked-as-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..3d145c537fa1f5e5b57e5d9e36d0768d38e41d30 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/invoked-as-accessor.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + Return undefined if this value does not have a [[TypedArrayName]] internal slot +info: | + 22.2.3.31 get %SendableTypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + ... + 3. If O does not have a [[TypedArrayName]] internal slot, return undefined. + ... +includes: [sendableTypedArray.js] +features: [Symbol.toStringTag, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(SendableTypedArrayPrototype[Symbol.toStringTag], undefined); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..89074c416c126e6741d36c2ce551bc2746005b2a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/invoked-as-func.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: If this value is not Object, return undefined. +info: | + 22.2.3.31 get %SendableTypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + 2. If Type(O) is not Object, return undefined. + ... +includes: [sendableTypedArray.js] +features: [Symbol.toStringTag, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, Symbol.toStringTag +).get; + +assert.sameValue(getter(), undefined); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/length.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/length.js new file mode 100644 index 0000000000000000000000000000000000000000..d3a35456008c8922b9d13a88207bee959edf4a89 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + get %SendableTypedArray%.prototype [ @@toStringTag ].length is 0. +info: | + get %SendableTypedArray%.prototype [ @@toStringTag ] + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [Symbol.toStringTag] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, Symbol.toStringTag); + +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/name.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/name.js new file mode 100644 index 0000000000000000000000000000000000000000..644bb57400c0495e4b4c7947ddeecbdbe5527665 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/name.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + get %SendableTypedArray%.prototype [ @@toStringTag ].name is "get [Symbol.toStringTag]". +info: | + get %SendableTypedArray%.prototype [ @@toStringTag ] + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [Symbol.toStringTag] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, Symbol.toStringTag); + +verifyProperty(desc.get, "name", { + value: "get [Symbol.toStringTag]", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..09e4d4075da30cd737f14a5c11d74ffe47156aa3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/prop-desc.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + "@@toStringTag" property of SendableTypedArrayPrototype +info: | + 22.2.3.31 get %SendableTypedArray%.prototype [ @@toStringTag ] + + %SendableTypedArray%.prototype[@@toStringTag] is an accessor property whose set + accessor function is undefined. + ... + + This property has the attributes { [[Enumerable]]: false, [[Configurable]]: + true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [Symbol.toStringTag] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var desc = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, Symbol.toStringTag +); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); +verifyNotEnumerable(SendableTypedArrayPrototype, Symbol.toStringTag); +verifyConfigurable(SendableTypedArrayPrototype, Symbol.toStringTag); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/return-typedarrayname.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/return-typedarrayname.js new file mode 100644 index 0000000000000000000000000000000000000000..e8c1b0900cfab81f66e210e7948b3d4acbacf456 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/return-typedarrayname.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + Return value from the [[TypedArrayName]] internal slot +info: | + 22.2.3.32 get %SendableTypedArray%.prototype [ @@toStringTag ] + + ... + 4. Let name be the value of O's [[TypedArrayName]] internal slot. + 5. Assert: name is a String value. + 6. Return name. +includes: [sendableTypedArray.js] +features: [Symbol.toStringTag, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta = new TA(); + assert.sameValue(ta[Symbol.toStringTag], TA.name, "property value"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/this-has-no-typedarrayname-internal.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/this-has-no-typedarrayname-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..460ccd29888f1cd09281a4957b83709abba29328 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/this-has-no-typedarrayname-internal.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + Return undefined when `this` does not have a [[TypedArrayName]] internal slot +info: | + 22.2.3.32 get %SendableTypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + ... + 3. If O does not have a [[TypedArrayName]] internal slot, return undefined. + ... +includes: [sendableTypedArray.js] +features: [Symbol.toStringTag, DataView, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, Symbol.toStringTag +).get; + +assert.sameValue(getter.call({}), undefined); +assert.sameValue(getter.call([]), undefined); +assert.sameValue(getter.call(new ArrayBuffer(8)), undefined); + +var ab = new ArrayBuffer(8); +var dv = new DataView(ab, 0, 1); +assert.sameValue(getter.call(dv), undefined); diff --git a/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..1d66becfd9be956190787d39f34f348c8aa829d8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/Symbol.toStringTag/this-is-not-object.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: Return undefined when `this` is not Object +info: | + 22.2.3.32 get %SendableTypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + 2. If Type(O) is not Object, return undefined. + ... +includes: [sendableTypedArray.js] +features: [Symbol, Symbol.toStringTag, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, Symbol.toStringTag +).get; + +assert.sameValue(getter.call(undefined), undefined, "this is undefined"); +assert.sameValue(getter.call(42), undefined, "this is 42"); +assert.sameValue(getter.call("foo"), undefined, "this is a string"); +assert.sameValue(getter.call(true), undefined, "this is true"); +assert.sameValue(getter.call(false), undefined, "this is false"); +assert.sameValue(getter.call(Symbol("s")), undefined, "this is a Symbol"); +assert.sameValue(getter.call(null), undefined, "this is null"); diff --git a/test/sendable/builtins/TypedArray/prototype/at/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/at/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..d3b5d9636206fc8280dea0ca98541ae2422839a1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, SendableTypedArray.prototype.at, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'implements SendableTypedArray.prototype.at' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.at(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.at(0); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the at operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.at(0); + throw new Test262Error('at completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/coerced-index-resize.js b/test/sendable/builtins/TypedArray/prototype/at/coerced-index-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..9fc2f5e20cf8f48d9a135bef597943085987cafe --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/coerced-index-resize.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + SendableTypedArray.p.at behaves correctly on SendableTypedArrays backed by resizable buffers + when the SendableTypedArray is resized during parameter conversion +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function SendableTypedArrayAtHelper(ta, index) { + const result = ta.at(index); + return Convert(result); +} + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2); + return 0; + } + }; + assert.sameValue(SendableTypedArrayAtHelper(fixedLength, evil), undefined); +} + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let evil = { + valueOf: () => { + rab.resize(2); + return -1; + } + }; + // The SendableTypedArray is *not* out of bounds since it's length-tracking. + assert.sameValue(SendableTypedArrayAtHelper(lengthTracking, evil), undefined); +} diff --git a/test/sendable/builtins/TypedArray/prototype/at/index-argument-tointeger.js b/test/sendable/builtins/TypedArray/prototype/at/index-argument-tointeger.js new file mode 100644 index 0000000000000000000000000000000000000000..7d4ff1d229896664d45742905c5b3d9f3ad7f78f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/index-argument-tointeger.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + Property type and descriptor. +info: | + %SendableTypedArray%.prototype.at( index ) + + Let relativeIndex be ? ToInteger(index). + +includes: [sendableTypedArray.js] +features: [TypedArray, TypedArray.prototype.at] +---*/ +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'The value of `typeof SendableTypedArray.prototype.at` is "function"' +); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.at, 'function', 'The value of `typeof TA.prototype.at` is "function"'); + let valueOfCallCount = 0; + let index = { + valueOf() { + valueOfCallCount++; + return 1; + } + }; + + let a = new TA([0,1,2,3]); + + assert.sameValue(a.at(index), 1, 'a.at({valueOf() {valueOfCallCount++; return 1;}}) must return 1'); + assert.sameValue(valueOfCallCount, 1, 'The value of `valueOfCallCount` is 1'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/index-non-numeric-argument-tointeger-invalid.js b/test/sendable/builtins/TypedArray/prototype/at/index-non-numeric-argument-tointeger-invalid.js new file mode 100644 index 0000000000000000000000000000000000000000..c427c01246b2e57bc86a49fde2bf03e28b23645e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/index-non-numeric-argument-tointeger-invalid.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + Property type and descriptor. +info: | + %SendableTypedArray%.prototype.at( index ) + + Let relativeIndex be ? ToInteger(index). + +includes: [sendableTypedArray.js] +features: [TypedArray, TypedArray.prototype.at] +---*/ +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'The value of `typeof SendableTypedArray.prototype.at` is "function"' +); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.at, 'function', 'The value of `typeof TA.prototype.at` is "function"'); + let a = new TA([0,1,2,3]); + + assert.throws(TypeError, () => { + a.at(Symbol()); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/index-non-numeric-argument-tointeger.js b/test/sendable/builtins/TypedArray/prototype/at/index-non-numeric-argument-tointeger.js new file mode 100644 index 0000000000000000000000000000000000000000..d7aebc1b2c19afeb0538225502c6cd40e302f7a3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/index-non-numeric-argument-tointeger.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + Property type and descriptor. +info: | + %SendableTypedArray%.prototype.at( index ) + + Let relativeIndex be ? ToInteger(index). + +includes: [sendableTypedArray.js] +features: [TypedArray, TypedArray.prototype.at] +---*/ +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'The value of `typeof SendableTypedArray.prototype.at` is "function"' +); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.at, 'function', 'The value of `typeof TA.prototype.at` is "function"'); + + let a = new TA([0,1,2,3]); + + assert.sameValue(a.at(false), 0, 'a.at(false) must return 0'); + assert.sameValue(a.at(null), 0, 'a.at(null) must return 0'); + assert.sameValue(a.at(undefined), 0, 'a.at(undefined) must return 0'); + assert.sameValue(a.at(""), 0, 'a.at("") must return 0'); + assert.sameValue(a.at(function() {}), 0, 'a.at(function() {}) must return 0'); + assert.sameValue(a.at([]), 0, 'a.at([]) must return 0'); + + assert.sameValue(a.at(true), 1, 'a.at(true) must return 1'); + assert.sameValue(a.at("1"), 1, 'a.at("1") must return 1'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/length.js b/test/sendable/builtins/TypedArray/prototype/at/length.js new file mode 100644 index 0000000000000000000000000000000000000000..d38ee95c5e466c58917293269806a3bac253d36d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/length.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + SendableTypedArray.prototype.at.length value and descriptor. +info: | + %SendableTypedArray%.prototype.at( index ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray.prototype.at] +---*/ +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'The value of `typeof SendableTypedArray.prototype.at` is "function"' +); + +verifyProperty(SendableTypedArray.prototype.at, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/name.js b/test/sendable/builtins/TypedArray/prototype/at/name.js new file mode 100644 index 0000000000000000000000000000000000000000..ba3b3ce40acfb43c614f1f519034a77a8d12734c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/name.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + %SendableTypedArray%.prototype.at.name value and descriptor. +info: | + %SendableTypedArray%.prototype.at( index ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray.prototype.at] +---*/ +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'The value of `typeof SendableTypedArray.prototype.at` is "function"' +); + +assert.sameValue( + SendableTypedArray.prototype.at.name, 'at', + 'The value of SendableTypedArray.prototype.at.name is "at"' +); + +verifyProperty(SendableTypedArray.prototype.at, 'name', { + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/at/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..23049435562505c409db2e0c3a54905b2e2b4afd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/prop-desc.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + Property type and descriptor. +info: | + %SendableTypedArray%.prototype.at( index ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray.prototype.at] +---*/ +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'The value of `typeof SendableTypedArray.prototype.at` is "function"' +); + +verifyProperty(SendableTypedArray.prototype, 'at', { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/at/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..09b5036ef27adc91ab7ff6010acc6593a9a3a401 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/resizable-buffer.js @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + SendableTypedArray.p.at behaves correctly on SendableTypedArrays backed by resizable buffers +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function SendableTypedArrayAtHelper(ta, index) { + const result = ta.at(index); + return Convert(result); +} + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + let ta_write = new ctor(rab); + for (let i = 0; i < 4; ++i) { + ta_write[i] = MayNeedBigInt(ta_write, i); + } + assert.sameValue(SendableTypedArrayAtHelper(fixedLength, -1), 3); + assert.sameValue(SendableTypedArrayAtHelper(lengthTracking, -1), 3); + assert.sameValue(SendableTypedArrayAtHelper(fixedLengthWithOffset, -1), 3); + assert.sameValue(SendableTypedArrayAtHelper(lengthTrackingWithOffset, -1), 3); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + SendableTypedArrayAtHelper(fixedLength, -1); + }); + assert.throws(TypeError, () => { + SendableTypedArrayAtHelper(fixedLengthWithOffset, -1); + }); + assert.sameValue(SendableTypedArrayAtHelper(lengthTracking, -1), 2); + assert.sameValue(SendableTypedArrayAtHelper(lengthTrackingWithOffset, -1), 2); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + SendableTypedArrayAtHelper(fixedLength, -1); + }); + assert.throws(TypeError, () => { + SendableTypedArrayAtHelper(fixedLengthWithOffset, -1); + }); + assert.throws(TypeError, () => { + SendableTypedArrayAtHelper(lengthTrackingWithOffset, -1); + }); + assert.sameValue(SendableTypedArrayAtHelper(lengthTracking, -1), 0); + + // Grow so that all TAs are back in-bounds. New memory is zeroed. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + assert.sameValue(SendableTypedArrayAtHelper(fixedLength, -1), 0); + assert.sameValue(SendableTypedArrayAtHelper(lengthTracking, -1), 0); + assert.sameValue(SendableTypedArrayAtHelper(fixedLengthWithOffset, -1), 0); + assert.sameValue(SendableTypedArrayAtHelper(lengthTrackingWithOffset, -1), 0); +} diff --git a/test/sendable/builtins/TypedArray/prototype/at/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/at/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..b92221a5628773a37cfe3b2544c725ca13f38ef1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, SendableTypedArray.prototype.at, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'implements SendableTypedArray.prototype.at' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.at(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.at(0); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the at operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.at(0); + throw new Test262Error('at completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/return-abrupt-from-this.js b/test/sendable/builtins/TypedArray/prototype/at/return-abrupt-from-this.js new file mode 100644 index 0000000000000000000000000000000000000000..35897e39884accde7dea15b3d574fdc6f945f60c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/return-abrupt-from-this.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + Return abrupt from ToObject(this value). +info: | + %SendableTypedArray%.prototype.at( index ) + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + +includes: [sendableTypedArray.js] +features: [TypedArray,TypedArray.prototype.at] +---*/ +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'The value of `typeof SendableTypedArray.prototype.at` is "function"' +); + +assert.throws(TypeError, () => { + SendableTypedArray.prototype.at.call(undefined); +}); + +assert.throws(TypeError, () => { + SendableTypedArray.prototype.at.call(null); +}); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.at, 'function', 'The value of `typeof TA.prototype.at` is "function"'); + + assert.throws(TypeError, () => { + TA.prototype.at.call(undefined); + }); + + assert.throws(TypeError, () => { + TA.prototype.at.call(null); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/returns-item-relative-index.js b/test/sendable/builtins/TypedArray/prototype/at/returns-item-relative-index.js new file mode 100644 index 0000000000000000000000000000000000000000..8a3ab63a0fcbdce2dd0b8a4215ae886c408b3f38 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/returns-item-relative-index.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + Returns the item value at the specified relative index +info: | + %SendableTypedArray%.prototype.at( index ) + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +includes: [sendableTypedArray.js] +features: [TypedArray,TypedArray.prototype.at] +---*/ +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'The value of `typeof SendableTypedArray.prototype.at` is "function"' +); + +testWithTypedArrayConstructors(TA => { + let a = new TA([1, 2, 3, 4, 5]); + assert.sameValue(a.at(0), 1, 'a.at(0) must return 1'); + assert.sameValue(a.at(-1), 5, 'a.at(-1) must return 5'); + assert.sameValue(a.at(-2), 4, 'a.at(-2) must return 4'); + assert.sameValue(a.at(-3), 3, 'a.at(-3) must return 3'); + assert.sameValue(a.at(-4), 2, 'a.at(-4) must return 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/returns-item.js b/test/sendable/builtins/TypedArray/prototype/at/returns-item.js new file mode 100644 index 0000000000000000000000000000000000000000..9fa216b280c850e0dfa12e1e4540e8f4af066bd8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/returns-item.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + Returns the item value at the specified index +info: | + %SendableTypedArray%.prototype.at( index ) + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +includes: [sendableTypedArray.js] +features: [TypedArray,TypedArray.prototype.at] +---*/ +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'The value of `typeof SendableTypedArray.prototype.at` is "function"' +); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.at, 'function', 'The value of `typeof TA.prototype.at` is "function"'); + let a = new TA([1, 2, 3, 4]); + + assert.sameValue(a.at(0), 1, 'a.at(0) must return 1'); + assert.sameValue(a.at(1), 2, 'a.at(1) must return 2'); + assert.sameValue(a.at(2), 3, 'a.at(2) must return 3'); + assert.sameValue(a.at(3), 4, 'a.at(3) must return 4'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/returns-undefined-for-holes-in-sparse-arrays.js b/test/sendable/builtins/TypedArray/prototype/at/returns-undefined-for-holes-in-sparse-arrays.js new file mode 100644 index 0000000000000000000000000000000000000000..b45c476969c408cd98c6fde044a2c9d3bb8e28b2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/returns-undefined-for-holes-in-sparse-arrays.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + Returns the item value at the specified index, holes are filled in sparse arrays. +info: | + %SendableTypedArray%.prototype.at( index ) + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +includes: [sendableTypedArray.js] +features: [TypedArray, TypedArray.prototype.at] +---*/ +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'The value of `typeof SendableTypedArray.prototype.at` is "function"' +); + +testWithTypedArrayConstructors(TA => { + let a = new TA([0, 1, , 3, 4, , 6]); + let filler = 0; + if (TA.name.startsWith('Float')) { + filler = NaN; + } + assert.sameValue(a.at(0), 0, 'a.at(0) must return 0'); + assert.sameValue(a.at(1), 1, 'a.at(1) must return 1'); + assert.sameValue(a.at(2), filler, 'a.at(2) must return the value of filler'); + assert.sameValue(a.at(3), 3, 'a.at(3) must return 3'); + assert.sameValue(a.at(4), 4, 'a.at(4) must return 4'); + assert.sameValue(a.at(5), filler, 'a.at(5) must return the value of filler'); + assert.sameValue(a.at(6), 6, 'a.at(6) must return 6'); + assert.sameValue(a.at(-0), 0, 'a.at(-0) must return 0'); + assert.sameValue(a.at(-1), 6, 'a.at(-1) must return 6'); + assert.sameValue(a.at(-2), filler, 'a.at(-2) must return the value of filler'); + assert.sameValue(a.at(-3), 4, 'a.at(-3) must return 4'); + assert.sameValue(a.at(-4), 3, 'a.at(-4) must return 3'); + assert.sameValue(a.at(-5), filler, 'a.at(-5) must return the value of filler'); + assert.sameValue(a.at(-6), 1, 'a.at(-6) must return 1'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/at/returns-undefined-for-out-of-range-index.js b/test/sendable/builtins/TypedArray/prototype/at/returns-undefined-for-out-of-range-index.js new file mode 100644 index 0000000000000000000000000000000000000000..4475d728ebd31f5849e641d1c3452849ec93e3f4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/at/returns-undefined-for-out-of-range-index.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.at +description: > + Returns undefined if the specified index less than or greater than the available index range. +info: | + %SendableTypedArray%.prototype.at( index ) + + If k < 0 or k ≥ len, then return undefined. + +includes: [sendableTypedArray.js] +features: [TypedArray,TypedArray.prototype.at] +---*/ +assert.sameValue( + typeof SendableTypedArray.prototype.at, + 'function', + 'The value of `typeof SendableTypedArray.prototype.at` is "function"' +); + +testWithTypedArrayConstructors(TA => { + assert.sameValue(typeof TA.prototype.at, 'function', 'The value of `typeof TA.prototype.at` is "function"'); + let a = new TA([]); + + assert.sameValue(a.at(-2), undefined, 'a.at(-2) must return undefined'); // wrap around the end + assert.sameValue(a.at(0), undefined, 'a.at(0) must return undefined'); + assert.sameValue(a.at(1), undefined, 'a.at(1) must return undefined'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/buffer/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9ffd1182eb2a18e96cee7cb1e1c3217572fecda2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/BigInt/detached-buffer.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: The getter method does not throw with a detached buffer +info: | + 22.2.3.1 get %SendableTypedArray%.prototype.buffer + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. Return buffer. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(8); + var sample = new TA(buffer, 0, 1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.buffer, buffer); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/BigInt/return-buffer.js b/test/sendable/builtins/TypedArray/prototype/buffer/BigInt/return-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9b86ce6ce7c904bbb64f197ffa88af41e12501bc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/BigInt/return-buffer.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: > + Return buffer from [[ViewedArrayBuffer]] internal slot +info: | + 22.2.3.1 get %SendableTypedArray%.prototype.buffer + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. Return buffer. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(TA.BYTES_PER_ELEMENT); + var ta = new TA(buffer); + + assert.sameValue(ta.buffer, buffer); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/buffer/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..3268ed2f066f0ce6165d8f458f9734db0e5bc8df --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/detached-buffer.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: The getter method does not throw with a detached buffer +info: | + 22.2.3.1 get %SendableTypedArray%.prototype.buffer + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. Return buffer. +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(8); + var sample = new TA(buffer, 0, 1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.buffer, buffer); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/invoked-as-accessor.js b/test/sendable/builtins/TypedArray/prototype/buffer/invoked-as-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..47f16876476c89faf9e58c7dfb597a889bfb46cc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/invoked-as-accessor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: > + Requires this value to have a [[ViewedArrayBuffer]] internal slot +info: | + 22.2.3.1 get %SendableTypedArray%.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.buffer; +}); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/buffer/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..95f0eee12107d3b4348ccf15b72aba6a5fab5515 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/invoked-as-func.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.1 get %SendableTypedArray%.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, 'buffer' +).get; + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/length.js b/test/sendable/builtins/TypedArray/prototype/buffer/length.js new file mode 100644 index 0000000000000000000000000000000000000000..758007e78a4d51cb6ee412f4da929832d2a66be3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: > + get %SendableTypedArray%.prototype.buffer.length is 0. +info: | + get %SendableTypedArray%.prototype.buffer + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, "buffer"); + +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/name.js b/test/sendable/builtins/TypedArray/prototype/buffer/name.js new file mode 100644 index 0000000000000000000000000000000000000000..6541a8bdd65d599b46b982f5947af9751d73fe6c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/name.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: > + get %SendableTypedArray%.prototype.buffer.name is "get buffer". +info: | + get %SendableTypedArray%.prototype.buffer + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, "buffer"); + +verifyProperty(desc.get, "name", { + value: "get buffer", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/buffer/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..c8dcd19a283afa8803e3756f7316a5bb6289346f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/prop-desc.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: > + "buffer" property of SendableTypedArrayPrototype +info: | + %SendableTypedArray%.prototype.buffer is an accessor property whose set accessor + function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var desc = Object.getOwnPropertyDescriptor(SendableTypedArrayPrototype, "buffer"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(SendableTypedArrayPrototype, "buffer"); +verifyConfigurable(SendableTypedArrayPrototype, "buffer"); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/return-buffer.js b/test/sendable/builtins/TypedArray/prototype/buffer/return-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..244b6643c43929b8bd46027ae46310acfe350423 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/return-buffer.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: > + Return buffer from [[ViewedArrayBuffer]] internal slot +info: | + 22.2.3.1 get %SendableTypedArray%.prototype.buffer + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. Return buffer. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(TA.BYTES_PER_ELEMENT); + var ta = new TA(buffer); + + assert.sameValue(ta.buffer, buffer); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/this-has-no-typedarrayname-internal.js b/test/sendable/builtins/TypedArray/prototype/buffer/this-has-no-typedarrayname-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..1607d783cb37f9c71f3954a970e36dfe6da4683d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/this-has-no-typedarrayname-internal.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: > + Throws a TypeError exception when `this` does not have a [[TypedArrayName]] + internal slot +info: | + 22.2.3.1 get %SendableTypedArray%.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [DataView, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, "buffer" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}); + +var dv = new DataView(new ArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/this-inherits-typedarray.js b/test/sendable/builtins/TypedArray/prototype/buffer/this-inherits-typedarray.js new file mode 100644 index 0000000000000000000000000000000000000000..e89ed798c48f9ba48f4d193077b9fa2177483fed --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/this-inherits-typedarray.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: > + Throws a TypeError exception when `this` does not have a [[TypedArrayName]] + internal slot, even if its prototype does +info: | + 22.2.3.1 get %SendableTypedArray%.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, "buffer" +).get; + +testWithTypedArrayConstructors(TA => { + var typedArray = new TA(5); + var o = {}; + Object.setPrototypeOf(o, typedArray); + assert.throws(TypeError, function() { + getter.call(o); + }, + "Internal slot should not be inherited"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/buffer/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/buffer/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..39e21e5f5b4287d074efc52d1b9d44d709e9a912 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/buffer/this-is-not-object.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.buffer +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.1 get %SendableTypedArray%.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, "buffer" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..73882533db932f1b4f46d30c10a9daf9dcdb5380 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/detached-buffer.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: Returns 0 if the instance has a detached buffer +info: | + 22.2.3.2 get %SendableTypedArray%.prototype.byteLength + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.byteLength, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/resizable-array-buffer-auto.js b/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/resizable-array-buffer-auto.js new file mode 100644 index 0000000000000000000000000000000000000000..e63951cd2319bafcff58e999eaada64644a6e89e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/resizable-array-buffer-auto.js @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the dynamically-sized SendableTypedArray instance +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE); + var expected = BPE * 3; + + assert.sameValue(array.byteLength, expected); + + try { + ab.resize(BPE * 5); + expected = BPE * 4; + } catch (_) {} + + assert.sameValue(array.byteLength, expected, "following grow"); + + try { + ab.resize(BPE * 3); + expected = BPE * 2; + } catch (_) {} + + assert.sameValue(array.byteLength, expected, "following shrink (within bounds)"); + + try { + ab.resize(BPE * 3 - 1); + expected = BPE; + } catch (_) {} + + assert.sameValue(array.byteLength, expected, "following shrink (partial element)"); + + try { + ab.resize(BPE); + expected = 0; + } catch (_) {} + + assert.sameValue(array.byteLength, expected, "following shrink (on boundary)"); + + try { + ab.resize(0); + expected = 0; + } catch (_) {} + + assert.sameValue(array.byteLength, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/resizable-array-buffer-fixed.js b/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000000000000000000000000000000000..56226551ce878dbd86e57cd8a253e24d467e7621 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/resizable-array-buffer-fixed.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the fixed-sized SendableTypedArray instance +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + assert.sameValue(array.byteLength, BPE * 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(array.byteLength, BPE * 2, "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue(array.byteLength, BPE * 2, "following shrink (within bounds)"); + + var expected; + try { + ab.resize(BPE * 3 - 1); + expected = 0; + } catch (_) { + expected = BPE * 2; + } + + assert.sameValue(array.byteLength, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/return-bytelength.js b/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/return-bytelength.js new file mode 100644 index 0000000000000000000000000000000000000000..b7e08500bfc9f9bf83a427c1c1a56bc2cb4181a3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/BigInt/return-bytelength.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: > + Return value from [[ByteLength]] internal slot +info: | + 22.2.3.2 get %SendableTypedArray%.prototype.byteLength + + ... + 6. Let size be the value of O's [[ByteLength]] internal slot. + 7. Return size. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bytesPerElement = TA.BYTES_PER_ELEMENT; + var ta1 = new TA(); + assert.sameValue(ta1.byteLength, 0); + + var ta2 = new TA(42); + assert.sameValue(ta2.byteLength, 42 * bytesPerElement); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/byteLength/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..41c72c1c052813d47a71d8bac34783e7f0a10152 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/detached-buffer.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: Returns 0 if the instance has a detached buffer +info: | + 22.2.3.2 get %SendableTypedArray%.prototype.byteLength + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.byteLength, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/invoked-as-accessor.js b/test/sendable/builtins/TypedArray/prototype/byteLength/invoked-as-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..573a776ac5f4db2f21499a27439cc59004189e97 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/invoked-as-accessor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: > + Requires this value to have a [[ViewedArrayBuffer]] internal slot +info: | + 22.2.3.2 get %SendableTypedArray%.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.byteLength; +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/byteLength/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..a6548fbbc3f455ccaac1d554e27da460744accc9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/invoked-as-func.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.2 get %SendableTypedArray%.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, 'byteLength' +).get; + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/length.js b/test/sendable/builtins/TypedArray/prototype/byteLength/length.js new file mode 100644 index 0000000000000000000000000000000000000000..3cee96fcafa69b7fa1173059248335c39266d1d9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: > + get %SendableTypedArray%.prototype.byteLength.length is 0. +info: | + get %SendableTypedArray%.prototype.byteLength + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, "byteLength"); + +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/name.js b/test/sendable/builtins/TypedArray/prototype/byteLength/name.js new file mode 100644 index 0000000000000000000000000000000000000000..d111aa04b3cf6402ab74b361a0906d4eb89f094d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/name.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: > + get %SendableTypedArray%.prototype.byteLength.name is "get byteLength". +info: | + get %SendableTypedArray%.prototype.byteLength + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, "byteLength"); + +verifyProperty(desc.get, "name", { + value: "get byteLength", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/byteLength/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..3f20227948b2a525f75cd66dea80c6313bc01d72 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/prop-desc.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: > + "byteLength" property of SendableTypedArrayPrototype +info: | + %SendableTypedArray%.prototype.byteLength is an accessor property whose set accessor + function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var desc = Object.getOwnPropertyDescriptor(SendableTypedArrayPrototype, "byteLength"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(SendableTypedArrayPrototype, "byteLength"); +verifyConfigurable(SendableTypedArrayPrototype, "byteLength"); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/resizable-array-buffer-auto.js b/test/sendable/builtins/TypedArray/prototype/byteLength/resizable-array-buffer-auto.js new file mode 100644 index 0000000000000000000000000000000000000000..25602ce6cc835890ef675374e758c97037013adf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/resizable-array-buffer-auto.js @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the dynamically-sized SendableTypedArray instance +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE); + var expected = BPE * 3; + + assert.sameValue(array.byteLength, expected); + + try { + ab.resize(BPE * 5); + expected = BPE * 4; + } catch (_) {} + + assert.sameValue(array.byteLength, expected, "following grow"); + + try { + ab.resize(BPE * 3); + expected = BPE * 2; + } catch (_) {} + + assert.sameValue(array.byteLength, expected, "following shrink (within bounds)"); + + try { + ab.resize(BPE * 3 - 1); + expected = BPE; + } catch (_) {} + + assert.sameValue(array.byteLength, expected, "following shrink (partial element)"); + + try { + ab.resize(BPE); + expected = 0; + } catch (_) {} + + assert.sameValue(array.byteLength, expected, "following shrink (on boundary)"); + + try { + ab.resize(0); + expected = 0; + } catch (_) {} + + assert.sameValue(array.byteLength, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/resizable-array-buffer-fixed.js b/test/sendable/builtins/TypedArray/prototype/byteLength/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000000000000000000000000000000000..6e747f2d182e0656e25eec6876b9b1867d4337a2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/resizable-array-buffer-fixed.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the fixed-sized SendableTypedArray instance +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + assert.sameValue(array.byteLength, BPE * 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(array.byteLength, BPE * 2, "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue(array.byteLength, BPE * 2, "following shrink (within bounds)"); + + var expected; + try { + ab.resize(BPE * 3 - 1); + expected = 0; + } catch (_) { + expected = BPE * 2; + } + + assert.sameValue(array.byteLength, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/resizable-buffer-assorted.js b/test/sendable/builtins/TypedArray/prototype/byteLength/resizable-buffer-assorted.js new file mode 100644 index 0000000000000000000000000000000000000000..80be3aedb166a5edeb105943142463980618d1ba --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/resizable-buffer-assorted.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: > + SendableTypedArray.p.byteLength behaves correctly on assorted kinds of receivers + backed by resizable buffers +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const rab = CreateResizableArrayBuffer(40, 80); +for (let ctor of ctors) { + const ta = new ctor(rab, 0, 3); + assert.compareArray(ta.buffer, rab); + assert.sameValue(ta.byteLength, 3 * ctor.BYTES_PER_ELEMENT); + const empty_ta = new ctor(rab, 0, 0); + assert.compareArray(empty_ta.buffer, rab); + assert.sameValue(empty_ta.byteLength, 0); + const ta_with_offset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 3); + assert.compareArray(ta_with_offset.buffer, rab); + assert.sameValue(ta_with_offset.byteLength, 3 * ctor.BYTES_PER_ELEMENT); + const empty_ta_with_offset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 0); + assert.compareArray(empty_ta_with_offset.buffer, rab); + assert.sameValue(empty_ta_with_offset.byteLength, 0); + const length_tracking_ta = new ctor(rab); + assert.compareArray(length_tracking_ta.buffer, rab); + assert.sameValue(length_tracking_ta.byteLength, 40); + const offset = 8; + const length_tracking_ta_with_offset = new ctor(rab, offset); + assert.compareArray(length_tracking_ta_with_offset.buffer, rab); + assert.sameValue(length_tracking_ta_with_offset.byteLength, 40 - offset); + const empty_length_tracking_ta_with_offset = new ctor(rab, 40); + assert.compareArray(empty_length_tracking_ta_with_offset.buffer, rab); + assert.sameValue(empty_length_tracking_ta_with_offset.byteLength, 0); +} diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/resized-out-of-bounds-1.js b/test/sendable/builtins/TypedArray/prototype/byteLength/resized-out-of-bounds-1.js new file mode 100644 index 0000000000000000000000000000000000000000..e53a44c86895e940140a722e7a89897e12e91e33 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/resized-out-of-bounds-1.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteLength +description: > + SendableTypedArray.p.byteLength behaves correctly when the underlying resizable buffer + is resized such that the SendableTypedArray becomes out of bounds. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const rab = CreateResizableArrayBuffer(16, 40); + +// Create TAs which cover the bytes 0-7. +let tas_and_lengths = []; +for (let ctor of ctors) { + const length = 8 / ctor.BYTES_PER_ELEMENT; + tas_and_lengths.push([ + new ctor(rab, 0, length), + length + ]); +} +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteLength, length * ta.BYTES_PER_ELEMENT); +} +rab.resize(2); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteLength, 0); +} +// Resize the rab so that it just barely covers the needed 8 bytes. +rab.resize(8); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteLength, length * ta.BYTES_PER_ELEMENT); +} +rab.resize(40); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteLength, length * ta.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/resized-out-of-bounds-2.js b/test/sendable/builtins/TypedArray/prototype/byteLength/resized-out-of-bounds-2.js new file mode 100644 index 0000000000000000000000000000000000000000..d1d64451f0e7788cb27e1109bef97d2039cf8945 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/resized-out-of-bounds-2.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteLength +description: > + SendableTypedArray.p.byteLength behaves as expected when the underlying resizable + buffer is resized such that the SendableTypedArray becomes out of bounds. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const rab = CreateResizableArrayBuffer(20, 40); + +// Create TAs with offset, which cover the bytes 8-15. +let tas_and_lengths = []; +for (let ctor of ctors) { + const length = 8 / ctor.BYTES_PER_ELEMENT; + tas_and_lengths.push([ + new ctor(rab, 8, length), + length + ]); +} +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteLength, length * ta.BYTES_PER_ELEMENT); +} +rab.resize(10); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteLength, 0); +} +// Resize the rab so that it just barely covers the needed 8 bytes. +rab.resize(16); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteLength, length * ta.BYTES_PER_ELEMENT); +} +rab.resize(40); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteLength, length * ta.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/return-bytelength.js b/test/sendable/builtins/TypedArray/prototype/byteLength/return-bytelength.js new file mode 100644 index 0000000000000000000000000000000000000000..099e481281a1bab16a82564440ba4a4444d722ee --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/return-bytelength.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: > + Return value from [[ByteLength]] internal slot +info: | + 22.2.3.2 get %SendableTypedArray%.prototype.byteLength + + ... + 6. Let size be the value of O's [[ByteLength]] internal slot. + 7. Return size. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bytesPerElement = TA.BYTES_PER_ELEMENT; + var ta1 = new TA(); + assert.sameValue(ta1.byteLength, 0); + + var ta2 = new TA(42); + assert.sameValue(ta2.byteLength, 42 * bytesPerElement); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/this-has-no-typedarrayname-internal.js b/test/sendable/builtins/TypedArray/prototype/byteLength/this-has-no-typedarrayname-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..a84ae4b1f9f4160bf90a24700121a343bb03a52a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/this-has-no-typedarrayname-internal.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: > + Throws a TypeError exception when `this` does not have a [[TypedArrayName]] + internal slot +info: | + 22.2.3.2 get %SendableTypedArray%.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [DataView, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}); + +var dv = new DataView(new ArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteLength/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/byteLength/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..692d85c635d1004f0a626805fe49960676cee7d3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteLength/this-is-not-object.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.bytelength +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.2 get %SendableTypedArray%.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..e01f018be991d845c6974f690830c7f1abc18980 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/detached-buffer.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: Returns 0 if the instance has a detached buffer +info: | + 22.2.3.3 get %SendableTypedArray%.prototype.byteOffset + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [sendableBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(128); + var sample = new TA(buffer, 8, 1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.byteOffset, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-auto.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-auto.js new file mode 100644 index 0000000000000000000000000000000000000000..6ebcd954b499c0aa8e601eded9d30c6d89234fcb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-auto.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the dynamically-sized SendableTypedArray instance +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE); + + assert.sameValue(array.byteOffset, BPE); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)"); + + try { + ab.resize(BPE * 3 - 1); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following shrink (partial element)"); + + try { + ab.resize(BPE); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following shrink (on boundary)"); + + var expected = BPE; + try { + ab.resize(0); + expected = 0; + } catch (_) {} + + assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-fixed.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000000000000000000000000000000000..b30773f1ae76bcfc3ed2432be36c41d0454bb28f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/resizable-array-buffer-fixed.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the fixed-sized SendableTypedArray instance +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + assert.sameValue(array.byteOffset, BPE); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)"); + + var expected; + try { + ab.resize(BPE * 3 - 1); + expected = 0; + } catch (_) { + expected = BPE; + } + + assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/return-byteoffset.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/return-byteoffset.js new file mode 100644 index 0000000000000000000000000000000000000000..667e34575cf77bd188e8f838c050470b060969e8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/BigInt/return-byteoffset.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: > + Return value from [[ByteOffset]] internal slot +info: | + 22.2.3.3 get %SendableTypedArray%.prototype.byteOffset + + ... + 6. Let offset be the value of O's [[ByteOffset]] internal slot. + 7. Return size. +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.byteOffset, 0, "Regular typedArray"); + + var offset = 4 * TA.BYTES_PER_ELEMENT; + + var buffer1 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT); + var ta2 = new TA(buffer1, offset); + assert.sameValue(ta2.byteOffset, offset, "TA(buffer, offset)"); + + var buffer2 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT); + var sample = new TA(buffer2, offset); + var ta3 = new TA(sample); + assert.sameValue(ta3.byteOffset, 0, "TA(typedArray)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..d2f7ce0fc019a80583fcab388a782fdde33b60c5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/detached-buffer.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: Returns 0 if the instance has a detached buffer +info: | + 22.2.3.3 get %SendableTypedArray%.prototype.byteOffset + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(128); + var sample = new TA(buffer, 8, 1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.byteOffset, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/invoked-as-accessor.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/invoked-as-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..abb2a943432a17157cd4017e7f6630ea19e2a434 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/invoked-as-accessor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: > + Requires this value to have a [[ViewedArrayBuffer]] internal slot +info: | + 22.2.3.3 get %SendableTypedArray%.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.byteOffset; +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..eab2ed22a80a0ef328459530256440e5342c3ffc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/invoked-as-func.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.3 get %SendableTypedArray%.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, 'byteOffset' +).get; + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/length.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/length.js new file mode 100644 index 0000000000000000000000000000000000000000..bde9b35f79a4e8528fa64a9cceb8978df3a6abba --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: > + get %SendableTypedArray%.prototype.byteOffset.length is 0. +info: | + get %SendableTypedArray%.prototype.byteOffset + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, "byteOffset"); + +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/name.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/name.js new file mode 100644 index 0000000000000000000000000000000000000000..ff533f27be099c1c6f61b2e51e7376830ec1164d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/name.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: > + get %SendableTypedArray%.prototype.byteOffset.name is "get byteOffset". +info: | + get %SendableTypedArray%.prototype.byteOffset + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, "byteOffset"); + +verifyProperty(desc.get, "name", { + value: "get byteOffset", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..f04a7e7d72532de7504355fe2dd96c2f6679d722 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/prop-desc.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: > + "byteOffset" property of SendableTypedArrayPrototype +info: | + %SendableTypedArray%.prototype.byteOffset is an accessor property whose set accessor + function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var desc = Object.getOwnPropertyDescriptor(SendableTypedArrayPrototype, "byteOffset"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(SendableTypedArrayPrototype, "byteOffset"); +verifyConfigurable(SendableTypedArrayPrototype, "byteOffset"); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/resizable-array-buffer-auto.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/resizable-array-buffer-auto.js new file mode 100644 index 0000000000000000000000000000000000000000..b957e4f70452a98698f20e2bc238db9b56999697 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/resizable-array-buffer-auto.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the dynamically-sized SendableTypedArray instance +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE); + + assert.sameValue(array.byteOffset, BPE); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)"); + + try { + ab.resize(BPE * 3 - 1); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following shrink (partial element)"); + + try { + ab.resize(BPE); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following shrink (on boundary)"); + + var expected = BPE; + try { + ab.resize(0); + expected = 0; + } catch (_) {} + + assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/resizable-array-buffer-fixed.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000000000000000000000000000000000..dfe53f112947ca3ae1f15137838e429003be6a13 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/resizable-array-buffer-fixed.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the fixed-sized SendableTypedArray instance +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + assert.sameValue(array.byteOffset, BPE); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue(array.byteOffset, BPE, "following shrink (within bounds)"); + + var expected; + try { + ab.resize(BPE * 3 - 1); + expected = 0; + } catch (_) { + expected = BPE; + } + + assert.sameValue(array.byteOffset, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/resized-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/resized-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..ba5338bf20acb068c61989efe2462dc9216c07cc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/resized-out-of-bounds.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteOffset +description: > + SendableTypedArray.p.byteOffset behaves as expected when the underlying resizable + buffer is resized such that the SendableTypedArray becomes out of bounds. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const rab = CreateResizableArrayBuffer(20, 40); + +// Create TAs which cover the bytes 8-15. +let tas_and_lengths = []; +for (let ctor of ctors) { + const length = 8 / ctor.BYTES_PER_ELEMENT; + tas_and_lengths.push([ + new ctor(rab, 8, length), + length + ]); +} +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteOffset, 8); +} +rab.resize(10); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteOffset, 0); +} +// Resize the rab so that it just barely covers the needed 8 bytes. +rab.resize(16); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteOffset, 8); +} +rab.resize(40); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.byteOffset, 8); +} diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/return-byteoffset.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/return-byteoffset.js new file mode 100644 index 0000000000000000000000000000000000000000..9b4259fb490a6b74084da0ef160f284f779318c7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/return-byteoffset.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: > + Return value from [[ByteOffset]] internal slot +info: | + 22.2.3.3 get %SendableTypedArray%.prototype.byteOffset + + ... + 6. Let offset be the value of O's [[ByteOffset]] internal slot. + 7. Return size. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.byteOffset, 0, "Regular typedArray"); + + var offset = 4 * TA.BYTES_PER_ELEMENT; + + var buffer1 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT); + var ta2 = new TA(buffer1, offset); + assert.sameValue(ta2.byteOffset, offset, "TA(buffer, offset)"); + + var buffer2 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT); + var sample = new TA(buffer2, offset); + var ta3 = new TA(sample); + assert.sameValue(ta3.byteOffset, 0, "TA(typedArray)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/this-has-no-typedarrayname-internal.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/this-has-no-typedarrayname-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..518382e8b97f638387b48f5c463b931937d482f0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/this-has-no-typedarrayname-internal.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: > + Throws a TypeError exception when `this` does not have a [[TypedArrayName]] + internal slot +info: | + 22.2.3.3 get %SendableTypedArray%.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [DataView, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, "byteOffset" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}); + +var dv = new DataView(new ArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/byteOffset/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/byteOffset/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..f6c97ad54d902f1b3fc75fe1aeda566bb608c1eb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/byteOffset/this-is-not-object.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.byteoffset +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.3 get %SendableTypedArray%.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, "byteOffset" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/constructor.js b/test/sendable/builtins/TypedArray/prototype/constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..52916252f9eec64bc2950825882857dfde771dc2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/constructor.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.constructor +description: > + Initial state of the constructor property +info: | + The initial value of %SendableTypedArray%.prototype.constructor is the %SendableTypedArray% intrinsic object. + + Per ES6 section 17, the method should exist on the %SendableTypedArray% prototype, and it + should be writable and configurable, but not enumerable. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(SendableTypedArray.prototype.constructor, SendableTypedArray); + +verifyProperty(SendableTypedArray.prototype, "constructor", { + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/coerced-values-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/coerced-values-end.js new file mode 100644 index 0000000000000000000000000000000000000000..f55b794fb99b77410e252dfcccc5469ceba16c3c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/coerced-values-end.js @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + end argument is coerced to an integer values. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, null), + [0n, 1n, 2n, 3n] + ), + 'null value coerced to 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, NaN), + [0n, 1n, 2n, 3n] + ), + 'NaN value coerced to 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, false), + [0n, 1n, 2n, 3n] + ), + 'false value coerced to 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, true), + [0n, 0n, 2n, 3n] + ), + 'true value coerced to 1' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, '-2'), + [0n, 0n, 1n, 3n] + ), + 'string "-2" value coerced to integer -2' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0, -2.5), + [0n, 0n, 1n, 3n] + ), + 'float -2.5 value coerced to integer -2' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/coerced-values-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/coerced-values-start.js new file mode 100644 index 0000000000000000000000000000000000000000..2ad353417f53d5f4be9b6e39958833bab74ab0b4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/coerced-values-start.js @@ -0,0 +1,105 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + start argument is coerced to an integer value. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 5. Let relativeStart be ? ToInteger(start). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1, undefined), + [0n, 0n, 1n, 2n] + ), + 'undefined value coerced to 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1, false), + [0n, 0n, 1n, 2n] + ), + 'false value coerced to 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1, NaN), + [0n, 0n, 1n, 2n] + ), + 'NaN value coerced to 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1, null), + [0n, 0n, 1n, 2n] + ), + 'null value coerced to 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, true), + [1n, 2n, 3n, 3n] + ), + 'true value coerced to 1' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, '1'), + [1n, 2n, 3n, 3n] + ), + 'string "1" value coerced to 1' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1, 0.5), + [0n, 0n, 1n, 2n] + ), + '0.5 float value coerced to integer 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1.5), + [1n, 2n, 3n, 3n] + ), + '1.5 float value coerced to integer 1' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/coerced-values-target.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/coerced-values-target.js new file mode 100644 index 0000000000000000000000000000000000000000..c353b382640849dae4d9c0bda8520d5b08561d7a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/coerced-values-target.js @@ -0,0 +1,105 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + target argument is coerced to an integer value. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 3. Let relativeTarget be ? ToInteger(target). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(undefined, 1), + [1n, 2n, 3n, 3n] + ), + 'undefined value coerced to 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(false, 1), + [1n, 2n, 3n, 3n] + ), + 'false value coerced to 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(NaN, 1), + [1n, 2n, 3n, 3n] + ), + 'NaN value coerced to 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(null, 1), + [1n, 2n, 3n, 3n] + ), + 'null value coerced to 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(true, 0), + [0n, 0n, 1n, 2n] + ), + 'true value coerced to 1' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin('1', 0), + [0n, 0n, 1n, 2n] + ), + 'string "1" value coerced to 1' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0.5, 1), + [1n, 2n, 3n, 3n] + ), + '0.5 float value coerced to integer 0' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(1.5, 0), + [0n, 0n, 1n, 2n] + ), + '1.5 float value coerced to integer 1' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..d2b4cf807cedba9df358e3e44e46a944e25da0f5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/detached-buffer.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [, end ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.copyWithin(obj, obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..1264f26ca733c0b53c30d21c75650d7ab8e0004d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/get-length-ignores-length-prop.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Unreachable abrupt from Get(O, "length") as [[ArrayLength]] is returned. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA(); + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + } + }); + + assert.sameValue(sample.copyWithin(0, 0), sample); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-end.js new file mode 100644 index 0000000000000000000000000000000000000000..c6f5f08dee927e5c7bc56d7aa1b6840a68e01ad2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-end.js @@ -0,0 +1,108 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with negative end argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 8. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1, -1), + [1n, 2n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, 1, -1) -> [1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(2, 0, -1), + [0n, 1n, 0n, 1n, 2n] + ), + '[0, 1, 2, 3, 4].copyWithin(2, 0, -1) -> [0, 1, 0, 1, 2]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(1, 2, -2), + [0n, 2n, 2n, 3n, 4n] + ), + '[0, 1, 2, 3, 4].copyWithin(1, 2, -2) -> [0, 2, 2, 3, 4]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, -2, -1), + [2n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, -2, -1) -> [2, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(2, -2, -1), + [0n, 1n, 3n, 3n, 4n] + ), + '[0, 1, 2, 3, 4].copyWithin(2, -2, 1) -> [0, 1, 3, 3, 4]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(-3, -2, -1), + [0n, 2n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(-3, -2, -1) -> [0, 2, 2, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-2, -3, -1), + [0n, 1n, 2n, 2n, 3n] + ), + '[0, 1, 2, 3, 4].copyWithin(-2, -3, -1) -> [0, 1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-5, -2, -1), + [3n, 1n, 2n, 3n, 4n] + ), + '[0, 1, 2, 3, 4].copyWithin(-5, -2, -1) -> [3, 1, 2, 3, 4]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-end.js new file mode 100644 index 0000000000000000000000000000000000000000..e38fd82312b7e3e82f6b396825076359951bc9a3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-end.js @@ -0,0 +1,124 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with negative out of bounds end argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 8. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1, -10), + [0n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, 1, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, 1, -Infinity), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, -2, -10), + [0n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, -2, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, -2, -Infinity), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, -9, -10), + [0n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, -9, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, -9, -Infinity), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(-3, -2, -10), + [0n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(-3, -2, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(-3, -2, -Infinity), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(-7, -8, -9), + [0n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(-7, -8, -9) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(-7, -8, -Infinity), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity) -> [1, 2, 3, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-start.js new file mode 100644 index 0000000000000000000000000000000000000000..8770c8611c0ecdd80a6c95179a8a893f80ab22c4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-start.js @@ -0,0 +1,106 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with out of bounds negative start argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 6. If relativeStart < 0, let from be max((len + relativeStart), 0); else let + from be min(relativeStart, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, -10), + [0n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3]).copyWithin(0, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, -Infinity), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5]).copyWithin(0, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(2, -10), + [0n, 1n, 0n, 1n, 2n] + ), + '[0, 1, 2, 3, 4]).copyWithin(2, -2) -> [0, 1, 0, 1, 2]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(2, -Infinity), + [1n, 2n, 1n, 2n, 3n] + ), + '[1, 2, 3, 4, 5]).copyWithin(2, -Infinity) -> [1, 2, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(10, -10), + [0n, 1n, 2n, 3n, 4n] + ), + '[0, 1, 2, 3, 4]).copyWithin(10, -10) -> [0, 1, 2, 3, 4]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(10, -Infinity), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5]).copyWithin(10, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(-9, -10), + [0n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(-9, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(-9, -Infinity), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(-9, -Infinity) -> [1, 2, 3, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-target.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-target.js new file mode 100644 index 0000000000000000000000000000000000000000..fc3cd28fa8c8a760d69c76f0b936a72074d95e38 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-target.js @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with out of bounds negative target argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 4. If relativeTarget < 0, let to be max((len + relativeTarget), 0); else let + to be min(relativeTarget, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(-10, 0), + [0n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(-10, 0) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(-Infinity, 0), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 0) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-10, 2), + [2n, 3n, 4n, 3n, 4n] + ), + '[0, 1, 2, 3, 4].copyWithin(-10, 2) -> [2, 3, 4, 3, 4]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(-Infinity, 2), + [3n, 4n, 5n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 2) -> [3, 4, 5, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-start.js new file mode 100644 index 0000000000000000000000000000000000000000..15b7bfc02d79ea8c04b727304967af34fb831ec8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-start.js @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with negative start argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 6. If relativeStart < 0, let from be max((len + relativeStart), 0); else let + from be min(relativeStart, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, -1), + [3n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, -1) -> [3, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(2, -2), + [0n, 1n, 3n, 4n, 4n] + ), + '[0, 1, 2, 3, 4].copyWithin(2, -2) -> [0, 1, 3, 4, 4]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(1, -2), + [0n, 3n, 4n, 3n, 4n] + ), + '[0, 1, 2, 3, 4].copyWithin(1, -2) -> [0, 3, 4, 3, 4]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(-1, -2), + [0n, 1n, 2n, 2n] + ), + '[0, 1, 2, 3].copyWithin(-1, -2) -> [ 0, 1, 2, 2 ]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-2, -3), + [0n, 1n, 2n, 2n, 3n] + ), + '[0, 1, 2, 3, 4].copyWithin(-2, -3) -> [0, 1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-5, -2), + [3n, 4n, 2n, 3n, 4n] + ), + '[0, 1, 2, 3, 4].copyWithin(-5, -2) -> [3, 4, 2, 3, 4]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-target.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-target.js new file mode 100644 index 0000000000000000000000000000000000000000..081458a09119de68c5492f46cf8e70f06ebf654c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/negative-target.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with negative target argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 4. If relativeTarget < 0, let to be max((len + relativeTarget), 0); else let + to be min(relativeTarget, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(-1, 0), + [0n, 1n, 2n, 0n] + ), + '[0, 1, 2, 3].copyWithin(-1, 0) -> [0, 1, 2, 0]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n]).copyWithin(-2, 2), + [0n, 1n, 2n, 2n, 3n] + ), + '[0, 1, 2, 3, 4].copyWithin(-2, 2) -> [0, 1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(-1, 2), + [0n, 1n, 2n, 2n] + ), + '[0, 1, 2, 3].copyWithin(-1, 2) -> [0, 1, 2, 2]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-end.js new file mode 100644 index 0000000000000000000000000000000000000000..1bd12738a02bc2a0813733179934f0ac15b82852 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-end.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Max value of end position is the this.length. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1, 6), + [1n, 2n, 3n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, 1, 6) -> [1, 2, 3, 3]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, 1, Infinity), + [2n, 3n, 4n, 5n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(0, 1, Infinity) -> [2, 3, 4, 5, 5]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(1, 3, 6), + [0n, 3n, 4n, 5n, 4n, 5n] + ), + '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 6) -> [0, 3, 4, 5, 4, 5]' + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(1, 3, Infinity), + [1n, 4n, 5n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(1, 3, Infinity) -> [1, 4, 5, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-target-and-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-target-and-start.js new file mode 100644 index 0000000000000000000000000000000000000000..95071c954f76ebdc17dda78c22ec984c4e4b0089 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-target-and-start.js @@ -0,0 +1,87 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Max values of target and start positions are this.length. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(6, 0), + [0n, 1n, 2n, 3n, 4n, 5n] + ) + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(Infinity, 0), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(Infinity, 0) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(0, 6), + [0n, 1n, 2n, 3n, 4n, 5n] + ) + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(0, Infinity), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(0, Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(6, 6), + [0n, 1n, 2n, 3n, 4n, 5n] + ) + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(10, 10), + [0n, 1n, 2n, 3n, 4n, 5n] + ) + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n]).copyWithin(Infinity, Infinity), + [1n, 2n, 3n, 4n, 5n] + ), + '[1, 2, 3, 4, 5].copyWithin(Infinity, Infinity) -> [1, 2, 3, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-and-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-and-start.js new file mode 100644 index 0000000000000000000000000000000000000000..1217bd2c6d977f0c66ed39698a31620afabc9167 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-and-start.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Copy values with non-negative target and start positions. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n, 6n]).copyWithin(0, 0), + [1n, 2n, 3n, 4n, 5n, 6n] + ) + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n, 6n]).copyWithin(0, 2), + [3n, 4n, 5n, 6n, 5n, 6n] + ) + ); + + assert( + compareArray( + new TA([1n, 2n, 3n, 4n, 5n, 6n]).copyWithin(3, 0), + [1n, 2n, 3n, 1n, 2n, 3n] + ) + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(1, 4), + [0n, 4n, 5n, 3n, 4n, 5n] + ) + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-start-and-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-start-and-end.js new file mode 100644 index 0000000000000000000000000000000000000000..8069308d4da97b78c404995f2684a275bfa3a931 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-start-and-end.js @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Copy values with non-negative target, start and end positions. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, 0, 0), + [0n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, 0, 0) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, 0, 2), + [0n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, 0, 2) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1, 2), + [1n, 1n, 2n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, 1, 2) -> [1, 1, 2, 3]' + ); + + /* + * 10. If from [0, 0, 1, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n, 4n, 5n]).copyWithin(1, 3, 5), + [0n, 3n, 4n, 3n, 4n, 5n] + ), + '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 5) -> [0, 3, 4, 3, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end-is-symbol.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end-is-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..e700a3d6d6b44c2d5760b89c76613f6afbf7e483 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end-is-symbol.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt if end is a Symbol. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol(1); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.copyWithin(0, 0, s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end.js new file mode 100644 index 0000000000000000000000000000000000000000..b2003fe67514201f15dafe216b66a5db9b19a6d5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt from ToInteger(end). +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var o1 = { + valueOf: function() { + throw new Test262Error(); + } + }; + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.copyWithin(0, 0, o1); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start-is-symbol.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start-is-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..5fecd5790037979d9b6dde356dbbad8f826836dd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start-is-symbol.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt if start is a Symbol. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 5. Let relativeStart be ? ToInteger(start). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol(1); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.copyWithin(0, s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start.js new file mode 100644 index 0000000000000000000000000000000000000000..5234c083ba8d59a2f6fe67c7ff8f3bea010d33f0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt from ToInteger(start). +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 5. Let relativeStart be ? ToInteger(start). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var err = { + valueOf: function() { + throw new Error("ToInteger(start) runs before ToInteger(end)"); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.copyWithin(0, o, err); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target-is-symbol.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target-is-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..991f8a1c3da7827a8ebce5f8ddcbde7c6008df2c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target-is-symbol.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt if target is a Symbol. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 3. Let relativeTarget be ? ToInteger(target). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol(1); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.copyWithin(s, 0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target.js new file mode 100644 index 0000000000000000000000000000000000000000..8f583d25e603955203701413b6bdf96b5e339bbd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt from ToInteger(target). +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 3. Let relativeTarget be ? ToInteger(target). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.copyWithin(o); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..1388edd10f8e981f1b2e527c6f628d9fe523b003 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.copyWithin, + 'function', + 'implements SendableTypedArray.prototype.copyWithin' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.copyWithin(0, 0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.copyWithin(0, 0); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the copyWithin operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.copyWithin(0, 0); + throw new Test262Error('copyWithin completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-this.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-this.js new file mode 100644 index 0000000000000000000000000000000000000000..499c55ed60b32ed66a1764f1969f7d207697f9f6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/return-this.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Returns `this`. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + 13. Return O. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(); + var result1 = sample1.copyWithin(0, 0); + + assert.sameValue(result1, sample1); + + var sample2 = new TA([1n, 2n, 3n]); + var result2 = sample2.copyWithin(1, 0); + + assert.sameValue(result2, sample2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/undefined-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/undefined-end.js new file mode 100644 index 0000000000000000000000000000000000000000..843aae8eeda5e9c14a5eb8dd4ef49b34b0cad462 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/BigInt/undefined-end.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + If `end` is undefined, set final position to `this.length`. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1, undefined), + [1n, 2n, 3n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, 1, undefined) -> [1, 2, 3]' + ); + + assert( + compareArray( + new TA([0n, 1n, 2n, 3n]).copyWithin(0, 1), + [1n, 2n, 3n, 3n] + ), + '[0, 1, 2, 3].copyWithin(0, 1) -> [1, 2, 3, 3]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/bit-precision.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/bit-precision.js new file mode 100644 index 0000000000000000000000000000000000000000..556fbebe1f779fe44698106afa426a9018112c9f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/bit-precision.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: Preservation of bit-level encoding +info: | + Array.prototype.copyWithin (target, start [ , end ] ) + + 12. Repeat, while count > 0 + [...] + d. If fromPresent is true, then + i. Let fromVal be ? Get(O, fromKey). + ii. Perform ? Set(O, toKey, fromVal, true). +includes: [nans.js, compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +function body(FloatArray) { + var subject = new FloatArray(NaNs.length * 2); + + NaNs.forEach(function(v, i) { + subject[i] = v; + }); + + var originalBytes, copiedBytes; + var length = NaNs.length * FloatArray.BYTES_PER_ELEMENT; + + originalBytes = new Uint8Array( + subject.buffer, + 0, + length + ); + + subject.copyWithin(NaNs.length, 0); + copiedBytes = new Uint8Array( + subject.buffer, + length + ); + + assert(compareArray(originalBytes, copiedBytes)); +} + +testWithTypedArrayConstructors(body, floatArrayConstructors); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/byteoffset.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/byteoffset.js new file mode 100644 index 0000000000000000000000000000000000000000..ad0350dea09378799b44dfd08411a7ce900ae77c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/byteoffset.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + copyWithin should respect typedarray's byteOffset +info: | + 22.2.3.5%SendableTypedArray%.prototype.copyWithin ( target, start [ , end ] ) + ... + 17. If count > 0, then + e. Let elementSize be the Element Size value specified in Table 72 for typedArrayName. + f. Let byteOffset be O.[[ByteOffset]]. + g. Let toByteIndex be to × elementSize + byteOffset. + h. Let fromByteIndex be from × elementSize + byteOffset. + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta = new TA([0, 1, 2, 3]); + assert.compareArray( + new TA(ta.buffer, TA.BYTES_PER_ELEMENT).copyWithin(2, 0), + [1, 2, 1], + 'copyWithin should respect typedarray\'s byteOffset' + ); + + assert.compareArray( + ta, + [0, 1, 2, 1], + 'underlying arraybuffer should have been updated' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-target-start-end-shrink.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-target-start-end-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..f736b7bcba13dacec19eb9439e32d6315ac02870 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-target-start-end-shrink.js @@ -0,0 +1,92 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-array.prototype.copywithin +description: > + SendableTypedArray.p.copyWithin behaves correctly when argument coercion shrinks the receiver +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 2; + } + }; + assert.throws(TypeError, () => { + fixedLength.copyWithin(evil, 0, 1); + }); + rab.resize(4 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.copyWithin(0, evil, 3); + }); + rab.resize(4 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.copyWithin(0, 1, evil); + }); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i); + } + // [0, 1, 2, 3] + // ^ + // target + // ^ + // start + const evil = { + valueOf: () => { + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + return 2; + } + }; + lengthTracking.copyWithin(evil, 0); + assert.compareArray(ToNumbers(lengthTracking), [ + 0, + 1, + 0 + ]); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i); + } + // [0, 1, 2, 3] + // ^ + // start + // ^ + // target + const evil = { + valueOf: () => { + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + return 2; + } + }; + lengthTracking.copyWithin(0, evil); + assert.compareArray(ToNumbers(lengthTracking), [ + 2, + 1, + 2 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-target-start-grow.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-target-start-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..e9f412cd658fb98987e91cfbc0d47eb41c787737 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-target-start-grow.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-array.prototype.copywithin +description: > + SendableTypedArray.p.copyWithin behaves correctly when argument coercion shrinks the receiver +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i); + } + const evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + lengthTracking[4] = MayNeedBigInt(lengthTracking, 4); + lengthTracking[5] = MayNeedBigInt(lengthTracking, 5); + return 0; + } + }; + // Orig. array: [0, 1, 2, 3] [4, 5] + // ^ ^ ^ new elements + // target start + lengthTracking.copyWithin(evil, 2); + assert.compareArray(ToNumbers(lengthTracking), [ + 2, + 3, + 2, + 3, + 4, + 5 + ]); + rab.resize(4 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i); + } + + // Orig. array: [0, 1, 2, 3] [4, 5] + // ^ ^ ^ new elements + // start target + lengthTracking.copyWithin(2, evil); + assert.compareArray(ToNumbers(lengthTracking), [ + 0, + 1, + 0, + 1, + 4, + 5 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-end-detached-prototype.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-end-detached-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..1675e13c6c0b937b58be0f9d90b37bae271282e3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-end-detached-prototype.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + SECURITY: end argument is coerced to an integer values + causing array detachment, but the value is still defined + by a prototype +info: | + 22.2.3.5%SendableTypedArray%.prototype.copyWithin ( target, start [ , end ] ) + ... + 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToInteger(end). + ... + 10. Let count be min(final - from, len - to). + 11. If count > 0, then + a. NOTE: The copying must be performed in a manner that preserves the bit-level encoding of the source data. + b. Let buffer be O.[[ViewedArrayBuffer]]. + c. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta; + var array = []; + + function detachAndReturnIndex(){ + $DETACHBUFFER(ta.buffer); + Object.setPrototypeOf(ta, array); + return 101; + } + + array.length = 10000; // big arrays are more likely to cause a crash if they are accessed after they are freed + array.fill(7, 0); + ta = new TA(array); + assert.throws(TypeError, function(){ + ta.copyWithin(0, 100, {valueOf : detachAndReturnIndex}); + }, "should throw TypeError as array is detached"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-end-detached.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-end-detached.js new file mode 100644 index 0000000000000000000000000000000000000000..0ee470958118d925771e9228e9ee0f296c425fd9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-end-detached.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + SECURITY: end argument is coerced to an integer values + causing array detachment +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin ( target, start [ , end ] ) + + ... + 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToInteger(end). + ... + 10. Let count be min(final - from, len - to). + 11. If count > 0, then + a. NOTE: The copying must be performed in a manner that preserves the bit-level encoding of the source data. + b. Let buffer be O.[[ViewedArrayBuffer]]. + c. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta; + function detachAndReturnIndex(){ + $DETACHBUFFER(ta.buffer); + return 900; + } + + var array = []; + array.length = 10000; // big arrays are more likely to cause a crash if they are accessed after they are freed + array.fill(7, 0); + ta = new TA(array); + assert.throws(TypeError, function(){ + ta.copyWithin(0, 100, {valueOf : detachAndReturnIndex}); + }, "should throw TypeError as array is detached"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-end.js new file mode 100644 index 0000000000000000000000000000000000000000..6147fc0cbb39f26383db2778b2e9a85e43a7e688 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-end.js @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + end argument is coerced to an integer values. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1, 0, null), + [0, 1, 2, 3] + ), + 'null value coerced to 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1, 0, NaN), + [0, 1, 2, 3] + ), + 'NaN value coerced to 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1, 0, false), + [0, 1, 2, 3] + ), + 'false value coerced to 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1, 0, true), + [0, 0, 2, 3] + ), + 'true value coerced to 1' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1, 0, '-2'), + [0, 0, 1, 3] + ), + 'string "-2" value coerced to integer -2' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1, 0, -2.5), + [0, 0, 1, 3] + ), + 'float -2.5 value coerced to integer -2' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-start-detached.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-start-detached.js new file mode 100644 index 0000000000000000000000000000000000000000..cb5e69a2ffcd95d42ef99efedca08a3f8f4ee995 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-start-detached.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + SECURITY: start argument is coerced to an integer value, which detached + the array +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin ( target, start [ , end ] ) + + ... + 6. Let relativeStart be ? ToInteger(start). + ... + 10. Let count be min(final - from, len - to). + 11. If count > 0, then + a. NOTE: The copying must be performed in a manner that preserves the bit-level encoding of the source data. + b. Let buffer be O.[[ViewedArrayBuffer]]. + c. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta; + function detachAndReturnIndex(){ + $DETACHBUFFER(ta.buffer); + return 100; + } + + var array = []; + array.length = 10000; // big arrays are more likely to cause a crash if they are accessed after they are freed + array.fill(7, 0); + ta = new TA(array); + assert.throws(TypeError, function(){ + ta.copyWithin(0, {valueOf : detachAndReturnIndex}, 1000); + }, "should throw TypeError as array is detached"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-start.js new file mode 100644 index 0000000000000000000000000000000000000000..f734c277878ced69435b71d715fc00bf5a9ac63f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-start.js @@ -0,0 +1,105 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + start argument is coerced to an integer value. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 5. Let relativeStart be ? ToInteger(start). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1, undefined), + [0, 0, 1, 2] + ), + 'undefined value coerced to 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1, false), + [0, 0, 1, 2] + ), + 'false value coerced to 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1, NaN), + [0, 0, 1, 2] + ), + 'NaN value coerced to 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1, null), + [0, 0, 1, 2] + ), + 'null value coerced to 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, true), + [1, 2, 3, 3] + ), + 'true value coerced to 1' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, '1'), + [1, 2, 3, 3] + ), + 'string "1" value coerced to 1' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1, 0.5), + [0, 0, 1, 2] + ), + '0.5 float value coerced to integer 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, 1.5), + [1, 2, 3, 3] + ), + '1.5 float value coerced to integer 1' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-target.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-target.js new file mode 100644 index 0000000000000000000000000000000000000000..b8da3e887cecb5d6563fbcbf1492f3a2da6e9e12 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/coerced-values-target.js @@ -0,0 +1,113 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + target argument is coerced to an integer value. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 3. Let relativeTarget be ? ToInteger(target). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(undefined, 1), + [1, 2, 3, 3] + ), + 'undefined value coerced to 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(false, 1), + [1, 2, 3, 3] + ), + 'false value coerced to 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(NaN, 1), + [1, 2, 3, 3] + ), + 'NaN value coerced to 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(null, 1), + [1, 2, 3, 3] + ), + 'null value coerced to 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(true, 0), + [0, 0, 1, 2] + ), + 'true value coerced to 1' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin('1', 0), + [0, 0, 1, 2] + ), + 'string "1" value coerced to 1' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0.5, 1), + [1, 2, 3, 3] + ), + '0.5 float value coerced to integer 0' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(1.5, 0), + [0, 0, 1, 2] + ), + '1.5 float value coerced to integer 1' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin({}, 1), + [1, 2, 3, 3] + ), + 'object value coerced to integer 0' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..1f3a66a632462c5996016843bc1aa524ea0584fd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/detached-buffer.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [, end ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.copyWithin(obj, obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..7d95991bc7e14890597951c2dd36c677e3f578b5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/get-length-ignores-length-prop.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Unreachable abrupt from Get(O, "length") as [[ArrayLength]] is returned. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA(); + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + } + }); + + assert.sameValue(sample.copyWithin(0, 0), sample); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..682b84ece81ed31caa9da6ae0e4268ea3229a64f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [, end ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var copyWithin = SendableTypedArray.prototype.copyWithin; + +assert.sameValue(typeof copyWithin, 'function'); + +assert.throws(TypeError, function() { + copyWithin(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..ccb02dcf8a6dc6a6efcabdc6d3386675fc63eee6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [, end ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.copyWithin, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.copyWithin(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/length.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/length.js new file mode 100644 index 0000000000000000000000000000000000000000..cfcdc342b5c79dab146d8e70923b5f07fa1e8790 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + %SendableTypedArray%.prototype.copyWithin.length is 2. +info: | + %SendableTypedArray%.prototype.copyWithin (target, start [, end ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.copyWithin, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/name.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/name.js new file mode 100644 index 0000000000000000000000000000000000000000..4f5eb19a2f6adcc44943d6b7c8f5884a477132c1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + %SendableTypedArray%.prototype.copyWithin.name is "copyWithin". +info: | + %SendableTypedArray%.prototype.copyWithin (target, start [, end ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.copyWithin, "name", { + value: "copyWithin", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-end.js new file mode 100644 index 0000000000000000000000000000000000000000..87d4a7daffcc9ae3080db831c37a5ef7b11082a8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-end.js @@ -0,0 +1,108 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with negative end argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 8. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, 1, -1), + [1, 2, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(0, 1, -1) -> [1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(2, 0, -1), + [0, 1, 0, 1, 2] + ), + '[0, 1, 2, 3, 4].copyWithin(2, 0, -1) -> [0, 1, 0, 1, 2]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(1, 2, -2), + [0, 2, 2, 3, 4] + ), + '[0, 1, 2, 3, 4].copyWithin(1, 2, -2) -> [0, 2, 2, 3, 4]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, -2, -1), + [2, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(0, -2, -1) -> [2, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(2, -2, -1), + [0, 1, 3, 3, 4] + ), + '[0, 1, 2, 3, 4].copyWithin(2, -2, 1) -> [0, 1, 3, 3, 4]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(-3, -2, -1), + [0, 2, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(-3, -2, -1) -> [0, 2, 2, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(-2, -3, -1), + [0, 1, 2, 2, 3] + ), + '[0, 1, 2, 3, 4].copyWithin(-2, -3, -1) -> [0, 1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(-5, -2, -1), + [3, 1, 2, 3, 4] + ), + '[0, 1, 2, 3, 4].copyWithin(-5, -2, -1) -> [3, 1, 2, 3, 4]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-out-of-bounds-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-out-of-bounds-end.js new file mode 100644 index 0000000000000000000000000000000000000000..c7b64fa13565ac811e8a8841d399a79ef003cd70 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-out-of-bounds-end.js @@ -0,0 +1,124 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with negative out of bounds end argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 8. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, 1, -10), + [0, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(0, 1, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, 1, -Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, -2, -10), + [0, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(0, -2, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, -2, -Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, -9, -10), + [0, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(0, -9, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, -9, -Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(-3, -2, -10), + [0, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(-3, -2, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(-3, -2, -Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(-7, -8, -9), + [0, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(-7, -8, -9) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(-7, -8, -Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity) -> [1, 2, 3, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-out-of-bounds-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-out-of-bounds-start.js new file mode 100644 index 0000000000000000000000000000000000000000..078f21bc00e6eedcf083223b6635b2f9e558b343 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-out-of-bounds-start.js @@ -0,0 +1,106 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with out of bounds negative start argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 6. If relativeStart < 0, let from be max((len + relativeStart), 0); else let + from be min(relativeStart, len). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, -10), + [0, 1, 2, 3] + ), + '[0, 1, 2, 3]).copyWithin(0, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, -Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5]).copyWithin(0, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(2, -10), + [0, 1, 0, 1, 2] + ), + '[0, 1, 2, 3, 4]).copyWithin(2, -2) -> [0, 1, 0, 1, 2]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(2, -Infinity), + [1, 2, 1, 2, 3] + ), + '[1, 2, 3, 4, 5]).copyWithin(2, -Infinity) -> [1, 2, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(10, -10), + [0, 1, 2, 3, 4] + ), + '[0, 1, 2, 3, 4]).copyWithin(10, -10) -> [0, 1, 2, 3, 4]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(10, -Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5]).copyWithin(10, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(-9, -10), + [0, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(-9, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(-9, -Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(-9, -Infinity) -> [1, 2, 3, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-out-of-bounds-target.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-out-of-bounds-target.js new file mode 100644 index 0000000000000000000000000000000000000000..b408e4ee7f51568725505df0ae8ea7b6d5ff16e3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-out-of-bounds-target.js @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with out of bounds negative target argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 4. If relativeTarget < 0, let to be max((len + relativeTarget), 0); else let + to be min(relativeTarget, len). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(-10, 0), + [0, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(-10, 0) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(-Infinity, 0), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 0) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(-10, 2), + [2, 3, 4, 3, 4] + ), + '[0, 1, 2, 3, 4].copyWithin(-10, 2) -> [2, 3, 4, 3, 4]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(-Infinity, 2), + [3, 4, 5, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 2) -> [3, 4, 5, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-start.js new file mode 100644 index 0000000000000000000000000000000000000000..1ecbe7172bec70b91f9fd00c5ce62026af3fc1a4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-start.js @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with negative start argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 6. If relativeStart < 0, let from be max((len + relativeStart), 0); else let + from be min(relativeStart, len). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, -1), + [3, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(0, -1) -> [3, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(2, -2), + [0, 1, 3, 4, 4] + ), + '[0, 1, 2, 3, 4].copyWithin(2, -2) -> [0, 1, 3, 4, 4]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(1, -2), + [0, 3, 4, 3, 4] + ), + '[0, 1, 2, 3, 4].copyWithin(1, -2) -> [0, 3, 4, 3, 4]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(-1, -2), + [0, 1, 2, 2] + ), + '[0, 1, 2, 3].copyWithin(-1, -2) -> [ 0, 1, 2, 2 ]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(-2, -3), + [0, 1, 2, 2, 3] + ), + '[0, 1, 2, 3, 4].copyWithin(-2, -3) -> [0, 1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(-5, -2), + [3, 4, 2, 3, 4] + ), + '[0, 1, 2, 3, 4].copyWithin(-5, -2) -> [3, 4, 2, 3, 4]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-target.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-target.js new file mode 100644 index 0000000000000000000000000000000000000000..8569636eb49b156357dd1ef08ee05d34bccf546a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/negative-target.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Set values with negative target argument. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 4. If relativeTarget < 0, let to be max((len + relativeTarget), 0); else let + to be min(relativeTarget, len). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(-1, 0), + [0, 1, 2, 0] + ), + '[0, 1, 2, 3].copyWithin(-1, 0) -> [0, 1, 2, 0]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4]).copyWithin(-2, 2), + [0, 1, 2, 2, 3] + ), + '[0, 1, 2, 3, 4].copyWithin(-2, 2) -> [0, 1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(-1, 2), + [0, 1, 2, 2] + ), + '[0, 1, 2, 3].copyWithin(-1, 2) -> [0, 1, 2, 2]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-end.js new file mode 100644 index 0000000000000000000000000000000000000000..2152cf57f3e292688d16448aa3910366bbfc0a8c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-end.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Max value of end position is the this.length. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, 1, 6), + [1, 2, 3, 3] + ), + '[0, 1, 2, 3].copyWithin(0, 1, 6) -> [1, 2, 3, 3]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, 1, Infinity), + [2, 3, 4, 5, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(0, 1, Infinity) -> [2, 3, 4, 5, 5]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4, 5]).copyWithin(1, 3, 6), + [0, 3, 4, 5, 4, 5] + ), + '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 6) -> [0, 3, 4, 5, 4, 5]' + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(1, 3, Infinity), + [1, 4, 5, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(1, 3, Infinity) -> [1, 4, 5, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js new file mode 100644 index 0000000000000000000000000000000000000000..036c61bf22833a92c74ab9d90d55ccb6d8d2871c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js @@ -0,0 +1,87 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Max values of target and start positions are this.length. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3, 4, 5]).copyWithin(6, 0), + [0, 1, 2, 3, 4, 5] + ) + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(Infinity, 0), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(Infinity, 0) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4, 5]).copyWithin(0, 6), + [0, 1, 2, 3, 4, 5] + ) + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(0, Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4, 5]).copyWithin(6, 6), + [0, 1, 2, 3, 4, 5] + ) + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4, 5]).copyWithin(10, 10), + [0, 1, 2, 3, 4, 5] + ) + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(Infinity, Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(Infinity, Infinity) -> [1, 2, 3, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-target-and-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-target-and-start.js new file mode 100644 index 0000000000000000000000000000000000000000..cc90480df655d5012b9e0539e13cb5118739d1ce --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-target-and-start.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Copy values with non-negative target and start positions. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([1, 2, 3, 4, 5, 6]).copyWithin(0, 0), + [1, 2, 3, 4, 5, 6] + ) + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5, 6]).copyWithin(0, 2), + [3, 4, 5, 6, 5, 6] + ) + ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5, 6]).copyWithin(3, 0), + [1, 2, 3, 1, 2, 3] + ) + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4, 5]).copyWithin(1, 4), + [0, 4, 5, 3, 4, 5] + ) + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-target-start-and-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-target-start-and-end.js new file mode 100644 index 0000000000000000000000000000000000000000..936224efafb1b7fcba161a288049d75f2146f4ce --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/non-negative-target-start-and-end.js @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Copy values with non-negative target, start and end positions. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, 0, 0), + [0, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(0, 0, 0) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, 0, 2), + [0, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(0, 0, 2) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, 1, 2), + [1, 1, 2, 3] + ), + '[0, 1, 2, 3].copyWithin(0, 1, 2) -> [1, 1, 2, 3]' + ); + + /* + * 10. If from [0, 0, 1, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3, 4, 5]).copyWithin(1, 3, 5), + [0, 3, 4, 3, 4, 5] + ), + '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 5) -> [0, 3, 4, 3, 4, 5]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..9d3e9020999ff32dce83ad706d9f67bc3a42fb2e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.copyWithin does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.copyWithin), + false, + 'isConstructor(SendableTypedArray.prototype.copyWithin) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.copyWithin(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..604f2a8ed8d4d68bf8bcc3f8e86cbaa79fd87e53 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + "copyWithin" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'copyWithin', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..ce9a3e17c13552cfb3f590130b5a037802e78731 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/resizable-buffer.js @@ -0,0 +1,191 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + SendableTypedArray.p.copyWithin behaves correctly when the receiver is backed by + resizable buffer +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + + // Orig. array: [0, 1, 2, 3] + // [0, 1, 2, 3] << fixedLength + // [2, 3] << fixedLengthWithOffset + // [0, 1, 2, 3, ...] << lengthTracking + // [2, 3, ...] << lengthTrackingWithOffset + + fixedLength.copyWithin(0, 2); + assert.compareArray(ToNumbers(fixedLength), [ + 2, + 3, + 2, + 3 + ]); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + fixedLengthWithOffset.copyWithin(0, 1); + assert.compareArray(ToNumbers(fixedLengthWithOffset), [ + 3, + 3 + ]); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + lengthTracking.copyWithin(0, 2); + assert.compareArray(ToNumbers(lengthTracking), [ + 2, + 3, + 2, + 3 + ]); + lengthTrackingWithOffset.copyWithin(0, 1); + assert.compareArray(ToNumbers(lengthTrackingWithOffset), [ + 3, + 3 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 3; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + + // Orig. array: [0, 1, 2] + // [0, 1, 2, ...] << lengthTracking + // [2, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.copyWithin(0, 1); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.copyWithin(0, 1); + }); + assert.compareArray(ToNumbers(lengthTracking), [ + 0, + 1, + 2 + ]); + lengthTracking.copyWithin(0, 1); + assert.compareArray(ToNumbers(lengthTracking), [ + 1, + 2, + 2 + ]); + lengthTrackingWithOffset.copyWithin(0, 1); + assert.compareArray(ToNumbers(lengthTrackingWithOffset), [2]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + taWrite[0] = MayNeedBigInt(taWrite, 0); + assert.throws(TypeError, () => { + fixedLength.copyWithin(0, 1, 1); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.copyWithin(0, 1, 1); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.copyWithin(0, 1, 1); + }); + assert.compareArray(ToNumbers(lengthTracking), [0]); + lengthTracking.copyWithin(0, 0, 1); + assert.compareArray(ToNumbers(lengthTracking), [0]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.copyWithin(0, 1, 1); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.copyWithin(0, 1, 1); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.copyWithin(0, 1, 1); + }); + assert.compareArray(ToNumbers(lengthTracking), []); + lengthTracking.copyWithin(0, 0, 1); + assert.compareArray(ToNumbers(lengthTracking), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + + // Orig. array: [0, 1, 2, 3, 4, 5] + // [0, 1, 2, 3] << fixedLength + // [2, 3] << fixedLengthWithOffset + // [0, 1, 2, 3, 4, 5, ...] << lengthTracking + // [2, 3, 4, 5, ...] << lengthTrackingWithOffset + + fixedLength.copyWithin(0, 2); + assert.compareArray(ToNumbers(fixedLength), [ + 2, + 3, + 2, + 3 + ]); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + fixedLengthWithOffset.copyWithin(0, 1); + assert.compareArray(ToNumbers(fixedLengthWithOffset), [ + 3, + 3 + ]); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + + // [0, 1, 2, 3, 4, 5, ...] << lengthTracking + // target ^ ^ start + lengthTracking.copyWithin(0, 2); + assert.compareArray(ToNumbers(lengthTracking), [ + 2, + 3, + 4, + 5, + 4, + 5 + ]); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + + // [2, 3, 4, 5, ...] << lengthTrackingWithOffset + // target ^ ^ start + lengthTrackingWithOffset.copyWithin(0, 1); + assert.compareArray(ToNumbers(lengthTrackingWithOffset), [ + 3, + 4, + 5, + 5 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-end-is-symbol.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-end-is-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..c9d6864d30415a95dc147763fbe63fbe3c307992 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-end-is-symbol.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt if end is a Symbol. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol(1); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.copyWithin(0, 0, s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-end.js new file mode 100644 index 0000000000000000000000000000000000000000..3310bc76c9a8e5f37352d3bea5b07ba52602b82d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-end.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt from ToInteger(end). +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var o1 = { + valueOf: function() { + throw new Test262Error(); + } + }; + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.copyWithin(0, 0, o1); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-start-is-symbol.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-start-is-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..3ab6588d6c0b5ba2b2a19e0ed97204510e56ba55 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-start-is-symbol.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt if start is a Symbol. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 5. Let relativeStart be ? ToInteger(start). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol(1); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.copyWithin(0, s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-start.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-start.js new file mode 100644 index 0000000000000000000000000000000000000000..53040647a87d43fdf5dcf959631ebeb21875e63b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-start.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt from ToInteger(start). +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 5. Let relativeStart be ? ToInteger(start). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var o = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var err = { + valueOf: function() { + throw new Error("ToInteger(start) runs before ToInteger(end)"); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.copyWithin(0, o, err); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-target-is-symbol.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-target-is-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..83a731d787495283c93dd37a8c8d222c1e1710b7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-target-is-symbol.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt if target is a Symbol. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 3. Let relativeTarget be ? ToInteger(target). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol(1); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.copyWithin(s, 0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-target.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-target.js new file mode 100644 index 0000000000000000000000000000000000000000..07404ea1f507879c0a9eac5a21fd6d5c8a2f43c5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-target.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Return abrupt from ToInteger(target). +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 3. Let relativeTarget be ? ToInteger(target). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var o = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.copyWithin(o); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..ce3b7eba3ad04bcce0a4aa80caa5166d1d41511e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.copyWithin, + 'function', + 'implements SendableTypedArray.prototype.copyWithin' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.copyWithin(0, 0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.copyWithin(0, 0); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the copyWithin operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.copyWithin(0, 0); + throw new Test262Error('copyWithin completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/return-this.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-this.js new file mode 100644 index 0000000000000000000000000000000000000000..3e8190a2a65c4d3568e83ed6328d3960bf7899e0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/return-this.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Returns `this`. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + 13. Return O. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA(); + var result1 = sample1.copyWithin(0, 0); + + assert.sameValue(result1, sample1); + + var sample2 = new TA([1, 2, 3]); + var result2 = sample2.copyWithin(1, 0); + + assert.sameValue(result2, sample2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..9a825365ab83d2693264a06eefcf0342227607cd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/this-is-not-object.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var copyWithin = SendableTypedArray.prototype.copyWithin; + +assert.throws(TypeError, function() { + copyWithin.call(undefined, 0, 0); +}, "this is undefined"); + +assert.throws(TypeError, function() { + copyWithin.call(null, 0, 0); +}, "this is null"); + +assert.throws(TypeError, function() { + copyWithin.call(42, 0, 0); +}, "this is 42"); + +assert.throws(TypeError, function() { + copyWithin.call("1", 0, 0); +}, "this is a string"); + +assert.throws(TypeError, function() { + copyWithin.call(true, 0, 0); +}, "this is true"); + +assert.throws(TypeError, function() { + copyWithin.call(false, 0, 0); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + copyWithin.call(s, 0, 0); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..fd7d128120376f2f1680a44dff3ee1eb8b6b4013 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/this-is-not-typedarray-instance.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var copyWithin = SendableTypedArray.prototype.copyWithin; + +assert.throws(TypeError, function() { + copyWithin.call({}, 0, 0); +}, "this is an Object"); + +assert.throws(TypeError, function() { + copyWithin.call([], 0, 0); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + copyWithin.call(ab, 0, 0); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + copyWithin.call(dv, 0, 0); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/copyWithin/undefined-end.js b/test/sendable/builtins/TypedArray/prototype/copyWithin/undefined-end.js new file mode 100644 index 0000000000000000000000000000000000000000..e456e13592c6d25160b45bfa5c6b565a00a1540f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/copyWithin/undefined-end.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.copywithin +description: > + If `end` is undefined, set final position to `this.length`. +info: | + 22.2.3.5 %SendableTypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %SendableTypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, 1, undefined), + [1, 2, 3, 3] + ), + '[0, 1, 2, 3].copyWithin(0, 1, undefined) -> [1, 2, 3]' + ); + + assert( + compareArray( + new TA([0, 1, 2, 3]).copyWithin(0, 1), + [1, 2, 3, 3] + ), + '[0, 1, 2, 3].copyWithin(0, 1) -> [1, 2, 3, 3]' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/entries/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..b7a148dac35cc5d5cfcb0ebe0c08b5d91694edfa --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/BigInt/detached-buffer.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.6 %SendableTypedArray%.prototype.entries ( ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.entries(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/BigInt/iter-prototype.js b/test/sendable/builtins/TypedArray/prototype/entries/BigInt/iter-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..6ec4797b1ff24189b0f784a43e5191d68350e14e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/BigInt/iter-prototype.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: > + The prototype of the returned iterator is ArrayIteratorPrototype +info: | + 22.2.3.6 %SendableTypedArray%.prototype.entries ( ) + + ... + 3. Return CreateArrayIterator(O, "key+value"). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n, 42n, 64n]); + var iter = sample.entries(); + + assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/entries/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..7f820b86790d0ffcf9fdd35efd42089e6c2684b9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.entries, + 'function', + 'implements SendableTypedArray.prototype.entries' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.entries(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.entries(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the entries operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.entries(); + throw new Test262Error('entries completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/BigInt/return-itor.js b/test/sendable/builtins/TypedArray/prototype/entries/BigInt/return-itor.js new file mode 100644 index 0000000000000000000000000000000000000000..f90280a747c1f70734aa2b3be90f32b33e31d345 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/BigInt/return-itor.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: Return an iterator for the entries. +info: | + 22.2.3.6 %SendableTypedArray%.prototype.entries ( ) + + ... + 3. Return CreateArrayIterator(O, "key+value"). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA([0n, 42n, 64n]); + var itor = typedArray.entries(); + + var next = itor.next(); + assert(compareArray(next.value, [0, 0n])); + assert.sameValue(next.done, false); + + next = itor.next(); + assert(compareArray(next.value, [1, 42n])); + assert.sameValue(next.done, false); + + next = itor.next(); + assert(compareArray(next.value, [2, 64n])); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, undefined); + assert.sameValue(next.done, true); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/entries/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..891162628fcfc39c657f3274e78ef89127b28293 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/detached-buffer.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.6 %SendableTypedArray%.prototype.entries ( ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.entries(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/entries/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..3dcbd52eb9be13a7e95ddbe947bf2e6d80fe0932 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/invoked-as-func.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.6 %SendableTypedArray%.prototype.entries ( ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var entries = SendableTypedArray.prototype.entries; + +assert.sameValue(typeof entries, 'function'); + +assert.throws(TypeError, function() { + entries(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/entries/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..154cb1ccc931c8af378cad95d2b8bd1cab8c8aab --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/invoked-as-method.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.6 %SendableTypedArray%.prototype.entries ( ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.entries, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.entries(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/iter-prototype.js b/test/sendable/builtins/TypedArray/prototype/entries/iter-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..8c9b8d675449243ebc8b3781dda3dc02d3d65ee4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/iter-prototype.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: > + The prototype of the returned iterator is ArrayIteratorPrototype +info: | + 22.2.3.6 %SendableTypedArray%.prototype.entries ( ) + + ... + 3. Return CreateArrayIterator(O, "key+value"). +includes: [sendableTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0, 42, 64]); + var iter = sample.entries(); + + assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/length.js b/test/sendable/builtins/TypedArray/prototype/entries/length.js new file mode 100644 index 0000000000000000000000000000000000000000..98efe9f00e818638c75bef2623030ab3c7af3725 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: > + %SendableTypedArray%.prototype.entries.length is 0. +info: | + %SendableTypedArray%.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.entries, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/name.js b/test/sendable/builtins/TypedArray/prototype/entries/name.js new file mode 100644 index 0000000000000000000000000000000000000000..224fc4524416684756b3ffb05422d4939109a5ba --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: > + %SendableTypedArray%.prototype.entries.name is "entries". +info: | + %SendableTypedArray%.prototype.entries ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.entries, "name", { + value: "entries", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/entries/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..b83926ed2b0bdc76175436bc230f3138778565ce --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.entries does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.entries), + false, + 'isConstructor(SendableTypedArray.prototype.entries) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.entries(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/entries/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/entries/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..b571c55bc36bece18a3419a3e086a1dcf5b2c55f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: > + "entries" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'entries', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/entries/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..5b1d75df32e22a159bcdc5520a16c43faa130dec --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,121 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: > + SendableTypedArray.p.entries behaves correctly when receiver is backed by a resizable + buffer and resized mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +// Iterating with entries() (the 4 loops below). +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + // The fixed length array is not affected by resizing. + TestIterationAndResize(fixedLength.entries(), [ + [ + 0, + 0 + ], + [ + 1, + 2 + ], + [ + 2, + 4 + ], + [ + 3, + 6 + ] + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + // The fixed length array is not affected by resizing. + TestIterationAndResize(fixedLengthWithOffset.entries(), [ + [ + 0, + 4 + ], + [ + 1, + 6 + ] + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(lengthTracking.entries(), [ + [ + 0, + 0 + ], + [ + 1, + 2 + ], + [ + 2, + 4 + ], + [ + 3, + 6 + ], + [ + 4, + 0 + ], + [ + 5, + 0 + ] + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + TestIterationAndResize(lengthTrackingWithOffset.entries(), [ + [ + 0, + 4 + ], + [ + 1, + 6 + ], + [ + 2, + 0 + ], + [ + 3, + 0 + ] + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/entries/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/entries/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..77f145802ddea73e867e390698f298e827c1bce3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: > + SendableTypedArray.p.entries behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +// Iterating with entries() (the 4 loops below). +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + + // The fixed length array goes out of bounds when the RAB is resized. + assert.throws(TypeError, () => { + TestIterationAndResize(fixedLength.entries(), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + + // The fixed length array goes out of bounds when the RAB is resized. + assert.throws(TypeError, () => { + TestIterationAndResize(fixedLengthWithOffset.entries(), null, rab, 1, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(lengthTracking.entries(), [ + [ + 0, + 0 + ], + [ + 1, + 2 + ], + [ + 2, + 4 + ] + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + TestIterationAndResize(lengthTrackingWithOffset.entries(), [ + [ + 0, + 4 + ], + [ + 1, + 6 + ] + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/entries/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/entries/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..4c4756b3f3948de5ec4381ac651087ce010ceb11 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/resizable-buffer.js @@ -0,0 +1,188 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + SendableTypedArray.p.values behaves correctly when receiver is backed by resizable + buffer +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function ValuesFromSendableTypedArrayEntries(ta) { + let result = []; + let expectedKey = 0; + for (let [key, value] of ta.entries()) { + assert.sameValue(key, expectedKey, 'SendableTypedArray method .entries should return `expectedKey`.'); + ++expectedKey; + result.push(Number(value)); + } + return result; +} + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + assert.compareArray(ValuesFromSendableTypedArrayEntries(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ValuesFromSendableTypedArrayEntries(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ValuesFromSendableTypedArrayEntries(lengthTracking), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ValuesFromSendableTypedArrayEntries(lengthTrackingWithOffset), [ + 4, + 6 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + // SendableTypedArray.prototype.{entries, keys, values} throw right away when + // called. Array.prototype.{entries, keys, values} don't throw, but when + // we try to iterate the returned ArrayIterator, that throws. + assert.throws(TypeError, () => { + fixedLength.entries(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.entries(); + }); + + assert.throws(TypeError, () => { + Array.from(fixedLength.entries()); + }); + assert.throws(TypeError, () => { + Array.from(fixedLengthWithOffset.entries()); + }); + assert.compareArray(ValuesFromSendableTypedArrayEntries(lengthTracking), [ + 0, + 2, + 4 + ]); + assert.compareArray(ValuesFromSendableTypedArrayEntries(lengthTrackingWithOffset), [4]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.entries(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.entries(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.entries(); + }); + + assert.throws(TypeError, () => { + Array.from(fixedLength.entries()); + }); + assert.throws(TypeError, () => { + Array.from(fixedLengthWithOffset.entries()); + }); + assert.throws(TypeError, () => { + Array.from(lengthTrackingWithOffset.entries()); + }); + assert.compareArray(ValuesFromSendableTypedArrayEntries(lengthTracking), [0]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.entries(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.entries(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.entries(); + }); + + assert.throws(TypeError, () => { + Array.from(fixedLength.entries()); + }); + assert.throws(TypeError, () => { + Array.from(fixedLengthWithOffset.entries()); + }); + assert.throws(TypeError, () => { + Array.from(lengthTrackingWithOffset.entries()); + }); + assert.compareArray(ValuesFromSendableTypedArrayEntries(lengthTracking), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.compareArray(ValuesFromSendableTypedArrayEntries(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ValuesFromSendableTypedArrayEntries(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ValuesFromSendableTypedArrayEntries(lengthTracking), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(ValuesFromSendableTypedArrayEntries(lengthTrackingWithOffset), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/entries/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/entries/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..e801c3629e0ae0c2e1d808519168bdf478e08d27 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.entries, + 'function', + 'implements SendableTypedArray.prototype.entries' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.entries(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.entries(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the entries operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.entries(); + throw new Test262Error('entries completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/return-itor.js b/test/sendable/builtins/TypedArray/prototype/entries/return-itor.js new file mode 100644 index 0000000000000000000000000000000000000000..b3b503b5122272e7683c80ffdd41e272ce6411cc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/return-itor.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: Return an iterator for the entries. +info: | + 22.2.3.6 %SendableTypedArray%.prototype.entries ( ) + + ... + 3. Return CreateArrayIterator(O, "key+value"). +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var sample = [0, 42, 64]; + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(sample); + var itor = typedArray.entries(); + + var next = itor.next(); + assert(compareArray(next.value, [0, 0])); + assert.sameValue(next.done, false); + + next = itor.next(); + assert(compareArray(next.value, [1, 42])); + assert.sameValue(next.done, false); + + next = itor.next(); + assert(compareArray(next.value, [2, 64])); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, undefined); + assert.sameValue(next.done, true); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/entries/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..1f1e022bd1fce13071089e2b852491642155449c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/this-is-not-object.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.6 %SendableTypedArray%.prototype.entries ( ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var entries = SendableTypedArray.prototype.entries; + +assert.throws(TypeError, function() { + entries.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + entries.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + entries.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + entries.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + entries.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + entries.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + entries.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/entries/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/entries/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..d53b87ba3ae83cdd42235792b5f583ef4964ed41 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/entries/this-is-not-typedarray-instance.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.entries +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.6 %SendableTypedArray%.prototype.entries ( ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var entries = SendableTypedArray.prototype.entries; + +assert.throws(TypeError, function() { + entries.call({}); +}, "this is an Object"); + +assert.throws(TypeError, function() { + entries.call([]); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + entries.call(ab); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + entries.call(dv); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-arguments-with-thisarg.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..6f198d9411d4b07d0fd96eb9f9b7171ad02b12dd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.every(function() { + results.push(arguments); + return true; + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-arguments-without-thisarg.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..5248247a68490a7245c55c47a49c8446420867b0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + callbackfn arguments +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.every(function() { + results.push(arguments); + return true; + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..ea8a0d1f60af9846ab86986ed70769acba9c4b02 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.every(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return true; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-no-interaction-over-non-integer.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 0000000000000000000000000000000000000000..6e40195c3bdf77fe6bcf70e14d7d60b54a47db85 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-no-interaction-over-non-integer.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Does not interact over non-integer properties +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.every(function() { + results.push(arguments); + return true; + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - key"); + assert.sameValue(results[1][1], 1, "results[1][1] - key"); + + assert.sameValue(results[0][0], 7n, "results[0][0] - value"); + assert.sameValue(results[1][0], 8n, "results[1][0] - value"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..88eaaed767d1032ac171d4fd60d10634390f87bb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-not-callable-throws.js @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Throws a TypeError if callbackfn is not callable +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.every(); + }, "no args"); + + assert.throws(TypeError, function() { + sample.every(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.every(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.every("abc"); + }, "string"); + + assert.throws(TypeError, function() { + sample.every(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.every(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.every(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.every(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.every({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.every(sample); + }, "same typedArray instance"); + + assert.throws(TypeError, function() { + sample.every(Symbol("1")); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..4117c1209bb6d6908f0432c8798a6abb85855bb8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().every(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..c021130519feb9abd6ae0404fc951046a0f9c71c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + + sample.every(function() { + return 43; + }); + + assert.sameValue(sample[0], 40n, "[0] == 40"); + assert.sameValue(sample[1], 41n, "[1] == 41"); + assert.sameValue(sample[2], 42n, "[2] == 42"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..af61aa3ab9e38e3cb60e2b61475445bff13abb9e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Returns abrupt from callbackfn +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.every(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-set-value-during-interaction.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000000000000000000000000000000000..d5dbe8ae0a25961edb2f9cc5ae6a30729f2829e7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-set-value-during-interaction.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.every(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1n, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7n), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + + return true; + }); + + assert.sameValue(sample[0], 7n, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1n, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2n, "changed values after iteration [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..6c2c2bff2a80e5cc2c51e121dc746bd5fb3f4667 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/callbackfn-this.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + callbackfn `this` value +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.every(function() { + results1.push(this); + return true; + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.every(function() { + results2.push(this); + return true; + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..be303d48a7d675685a005f1d1c0a8b43024c0af3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.every(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..12f61ad6032c5d27cd4dcb68aef31d15b0af9714 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.every(function() { + calls++; + return true; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..7b346ec55efe9ee52855cce2c061b0fa56bf833c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.every, + 'function', + 'implements SendableTypedArray.prototype.every' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.every(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.every(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the every operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.every(() => {}); + throw new Test262Error('every completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/returns-false-if-any-cb-returns-false.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/returns-false-if-any-cb-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..6b6f95f400a65dd9d0ce1740ec0c86fbb274811d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/returns-false-if-any-cb-returns-false.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Returns false if any callbackfn call returns a coerced false. +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + + [ + false, + "", + 0, + -0, + NaN, + undefined, + null + ].forEach(function(val) { + var called = 0; + var result = sample.every(function() { + called++; + if (called === 1) { + return true; + } + return val; + }); + assert.sameValue(called, 2, "callbackfn called until it returned " + val); + assert.sameValue(result, false, "result is false when it returned " + val); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/returns-true-if-every-cb-returns-true.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/returns-true-if-every-cb-returns-true.js new file mode 100644 index 0000000000000000000000000000000000000000..3870a7ad3db1c19cf7173a1ed7bb6c4c9837d114 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/returns-true-if-every-cb-returns-true.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Returns true if every callbackfn returns a coerced true. +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + var values = [ + true, + 1, + "test262", + Symbol("1"), + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ]; + var sample = new TA(values.length); + var result = sample.every(function() { + called++; + return values.unshift(); + }); + + assert.sameValue(called, sample.length, "callbackfn called for each index"); + assert.sameValue(result, true, "return is true"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/BigInt/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/every/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..d8c301fafe1baab56e48ea616c684db424c01184 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/BigInt/values-are-not-cached.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + sample.every(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42n; + } + + assert.sameValue( + v, 42n, "method does not cache values before callbackfn calls" + ); + return true; + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/callbackfn-arguments-with-thisarg.js b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..f62170e6eb5a5a2e9c19e64774afb3ca7c4514c1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.every(function() { + results.push(arguments); + return true; + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/callbackfn-arguments-without-thisarg.js b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..7a4d5cb645728afae88c4d890ce367054cadf6ab --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + callbackfn arguments +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + + sample.every(function() { + results.push(arguments); + return true; + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..728b36e07c9086b3dff377e2ebd2a5662d111eaa --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-detachbuffer.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 5. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [detachArrayBuffer.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.every(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return true; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/callbackfn-no-interaction-over-non-integer.js b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 0000000000000000000000000000000000000000..f0e12d1a8e2cc4f4040656d683322a19713fd132 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-no-interaction-over-non-integer.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Does not interact over non-integer properties +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7, 8]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.every(function() { + results.push(arguments); + return true; + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - key"); + assert.sameValue(results[1][1], 1, "results[1][1] - key"); + + assert.sameValue(results[0][0], 7, "results[0][0] - value"); + assert.sameValue(results[1][0], 8, "results[1][0] - value"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/callbackfn-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..72130078918607c63952f1709ebab6c29c27f390 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-not-callable-throws.js @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Throws a TypeError if callbackfn is not callable +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.every(); + }, "no args"); + + assert.throws(TypeError, function() { + sample.every(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.every(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.every("abc"); + }, "string"); + + assert.throws(TypeError, function() { + sample.every(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.every(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.every(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.every(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.every({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.every(sample); + }, "same typedArray instance"); + + assert.throws(TypeError, function() { + sample.every(Symbol("1")); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..9df0bb2ec877634540f81a5fb563cd3e2cffdc73 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-not-called-on-empty.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().every(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/callbackfn-resize.js b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..14dfa0cc75fad5f4cabb288a2c76b74dd298426b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-resize.js @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Instance buffer can be resized during iteration +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var finalElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + + elements = []; + indices = []; + arrays = []; + result = sample.every(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + finalElement = undefined; + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + finalElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return true; + }); + + assert.compareArray(elements, [0, 0, finalElement], 'elements (shrink)'); + assert.compareArray(indices, [0, 1, 2], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, true, 'result (shrink)'); + + elements = []; + indices = []; + arrays = []; + result = sample.every(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return true; + }); + + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, true, 'result (grow)'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..add856e26e88964e16ee31d2e537c32b98c019f9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42]); + + sample.every(function() { + return 43; + }); + + assert.sameValue(sample[0], 40, "[0] == 40"); + assert.sameValue(sample[1], 41, "[1] == 41"); + assert.sameValue(sample[2], 42, "[2] == 42"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..c40e7d6e3bd5a9bf04d690b5bb76096c14b6944a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-returns-abrupt.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Returns abrupt from callbackfn +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.every(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/callbackfn-set-value-during-interaction.js b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000000000000000000000000000000000..78ec751487025d10ed505a85b58154a84a9bb371 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-set-value-during-interaction.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [Reflect.set, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + var newVal = 0; + + sample.every(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + + return true; + }); + + assert.sameValue(sample[0], 7, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2, "changed values after iteration [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..8218bf5d195d5a917c387aca0600283d125e6752 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/callbackfn-this.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + callbackfn `this` value +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.every(function() { + results1.push(this); + return true; + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.every(function() { + results2.push(this); + return true; + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/every/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..900a648c7adb2080dd363ef763320dcbcf4eba49 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.every(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/every/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..45e26c1687921487af5b8a395d7f881a92a4e4c8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/get-length-uses-internal-arraylength.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.every(function() { + calls++; + return true; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/every/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..2eb963667582da4d1e2934ff66e65d13598359ec --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var every = SendableTypedArray.prototype.every; + +assert.sameValue(typeof every, 'function'); + +assert.throws(TypeError, function() { + every(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/every/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..51eb42cc881d494276e2fc27f8f81e625c9527b5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.every, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.every(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/length.js b/test/sendable/builtins/TypedArray/prototype/every/length.js new file mode 100644 index 0000000000000000000000000000000000000000..2e1155b28dfc051dbf7eb8eb8a80df2d73dc7325 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + %SendableTypedArray%.prototype.every.length is 1. +info: | + %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.every, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/name.js b/test/sendable/builtins/TypedArray/prototype/every/name.js new file mode 100644 index 0000000000000000000000000000000000000000..929f48b74591e3950de0e7dc39d09605fbad5e9c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + %SendableTypedArray%.prototype.every.name is "every". +info: | + %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.every, "name", { + value: "every", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/every/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..733e8f6b91fb6f2606496f2cc2f3754259ab785d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.every does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.every), + false, + 'isConstructor(SendableTypedArray.prototype.every) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.every(() => {}); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/every/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/every/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..e335427fbe7e89b41dbb177aa3d6d20bf89a7321 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + "every" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'every', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/every/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..313d0a1c27429f981146189d364039c41b8f56f6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + SendableTypedArray.p.every behaves correctly when receiver is backed by resizable + buffer that is grown mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + // Returns true by default. + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(fixedLength.every(ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(fixedLengthWithOffset.every(ResizeMidIteration)); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(lengthTracking.every(ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(lengthTrackingWithOffset.every(ResizeMidIteration)); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/every/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/every/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..6c5c6e1ebf425fa2635260384f8ef023c0bb583f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + SendableTypedArray.p.every behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + // Returns true by default. + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(fixedLength.every(ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(fixedLengthWithOffset.every(ResizeMidIteration)); + assert.compareArray(values, [ + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(lengthTracking.every(ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(lengthTrackingWithOffset.every(ResizeMidIteration)); + assert.compareArray(values, [ + 4, + undefined + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/every/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/every/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..7d9bd6036ee87a0c6197b6c5e75fa57d7784ad84 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/resizable-buffer.js @@ -0,0 +1,134 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + SendableTypedArray.p.every behaves correctly when the receiver is backed by + resizable buffer +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function div3(n) { + return Number(n) % 3 == 0; + } + function even(n) { + return Number(n) % 2 == 0; + } + function over10(n) { + return Number(n) > 10; + } + assert(!fixedLength.every(div3)); + assert(fixedLength.every(even)); + assert(!fixedLengthWithOffset.every(div3)); + assert(fixedLengthWithOffset.every(even)); + assert(!lengthTracking.every(div3)); + assert(lengthTracking.every(even)); + assert(!lengthTrackingWithOffset.every(div3)); + assert(lengthTrackingWithOffset.every(even)); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + // Calling .every on an out of bounds TA throws. + assert.throws(TypeError, () => { + fixedLength.every(div3); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.every(div3); + }); + + assert(!lengthTracking.every(div3)); + assert(lengthTracking.every(even)); + assert(!lengthTrackingWithOffset.every(div3)); + assert(lengthTrackingWithOffset.every(even)); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + // Calling .every on an out of bounds TA throws. + assert.throws(TypeError, () => { + fixedLength.every(div3); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.every(div3); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.every(div3); + }); + + assert(lengthTracking.every(div3)); + assert(lengthTracking.every(even)); + + // Shrink to zero. + rab.resize(0); + // Calling .every on an out of bounds TA throws. + assert.throws(TypeError, () => { + fixedLength.every(div3); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.every(div3); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.every(div3); + }); + + assert(lengthTracking.every(div3)); + assert(lengthTracking.every(even)); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert(!fixedLength.every(div3)); + assert(fixedLength.every(even)); + assert(!fixedLengthWithOffset.every(div3)); + assert(fixedLengthWithOffset.every(even)); + assert(!lengthTracking.every(div3)); + assert(lengthTracking.every(even)); + assert(!lengthTrackingWithOffset.every(div3)); + assert(lengthTrackingWithOffset.every(even)); +} diff --git a/test/sendable/builtins/TypedArray/prototype/every/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/every/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..8edfcf53e96c259fb2b212ffc24e16c82a7a9718 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.every, + 'function', + 'implements SendableTypedArray.prototype.every' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.every(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.every(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the every operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.every(() => {}); + throw new Test262Error('every completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/returns-false-if-any-cb-returns-false.js b/test/sendable/builtins/TypedArray/prototype/every/returns-false-if-any-cb-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..36a151412e2a111a333912e27737aa7ee956f1de --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/returns-false-if-any-cb-returns-false.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Returns false if any callbackfn call returns a coerced false. +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(42); + + [ + false, + "", + 0, + -0, + NaN, + undefined, + null + ].forEach(function(val) { + var called = 0; + var result = sample.every(function() { + called++; + if (called === 1) { + return true; + } + return val; + }); + assert.sameValue(called, 2, "callbackfn called until it returned " + val); + assert.sameValue(result, false, "result is false when it returned " + val); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/returns-true-if-every-cb-returns-true.js b/test/sendable/builtins/TypedArray/prototype/every/returns-true-if-every-cb-returns-true.js new file mode 100644 index 0000000000000000000000000000000000000000..95720808a9061fbba216ec0698dbd710c794edcd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/returns-true-if-every-cb-returns-true.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Returns true if every callbackfn returns a coerced true. +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + var values = [ + true, + 1, + "test262", + Symbol("1"), + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ]; + var sample = new TA(values.length); + var result = sample.every(function() { + called++; + return values.unshift(); + }); + + assert.sameValue(called, sample.length, "callbackfn called for each index"); + assert.sameValue(result, true, "return is true"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/every/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/every/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..4d81422ce3d75c817c6d3fdd2034798b79d12f02 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/this-is-not-object.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var every = SendableTypedArray.prototype.every; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + every.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + every.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + every.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + every.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + every.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + every.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + every.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/every/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/every/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..f06c094043b9d8f106685db58b6b1934a3625ce0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/this-is-not-typedarray-instance.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var every = SendableTypedArray.prototype.every; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + every.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + every.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + every.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + every.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/every/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/every/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..22e047ff2fb28e4dc3469151b8c5e48b517ec8e0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/every/values-are-not-cached.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.every +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.7 %SendableTypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + sample.every(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42; + } + + assert.sameValue( + v, 42, "method does not cache values before callbackfn calls" + ); + return true; + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/coerced-indexes.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/coerced-indexes.js new file mode 100644 index 0000000000000000000000000000000000000000..ef8a08449a615a86b5ef47d2c8a199ced5c70106 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/coerced-indexes.js @@ -0,0 +1,117 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills elements from coerced to Integer `start` and `end` values +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + 4. If relativeStart < 0, let k be max((len + relativeStart), 0); else let k be + min(relativeStart, len). + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray(new TA([0n, 0n]).fill(1n, undefined), [1n, 1n]), + '`undefined` start coerced to 0' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, 0, undefined), [1n, 1n]), + 'If end is undefined, let relativeEnd be len' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, null), [1n, 1n]), + '`null` start coerced to 0' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, 0, null), [0n, 0n]), + '`null` end coerced to 0' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, true), [0n, 1n]), + '`true` start coerced to 1' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, 0, true), [1n, 0n]), + '`true` end coerced to 1' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, false), [1n, 1n]), + '`false` start coerced to 0' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, 0, false), [0n, 0n]), + '`false` end coerced to 0' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, NaN), [1n, 1n]), + '`NaN` start coerced to 0' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, 0, NaN), [0n, 0n]), + '`NaN` end coerced to 0' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, '1'), [0n, 1n]), + 'string start coerced' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, 0, '1'), [1n, 0n]), + 'string end coerced' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, 1.5), [0n, 1n]), + 'start as a float number coerced' + ); + + assert( + compareArray(new TA([0n, 0n]).fill(1n, 0, 1.5), [1n, 0n]), + 'end as a float number coerced' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..3c108af2aee50312bed4d114f03a5c40834a6de6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/detached-buffer.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.fill(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js new file mode 100644 index 0000000000000000000000000000000000000000..ecb209433aa737a06572a79b60c7bbbd72d30967 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements with non numeric values values. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. If O.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + var n = 1n; + sample.fill({ valueOf() { return n++; } }); + + assert.sameValue(n, 2n, "additional unexpected ToBigInt() calls"); + assert.sameValue(sample[0], 1n, "incorrect ToNumber result in index 0"); + assert.sameValue(sample[1], 1n, "incorrect ToNumber result in index 1"); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-custom-start-and-end.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-custom-start-and-end.js new file mode 100644 index 0000000000000000000000000000000000000000..ab50201c747c3bbfaa81c78efad849bca0454b67 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-custom-start-and-end.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements from a with a custom start and end indexes. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + 4. If relativeStart < 0, let k be max((len + relativeStart), 0); else let k be + min(relativeStart, len). + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 6. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert(compareArray(new TA([0n, 0n, 0n]).fill(8n, 1, 2), [0n, 8n, 0n])); + assert(compareArray(new TA([0n, 0n, 0n, 0n, 0n]).fill(8n, -3, 4), [0n, 0n, 8n, 8n, 0n])); + assert(compareArray(new TA([0n, 0n, 0n, 0n, 0n]).fill(8n, -2, -1), [0n, 0n, 0n, 8n, 0n])); + assert(compareArray(new TA([0n, 0n, 0n, 0n, 0n]).fill(8n, -1, -3), [0n, 0n, 0n, 0n, 0n])); + assert(compareArray(new TA([0n, 0n, 0n, 0n, 0n]).fill(8n, 1, 3), [0n, 8n, 8n, 0n, 0n])); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric-throw.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..24197713100bdea525efae3d65a0f1d97a232bda --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric-throw.js @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements with non numeric values values. +info: | + %SendableTypedArray%.prototype.fill ( value [ , start [ , end ] ] ) + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If O.[[ContentType]] is BigInt, set value to ? ToBigInt(value). + Otherwise, set value to ? ToNumber(value). + Let relativeStart be ? ToIntegerOrInfinity(start). + If relativeStart is -Infinity, let k be 0. + Else if relativeStart < 0, let k be max(len + relativeStart, 0). + Else, let k be min(relativeStart, len). + If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end). + If relativeEnd is -Infinity, let final be 0. + Else if relativeEnd < 0, let final be max(len + relativeEnd, 0). + Else, let final be min(relativeEnd, len). + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + Repeat, while k < final, + Let Pk be ! ToString(F(k)). + Perform ! Set(O, Pk, value, true). + Set k to k + 1. + Return O. + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n]); + + assert.throws(TypeError, function() { + sample.fill(undefined); + }, "abrupt completion from undefined"); + + assert.throws(TypeError, function() { + sample.fill(null); + }, "abrupt completion from null"); + + assert.throws(SyntaxError, function() { + sample.fill("nonsense"); + }, "abrupt completion from string"); + +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric.js new file mode 100644 index 0000000000000000000000000000000000000000..5b0fceaae09627c433a1632699318546c012bcb4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric.js @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements with non numeric values values. +info: | + %SendableTypedArray%.prototype.fill ( value [ , start [ , end ] ] ) + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If O.[[ContentType]] is BigInt, set value to ? ToBigInt(value). + Otherwise, set value to ? ToNumber(value). + Let relativeStart be ? ToIntegerOrInfinity(start). + If relativeStart is -Infinity, let k be 0. + Else if relativeStart < 0, let k be max(len + relativeStart, 0). + Else, let k be min(relativeStart, len). + If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end). + If relativeEnd is -Infinity, let final be 0. + Else if relativeEnd < 0, let final be max(len + relativeEnd, 0). + Else, let final be min(relativeEnd, len). + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + Repeat, while k < final, + Let Pk be ! ToString(F(k)). + Perform ! Set(O, Pk, value, true). + Set k to k + 1. + Return O. + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n]); + sample.fill(false); + assert.sameValue(sample[0], 0n, "false => 0"); + + sample = new TA([42n]); + sample.fill(true); + assert.sameValue(sample[0], 1n, "true => 1"); + + sample = new TA([42n]); + sample.fill("7"); + assert.sameValue(sample[0], 7n, "string conversion"); + + sample = new TA([42n]); + sample.fill({ + toString: function() { + return "1"; + }, + valueOf: function() { + return 7n; + } + }); + assert.sameValue(sample[0], 7n, "object valueOf conversion before toString"); + + sample = new TA([42n]); + sample.fill({ + toString: function() { + return "7"; + } + }); + assert.sameValue(sample[0], 7n, "object toString when valueOf is absent"); + +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-relative-end.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-relative-end.js new file mode 100644 index 0000000000000000000000000000000000000000..d889ed80f1ee14124d9f2445de7d5aab7cda1bc4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-relative-end.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements from a with a custom end index. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 6. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray(new TA([0n, 0n, 0n]).fill(8n, 0, 1), [8n, 0n, 0n]), + "Fill elements from custom end position" + ); + + assert( + compareArray(new TA([0n, 0n, 0n]).fill(8n, 0, -1), [8n, 8n, 0n]), + "negative end sets final position to max((length + relativeEnd), 0)" + ); + + assert( + compareArray(new TA([0n, 0n, 0n]).fill(8n, 0, 5), [8n, 8n, 8n]), + "end position is never higher than of length" + ); + + assert( + compareArray(new TA([0n, 0n, 0n]).fill(8n, 0, -4), [0n, 0n, 0n]), + "end position is 0 when (len + relativeEnd) < 0" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-relative-start.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-relative-start.js new file mode 100644 index 0000000000000000000000000000000000000000..fb96a7be17a81802398f73bf4ba945ae2637b98b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-relative-start.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements from a with a custom start index. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 4. If relativeStart < 0, let k be max((len + relativeStart), 0); else let k be + min(relativeStart, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray(new TA([0n, 0n, 0n]).fill(8n, 1), [0n, 8n, 8n]), + "Fill elements from custom start position" + ); + + assert( + compareArray(new TA([0n, 0n, 0n]).fill(8n, 4), [0n, 0n, 0n]), + "start position is never higher than length" + ); + + assert( + compareArray(new TA([0n, 0n, 0n]).fill(8n, -1), [0n, 0n, 8n]), + "start < 0 sets initial position to max((len + relativeStart), 0)" + ); + + assert( + compareArray(new TA([0n, 0n, 0n]).fill(8n, -5), [8n, 8n, 8n]), + "start position is 0 when (len + relativeStart) < 0" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-symbol-throws.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-symbol-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..98c5d56cefb0710946ca7f25d5d7b97e731d2baf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values-symbol-throws.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Throws a TypeError if value is a Symbol +info: | + %SendableTypedArray%.prototype.fill ( value [ , start [ , end ] ] ) + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If O.[[ContentType]] is BigInt, set value to ? ToBigInt(value). + Otherwise, set value to ? ToNumber(value). + Let relativeStart be ? ToIntegerOrInfinity(start). + If relativeStart is -Infinity, let k be 0. + Else if relativeStart < 0, let k be max(len + relativeStart, 0). + Else, let k be min(relativeStart, len). + If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end). + If relativeEnd is -Infinity, let final be 0. + Else if relativeEnd < 0, let final be max(len + relativeEnd, 0). + Else, let final be min(relativeEnd, len). + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + Repeat, while k < final, + Let Pk be ! ToString(F(k)). + Perform ! Set(O, Pk, value, true). + Set k to k + 1. + Return O. + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol('1'); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.fill(s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values.js new file mode 100644 index 0000000000000000000000000000000000000000..6e5eb9fd8542a0598546c05ee863e46d2106effa --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/fill-values.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements with `value` from a default start and index. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA().fill(8n), + [] + ), + "does not fill an empty instance" + ); + + assert( + compareArray(new TA([0n, 0n, 0n]).fill(8n), [8n, 8n, 8n]), + "Default start and end indexes are 0 and this.length" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..de323fba07e66773615232ec6cd27555d8d5aac1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/get-length-ignores-length-prop.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Unreachable abrupt from Get(O, "length") as [[ArrayLength]] is returned. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA(1); + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + } + }); + + assert.sameValue(sample.fill(1n, 0), sample); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end-as-symbol.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..b971db3c52bf8cdb3590062e9f99c25283abdbba --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end-as-symbol.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Return abrupt if end is a Symbol. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var end = Symbol(1); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.fill(1n, 0, end); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end.js new file mode 100644 index 0000000000000000000000000000000000000000..c9b4da6595c6ce9f85dad990f271eb7e74861a29 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Return abrupt from ToInteger(end). +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var end = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.fill(1n, 0, end); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-set-value.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-set-value.js new file mode 100644 index 0000000000000000000000000000000000000000..0c63a002e0779e93e265a55c66671ac4124b179e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-set-value.js @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Returns abrupt from value set +info: | + %SendableTypedArray%.prototype.fill ( value [ , start [ , end ] ] ) + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If O.[[ContentType]] is BigInt, set value to ? ToBigInt(value). + Otherwise, set value to ? ToNumber(value). + Let relativeStart be ? ToIntegerOrInfinity(start). + If relativeStart is -Infinity, let k be 0. + Else if relativeStart < 0, let k be max(len + relativeStart, 0). + Else, let k be min(relativeStart, len). + If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end). + If relativeEnd is -Infinity, let final be 0. + Else if relativeEnd < 0, let final be max(len + relativeEnd, 0). + Else, let final be min(relativeEnd, len). + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + Repeat, while k < final, + Let Pk be ! ToString(F(k)). + Perform ! Set(O, Pk, value, true). + Set k to k + 1. + Return O. + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + var obj = { + valueOf: function() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample.fill(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start-as-symbol.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..9f163792de120f4ae20518f41ed607b8cb1fb732 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start-as-symbol.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Return abrupt from ToInteger(start) as a Symbol. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var start = Symbol(1); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.fill(1n, start); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start.js new file mode 100644 index 0000000000000000000000000000000000000000..a92f3edd28154fc9d226e5f80939f950683ce312 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Return abrupt from ToInteger(start). +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var start = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.fill(1n, start); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..864ca283a75b9d2bd0e4358ed2788b147484e81d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.fill, + 'function', + 'implements SendableTypedArray.prototype.fill' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.fill(0n); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.fill(0n); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the fill operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.fill(0n); + throw new Test262Error('fill completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-this.js b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-this.js new file mode 100644 index 0000000000000000000000000000000000000000..6ef854fe04e9c5d7ec7b9349f36293b60a9c7de4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/BigInt/return-this.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Returns `this`. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(); + var result1 = sample1.fill(1n); + + assert.sameValue(result1, sample1); + + var sample2 = new TA(42); + var result2 = sample2.fill(7n); + assert.sameValue(result2, sample2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/absent-indices-computed-from-initial-length.js b/test/sendable/builtins/TypedArray/prototype/fill/absent-indices-computed-from-initial-length.js new file mode 100644 index 0000000000000000000000000000000000000000..9f13ee55a91d42fb99280abd9af26e346561cbe1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/absent-indices-computed-from-initial-length.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Absent start and end parameters are computed from initial length. +info: | + %SendableTypedArray%.prototype.fill ( value [ , start [ , end ] ] ) + + ... + 2. Let taRecord be ? ValidateSendableTypedArray(O, seq-cst). + 3. Let len be SendableTypedArrayLength(taRecord). + ... + 5. Otherwise, set value to ? ToNumber(value). + 6. Let relativeStart be ? ToIntegerOrInfinity(start). + ... + 9. Else, let startIndex be min(relativeStart, len). + 10. If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end). + ... + 13. Else, let endIndex be min(relativeEnd, len). + ... + +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(1, {maxByteLength: 4}); +let ta = new Int8Array(rab); + +let value = { + valueOf() { + // Set buffer to maximum byte length. + rab.resize(4); + + // Return the fill value. + return 123; + } +}; + +// Ensure typed array is correctly initialised. +assert.sameValue(ta.length, 1); +assert.sameValue(ta[0], 0); + +ta.fill(value); + +// Ensure typed array has correct length and only the first element was filled. +assert.sameValue(ta.length, 4); +assert.sameValue(ta[0], 123); +assert.sameValue(ta[1], 0); +assert.sameValue(ta[2], 0); +assert.sameValue(ta[3], 0); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/coerced-end-detach.js b/test/sendable/builtins/TypedArray/prototype/fill/coerced-end-detach.js new file mode 100644 index 0000000000000000000000000000000000000000..790e2db257701d59957f78cfbd631d90d23c54b1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/coerced-end-detach.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Security Throws a TypeError if end coercion detaches the buffer +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + 9. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let final be min(relativeEnd, len). + 10. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(10); + + function detachAndReturnIndex(){ + $DETACHBUFFER(sample.buffer); + return 10; + } + + assert.throws(TypeError, function() { + sample.fill(0x77, 0, {valueOf: detachAndReturnIndex}); + }, "Detachment when coercing end should throw TypeError"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/coerced-indexes.js b/test/sendable/builtins/TypedArray/prototype/fill/coerced-indexes.js new file mode 100644 index 0000000000000000000000000000000000000000..ae608a9e91be97abc028028474b128578d11b991 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/coerced-indexes.js @@ -0,0 +1,117 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills elements from coerced to Integer `start` and `end` values +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + 4. If relativeStart < 0, let k be max((len + relativeStart), 0); else let k be + min(relativeStart, len). + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray(new TA([0, 0]).fill(1, undefined), [1, 1]), + '`undefined` start coerced to 0' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, 0, undefined), [1, 1]), + 'If end is undefined, let relativeEnd be len' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, null), [1, 1]), + '`null` start coerced to 0' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, 0, null), [0, 0]), + '`null` end coerced to 0' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, true), [0, 1]), + '`true` start coerced to 1' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, 0, true), [1, 0]), + '`true` end coerced to 1' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, false), [1, 1]), + '`false` start coerced to 0' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, 0, false), [0, 0]), + '`false` end coerced to 0' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, NaN), [1, 1]), + '`NaN` start coerced to 0' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, 0, NaN), [0, 0]), + '`NaN` end coerced to 0' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, '1'), [0, 1]), + 'string start coerced' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, 0, '1'), [1, 0]), + 'string end coerced' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, 1.5), [0, 1]), + 'start as a float number coerced' + ); + + assert( + compareArray(new TA([0, 0]).fill(1, 0, 1.5), [1, 0]), + 'end as a float number coerced' + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/coerced-start-detach.js b/test/sendable/builtins/TypedArray/prototype/fill/coerced-start-detach.js new file mode 100644 index 0000000000000000000000000000000000000000..fb988bec2e482920c510ed1e616ccbb2e0113674 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/coerced-start-detach.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Security Throws a TypeError if start coercion detaches the buffer +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + 6. Let relativeStart be ? ToInteger(start). + ... + 10. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(10); + + function detachAndReturnIndex(){ + $DETACHBUFFER(sample.buffer); + return 0; + } + + assert.throws(TypeError, function() { + sample.fill(0x77, {valueOf: detachAndReturnIndex}, 10); + }, "Detachment when coercing start should throw TypeError"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/coerced-value-detach.js b/test/sendable/builtins/TypedArray/prototype/fill/coerced-value-detach.js new file mode 100644 index 0000000000000000000000000000000000000000..dcb725e3e22a1b3ed383c5d4b81f24f50b3841b3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/coerced-value-detach.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Security Throws a TypeError if value coercion detaches the buffer +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + 5. Otherwise, set value to ? ToNumber(value). + ... + 10. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(10); + + function detachAndReturnIndex(){ + $DETACHBUFFER(sample.buffer); + return 0x77; + } + + assert.throws(TypeError, function() { + sample.fill({valueOf: detachAndReturnIndex}, 0, 10); + }, "Detachment when coercing value should throw TypeError"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/coerced-value-start-end-resize.js b/test/sendable/builtins/TypedArray/prototype/fill/coerced-value-start-end-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..b3d192310af9dc8917f69f936af9c1d236b5b5d8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/coerced-value-start-end-resize.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + SendableTypedArray.p.fill behaves correctly on receivers backed by a resizable + buffer that's resized during argument coercion +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function SendableTypedArrayFillHelper(ta, n, start, end) { + if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) { + ta.fill(BigInt(n), start, end); + } else { + ta.fill(n, start, end); + } +} + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 3; + } + }; + assert.throws(TypeError, () => { + SendableTypedArrayFillHelper(fixedLength, evil, 1, 2); + }); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 1; + } + }; + assert.throws(TypeError, () => { + SendableTypedArrayFillHelper(fixedLength, 3, evil, 2); + }); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 2; + } + }; + assert.throws(TypeError, () => { + SendableTypedArrayFillHelper(fixedLength, 3, 1, evil); + }); +} diff --git a/test/sendable/builtins/TypedArray/prototype/fill/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/fill/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..54b5c0fe3fc25f789ce7421e0240a6091fd5043d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/detached-buffer.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.fill(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/fill-values-conversion-once.js b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-conversion-once.js new file mode 100644 index 0000000000000000000000000000000000000000..ff9906508033b60575ace3e3e5efce185e97fb4e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-conversion-once.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements with non numeric values values. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let _value_ be ? ToNumber(_value_). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + var n = 1; + sample.fill({ valueOf() { return n++; } }); + + assert.sameValue(n, 2, "additional unexpected ToNumber() calls"); + assert.sameValue(sample[0], 1, "incorrect ToNumber result in index 0"); + assert.sameValue(sample[1], 1, "incorrect ToNumber result in index 1"); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/fill/fill-values-conversion-operations-consistent-nan.js b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-conversion-operations-consistent-nan.js new file mode 100644 index 0000000000000000000000000000000000000000..318b760b68f5a4fb43dd0de403279299363e255b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-conversion-operations-consistent-nan.js @@ -0,0 +1,114 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + An implementation must always choose either the same encoding for each implementation distinguishable *NaN* value, or an implementation-defined canonical value. +info: | + This test does not compare the actual byte values, instead it simply checks that + the value is some valid NaN encoding. + + --- + + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + #sec-array.prototype.fill + Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). + ... + + #sec-setvalueinbuffer + SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + + #sec-numbertorawbytes + NumberToRawBytes( type, value, isLittleEndian ) + + 1. If type is "Float32", then + a. Set rawBytes to a List containing the 4 bytes that are the result + of converting value to IEEE 754-2008 binary32 format using “Round to + nearest, ties to even” rounding mode. If isLittleEndian is false, the + bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number + encoding. An implementation must always choose either the same encoding + for each implementation distinguishable *NaN* value, or an + implementation-defined canonical value. + 2. Else, if type is "Float64", then + a. Set _rawBytes_ to a List containing the 8 bytes that are the IEEE + 754-2008 binary64 format encoding of _value_. If _isLittleEndian_ is + *false*, the bytes are arranged in big endian order. Otherwise, + the bytes are arranged in little endian order. If _value_ is *NaN*, + _rawValue_ may be set to any implementation chosen IEEE 754-2008 + binary64 format Not-a-Number encoding. An implementation must + always choose either the same encoding for each implementation + distinguishable *NaN* value, or an implementation-defined + canonical value. + ... + + #sec-isnan-number + + NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is + an expression of the form X !== X. The result will be true if and only + if X is a NaN. +includes: [nans.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(FA) { + var precision = floatTypedArrayConstructorPrecision(FA); + var samples = new FA(3); + var controls, idx, aNaN; + + for (idx = 0; idx < NaNs.length; ++idx) { + aNaN = NaNs[idx]; + controls = new Float32Array([aNaN, aNaN, aNaN]); + + samples.fill(aNaN); + + for (var i = 0; i < samples.length; i++) { + var sample = samples[i]; + var control = controls[i]; + + assert( + samples[i] !== samples[i], + `samples (index=${idx}) produces a valid NaN (${precision} precision)` + ); + + assert( + controls[i] !== controls[i], + `controls (index=${idx}) produces a valid NaN (${precision} precision)` + ); + } + } +}, floatArrayConstructors); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/fill-values-conversion-operations.js b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-conversion-operations.js new file mode 100644 index 0000000000000000000000000000000000000000..cf807167c1dc87250754a02d6c867e1d3fbc9ae5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-conversion-operations.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements with non numeric values values. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + ... + 9. Else, if type is "Float64", then + ... + 10. Else, + ... + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 50 for Element Type type. + c. Let intValue be convOp(value). + d. If intValue ≥ 0, then + ... + e. Else, + ... +includes: [byteConversionValues.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + sample.fill(value); + + assert.sameValue(sample[0], expected, value + " converts to " + expected); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/fill-values-custom-start-and-end.js b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-custom-start-and-end.js new file mode 100644 index 0000000000000000000000000000000000000000..8ef40d0c48f856a15fe7a5388fb8518f43d2a092 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-custom-start-and-end.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements from a with a custom start and end indexes. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + 4. If relativeStart < 0, let k be max((len + relativeStart), 0); else let k be + min(relativeStart, len). + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 6. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert(compareArray(new TA([0, 0, 0]).fill(8, 1, 2), [0, 8, 0])); + assert(compareArray(new TA([0, 0, 0, 0, 0]).fill(8, -3, 4), [0, 0, 8, 8, 0])); + assert(compareArray(new TA([0, 0, 0, 0, 0]).fill(8, -2, -1), [0, 0, 0, 8, 0])); + assert(compareArray(new TA([0, 0, 0, 0, 0]).fill(8, -1, -3), [0, 0, 0, 0, 0])); + assert(compareArray(new TA([0, 0, 0, 0, 0]).fill(8, 1, 3), [0, 8, 8, 0, 0])); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/fill-values-non-numeric.js b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-non-numeric.js new file mode 100644 index 0000000000000000000000000000000000000000..1ad8c1157a493d7bbc3b8fd6fcc35e1d88f59641 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-non-numeric.js @@ -0,0 +1,100 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements with non numeric values values. +info: | + %SendableTypedArray%.prototype.fill ( value [ , start [ , end ] ] ) + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If O.[[ContentType]] is BigInt, set value to ? ToBigInt(value). + Otherwise, set value to ? ToNumber(value). + Let relativeStart be ? ToIntegerOrInfinity(start). + If relativeStart is -Infinity, let k be 0. + Else if relativeStart < 0, let k be max(len + relativeStart, 0). + Else, let k be min(relativeStart, len). + If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end). + If relativeEnd is -Infinity, let final be 0. + Else if relativeEnd < 0, let final be max(len + relativeEnd, 0). + Else, let final be min(relativeEnd, len). + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + Repeat, while k < final, + Let Pk be ! ToString(F(k)). + Perform ! Set(O, Pk, value, true). + Set k to k + 1. + Return O. + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42]); + sample.fill(null); + assert.sameValue(sample[0], 0, "null => 0"); + + sample = new TA([42]); + sample.fill(false); + assert.sameValue(sample[0], 0, "false => 0"); + + sample = new TA([42]); + sample.fill(true); + assert.sameValue(sample[0], 1, "true => 1"); + + sample = new TA([42]); + sample.fill("7"); + assert.sameValue(sample[0], 7, "string conversion"); + + sample = new TA([42]); + sample.fill({ + toString: function() { + return "1"; + }, + valueOf: function() { + return 7; + } + }); + assert.sameValue(sample[0], 7, "object valueOf conversion before toString"); + + sample = new TA([42]); + sample.fill({ + toString: function() { + return "7"; + } + }); + assert.sameValue(sample[0], 7, "object toString when valueOf is absent"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/fill-values-relative-end.js b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-relative-end.js new file mode 100644 index 0000000000000000000000000000000000000000..d88a75d191b726e029ac860b2e40f81b91463ba9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-relative-end.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements from a with a custom end index. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 6. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray(new TA([0, 0, 0]).fill(8, 0, 1), [8, 0, 0]), + "Fill elements from custom end position" + ); + + assert( + compareArray(new TA([0, 0, 0]).fill(8, 0, -1), [8, 8, 0]), + "negative end sets final position to max((length + relativeEnd), 0)" + ); + + assert( + compareArray(new TA([0, 0, 0]).fill(8, 0, 5), [8, 8, 8]), + "end position is never higher than of length" + ); + + assert( + compareArray(new TA([0, 0, 0]).fill(8, 0, -4), [0, 0, 0]), + "end position is 0 when (len + relativeEnd) < 0" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/fill-values-relative-start.js b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-relative-start.js new file mode 100644 index 0000000000000000000000000000000000000000..33d00636ac4e7720edc6f0f324522547ab188790 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-relative-start.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements from a with a custom start index. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 4. If relativeStart < 0, let k be max((len + relativeStart), 0); else let k be + min(relativeStart, len). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray(new TA([0, 0, 0]).fill(8, 1), [0, 8, 8]), + "Fill elements from custom start position" + ); + + assert( + compareArray(new TA([0, 0, 0]).fill(8, 4), [0, 0, 0]), + "start position is never higher than length" + ); + + assert( + compareArray(new TA([0, 0, 0]).fill(8, -1), [0, 0, 8]), + "start < 0 sets initial position to max((len + relativeStart), 0)" + ); + + assert( + compareArray(new TA([0, 0, 0]).fill(8, -5), [8, 8, 8]), + "start position is 0 when (len + relativeStart) < 0" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/fill-values-symbol-throws.js b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-symbol-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..05966a944b9ae91f8910b0b55e443ea461f78c43 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/fill-values-symbol-throws.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Throws a TypeError if value is a Symbol +info: | + %SendableTypedArray%.prototype.fill ( value [ , start [ , end ] ] ) + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If O.[[ContentType]] is BigInt, set value to ? ToBigInt(value). + Otherwise, set value to ? ToNumber(value). + Let relativeStart be ? ToIntegerOrInfinity(start). + If relativeStart is -Infinity, let k be 0. + Else if relativeStart < 0, let k be max(len + relativeStart, 0). + Else, let k be min(relativeStart, len). + If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end). + If relativeEnd is -Infinity, let final be 0. + Else if relativeEnd < 0, let final be max(len + relativeEnd, 0). + Else, let final be min(relativeEnd, len). + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + Repeat, while k < final, + Let Pk be ! ToString(F(k)). + Perform ! Set(O, Pk, value, true). + Set k to k + 1. + Return O. + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol('1'); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.fill(s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/fill-values.js b/test/sendable/builtins/TypedArray/prototype/fill/fill-values.js new file mode 100644 index 0000000000000000000000000000000000000000..2f45406cde15174641c8b507cdbc5902733c4b98 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/fill-values.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Fills all the elements with `value` from a default start and index. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA().fill(8), + [] + ), + "does not fill an empty instance" + ); + + assert( + compareArray(new TA([0, 0, 0]).fill(8), [8, 8, 8]), + "Default start and end indexes are 0 and this.length" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/fill/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..f0ecefd2cd3dcfe6d302245eeade5388052a8169 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/get-length-ignores-length-prop.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Unreachable abrupt from Get(O, "length") as [[ArrayLength]] is returned. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA(1); + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + } + }); + + assert.sameValue(sample.fill(1, 0), sample); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/fill/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..f8c6d60c30e03a4975dd91574828a5ddcae31587 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var fill = SendableTypedArray.prototype.fill; + +assert.sameValue(typeof fill, 'function'); + +assert.throws(TypeError, function() { + fill(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/fill/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..3c49138fe5bf0354b1327ab0cc97e9d691151a2b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.fill, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.fill(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/length.js b/test/sendable/builtins/TypedArray/prototype/fill/length.js new file mode 100644 index 0000000000000000000000000000000000000000..1e75a59329b83018354febb8b7f32a4d35161492 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + %SendableTypedArray%.prototype.fill.length is 1. +info: | + %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.fill, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/name.js b/test/sendable/builtins/TypedArray/prototype/fill/name.js new file mode 100644 index 0000000000000000000000000000000000000000..329bd6cf9516eca22055806224af295426a0e0ea --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + %SendableTypedArray%.prototype.fill.name is "fill". +info: | + %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.fill, "name", { + value: "fill", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/fill/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..a4b63d5cd7d04c10e06a71545ac7a909b5853007 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.fill does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.fill), + false, + 'isConstructor(SendableTypedArray.prototype.fill) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.fill(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/fill/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/fill/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..16bc2a5cdd7bfe41988c18b0386e6ae258280d8b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + "fill" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'fill', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/fill/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..23aed70d3a14474756710f2b1008ab3ef8e83870 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/resizable-buffer.js @@ -0,0 +1,192 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + SendableTypedArray.p.fill behaves correctly when the receiver is backed by + resizable buffer +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function ReadDataFromBuffer(ab, ctor) { + let result = []; + const ta = new ctor(ab, 0, ab.byteLength / ctor.BYTES_PER_ELEMENT); + for (let item of ta) { + result.push(Number(item)); + } + return result; +} + +function SendableTypedArrayFillHelper(ta, n, start, end) { + if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) { + ta.fill(BigInt(n), start, end); + } else { + ta.fill(n, start, end); + } +} + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 0, + 0, + 0, + 0 + ]); + SendableTypedArrayFillHelper(fixedLength, 1); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 1, + 1, + 1, + 1 + ]); + SendableTypedArrayFillHelper(fixedLengthWithOffset, 2); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 1, + 1, + 2, + 2 + ]); + SendableTypedArrayFillHelper(lengthTracking, 3); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 3, + 3, + 3, + 3 + ]); + SendableTypedArrayFillHelper(lengthTrackingWithOffset, 4); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 3, + 3, + 4, + 4 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => SendableTypedArrayFillHelper(fixedLength, 5)); + assert.throws(TypeError, () => SendableTypedArrayFillHelper(fixedLengthWithOffset, 6)); + + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 3, + 3, + 4 + ]); + SendableTypedArrayFillHelper(lengthTracking, 7); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 7, + 7, + 7 + ]); + SendableTypedArrayFillHelper(lengthTrackingWithOffset, 8); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 7, + 7, + 8 + ]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => SendableTypedArrayFillHelper(fixedLength, 9)); + assert.throws(TypeError, () => SendableTypedArrayFillHelper(fixedLengthWithOffset, 10)); + assert.throws(TypeError, () => SendableTypedArrayFillHelper(lengthTrackingWithOffset, 11)); + + assert.compareArray(ReadDataFromBuffer(rab, ctor), [7]); + SendableTypedArrayFillHelper(lengthTracking, 12); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [12]); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + SendableTypedArrayFillHelper(fixedLength, 13); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 13, + 13, + 13, + 13, + 0, + 0 + ]); + SendableTypedArrayFillHelper(fixedLengthWithOffset, 14); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 13, + 13, + 14, + 14, + 0, + 0 + ]); + SendableTypedArrayFillHelper(lengthTracking, 15); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 15, + 15, + 15, + 15, + 15 + ]); + SendableTypedArrayFillHelper(lengthTrackingWithOffset, 16); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 15, + 16, + 16, + 16, + 16 + ]); + + // Filling with non-undefined start & end. + SendableTypedArrayFillHelper(fixedLength, 17, 1, 3); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 17, + 17, + 16, + 16, + 16 + ]); + SendableTypedArrayFillHelper(fixedLengthWithOffset, 18, 1, 2); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 17, + 17, + 18, + 16, + 16 + ]); + SendableTypedArrayFillHelper(lengthTracking, 19, 1, 3); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 19, + 19, + 18, + 16, + 16 + ]); + SendableTypedArrayFillHelper(lengthTrackingWithOffset, 20, 1, 2); + assert.compareArray(ReadDataFromBuffer(rab, ctor), [ + 15, + 19, + 19, + 20, + 16, + 16 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-end-as-symbol.js b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-end-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..131d48f223e4ef5d0ac7eb1ab8e4615a817137a7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-end-as-symbol.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Return abrupt if end is a Symbol. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var end = Symbol(1); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.fill(1, 0, end); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-end.js b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-end.js new file mode 100644 index 0000000000000000000000000000000000000000..5d4fa5f79d1274cd0128c36296674fc911e3cc3b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-end.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Return abrupt from ToInteger(end). +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var end = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.fill(1, 0, end); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-set-value.js b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-set-value.js new file mode 100644 index 0000000000000000000000000000000000000000..777e60a186f172bfa1f8e2e23b21f11ecc24d1dd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-set-value.js @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Returns abrupt from value set +info: | + %SendableTypedArray%.prototype.fill ( value [ , start [ , end ] ] ) + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If O.[[ContentType]] is BigInt, set value to ? ToBigInt(value). + Otherwise, set value to ? ToNumber(value). + Let relativeStart be ? ToIntegerOrInfinity(start). + If relativeStart is -Infinity, let k be 0. + Else if relativeStart < 0, let k be max(len + relativeStart, 0). + Else, let k be min(relativeStart, len). + If end is undefined, let relativeEnd be len; else let relativeEnd be ? ToIntegerOrInfinity(end). + If relativeEnd is -Infinity, let final be 0. + Else if relativeEnd < 0, let final be max(len + relativeEnd, 0). + Else, let final be min(relativeEnd, len). + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + Repeat, while k < final, + Let Pk be ! ToString(F(k)). + Perform ! Set(O, Pk, value, true). + Set k to k + 1. + Return O. + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + var obj = { + valueOf: function() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample.fill(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-start-as-symbol.js b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-start-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..4c70e3920591a5d0627e68e67c41a374fc95dd84 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-start-as-symbol.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Return abrupt from ToInteger(start) as a Symbol. +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var start = Symbol(1); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.fill(1, start); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-start.js b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-start.js new file mode 100644 index 0000000000000000000000000000000000000000..fd5f49b80f7495d97fc61da57ea7ec55549f48d8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-start.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Return abrupt from ToInteger(start). +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %SendableTypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var start = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.fill(1, start); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..2fa534a5015c8f5d0a5a5cd6737effad511aaead --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.fill, + 'function', + 'implements SendableTypedArray.prototype.fill' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.fill(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.fill(0); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the fill operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.fill(0); + throw new Test262Error('fill completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/return-this.js b/test/sendable/builtins/TypedArray/prototype/fill/return-this.js new file mode 100644 index 0000000000000000000000000000000000000000..873f01f9ce5c95c1524e59a51878bcb63ca45541 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/return-this.js @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Returns `this`. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA(); + var result1 = sample1.fill(1); + + assert.sameValue(result1, sample1); + + var sample2 = new TA(42); + var result2 = sample2.fill(7); + assert.sameValue(result2, sample2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/fill/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..a84696cb76d11f339c0117670e2f859f164c8717 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/this-is-not-object.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var fill = SendableTypedArray.prototype.fill; + +assert.throws(TypeError, function() { + fill.call(undefined, 0); +}, "this is undefined"); + +assert.throws(TypeError, function() { + fill.call(null, 0); +}, "this is null"); + +assert.throws(TypeError, function() { + fill.call(42, 0); +}, "this is 42"); + +assert.throws(TypeError, function() { + fill.call("1", 0); +}, "this is a string"); + +assert.throws(TypeError, function() { + fill.call(true, 0); +}, "this is true"); + +assert.throws(TypeError, function() { + fill.call(false, 0); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + fill.call(s, 0); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/fill/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/fill/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..4b791ccf10050f2afcfe1ea65c3102b0c7742315 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/fill/this-is-not-typedarray-instance.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.fill +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.8 %SendableTypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var fill = SendableTypedArray.prototype.fill; + +assert.throws(TypeError, function() { + fill.call({}, 0); +}, "this is an Object"); + +assert.throws(TypeError, function() { + fill.call([], 0); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + fill.call(ab, 0); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + fill.call(dv, 0); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..ede21fbf08c4d92f5d9ff2e27d00e432de42a4b1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/arraylength-internal.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Uses internal ArrayLength instead of length property +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(4); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.filter(function() { + calls++; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 4, "interactions are not affected by custom length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-with-thisarg.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..43c8811659f49e75ab312d2ed3da2ac2ed9745f3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.filter(function() { + results.push(arguments); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-without-thisarg.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..889f275079adc547d77d0f53753d59e9010d367f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + callbackfn arguments +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.filter(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-ctor.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..7c9aa7fff3cdbd40cecbc2662ba69956ad2e6786 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-ctor.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: callbackfn is called for each item before SendableTypedArraySpeciesCreate +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var length = 42; + var sample = new TA(length); + var calls = 0; + var before = false; + + sample.constructor = {}; + Object.defineProperty(sample, "constructor", { + get: function() { + before = calls === length; + } + }); + + sample.filter(function() { + calls++; + }); + + assert.sameValue(calls, 42, "callbackfn called for each item"); + assert.sameValue(before, true, "all callbackfn called before"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-species.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-species.js new file mode 100644 index 0000000000000000000000000000000000000000..89ac7d5f6097b600afd217ad7e0d520482d29079 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-species.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: callbackfn is called for each item before SendableTypedArraySpeciesCreate +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var length = 42; + var sample = new TA(length); + var calls = 0; + var before = false; + + sample.constructor = {}; + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + before = calls === length; + } + }); + + sample.filter(function() { + calls++; + }); + + assert.sameValue(calls, 42, "callbackfn called for each item"); + assert.sameValue(before, true, "all callbackfn called before"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..570f9115fcfaa97acf9087968ec1c050727ebbc2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + b. Let kValue be ? Get(O, Pk). + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [detachArrayBuffer.js, sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.filter(function() { + var flag = true; + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } else { + flag = false; + } + loops++; + return flag; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-no-iteration-over-non-integer.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-no-iteration-over-non-integer.js new file mode 100644 index 0000000000000000000000000000000000000000..30aee4f5d2da8b3ec18f0b1a2b9b963bde98341f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-no-iteration-over-non-integer.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Does not iterate over non-integer properties +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.filter(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + + assert.sameValue(results[0][0], 7n, "results[0][0] - kValue"); + assert.sameValue(results[1][0], 8n, "results[1][0] - kValue"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..c8e196402fda36787137f82449793e1002b765ec --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-not-callable-throws.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Throws TypeError if callbackfn is not callable +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert.throws(TypeError, function() { + sample.filter(); + }, "no arg"); + + assert.throws(TypeError, function() { + sample.filter(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.filter(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.filter(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.filter(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.filter({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.filter([]); + }, "[]"); + + assert.throws(TypeError, function() { + sample.filter(1); + }, "Number"); + + assert.throws(TypeError, function() { + sample.filter(Symbol("")); + }, "symbol"); + + assert.throws(TypeError, function() { + sample.filter(""); + }, "string"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..9a1db8b8cc7205e151617bf3926b2a9e4ccab3a5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().filter(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..3b4d74898f833f2a354d17e3a38daf153404f204 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + The callbackfn return does not change the instance +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(3); + + sample1[1] = 1n; + + sample1.filter(function() { + return 42; + }); + + assert.sameValue(sample1[0], 0n, "[0] == 0"); + assert.sameValue(sample1[1], 1n, "[1] == 1"); + assert.sameValue(sample1[2], 0n, "[2] == 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..7522678381ca325ab59876f82e9bb87d8303b931 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.filter(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-set-value-during-iteration.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-set-value-during-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..11680d0e49a16cba451ca0ce79c7c92c5c68d750 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-set-value-during-iteration.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.filter(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1n, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7n), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during interaction" + ); + + newVal++; + }); + + assert.sameValue(sample[0], 7n, "changed values after interaction [0] == 7"); + assert.sameValue(sample[1], 1n, "changed values after interaction [1] == 1"); + assert.sameValue(sample[2], 2n, "changed values after interaction [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..c912206fbf5f76708ef2b0ebf6b14392d2fb8764 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/callbackfn-this.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + callbackfn `this` value +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.filter(function() { + results1.push(this); + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.filter(function() { + results2.push(this); + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..12ed1cc9065295f4ccdac1752b8560284793e892 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/result-does-not-share-buffer.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/result-does-not-share-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..086dbf13e86ef94c26db5cd45fbdc3982d1e79f7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/result-does-not-share-buffer.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Return does not share buffer +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + 13. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + var result; + + result = sample.filter(function() { return true; }); + assert.notSameValue(result.buffer, sample.buffer); + + result = sample.filter(function() { return false; }); + assert.notSameValue(result.buffer, sample.buffer); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/result-empty-callbackfn-returns-false.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/result-empty-callbackfn-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..c657bf0732e69f35205acef2763d2b0133824bfa --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/result-empty-callbackfn-returns-false.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Returns empty if every callbackfn returns boolean false +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 12. For each element e of kept + a. Perform ! Set(A, ! ToString(n), e, true). + b. Increment n by 1. + 13. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + [ + false, + "", + 0, + -0, + NaN, + undefined, + null + ].forEach(function(val) { + var result = sample.filter(function() { + return val; + }); + assert.sameValue(result.length, 0, val); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/result-full-callbackfn-returns-true.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/result-full-callbackfn-returns-true.js new file mode 100644 index 0000000000000000000000000000000000000000..dda6b5bca433afecba2796c10be9685ba077e74e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/result-full-callbackfn-returns-true.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Returns full length result if every callbackfn returns boolean false +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 12. For each element e of kept + a. Perform ! Set(A, ! ToString(n), e, true). + b. Increment n by 1. + 13. Return A. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + + [ + true, + 1, + "test262", + Symbol("1"), + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ].forEach(function(val) { + var result = sample.filter(function() { return val; }); + assert(compareArray(result, sample), val); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..c111fe978846fc2b9b59f5b749e9debc5d1e1c33 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.filter, + 'function', + 'implements SendableTypedArray.prototype.filter' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.filter(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.filter(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the filter operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.filter(() => {}); + throw new Test262Error('filter completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-destination-resizable.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-destination-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..44c44ca8c87a49aa382cab46484600c830189495 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-destination-resizable.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Throws a TypeError if new typedArray's length < count +info: | + 23.2.3.10 %SendableTypedArray%.prototype.filter ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const rab1 = new ArrayBuffer(8, {maxByteLength: 100}); + const ta = new TA(rab1); + const rab2 = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab2); + rab2.resize(0); + ta.constructor = { [Symbol.species]: function() { return lengthTracking; } }; + assert.throws(TypeError, function() { + ta.filter(() => true); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-abrupt.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..bc49fc49c0707338f90ec947a3ef98514923e6d5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.filter(function() { + return true; + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-inherited.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000000000000000000000000000000000..a099d9ccab2def2d8ffaaf41023e4ef719475c65 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-inherited.js @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var calls = 0; + var result; + + Object.defineProperty(TA.prototype, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.filter(function() { + return true; + }); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + undefined, + "used defaultCtor but still checks the inherited .constructor" + ); + + calls = 6; + result.constructor; + assert.sameValue( + calls, + 7, + "result.constructor triggers the inherited accessor property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..1e7bf06ebe4eedae2f3e740774a36305503e4659 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var callbackfn = function() { return true; }; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..08101a2dba5c71a8e0f9444a28dde1ebf4e91168 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: get constructor on SpeciesConstructor +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var calls = 0; + var result; + + Object.defineProperty(sample, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.filter(function() { return true; }); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + TA, + "use defaultCtor on an undefined return - .constructor check" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-abrupt.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..2b9aa443b0c3e2c1059dd5007c244447f6fa4ee5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-abrupt.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.filter(function() { return true; }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-invocation.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000000000000000000000000000000000..7b30f556bee1945f10eebd6265ebd70c1d9f5964 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 42n, 42n]); + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + result = arguments; + ctorThis = this; + return new TA(count); + }; + + sample.filter(function(v) { return v === 42n; }); + + assert.sameValue(result.length, 1, "called with 1 argument"); + assert.sameValue(result[0], 2, "[0] is the new captured length"); + + assert( + ctorThis instanceof sample.constructor[Symbol.species], + "`this` value in the @@species fn is an instance of the function itself" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..315ba7414e034cbe9e866734e5f3e89014c97892 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Throws a TypeError if new typedArray's length < count +info: | + 23.2.3.10 %SendableTypedArray%.prototype.filter ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + const rab = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab); + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return lengthTracking; + }; + rab.resize(0); + assert.throws(TypeError, function() { + sample.filter(() => { return true; }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length-throws.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..0634c019202a9424f428f75fb0bd9f03ee1901f0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length-throws.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Throws a TypeError if new typedArray's length < captured +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(); + }; + + assert.throws(TypeError, function() { + sample.filter(function() { return true; }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length.js new file mode 100644 index 0000000000000000000000000000000000000000..4eb36c182eb6417fafe5f317293ba81b16fb7167 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Does not throw a TypeError if new typedArray's length >= captured +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var customCount, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(customCount); + }; + + customCount = 2; + result = sample.filter(function() { return true; }); + assert.sameValue(result.length, customCount, "length == count"); + + customCount = 5; + result = sample.filter(function() { return true; }); + assert.sameValue(result.length, customCount, "length > count"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..9540da808daad5f6ce064f66b913b113578fd26b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Custom @@species constructor may return a different SendableTypedArray +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n]); + var otherTA = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var other = new otherTA([1n, 0n, 1n]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.filter(function() {}); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [1n, 0n, 1n]), "the returned object is preserved"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-throws.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..641135030a130484e0a912a3ff7f332ecee58730 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = Array; + + assert.throws(TypeError, function() { + sample.filter(function() {}); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..bbe6d772567a28d68e8db50115c638ccfa5ee98d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Use custom @@species constructor if available +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + var calls = 0; + var other, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(captured) { + calls++; + other = new TA(captured); + return other; + }; + + result = sample.filter(function() { return true; }); + + assert.sameValue(calls, 1, "ctor called once"); + assert.sameValue(result, other, "return is instance of custom constructor"); + assert(compareArray(result, [40n, 41n, 42n]), "values are set on the new obj"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..750652fe39b0b8d183e5e90a3db0d9492b75e2b1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-returns-throws.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + sample.constructor[Symbol.species] = 0; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "true"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-use-default-ctor.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..5214bce1b90b4c4a9eeef6fd4ef9de68e96074fd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var result; + + sample.constructor = {}; + + result = sample.filter(function() {}); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "undefined @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "undefined @@species - ctor check"); + + sample.constructor[Symbol.species] = null; + result = sample.filter(function() {}); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "null @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "null @@species - ctor check"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species.js new file mode 100644 index 0000000000000000000000000000000000000000..96f9e1e1b824a06076df830c90050a10935871ea --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/speciesctor-get-species.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + get @@species from found constructor +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calls = 0; + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + calls++; + } + }); + + sample.filter(function() {}); + + assert.sameValue(calls, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..d034efa19c47cef64f29a278562f964cc86ce54a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/values-are-not-cached.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Integer indexed values are not cached before interaction +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + sample.filter(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42n; + } + + assert.sameValue( + v, 42n, "method does not cache values before callbackfn calls" + ); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/BigInt/values-are-set.js b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/values-are-set.js new file mode 100644 index 0000000000000000000000000000000000000000..0b46e2136e24dfb31f33c233b29c96ac31e87a65 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/BigInt/values-are-set.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Returned instance with filtered values set on it +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 12. For each element e of kept + a. Perform ! Set(A, ! ToString(n), e, true). + b. Increment n by 1. + 13. Return A. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([41n, 1n, 42n, 7n]); + var result; + + result = sample.filter(function() { return true; }); + assert(compareArray(result, [41n, 1n, 42n, 7n]), "values are set #1"); + + result = sample.filter(function(v) { + return v > 40n; + }); + assert(compareArray(result, [41n, 42n]), "values are set #2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/filter/arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..241be65e5a3b6084baea4ee107515626e7098db1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/arraylength-internal.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Uses internal ArrayLength instead of length property +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(4); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.filter(function() { + calls++; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 4, "interactions are not affected by custom length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-arguments-with-thisarg.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..44659bceb153e27c89b3cdccb99db3e1917dd390 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.filter(function() { + results.push(arguments); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-arguments-without-thisarg.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..a4faf397c97027350665c5a0b908a89bb5f1d0c9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + callbackfn arguments +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + + sample.filter(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-called-before-ctor.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-called-before-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..118ee68cb534a3e7d83b886fa8eb8a7e07996751 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-called-before-ctor.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: callbackfn is called for each item before SendableTypedArraySpeciesCreate +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var length = 42; + var sample = new TA(length); + var calls = 0; + var before = false; + + sample.constructor = {}; + Object.defineProperty(sample, "constructor", { + get: function() { + before = calls === length; + } + }); + + sample.filter(function() { + calls++; + }); + + assert.sameValue(calls, 42, "callbackfn called for each item"); + assert.sameValue(before, true, "all callbackfn called before"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-called-before-species.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-called-before-species.js new file mode 100644 index 0000000000000000000000000000000000000000..ddd10e9ce9c16c11e225b5aac64cbcf5767311a9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-called-before-species.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: callbackfn is called for each item before SendableTypedArraySpeciesCreate +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var length = 42; + var sample = new TA(length); + var calls = 0; + var before = false; + + sample.constructor = {}; + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + before = calls === length; + } + }); + + sample.filter(function() { + calls++; + }); + + assert.sameValue(calls, 42, "callbackfn called for each item"); + assert.sameValue(before, true, "all callbackfn called before"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f97f27710427836104d1bad1f492ec77232f48b3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-detachbuffer.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + b. Let kValue be ? Get(O, Pk). + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [detachArrayBuffer.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.filter(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return true; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-no-iteration-over-non-integer.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-no-iteration-over-non-integer.js new file mode 100644 index 0000000000000000000000000000000000000000..4428c757a279b81f6616d60c84f372a861e39b3d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-no-iteration-over-non-integer.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Does not iterate over non-integer properties +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7, 8]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.filter(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + + assert.sameValue(results[0][0], 7, "results[0][0] - kValue"); + assert.sameValue(results[1][0], 8, "results[1][0] - kValue"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..1a05a4247feb0dcb0590b30110a0c4f70cf7f1c1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-not-callable-throws.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Throws TypeError if callbackfn is not callable +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert.throws(TypeError, function() { + sample.filter(); + }, "no arg"); + + assert.throws(TypeError, function() { + sample.filter(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.filter(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.filter(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.filter(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.filter({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.filter([]); + }, "[]"); + + assert.throws(TypeError, function() { + sample.filter(1); + }, "Number"); + + assert.throws(TypeError, function() { + sample.filter(Symbol("")); + }, "symbol"); + + assert.throws(TypeError, function() { + sample.filter(""); + }, "string"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..f399c71a1092bc2adba3ac8072e3219f0ece2571 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-not-called-on-empty.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().filter(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-resize.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..f8d1db90d5b0f4aa1e17b2a65103a431cb445078 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-resize.js @@ -0,0 +1,89 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Instance buffer can be resized during iteration +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var NaNvalue = isFloatSendableTypedArrayConstructor(TA) ? NaN : 0; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var finalElement, finalResult, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + + elements = []; + indices = []; + arrays = []; + result = sample.filter(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + finalElement = undefined; + finalResult = NaNvalue; + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + finalElement = 0; + finalResult = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return true; + }); + + assert.compareArray(elements, [0, 0, finalElement], 'elements (shrink)'); + assert.compareArray(indices, [0, 1, 2], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.compareArray(result, [0, 0, finalResult], 'result (shrink)'); + + elements = []; + indices = []; + arrays = []; + result = sample.filter(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return true; + }); + + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.compareArray(result, expectedElements, 'result (grow)'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..8fdb5badff0a3e47116130d4d8f419f25936728e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + The callbackfn return does not change the instance +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA(3); + + sample1[1] = 1; + + sample1.filter(function() { + return 42; + }); + + assert.sameValue(sample1[0], 0, "[0] == 0"); + assert.sameValue(sample1[1], 1, "[1] == 1"); + assert.sameValue(sample1[2], 0, "[2] == 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..74bb08f7fedf2b183c98bb168936d447ccd8e044 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-returns-abrupt.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.filter(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-set-value-during-iteration.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-set-value-during-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..c53ae985b10bb9494e2deef9e80026d6f400afbd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-set-value-during-iteration.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [Reflect.set, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + var newVal = 0; + + sample.filter(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during interaction" + ); + + newVal++; + }); + + assert.sameValue(sample[0], 7, "changed values after interaction [0] == 7"); + assert.sameValue(sample[1], 1, "changed values after interaction [1] == 1"); + assert.sameValue(sample[2], 2, "changed values after interaction [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..28021231617f7cb506bb042bd2cde9e50240e0e1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/callbackfn-this.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + callbackfn `this` value +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.filter(function() { + results1.push(this); + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.filter(function() { + results2.push(this); + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/filter/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..d8cbdf3ed15180e46753d98bff0db0e40d66315a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/filter/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..3f9222cf94ed702ad36adfedd5da5810a10dc71f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/invoked-as-func.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var filter = SendableTypedArray.prototype.filter; + +assert.sameValue(typeof filter, 'function'); + +assert.throws(TypeError, function() { + filter(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/filter/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..1b49e0bf04b0a0420383b4814233c541d3ae1a60 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/invoked-as-method.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.filter, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.filter(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/length.js b/test/sendable/builtins/TypedArray/prototype/filter/length.js new file mode 100644 index 0000000000000000000000000000000000000000..489dfd7e0367e9a539a661f9f339249f811c7cc8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + %SendableTypedArray%.prototype.filter.length is 1. +info: | + %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.filter, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/name.js b/test/sendable/builtins/TypedArray/prototype/filter/name.js new file mode 100644 index 0000000000000000000000000000000000000000..d9bd7a41c4f29cabe9634c6744b244a2c5fcd135 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + %SendableTypedArray%.prototype.filter.name is "filter". +info: | + %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.filter, "name", { + value: "filter", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/filter/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..7e91442148be38c50a2ff8031a19bc3dccebe10e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.filter does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.filter), + false, + 'isConstructor(SendableTypedArray.prototype.filter) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.filter(() => {}); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/filter/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/filter/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..c9d0d9652a0248ad00ca6c18877c868a7969a756 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + "filter" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'filter', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/filter/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..06caa6827019a4af27429bdd28e1c16e7d89f839 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + SendableTypedArray.p.filter behaves correctly on SendableTypedArrays backed by resizable + buffers that grow mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(fixedLength.filter(ResizeMidIteration)), []); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(fixedLengthWithOffset.filter(ResizeMidIteration)), []); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(lengthTracking.filter(ResizeMidIteration)), []); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(lengthTrackingWithOffset.filter(ResizeMidIteration)), []); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/filter/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/filter/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..1d31584ab23575f8e3f0d6e5fe82265672412f3d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + SendableTypedArray.p.filter behaves correctly on SendableTypedArrays backed by resizable + buffers that are shrunk mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(fixedLength.filter(ResizeMidIteration)),[]); + assert.compareArray(values, [ + 0, + 2, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(fixedLengthWithOffset.filter(ResizeMidIteration)),[]); + assert.compareArray(values, [ + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(lengthTracking.filter(ResizeMidIteration)),[]); + assert.compareArray(values, [ + 0, + 2, + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.compareArray(ToNumbers(lengthTrackingWithOffset.filter(ResizeMidIteration)),[]); + assert.compareArray(values, [ + 4, + undefined + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/filter/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/filter/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..cb903fc33fededef5f92e7aa2eeb9d7736f078de --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/resizable-buffer.js @@ -0,0 +1,132 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + SendableTypedArray.p.filter behaves correctly on SendableTypedArrays backed by resizable + buffers +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + + // Orig. array: [0, 1, 2, 3] + // [0, 1, 2, 3] << fixedLength + // [2, 3] << fixedLengthWithOffset + // [0, 1, 2, 3, ...] << lengthTracking + // [2, 3, ...] << lengthTrackingWithOffset + + function isEven(n) { + return n != undefined && Number(n) % 2 == 0; + } + assert.compareArray(ToNumbers(fixedLength.filter(isEven)), [ + 0, + 2 + ]); + assert.compareArray(ToNumbers(fixedLengthWithOffset.filter(isEven)), [2]); + assert.compareArray(ToNumbers(lengthTracking.filter(isEven)), [ + 0, + 2 + ]); + assert.compareArray(ToNumbers(lengthTrackingWithOffset.filter(isEven)), [2]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 1, 2] + // [0, 1, 2, ...] << lengthTracking + // [2, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.filter(isEven); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.filter(isEven); + }); + + assert.compareArray(ToNumbers(lengthTracking.filter(isEven)), [ + 0, + 2 + ]); + assert.compareArray(ToNumbers(lengthTrackingWithOffset.filter(isEven)), [2]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.filter(isEven); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.filter(isEven); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.filter(isEven); + }); + + assert.compareArray(ToNumbers(lengthTracking.filter(isEven)), [0]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.filter(isEven); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.filter(isEven); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.filter(isEven); + }); + + assert.compareArray(ToNumbers(lengthTracking.filter(isEven)), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + + // Orig. array: [0, 1, 2, 3, 4, 5] + // [0, 1, 2, 3] << fixedLength + // [2, 3] << fixedLengthWithOffset + // [0, 1, 2, 3, 4, 5, ...] << lengthTracking + // [2, 3, 4, 5, ...] << lengthTrackingWithOffset + + assert.compareArray(ToNumbers(fixedLength.filter(isEven)), [ + 0, + 2 + ]); + assert.compareArray(ToNumbers(fixedLengthWithOffset.filter(isEven)), [2]); + assert.compareArray(ToNumbers(lengthTracking.filter(isEven)), [ + 0, + 2, + 4 + ]); + assert.compareArray(ToNumbers(lengthTrackingWithOffset.filter(isEven)), [ + 2, + 4 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/filter/result-does-not-share-buffer.js b/test/sendable/builtins/TypedArray/prototype/filter/result-does-not-share-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..2a1c1627f1540b8f603d5b047f10b98e505c49d9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/result-does-not-share-buffer.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Return does not share buffer +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + 13. Return A. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42]); + var result; + + result = sample.filter(function() { return true; }); + assert.notSameValue(result.buffer, sample.buffer); + + result = sample.filter(function() { return false; }); + assert.notSameValue(result.buffer, sample.buffer); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/result-empty-callbackfn-returns-false.js b/test/sendable/builtins/TypedArray/prototype/filter/result-empty-callbackfn-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..f78eee3f4f392f05fdcf1593b86c8131bb2500d3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/result-empty-callbackfn-returns-false.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Returns empty if every callbackfn returns boolean false +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 12. For each element e of kept + a. Perform ! Set(A, ! ToString(n), e, true). + b. Increment n by 1. + 13. Return A. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + [ + false, + "", + 0, + -0, + NaN, + undefined, + null + ].forEach(function(val) { + var result = sample.filter(function() { + return val; + }); + assert.sameValue(result.length, 0, val); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/result-full-callbackfn-returns-true.js b/test/sendable/builtins/TypedArray/prototype/filter/result-full-callbackfn-returns-true.js new file mode 100644 index 0000000000000000000000000000000000000000..c310248d08a9698c3cdbdadb79861d1aa2eb0f24 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/result-full-callbackfn-returns-true.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Returns full length result if every callbackfn returns boolean false +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 12. For each element e of kept + a. Perform ! Set(A, ! ToString(n), e, true). + b. Increment n by 1. + 13. Return A. +includes: [sendableTypedArray.js, compareArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42]); + + [ + true, + 1, + "test262", + Symbol("1"), + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ].forEach(function(val) { + var result = sample.filter(function() { return val; }); + assert(compareArray(result, sample), val); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/filter/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..cd22bc57e9c2d71a44a5852c2a043c2b308aa777 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.filter, + 'function', + 'implements SendableTypedArray.prototype.filter' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.filter(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.filter(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the filter operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.filter(() => {}); + throw new Test262Error('filter completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-destination-resizable.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-destination-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..517c7ee86e237b10488274f998777e75f85c0ea6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-destination-resizable.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Throws a TypeError if new typedArray's length < count +info: | + 23.2.3.10 %SendableTypedArray%.prototype.filter ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const rab1 = new ArrayBuffer(8, {maxByteLength: 100}); + const ta = new TA(rab1); + const rab2 = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab2); + rab2.resize(0); + ta.constructor = { [Symbol.species]: function() { return lengthTracking; } }; + assert.throws(TypeError, function() { + ta.filter(() => true); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor-abrupt.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..525f8657d554a375d4be38e8179863e74d7fddba --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.filter(function() { + return true; + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor-inherited.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000000000000000000000000000000000..6ab172c1b2be2b6e2b8e99e85b82c630ddaa7e1c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor-inherited.js @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var calls = 0; + var result; + + Object.defineProperty(TA.prototype, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.filter(function() { + return true; + }); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + undefined, + "used defaultCtor but still checks the inherited .constructor" + ); + + calls = 6; + result.constructor; + assert.sameValue( + calls, + 7, + "result.constructor triggers the inherited accessor property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..b474bfedcef21584b57906c4ba39315f193c20c3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var callbackfn = function() { return true; }; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..45571f94f6996fb610134b9fa9e6093491b53ba1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: get constructor on SpeciesConstructor +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var calls = 0; + var result; + + Object.defineProperty(sample, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.filter(function() { return true; }); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + TA, + "use defaultCtor on an undefined return - .constructor check" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-abrupt.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..ee52d339e43227123bc82c4e45bb9a2f1a7f3485 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-abrupt.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.filter(function() { return true; }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-invocation.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000000000000000000000000000000000..cf16d629adbf2ff6cd0b441457aaaec304ba6958 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 42, 42]); + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + result = arguments; + ctorThis = this; + return new TA(count); + }; + + sample.filter(function(v) { return v === 42; }); + + assert.sameValue(result.length, 1, "called with 1 argument"); + assert.sameValue(result[0], 2, "[0] is the new captured length"); + + assert( + ctorThis instanceof sample.constructor[Symbol.species], + "`this` value in the @@species fn is an instance of the function itself" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..470b354f9345204a6ef324b86d6ade927fac2786 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Throws a TypeError if new typedArray's length < count +info: | + 23.2.3.10 %SendableTypedArray%.prototype.filter ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + const rab = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab); + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return lengthTracking; + }; + rab.resize(0); + assert.throws(TypeError, function() { + sample.filter(() => { return true; }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-length-throws.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..2683593057e16ac5c20bd21a6d6f3faa8e828d12 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-length-throws.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Throws a TypeError if new typedArray's length < captured +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(); + }; + + assert.throws(TypeError, function() { + sample.filter(function() { return true; }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-length.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-length.js new file mode 100644 index 0000000000000000000000000000000000000000..c6a5e9ea56b31edd74f2ec9b594c1457e0c9aeed --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-length.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Does not throw a TypeError if new typedArray's length >= captured +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var customCount, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(customCount); + }; + + customCount = 2; + result = sample.filter(function() { return true; }); + assert.sameValue(result.length, customCount, "length == count"); + + customCount = 5; + result = sample.filter(function() { return true; }); + assert.sameValue(result.length, customCount, "length > count"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-returns-another-instance.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..ab86d1f64d52744b85ad85f5855f40c5366cceb8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Custom @@species constructor may return a different SendableTypedArray +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js, compareArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40]); + var otherTA = TA === Int8Array ? Int16Array : Int8Array; + var other = new otherTA([1, 0, 1]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.filter(function() {}); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [1, 0, 1]), "the returned object is preserved"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-throws.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9564074f9632c84e0402b453cbd050a1752178f6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = Array; + + assert.throws(TypeError, function() { + sample.filter(function() {}); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..4146547d31917c90e7f182a25c4b689f3c16e620 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Use custom @@species constructor if available +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js, compareArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42]); + var calls = 0; + var other, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(captured) { + calls++; + other = new TA(captured); + return other; + }; + + result = sample.filter(function() { return true; }); + + assert.sameValue(calls, 1, "ctor called once"); + assert.sameValue(result, other, "return is instance of custom constructor"); + assert(compareArray(result, [40, 41, 42]), "values are set on the new obj"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..eeb1f3220f3025f219a546887e0798ef02990c5e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-returns-throws.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + sample.constructor[Symbol.species] = 0; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "true"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-use-default-ctor.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..3b6cbe5436b0402ed4f7959b7c4505ac293e0611 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var result; + + sample.constructor = {}; + + result = sample.filter(function() {}); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "undefined @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "undefined @@species - ctor check"); + + sample.constructor[Symbol.species] = null; + result = sample.filter(function() {}); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "null @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "null @@species - ctor check"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species.js b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species.js new file mode 100644 index 0000000000000000000000000000000000000000..9cc1acc15c01804b482bcaea619c67eb4642452e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/speciesctor-get-species.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + get @@species from found constructor +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? SendableTypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calls = 0; + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + calls++; + } + }); + + sample.filter(function() {}); + + assert.sameValue(calls, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/filter/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..9be3a35cc3c3950174d7858f191922c48bacb6df --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/this-is-not-object.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var filter = SendableTypedArray.prototype.filter; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + filter.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + filter.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + filter.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + filter.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + filter.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + filter.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + filter.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/filter/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..73e2a0a8ccc58d8e12bd3e804d11140dc5456054 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/this-is-not-typedarray-instance.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var filter = SendableTypedArray.prototype.filter; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + filter.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + filter.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + filter.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + filter.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/filter/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..f90d28eade26d0f3430d1574e36083dc7a58e966 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/values-are-not-cached.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Integer indexed values are not cached before interaction +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + sample.filter(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42; + } + + assert.sameValue( + v, 42, "method does not cache values before callbackfn calls" + ); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/filter/values-are-set.js b/test/sendable/builtins/TypedArray/prototype/filter/values-are-set.js new file mode 100644 index 0000000000000000000000000000000000000000..ec96f5dce971a715c63fca1cf4426840a5f853a9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/filter/values-are-set.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.filter +description: > + Returned instance with filtered values set on it +info: | + 22.2.3.9 %SendableTypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 12. For each element e of kept + a. Perform ! Set(A, ! ToString(n), e, true). + b. Increment n by 1. + 13. Return A. +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([41, 1, 42, 7]); + var result; + + result = sample.filter(function() { return true; }); + assert(compareArray(result, [41, 1, 42, 7]), "values are set #1"); + + result = sample.filter(function(v) { + return v > 40; + }); + assert(compareArray(result, [41, 42]), "values are set #2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9f7692d1d51effbe21dbe116183c876314bba772 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.find(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..784263067ed04606ae8bdf51961269e299bba4ac --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/get-length-ignores-length-prop.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + [[Get]] of "length" uses [[ArrayLength]] +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([42n]); + + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true + }); + + assert.sameValue( + sample.find(function() { return true; }), + 42n + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-changes-value.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-changes-value.js new file mode 100644 index 0000000000000000000000000000000000000000..5f02d662402cefaaf86bdf73091604a3ba7be715 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-changes-value.js @@ -0,0 +1,91 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Change values during predicate call +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var arr = [1n, 2n, 3n]; + var sample; + var result; + + sample = new TA(3); + sample.find(function(val, i) { + sample[i] = arr[i]; + + assert.sameValue(val, 0n, "value is not mapped to instance"); + }); + assert(compareArray(sample, arr), "values set during each predicate call"); + + sample = new TA(arr); + result = sample.find(function(val, i) { + if ( i === 0 ) { + sample[2] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, 7n, "value found"); + + sample = new TA(arr); + result = sample.find(function(val, i) { + if ( i === 0 ) { + sample[2] = 7n; + } + return val === 3n; + }); + assert.sameValue(result, undefined, "value not found"); + + sample = new TA(arr); + result = sample.find(function(val, i) { + if ( i > 0 ) { + sample[0] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, undefined, "value not found - changed after call"); + + sample = new TA(arr); + result = sample.find(function() { + sample[0] = 7n; + return true; + }); + assert.sameValue(result, 1n, "find() returns previous found value"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-parameters.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..8dafd4ece5d8698373f4210edec5394046b5c7c6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-parameters.js @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([39n, 2n, 62n]); + var results = []; + var result; + + sample.foo = "bar"; // Ignores non integer index properties + + sample.find(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "predicate is called for each index"); + + result = results[0]; + assert.sameValue(result[0], 39n, "results[0][0] === 39, value"); + assert.sameValue(result[1], 0, "results[0][1] === 0, index"); + assert.sameValue(result[2], sample, "results[0][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[0].length === 3 arguments"); + + result = results[1]; + assert.sameValue(result[0], 2n, "results[1][0] === 2, value"); + assert.sameValue(result[1], 1, "results[1][1] === 1, index"); + assert.sameValue(result[2], sample, "results[1][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[1].length === 3 arguments"); + + result = results[2]; + assert.sameValue(result[0], 62n, "results[2][0] === 62, value"); + assert.sameValue(result[1], 2, "results[2][1] === 2, index"); + assert.sameValue(result[2], sample, "results[2][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[2].length === 3 arguments"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-this-non-strict.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..6a95abd387f68cdaf1dbf192af8994cba0847547 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-this-non-strict.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Verify predicate this on non-strict mode +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var T = this; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.find(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.find(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.find(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-this-strict.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..3bb6873eeaeacf48e01c12297818485b25d48474 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-call-this-strict.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Verify predicate this on strict mode +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.find(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.find(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9bfa6dc579b40e868afc9c4098efa6f1571a5e62 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-is-not-callable-throws.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Throws a TypeError exception if predicate is not callable. +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 3. If IsCallable(predicate) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.find({}); + }, "object"); + + assert.throws(TypeError, function() { + sample.find(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.find(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.find(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.find(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.find(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.find(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.find([]); + }, "array"); + + assert.throws(TypeError, function() { + sample.find(/./); + }, "regexp"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f997d4f91ca46edab256ef4f29e77b7b4db47a48 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Predicate may detach the buffer +info: | + %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 + + ... + + However, such optimization must not introduce any observable changes in the + specified behaviour of the algorithm and must take into account the + possibility that calls to predicate may cause the this value to become + detached. + + + Array.prototype.find ( predicate[ , thisArg ] ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfArrayLike(O). + If IsCallable(predicate) is false, throw a TypeError exception. + Let k be 0. + Repeat, while k < len, + Let Pk be ! ToString(𝔽(k)). + Let kValue be ? Get(O, Pk). + Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + If testResult is true, return kValue. + Set k to k + 1. + Return undefined. + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.find(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-not-called-on-empty-array.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..15c7834e2b602011d37f9e18aece2f7be4ea2ae5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/predicate-not-called-on-empty-array.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Predicate is not called on empty instances +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + var called = false; + + var result = sample.find(function() { + called = true; + return true; + }); + + assert.sameValue( + called, + false, + "empty instance does not call predicate" + ); + assert.sameValue( + result, + undefined, + "find returns undefined when predicate is not called" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-abrupt-from-predicate-call.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..27019a22fee97e3d891dff39d29d15c6d8e4c99a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-abrupt-from-predicate-call.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Return abrupt from predicate call. +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + var predicate = function() { + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + sample.find(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..8b0787579deba762acda29029e935d954d0e64e8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.find, + 'function', + 'implements SendableTypedArray.prototype.find' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.find(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.find(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the find operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.find(() => {}); + throw new Test262Error('find completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-found-value-predicate-result-is-true.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-found-value-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..b037e77d1a700146be4cd8b2dd4d7def305cf270 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-found-value-predicate-result-is-true.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Return found value if predicate return a boolean true value. +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + d. If testResult is true, return kValue. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([39n, 2n, 62n]); + var called, result; + + called = 0; + result = sample.find(function() { + called++; + return true; + }); + assert.sameValue(result, 39n, "returned true on sample[0]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.find(function(val) { + called++; + return val === 62n; + }); + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 62n, "returned true on sample[3]"); + + result = sample.find(function() { return "string"; }); + assert.sameValue(result, 39n, "ToBoolean(string)"); + + result = sample.find(function() { return {}; }); + assert.sameValue(result, 39n, "ToBoolean(object)"); + + result = sample.find(function() { return Symbol(""); }); + assert.sameValue(result, 39n, "ToBoolean(symbol)"); + + result = sample.find(function() { return 1; }); + assert.sameValue(result, 39n, "ToBoolean(number)"); + + result = sample.find(function() { return -1; }); + assert.sameValue(result, 39n, "ToBoolean(negative number)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-undefined-if-predicate-returns-false-value.js b/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-undefined-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..a67c918a52bc3eee09ae26bed61278dc1acefbd4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/BigInt/return-undefined-if-predicate-returns-false-value.js @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Return undefined if predicate always returns a boolean false value. +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + 7. Return undefined. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + var called = 0; + + var result = sample.find(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, undefined); + + result = sample.find(function() { return ""; }); + assert.sameValue(result, undefined, "ToBoolean(empty string)"); + + result = sample.find(function() { return undefined; }); + assert.sameValue(result, undefined, "ToBoolean(undefined)"); + + result = sample.find(function() { return null; }); + assert.sameValue(result, undefined, "ToBoolean(null)"); + + result = sample.find(function() { return 0; }); + assert.sameValue(result, undefined, "ToBoolean(0)"); + + result = sample.find(function() { return -0; }); + assert.sameValue(result, undefined, "ToBoolean(-0)"); + + result = sample.find(function() { return NaN; }); + assert.sameValue(result, undefined, "ToBoolean(NaN)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/callbackfn-resize.js b/test/sendable/builtins/TypedArray/prototype/find/callbackfn-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..35a92bb89d375d57e2d3c16f0659f31347b5e49f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/callbackfn-resize.js @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: Instance buffer can be resized during iteration +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var finalElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + + elements = []; + indices = []; + arrays = []; + result = sample.find(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + finalElement = undefined; + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + finalElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + + assert.compareArray(elements, [0, 0, finalElement], 'elements (shrink)'); + assert.compareArray(indices, [0, 1, 2], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, undefined, 'result (shrink)'); + + elements = []; + indices = []; + arrays = []; + result = sample.find(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, undefined, 'result (grow)'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/find/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..b8e3aca0583ada3d6f3c7cb9f7accccc4d79ca40 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.find(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/find/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..88ed702fcab22659b8230ea7d6b72229add75592 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/get-length-ignores-length-prop.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + [[Get]] of "length" uses [[ArrayLength]] +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([42]); + + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true + }); + + assert.sameValue( + sample.find(function() { return true; }), + 42 + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/find/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..7ec03a6a0ee5917e67591172cfdf51b1c91e7e0a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var find = SendableTypedArray.prototype.find; + +assert.sameValue(typeof find, 'function'); + +assert.throws(TypeError, function() { + find(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/find/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..5079ffa3cd81616da7b3b90f340a50ada2da9bd8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.find, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.find(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/length.js b/test/sendable/builtins/TypedArray/prototype/find/length.js new file mode 100644 index 0000000000000000000000000000000000000000..c7bddbe6fac9e864fe1ab9d1dd3f4e37093ff563 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + %SendableTypedArray%.prototype.find.length is 1. +info: | + %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.find, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/name.js b/test/sendable/builtins/TypedArray/prototype/find/name.js new file mode 100644 index 0000000000000000000000000000000000000000..ca92e3251cf5b3da22b6d821ca8e2cf897015e61 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + %SendableTypedArray%.prototype.find.name is "find". +info: | + %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.find, "name", { + value: "find", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/find/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..81099b2e14fbd6b5dfdecd7c0e9b8d1c6b346859 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.find does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.find), + false, + 'isConstructor(SendableTypedArray.prototype.find) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.find(() => {}); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/find/predicate-call-changes-value.js b/test/sendable/builtins/TypedArray/prototype/find/predicate-call-changes-value.js new file mode 100644 index 0000000000000000000000000000000000000000..cceca867509a1a53c7b8dca5713a067baed5b956 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/predicate-call-changes-value.js @@ -0,0 +1,91 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Change values during predicate call +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var arr = [1, 2, 3]; + var sample; + var result; + + sample = new TA(3); + sample.find(function(val, i) { + sample[i] = arr[i]; + + assert.sameValue(val, 0, "value is not mapped to instance"); + }); + assert(compareArray(sample, arr), "values set during each predicate call"); + + sample = new TA(arr); + result = sample.find(function(val, i) { + if ( i === 0 ) { + sample[2] = 7; + } + return val === 7; + }); + assert.sameValue(result, 7, "value found"); + + sample = new TA(arr); + result = sample.find(function(val, i) { + if ( i === 0 ) { + sample[2] = 7; + } + return val === 3; + }); + assert.sameValue(result, undefined, "value not found"); + + sample = new TA(arr); + result = sample.find(function(val, i) { + if ( i > 0 ) { + sample[0] = 7; + } + return val === 7; + }); + assert.sameValue(result, undefined, "value not found - changed after call"); + + sample = new TA(arr); + result = sample.find(function() { + sample[0] = 7; + return true; + }); + assert.sameValue(result, 1, "find() returns previous found value"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/predicate-call-parameters.js b/test/sendable/builtins/TypedArray/prototype/find/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..3088b5f9b3151e3bcdea8219b185ef9046c75a86 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/predicate-call-parameters.js @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([39, 2, 62]); + var results = []; + var result; + + sample.foo = "bar"; // Ignores non integer index properties + + sample.find(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "predicate is called for each index"); + + result = results[0]; + assert.sameValue(result[0], 39, "results[0][0] === 39, value"); + assert.sameValue(result[1], 0, "results[0][1] === 0, index"); + assert.sameValue(result[2], sample, "results[0][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[0].length === 3 arguments"); + + result = results[1]; + assert.sameValue(result[0], 2, "results[1][0] === 2, value"); + assert.sameValue(result[1], 1, "results[1][1] === 1, index"); + assert.sameValue(result[2], sample, "results[1][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[1].length === 3 arguments"); + + result = results[2]; + assert.sameValue(result[0], 62, "results[2][0] === 62, value"); + assert.sameValue(result[1], 2, "results[2][1] === 2, index"); + assert.sameValue(result[2], sample, "results[2][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[2].length === 3 arguments"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/predicate-call-this-non-strict.js b/test/sendable/builtins/TypedArray/prototype/find/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..670f1a1949b1d34c476e78104e0ee9ca9ad9ba88 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/predicate-call-this-non-strict.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Verify predicate this on non-strict mode +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [noStrict] +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var T = this; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.find(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.find(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.find(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/predicate-call-this-strict.js b/test/sendable/builtins/TypedArray/prototype/find/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..e6a89e1ce4f3ec4403ab3d00ace47835c2f9cbad --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/predicate-call-this-strict.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Verify predicate this on strict mode +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [onlyStrict] +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.find(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.find(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/predicate-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/find/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..5f11447d6ba8803b8844a5aee609821bd6b2459e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/predicate-is-not-callable-throws.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Throws a TypeError exception if predicate is not callable. +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 3. If IsCallable(predicate) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.find({}); + }, "object"); + + assert.throws(TypeError, function() { + sample.find(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.find(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.find(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.find(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.find(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.find(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.find([]); + }, "array"); + + assert.throws(TypeError, function() { + sample.find(/./); + }, "regexp"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/predicate-may-detach-buffer.js b/test/sendable/builtins/TypedArray/prototype/find/predicate-may-detach-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..d57f276b56d87589f9ddca78b9ec19a7d2abcc64 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/predicate-may-detach-buffer.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Predicate may detach the buffer +info: | + %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 + + ... + + However, such optimization must not introduce any observable changes in the + specified behaviour of the algorithm and must take into account the + possibility that calls to predicate may cause the this value to become + detached. + + + Array.prototype.find ( predicate[ , thisArg ] ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfArrayLike(O). + If IsCallable(predicate) is false, throw a TypeError exception. + Let k be 0. + Repeat, while k < len, + Let Pk be ! ToString(F(k)). + Let kValue be ? Get(O, Pk). + Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, F(k), O »)). + If testResult is true, return kValue. + Set k to k + 1. + Return undefined. + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.find(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/predicate-not-called-on-empty-array.js b/test/sendable/builtins/TypedArray/prototype/find/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..b096aa95309d0c94d455052840e366fd84ff9d03 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/predicate-not-called-on-empty-array.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Predicate is not called on empty instances +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var called = false; + + var result = sample.find(function() { + called = true; + return true; + }); + + assert.sameValue( + called, + false, + "empty instance does not call predicate" + ); + assert.sameValue( + result, + undefined, + "find returns undefined when predicate is not called" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/find/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..c3988d4de970d710a9cfbaafbda188270521695e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + "find" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'find', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/find/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..4d9154decb059de6e4da59635c9fee20e9bad7ac --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + SendableTypedArray.p.find behaves correctly when receiver is backed by resizable + buffer that is grown mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLength.find(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLengthWithOffset.find(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTracking.find(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTrackingWithOffset.find(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/find/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/find/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..f0b2926bb917ba6a3e8c7ccd31b81e4bf002cae5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,97 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + SendableTypedArray.p.find behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLength.find(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 0, + 2, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLengthWithOffset.find(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTracking.find(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 0, + 2, + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTrackingWithOffset.find(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 4, + undefined + ]); +} + diff --git a/test/sendable/builtins/TypedArray/prototype/find/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/find/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..5942f42171909615f306168ad8433ff5e4bbb8a0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/resizable-buffer.js @@ -0,0 +1,115 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + SendableTypedArray.p.find behaves correctly when receiver is backed by resizable + buffer +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function isTwoOrFour(n) { + return n == 2 || n == 4; + } + assert.sameValue(Number(fixedLength.find(isTwoOrFour)), 2); + assert.sameValue(Number(fixedLengthWithOffset.find(isTwoOrFour)), 4); + assert.sameValue(Number(lengthTracking.find(isTwoOrFour)), 2); + assert.sameValue(Number(lengthTrackingWithOffset.find(isTwoOrFour)), 4); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.find(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.find(isTwoOrFour); + }); + + assert.sameValue(Number(lengthTracking.find(isTwoOrFour)), 2); + assert.sameValue(Number(lengthTrackingWithOffset.find(isTwoOrFour)), 4); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.find(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.find(isTwoOrFour); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.find(isTwoOrFour); + }); + + assert.sameValue(lengthTracking.find(isTwoOrFour), undefined); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.find(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.find(isTwoOrFour); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.find(isTwoOrFour); + }); + + assert.sameValue(lengthTracking.find(isTwoOrFour), undefined); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 0); + } + taWrite[4] = MayNeedBigInt(taWrite, 2); + taWrite[5] = MayNeedBigInt(taWrite, 4); + + // Orig. array: [0, 0, 0, 0, 2, 4] + // [0, 0, 0, 0] << fixedLength + // [0, 0] << fixedLengthWithOffset + // [0, 0, 0, 0, 2, 4, ...] << lengthTracking + // [0, 0, 2, 4, ...] << lengthTrackingWithOffset + + assert.sameValue(fixedLength.find(isTwoOrFour), undefined); + assert.sameValue(fixedLengthWithOffset.find(isTwoOrFour), undefined); + assert.sameValue(Number(lengthTracking.find(isTwoOrFour)), 2); + assert.sameValue(Number(lengthTrackingWithOffset.find(isTwoOrFour)), 2); +} diff --git a/test/sendable/builtins/TypedArray/prototype/find/return-abrupt-from-predicate-call.js b/test/sendable/builtins/TypedArray/prototype/find/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..6690a27addc25d5be93696c52ba96be5fb2137b6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/return-abrupt-from-predicate-call.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Return abrupt from predicate call. +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + var predicate = function() { + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + sample.find(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/find/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..a046d86a0b3fe661c0dd6a72fd42917fbd50db66 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.find, + 'function', + 'implements SendableTypedArray.prototype.find' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.find(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.find(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the find operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.find(() => {}); + throw new Test262Error('find completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/return-found-value-predicate-result-is-true.js b/test/sendable/builtins/TypedArray/prototype/find/return-found-value-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..1aa11bdba8d39a5059649f0008378a4cefc4602f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/return-found-value-predicate-result-is-true.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Return found value if predicate return a boolean true value. +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + d. If testResult is true, return kValue. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([39, 2, 62]); + var called, result; + + called = 0; + result = sample.find(function() { + called++; + return true; + }); + assert.sameValue(result, 39, "returned true on sample[0]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.find(function(val) { + called++; + return val === 62; + }); + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 62, "returned true on sample[3]"); + + result = sample.find(function() { return "string"; }); + assert.sameValue(result, 39, "ToBoolean(string)"); + + result = sample.find(function() { return {}; }); + assert.sameValue(result, 39, "ToBoolean(object)"); + + result = sample.find(function() { return Symbol(""); }); + assert.sameValue(result, 39, "ToBoolean(symbol)"); + + result = sample.find(function() { return 1; }); + assert.sameValue(result, 39, "ToBoolean(number)"); + + result = sample.find(function() { return -1; }); + assert.sameValue(result, 39, "ToBoolean(negative number)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/return-undefined-if-predicate-returns-false-value.js b/test/sendable/builtins/TypedArray/prototype/find/return-undefined-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..3f1aaff92ea3e2bed3d124aa4dd5d129b184a384 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/return-undefined-if-predicate-returns-false-value.js @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Return undefined if predicate always returns a boolean false value. +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + 7. Return undefined. +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + var called = 0; + + var result = sample.find(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, undefined); + + result = sample.find(function() { return ""; }); + assert.sameValue(result, undefined, "ToBoolean(empty string)"); + + result = sample.find(function() { return undefined; }); + assert.sameValue(result, undefined, "ToBoolean(undefined)"); + + result = sample.find(function() { return null; }); + assert.sameValue(result, undefined, "ToBoolean(null)"); + + result = sample.find(function() { return 0; }); + assert.sameValue(result, undefined, "ToBoolean(0)"); + + result = sample.find(function() { return -0; }); + assert.sameValue(result, undefined, "ToBoolean(-0)"); + + result = sample.find(function() { return NaN; }); + assert.sameValue(result, undefined, "ToBoolean(NaN)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/find/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/find/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..261752b71d44474b08699cfbe1f6e762865ae015 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/this-is-not-object.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var find = SendableTypedArray.prototype.find; +var predicate = function() {}; + +assert.throws(TypeError, function() { + find.call(undefined, predicate); +}, "this is undefined"); + +assert.throws(TypeError, function() { + find.call(null, predicate); +}, "this is null"); + +assert.throws(TypeError, function() { + find.call(42, predicate); +}, "this is 42"); + +assert.throws(TypeError, function() { + find.call("1", predicate); +}, "this is a string"); + +assert.throws(TypeError, function() { + find.call(true, predicate); +}, "this is true"); + +assert.throws(TypeError, function() { + find.call(false, predicate); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + find.call(s, predicate); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/find/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/find/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..b4d3d243eb43e11bbc6ee12957597040af62f81f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/find/this-is-not-typedarray-instance.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.find +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.10 %SendableTypedArray%.prototype.find (predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var find = SendableTypedArray.prototype.find; +var predicate = function() {}; + +assert.throws(TypeError, function() { + find.call({}, predicate); +}, "this is an Object"); + +assert.throws(TypeError, function() { + find.call([], predicate); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + find.call(ab, predicate); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + find.call(dv, predicate); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..e25bc0e87d13b2e07158cd50e6bc03a51cd78662 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.findIndex(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..3916a9634b0e9a3d65240e8ff36976cdaedae17e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/get-length-ignores-length-prop.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + [[Get]] of "length" uses [[ArrayLength]] +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([42n]); + + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true + }); + + assert.sameValue( + sample.findIndex(function() { return true; }), + 0 + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-changes-value.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-changes-value.js new file mode 100644 index 0000000000000000000000000000000000000000..94dcb2df541ada9b34708e5d6997db002b8c5ae6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-changes-value.js @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Change values during predicate call +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var arr = [10n, 20n, 30n]; + var sample; + var result; + + sample = new TA(3); + sample.findIndex(function(val, i) { + sample[i] = arr[i]; + + assert.sameValue(val, 0n, "value is not mapped to instance"); + }); + assert(compareArray(sample, arr), "values set during each predicate call"); + + sample = new TA(arr); + result = sample.findIndex(function(val, i) { + if ( i === 0 ) { + sample[2] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, 2, "value found"); + + sample = new TA(arr); + result = sample.findIndex(function(val, i) { + if ( i === 0 ) { + sample[2] = 7n; + } + return val === 30n; + }); + assert.sameValue(result, -1, "value not found"); + + sample = new TA(arr); + result = sample.findIndex(function(val, i) { + if ( i > 0 ) { + sample[0] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, -1, "value not found - changed after call"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-parameters.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..d60183624ba53ccb0bcb497f9b286b69926b98db --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-parameters.js @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([39n, 2n, 62n]); + var results = []; + var result; + + sample.foo = "bar"; // Ignores non integer index properties + + sample.findIndex(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "predicate is called for each index"); + + result = results[0]; + assert.sameValue(result[0], 39n, "results[0][0] === 39, value"); + assert.sameValue(result[1], 0, "results[0][1] === 0, index"); + assert.sameValue(result[2], sample, "results[0][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[0].length === 3, arguments"); + + result = results[1]; + assert.sameValue(result[0], 2n, "results[1][0] === 2, value"); + assert.sameValue(result[1], 1, "results[1][1] === 1, index"); + assert.sameValue(result[2], sample, "results[1][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[1].length === 3, arguments"); + + result = results[2]; + assert.sameValue(result[0], 62n, "results[2][0] === 62, value"); + assert.sameValue(result[1], 2, "results[2][1] === 2, index"); + assert.sameValue(result[2], sample, "results[2][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[2].length === 3, arguments"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-non-strict.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..b2dfa5c504b41e78e41ae3395fd031269905204d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-non-strict.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Verify predicate this on non-strict mode +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [noStrict] +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var T = this; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findIndex(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.findIndex(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.findIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-strict.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..87f43cb329de55d598b802aab94fedb799b9463b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-strict.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findIndex(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.findIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9c7dd86f0985101bbdae4df25861e38436c5e17d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-is-not-callable-throws.js @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Throws a TypeError exception if predicate is not callable. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 3. If IsCallable(predicate) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.findIndex({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.findIndex(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.findIndex(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.findIndex(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.findIndex(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.findIndex(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.findIndex(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.findIndex([]); + }, "[]"); + + assert.throws(TypeError, function() { + sample.findIndex(/./); + }, "/./"); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-may-detach-buffer.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-may-detach-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f58ac3841bb2123ac9a4d346e685f15fe344b137 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-may-detach-buffer.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Predicate may detach the buffer +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + b. Let kValue be ? Get(O, Pk). + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var loops = 0; + + sample.findIndex(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + assert.sameValue(loops, 2, "predicate is called once"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-not-called-on-empty-array.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..e6640ba4681e49a5e82a2d922d5f71a52811b963 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/predicate-not-called-on-empty-array.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Predicate is not called on an empty instance +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + 7. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + var called = false; + + var predicate = function() { + called = true; + return true; + }; + + var result = sample.findIndex(predicate); + + assert.sameValue( + called, false, + "does not call predicate" + ); + assert.sameValue( + result, -1, + "returns -1 on an empty instance" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-predicate-call.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..06eb505ab24145eff620d3f9f852fea325ebccc4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-predicate-call.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Return abrupt from predicate call. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + assert.throws(Test262Error, function() { + sample.findIndex(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..983a7531dcc5141294b5579bb7ba8daa3d7a228a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.findIndex, + 'function', + 'implements SendableTypedArray.prototype.findIndex' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.findIndex(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.findIndex(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the findIndex operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.findIndex(() => {}); + throw new Test262Error('findIndex completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-index-predicate-result-is-true.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-index-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..c7d3c3f991aa82d70a2d4c965b88a241e723f7b7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-index-predicate-result-is-true.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Return index if predicate return a boolean true value. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + d. If testResult is true, return k. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([39n, 3n, 9n]); + var called = 0; + + var result = sample.findIndex(function() { + called++; + return true; + }); + + assert.sameValue(result, 0, "returned true on sample[0]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.findIndex(function(val) { + called++; + return val === 9n; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 2, "returned true on sample[3]"); + + result = sample.findIndex(function() { return "string"; }); + assert.sameValue(result, 0, "ToBoolean(string)"); + + result = sample.findIndex(function() { return {}; }); + assert.sameValue(result, 0, "ToBoolean(object)"); + + result = sample.findIndex(function() { return Symbol(""); }); + assert.sameValue(result, 0, "ToBoolean(symbol)"); + + result = sample.findIndex(function() { return 1; }); + assert.sameValue(result, 0, "ToBoolean(number)"); + + result = sample.findIndex(function() { return -1; }); + assert.sameValue(result, 0, "ToBoolean(negative number)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..e361c7fae7789eae0e41afae2fd2b5daeefc1069 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Return -1 if predicate always returns a boolean false value. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + 7. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 3n]); + var called = 0; + + var result = sample.findIndex(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, -1, "result is -1 when predicate returns are false"); + + result = sample.findIndex(function() { return ""; }); + assert.sameValue(result, -1, "ToBoolean(string)"); + + result = sample.findIndex(function() { return undefined; }); + assert.sameValue(result, -1, "ToBoolean(undefined)"); + + result = sample.findIndex(function() { return null; }); + assert.sameValue(result, -1, "ToBoolean(null)"); + + result = sample.findIndex(function() { return 0; }); + assert.sameValue(result, -1, "ToBoolean(0)"); + + result = sample.findIndex(function() { return -0; }); + assert.sameValue(result, -1, "ToBoolean(-0)"); + + result = sample.findIndex(function() { return NaN; }); + assert.sameValue(result, -1, "ToBoolean(NaN)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/callbackfn-resize.js b/test/sendable/builtins/TypedArray/prototype/findIndex/callbackfn-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..9ac34d40f2b0890af207ae9b01801ae60429576c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/callbackfn-resize.js @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: Instance buffer can be resized during iteration +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var finalElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + + elements = []; + indices = []; + arrays = []; + result = sample.findIndex(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + finalElement = undefined; + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + finalElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + + assert.compareArray(elements, [0, 0, finalElement], 'elements (shrink)'); + assert.compareArray(indices, [0, 1, 2], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, -1, 'result (shrink)'); + + elements = []; + indices = []; + arrays = []; + result = sample.findIndex(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, -1, 'result (grow)'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/findIndex/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..4ba4a33f604f3adbd95f17c5a8f705f0c8dc60f2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.findIndex(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/findIndex/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..446683bf9486313098690ea5074569d1def94513 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/get-length-ignores-length-prop.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + [[Get]] of "length" uses [[ArrayLength]] +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([42]); + + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true + }); + + assert.sameValue( + sample.findIndex(function() { return true; }), + 0 + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/findIndex/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..2a3ea2f351b11a95e7179b58c2dc3ff046e08d3d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var findIndex = SendableTypedArray.prototype.findIndex; + +assert.sameValue(typeof findIndex, 'function'); + +assert.throws(TypeError, function() { + findIndex(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/findIndex/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..10575592ddbd6914f53f39aafbd78cfed6f08805 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.findIndex, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.findIndex(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/length.js b/test/sendable/builtins/TypedArray/prototype/findIndex/length.js new file mode 100644 index 0000000000000000000000000000000000000000..6d9ce26a2fffb63fc69f0a885450d3220eb79fd3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + %SendableTypedArray%.prototype.findIndex.length is 1. +info: | + %SendableTypedArray%.prototype.findIndex (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.findIndex, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/name.js b/test/sendable/builtins/TypedArray/prototype/findIndex/name.js new file mode 100644 index 0000000000000000000000000000000000000000..1e6ffbdf88d261e8411548a15e76fc86856c6359 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + %SendableTypedArray%.prototype.findIndex.name is "findIndex". +info: | + %SendableTypedArray%.prototype.findIndex (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.findIndex, "name", { + value: "findIndex", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/findIndex/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..38eba87f4c35a5ef4ad7bb3be51a95f8a83d0ded --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.findIndex does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.findIndex), + false, + 'isConstructor(SendableTypedArray.prototype.findIndex) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.findIndex(() => {}); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-changes-value.js b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-changes-value.js new file mode 100644 index 0000000000000000000000000000000000000000..816ebfef901760af5761793748d5659ad352b85d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-changes-value.js @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Change values during predicate call +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var arr = [10, 20, 30]; + var sample; + var result; + + sample = new TA(3); + sample.findIndex(function(val, i) { + sample[i] = arr[i]; + + assert.sameValue(val, 0, "value is not mapped to instance"); + }); + assert(compareArray(sample, arr), "values set during each predicate call"); + + sample = new TA(arr); + result = sample.findIndex(function(val, i) { + if ( i === 0 ) { + sample[2] = 7; + } + return val === 7; + }); + assert.sameValue(result, 2, "value found"); + + sample = new TA(arr); + result = sample.findIndex(function(val, i) { + if ( i === 0 ) { + sample[2] = 7; + } + return val === 30; + }); + assert.sameValue(result, -1, "value not found"); + + sample = new TA(arr); + result = sample.findIndex(function(val, i) { + if ( i > 0 ) { + sample[0] = 7; + } + return val === 7; + }); + assert.sameValue(result, -1, "value not found - changed after call"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-parameters.js b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..32c3bbfe2b2230387add24202b46aa5de1e8f0c1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-parameters.js @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([39, 2, 62]); + var results = []; + var result; + + sample.foo = "bar"; // Ignores non integer index properties + + sample.findIndex(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "predicate is called for each index"); + + result = results[0]; + assert.sameValue(result[0], 39, "results[0][0] === 39, value"); + assert.sameValue(result[1], 0, "results[0][1] === 0, index"); + assert.sameValue(result[2], sample, "results[0][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[0].length === 3, arguments"); + + result = results[1]; + assert.sameValue(result[0], 2, "results[1][0] === 2, value"); + assert.sameValue(result[1], 1, "results[1][1] === 1, index"); + assert.sameValue(result[2], sample, "results[1][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[1].length === 3, arguments"); + + result = results[2]; + assert.sameValue(result[0], 62, "results[2][0] === 62, value"); + assert.sameValue(result[1], 2, "results[2][1] === 2, index"); + assert.sameValue(result[2], sample, "results[2][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[2].length === 3, arguments"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-this-non-strict.js b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..4a90ab70cf9f0c9656489e47a577f799ccc979f6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-this-non-strict.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Verify predicate this on non-strict mode +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [noStrict] +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var T = this; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findIndex(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.findIndex(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.findIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-this-strict.js b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..6cf0a972ca39ee390ae008b6b0e34b3b6494b8a6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-call-this-strict.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [onlyStrict] +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findIndex(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.findIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..588a97250561dfe6da653a1b46530b11109953fe --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-is-not-callable-throws.js @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Throws a TypeError exception if predicate is not callable. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 3. If IsCallable(predicate) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.findIndex({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.findIndex(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.findIndex(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.findIndex(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.findIndex(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.findIndex(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.findIndex(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.findIndex([]); + }, "[]"); + + assert.throws(TypeError, function() { + sample.findIndex(/./); + }, "/./"); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-may-detach-buffer.js b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-may-detach-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..a854027b06ee154b1bd08f5a9add1c382bb56572 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-may-detach-buffer.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Predicate may detach the buffer +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + Repeat, while k < len, + Let Pk be ! ToString(F(k)). + Let kValue be ? Get(O, Pk). + Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, F(k), O »)). + ... + + IntegerIndexedElementGet ( O, index ) + + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var loops = 0; + + sample.findIndex(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + assert.sameValue(loops, 2, "predicate is called once"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-not-called-on-empty-array.js b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..18729d915ac999bd75ed4703c00ad0e0d6726cdd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/predicate-not-called-on-empty-array.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Predicate is not called on an empty instance +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + 7. Return -1. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var called = false; + + var predicate = function() { + called = true; + return true; + }; + + var result = sample.findIndex(predicate); + + assert.sameValue( + called, false, + "does not call predicate" + ); + assert.sameValue( + result, -1, + "returns -1 on an empty instance" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/findIndex/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..a448fd79aad2e9c34e974879250de97bac098d59 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + "findIndex" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'findIndex', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/findIndex/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..426192a180f3b8e655de4db5ed2b873069b42b99 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + SendableTypedArray.p.findIndex behaves correctly when receiver is backed by resizable + buffer that is grown mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLength.findIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLengthWithOffset.findIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTracking.findIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTrackingWithOffset.findIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/findIndex/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..a8f35e6f0c292acea2c42d52592ad59b9f26184b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + SendableTypedArray.p.findIndex behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLength.findIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 0, + 2, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLengthWithOffset.findIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTracking.findIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 0, + 2, + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTrackingWithOffset.findIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 4, + undefined + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/findIndex/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..3c472987206f979c3904fd354535bdea2b1da307 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/resizable-buffer.js @@ -0,0 +1,114 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + SendableTypedArray.p.findIndex behaves correctly when receiver is backed by resizable + buffer +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function isTwoOrFour(n) { + return n == 2 || n == 4; + } + assert.sameValue(fixedLength.findIndex(isTwoOrFour), 1); + assert.sameValue(fixedLengthWithOffset.findIndex(isTwoOrFour), 0); + assert.sameValue(lengthTracking.findIndex(isTwoOrFour), 1); + assert.sameValue(lengthTrackingWithOffset.findIndex(isTwoOrFour), 0); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.findIndex(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.findIndex(isTwoOrFour); + }); + + assert.sameValue(lengthTracking.findIndex(isTwoOrFour), 1); + assert.sameValue(lengthTrackingWithOffset.findIndex(isTwoOrFour), 0); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.findIndex(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.findIndex(isTwoOrFour); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.findIndex(isTwoOrFour); + }); + assert.sameValue(lengthTracking.findIndex(isTwoOrFour), -1); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.findIndex(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.findIndex(isTwoOrFour); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.findIndex(isTwoOrFour); + }); + + assert.sameValue(lengthTracking.findIndex(isTwoOrFour), -1); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 0); + } + taWrite[4] = MayNeedBigInt(taWrite, 2); + taWrite[5] = MayNeedBigInt(taWrite, 4); + + // Orig. array: [0, 0, 0, 0, 2, 4] + // [0, 0, 0, 0] << fixedLength + // [0, 0] << fixedLengthWithOffset + // [0, 0, 0, 0, 2, 4, ...] << lengthTracking + // [0, 0, 2, 4, ...] << lengthTrackingWithOffset + + assert.sameValue(fixedLength.findIndex(isTwoOrFour), -1); + assert.sameValue(fixedLengthWithOffset.findIndex(isTwoOrFour), -1); + assert.sameValue(lengthTracking.findIndex(isTwoOrFour), 4); + assert.sameValue(lengthTrackingWithOffset.findIndex(isTwoOrFour), 2); +} diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/return-abrupt-from-predicate-call.js b/test/sendable/builtins/TypedArray/prototype/findIndex/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..225144cc21533c23f8f7e0773a1cef995cca0517 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/return-abrupt-from-predicate-call.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Return abrupt from predicate call. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + assert.throws(Test262Error, function() { + sample.findIndex(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/findIndex/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..3cb68fe089d711c8031f44bb6eb98144414bb13f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.findIndex, + 'function', + 'implements SendableTypedArray.prototype.findIndex' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.findIndex(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.findIndex(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the findIndex operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.findIndex(() => {}); + throw new Test262Error('findIndex completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/return-index-predicate-result-is-true.js b/test/sendable/builtins/TypedArray/prototype/findIndex/return-index-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..5a31a939130da325a7e9c930af8a60de4cc500d0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/return-index-predicate-result-is-true.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Return index if predicate return a boolean true value. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + d. If testResult is true, return k. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([39, 3, 9]); + var called = 0; + + var result = sample.findIndex(function() { + called++; + return true; + }); + + assert.sameValue(result, 0, "returned true on sample[0]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.findIndex(function(val) { + called++; + return val === 9; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 2, "returned true on sample[3]"); + + result = sample.findIndex(function() { return "string"; }); + assert.sameValue(result, 0, "ToBoolean(string)"); + + result = sample.findIndex(function() { return {}; }); + assert.sameValue(result, 0, "ToBoolean(object)"); + + result = sample.findIndex(function() { return Symbol(""); }); + assert.sameValue(result, 0, "ToBoolean(symbol)"); + + result = sample.findIndex(function() { return 1; }); + assert.sameValue(result, 0, "ToBoolean(number)"); + + result = sample.findIndex(function() { return -1; }); + assert.sameValue(result, 0, "ToBoolean(negative number)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js b/test/sendable/builtins/TypedArray/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..72438996ee4613583d84cd27ec723378c024b374 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Return -1 if predicate always returns a boolean false value. +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %SendableTypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + 7. Return -1. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 2, 3]); + var called = 0; + + var result = sample.findIndex(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, -1, "result is -1 when predicate returns are false"); + + result = sample.findIndex(function() { return ""; }); + assert.sameValue(result, -1, "ToBoolean(string)"); + + result = sample.findIndex(function() { return undefined; }); + assert.sameValue(result, -1, "ToBoolean(undefined)"); + + result = sample.findIndex(function() { return null; }); + assert.sameValue(result, -1, "ToBoolean(null)"); + + result = sample.findIndex(function() { return 0; }); + assert.sameValue(result, -1, "ToBoolean(0)"); + + result = sample.findIndex(function() { return -0; }); + assert.sameValue(result, -1, "ToBoolean(-0)"); + + result = sample.findIndex(function() { return NaN; }); + assert.sameValue(result, -1, "ToBoolean(NaN)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/findIndex/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..ba961f005db33457521efa7d61997b2a6bd1ab13 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/this-is-not-object.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var findIndex = SendableTypedArray.prototype.findIndex; +var predicate = function() {}; + +assert.throws(TypeError, function() { + findIndex.call(undefined, predicate); +}, "this is undefined"); + +assert.throws(TypeError, function() { + findIndex.call(null, predicate); +}, "this is null"); + +assert.throws(TypeError, function() { + findIndex.call(42, predicate); +}, "this is 42"); + +assert.throws(TypeError, function() { + findIndex.call("1", predicate); +}, "this is a string"); + +assert.throws(TypeError, function() { + findIndex.call(true, predicate); +}, "this is true"); + +assert.throws(TypeError, function() { + findIndex.call(false, predicate); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + findIndex.call(s, predicate); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/findIndex/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/findIndex/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..939c0af80e975ee29fa6d1bfb2d6b203bd23fb5e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findIndex/this-is-not-typedarray-instance.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findindex +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.11 %SendableTypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var findIndex = SendableTypedArray.prototype.findIndex; +var predicate = function() {}; + +assert.throws(TypeError, function() { + findIndex.call({}, predicate); +}, "this is an Object"); + +assert.throws(TypeError, function() { + findIndex.call([], predicate); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + findIndex.call(ab, predicate); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + findIndex.call(dv, predicate); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..2ca1044eb06daa307f606ed13573470b882541f7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/detached-buffer.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: Throws a TypeError if this has a detached buffer +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.findLast(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..b96d0939a75aed5c13de92dceb2eadbd6fa1247c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/get-length-ignores-length-prop.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + [[Get]] of "length" uses [[ArrayLength]] +info: | + 22.2.3.10 %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + ... + 3. Let len be O.[[ArrayLength]]. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([42n]); + + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true + }); + + assert.sameValue( + sample.findLast(function() { return true; }), + 42n + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-changes-value.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-changes-value.js new file mode 100644 index 0000000000000000000000000000000000000000..57d8014409451b739a32529525416b956487bcb7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-changes-value.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Change values during predicate call +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var arr = [1n, 2n, 3n]; + var sample; + var result; + + sample = new TA(3); + sample.findLast(function(val, i) { + sample[i] = arr[i]; + + assert.sameValue(val, 0n, "value is not mapped to instance"); + }); + assert(compareArray(sample, arr), "values set during each predicate call"); + + sample = new TA(arr); + result = sample.findLast(function(val, i) { + if ( i === 2 ) { + sample[0] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, 7n, "value found"); + + sample = new TA(arr); + result = sample.findLast(function(val, i) { + if ( i === 2 ) { + sample[0] = 7n; + } + return val === 1n; + }); + assert.sameValue(result, undefined, "value not found"); + + sample = new TA(arr); + result = sample.findLast(function(val, i) { + if ( i < 2 ) { + sample[2] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, undefined, "value not found - changed after call"); + + sample = new TA(arr); + result = sample.findLast(function() { + sample[2] = 7n; + return true; + }); + assert.sameValue(result, 3n, "findLast() returns previous found value"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-parameters.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..b7e6b7c4d6de59435bd71993ce3b0a1632de9a5c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-parameters.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([39n, 2n, 62n]); + var results = []; + var result; + + sample.foo = "bar"; // Ignores non integer index properties + + sample.findLast(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "predicate is called for each index"); + + result = results[0]; + assert.sameValue(result[0], 62n, "results[0][0] === 62, value"); + assert.sameValue(result[1], 2, "results[0][1] === 2, index"); + assert.sameValue(result[2], sample, "results[0][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[0].length === 3 arguments"); + + result = results[1]; + assert.sameValue(result[0], 2n, "results[1][0] === 2, value"); + assert.sameValue(result[1], 1, "results[1][1] === 1, index"); + assert.sameValue(result[2], sample, "results[1][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[1].length === 3 arguments"); + + result = results[2]; + assert.sameValue(result[0], 39n, "results[2][0] === 39, value"); + assert.sameValue(result[1], 0, "results[2][1] === 0, index"); + assert.sameValue(result[2], sample, "results[2][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[2].length === 3 arguments"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-this-non-strict.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..fc205b1c69b89cf3396fae1a471aad0088e496d7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-this-non-strict.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Verify predicate this on non-strict mode +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +flags: [noStrict] +includes: [sendableBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +var T = this; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findLast(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.findLast(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.findLast(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-this-strict.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..732fd2a653bf2ffa026d53efd5946d37f5dde953 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-call-this-strict.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Verify predicate this on strict mode +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findLast(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.findLast(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..b21559fa735a476f072152305da793ce047d71ec --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-is-not-callable-throws.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Throws a TypeError exception if predicate is not callable. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + ... + 4. If IsCallable(predicate) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.findLast({}); + }, "object"); + + assert.throws(TypeError, function() { + sample.findLast(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.findLast(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.findLast(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.findLast(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.findLast(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.findLast(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.findLast([]); + }, "array"); + + assert.throws(TypeError, function() { + sample.findLast(/./); + }, "regexp"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-may-detach-buffer.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-may-detach-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..c24f3ffa84d4f0c543243482adf1f5aca8865518 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-may-detach-buffer.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Predicate may detach the buffer +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + ... + + However, such optimization must not introduce any observable changes in the + specified behaviour of the algorithm and must take into account the + possibility that calls to predicate may cause the this value to become + detached. + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [sendableBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.findLast(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-not-called-on-empty-array.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..cde5b85b2e062e87d2933782bb3ab8d1494ffb88 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/predicate-not-called-on-empty-array.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Predicate is not called on empty instances +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + var called = false; + + var result = sample.findLast(function() { + called = true; + return true; + }); + + assert.sameValue( + called, + false, + "empty instance does not call predicate" + ); + assert.sameValue( + result, + undefined, + "findLast returns undefined when predicate is not called" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-abrupt-from-predicate-call.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..ed410e2d0ede6b59d364c6fcf9cc22458f72a210 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-abrupt-from-predicate-call.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Return abrupt from predicate call. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + var predicate = function() { + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + sample.findLast(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..ffdb2357d1ccb030099c9dc5ffe46ed421236dbe --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, array-find-from-last, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.findLast, + 'function', + 'implements SendableTypedArray.prototype.findLast' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.findLast(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.findLast(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the findLast operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.findLast(() => {}); + throw new Test262Error('findLast completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-found-value-predicate-result-is-true.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-found-value-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..720796074ad315f302cb221dd9fd87a2a0f6f8a5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-found-value-predicate-result-is-true.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Return found value if predicate return a boolean true value. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + d. If testResult is true, return kValue. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([39n, 2n, 62n]); + var called, result; + + called = 0; + result = sample.findLast(function() { + called++; + return true; + }); + assert.sameValue(result, 62n, "returned true on sample[2]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.findLast(function(val) { + called++; + return val === 39n; + }); + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 39n, "returned true on sample[0]"); + + result = sample.findLast(function() { return "string"; }); + assert.sameValue(result, 62n, "ToBoolean(string)"); + + result = sample.findLast(function() { return {}; }); + assert.sameValue(result, 62n, "ToBoolean(object)"); + + result = sample.findLast(function() { return Symbol(""); }); + assert.sameValue(result, 62n, "ToBoolean(symbol)"); + + result = sample.findLast(function() { return 1; }); + assert.sameValue(result, 62n, "ToBoolean(number)"); + + result = sample.findLast(function() { return -1; }); + assert.sameValue(result, 62n, "ToBoolean(negative number)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-undefined-if-predicate-returns-false-value.js b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-undefined-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..09090889f93773ccdc92ce936215287c76a45e1a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/BigInt/return-undefined-if-predicate-returns-false-value.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Return undefined if predicate always returns a boolean false value. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + ... + 6. 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... + 7. Return undefined. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + var called = 0; + + var result = sample.findLast(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, undefined); + + result = sample.findLast(function() { return ""; }); + assert.sameValue(result, undefined, "ToBoolean(empty string)"); + + result = sample.findLast(function() { return undefined; }); + assert.sameValue(result, undefined, "ToBoolean(undefined)"); + + result = sample.findLast(function() { return null; }); + assert.sameValue(result, undefined, "ToBoolean(null)"); + + result = sample.findLast(function() { return 0; }); + assert.sameValue(result, undefined, "ToBoolean(0)"); + + result = sample.findLast(function() { return -0; }); + assert.sameValue(result, undefined, "ToBoolean(-0)"); + + result = sample.findLast(function() { return NaN; }); + assert.sameValue(result, undefined, "ToBoolean(NaN)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/callbackfn-resize.js b/test/sendable/builtins/TypedArray/prototype/findLast/callbackfn-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..996b92de28bc21c82a6b5d1071d268683686f03c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/callbackfn-resize.js @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: Instance buffer can be resized during iteration +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var secondElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + + elements = []; + indices = []; + arrays = []; + result = sample.findLast(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(BPE); + secondElement = undefined; + expectedElements = [0]; + expectedIndices = [0]; + expectedArrays = [sample]; + } catch (_) { + secondElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [2, 1, 0]; + expectedArrays = [sample, sample, sample]; + } + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + + assert.compareArray(elements, [0, secondElement, 0], 'elements (shrink)'); + assert.compareArray(indices, [2, 1, 0], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, undefined, 'result (shrink)'); + + elements = []; + indices = []; + arrays = []; + result = sample.findLast(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, undefined, 'result (grow)'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/findLast/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..62e188aca42b3b2f643d11e283c1af7fe3e9a1d7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/detached-buffer.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: Throws a TypeError if this has a detached buffer +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray, array-find-from-last] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.findLast(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/findLast/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..e90bdf4725bc33dfef021ee6fbf49a0cf3e02256 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/get-length-ignores-length-prop.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + [[Get]] of "length" uses [[ArrayLength]] +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + ... + 3. Let len be O.[[ArrayLength]]. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([42]); + + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true + }); + + assert.sameValue( + sample.findLast(function() { return true; }), + 42 + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/findLast/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..47db6caf3acf85e7e1eb9c12d1606a1430ac94f5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/invoked-as-func.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: Throws a TypeError exception when invoked as a function +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +var findLast = SendableTypedArray.prototype.findLast; + +assert.sameValue(typeof findLast, 'function'); + +assert.throws(TypeError, function() { + findLast(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/findLast/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..9f09b793d3bbec51494d32583cdbc420c3f26506 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/invoked-as-method.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: Requires a [[TypedArrayName]] internal slot. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.findLast, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.findLast(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/length.js b/test/sendable/builtins/TypedArray/prototype/findLast/length.js new file mode 100644 index 0000000000000000000000000000000000000000..03f7bf1ff2c38b9861f14b4f728fd62cd4d9d8d1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/length.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + %SendableTypedArray%.prototype.findLast.length is 1. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +assert.sameValue(SendableTypedArray.prototype.findLast.length, 1); + +verifyProperty(SendableTypedArray.prototype.findLast, "length", { + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/name.js b/test/sendable/builtins/TypedArray/prototype/findLast/name.js new file mode 100644 index 0000000000000000000000000000000000000000..8259b57b37a602c2a5533cd4e901de31ae6feb35 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/name.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + %SendableTypedArray%.prototype.findLast.name is "findLast". +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +assert.sameValue(SendableTypedArray.prototype.findLast.name, "findLast"); + +verifyProperty(SendableTypedArray.prototype.findLast, "name", { + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/findLast/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..c7ab952461e201ca9e9bbc422fce7e1961e350d5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.findLast does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, SendableTypedArray, array-find-from-last] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.findLast), + false, + 'isConstructor(SendableTypedArray.prototype.findLast) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.findLast(() => {}); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-changes-value.js b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-changes-value.js new file mode 100644 index 0000000000000000000000000000000000000000..ae88f3e51a3308e729629041b7e41eade6a44761 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-changes-value.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Change values during predicate call +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... + +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var arr = [1, 2, 3]; + var sample; + var result; + + sample = new TA(3); + sample.findLast(function(val, i) { + sample[i] = arr[i]; + + assert.sameValue(val, 0, "value is not mapped to instance"); + }); + assert(compareArray(sample, arr), "values set during each predicate call"); + + sample = new TA(arr); + result = sample.findLast(function(val, i) { + if ( i === 2 ) { + sample[0] = 7; + } + return val === 7; + }); + assert.sameValue(result, 7, "value found"); + + sample = new TA(arr); + result = sample.findLast(function(val, i) { + if ( i === 2 ) { + sample[0] = 7; + } + return val === 1; + }); + assert.sameValue(result, undefined, "value not found"); + + sample = new TA(arr); + result = sample.findLast(function(val, i) { + if ( i < 2 ) { + sample[2] = 7; + } + return val === 7; + }); + assert.sameValue(result, undefined, "value not found - changed after call"); + + sample = new TA(arr); + result = sample.findLast(function() { + sample[2] = 7; + return true; + }); + assert.sameValue(result, 3, "findLast() returns previous found value"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-parameters.js b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..e405330160bd28fda973687400287644cf4a6351 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-parameters.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([39, 2, 62]); + var results = []; + var result; + + sample.foo = "bar"; // Ignores non integer index properties + + sample.findLast(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "predicate is called for each index"); + + result = results[0]; + assert.sameValue(result[0], 62, "results[0][0] === 62, value"); + assert.sameValue(result[1], 2, "results[0][1] === 2, index"); + assert.sameValue(result[2], sample, "results[0][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[0].length === 3 arguments"); + + result = results[1]; + assert.sameValue(result[0], 2, "results[1][0] === 2, value"); + assert.sameValue(result[1], 1, "results[1][1] === 1, index"); + assert.sameValue(result[2], sample, "results[1][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[1].length === 3 arguments"); + + result = results[2]; + assert.sameValue(result[0], 39, "results[2][0] === 39, value"); + assert.sameValue(result[1], 0, "results[2][1] === 0, index"); + assert.sameValue(result[2], sample, "results[2][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[2].length === 3 arguments"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-this-non-strict.js b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..886f5460b17a00bffacf8c2363e8c0837a22f00c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-this-non-strict.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Verify predicate this on non-strict mode +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +flags: [noStrict] +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +var T = this; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findLast(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.findLast(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.findLast(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-this-strict.js b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..5ebba876c673c68caf536640cd135931faea5ebd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-call-this-strict.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Verify predicate this on strict mode +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +flags: [onlyStrict] +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findLast(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.findLast(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/predicate-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..dd7cb5e47fff4587a16157d5f1ef7e16e82e2587 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-is-not-callable-throws.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Throws a TypeError exception if predicate is not callable. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + ... + 4. If IsCallable(predicate) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.findLast({}); + }, "object"); + + assert.throws(TypeError, function() { + sample.findLast(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.findLast(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.findLast(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.findLast(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.findLast(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.findLast(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.findLast([]); + }, "array"); + + assert.throws(TypeError, function() { + sample.findLast(/./); + }, "regexp"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/predicate-may-detach-buffer.js b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-may-detach-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..1995e7584942dc891421ed7d8dff6db619fd2c9b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-may-detach-buffer.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Predicate may detach the buffer +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + ... + + However, such optimization must not introduce any observable changes in the + specified behaviour of the algorithm and must take into account the + possibility that calls to predicate may cause the this value to become + detached. + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.findLast(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/predicate-not-called-on-empty-array.js b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..a573f35f0ada29d6b947c8458adafec2bd69be5e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/predicate-not-called-on-empty-array.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Predicate is not called on empty instances +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var called = false; + + var result = sample.findLast(function() { + called = true; + return true; + }); + + assert.sameValue( + called, + false, + "empty instance does not call predicate" + ); + assert.sameValue( + result, + undefined, + "findLast returns undefined when predicate is not called" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/findLast/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..3b80b0daf0038747d77763ec9556d3d450bdda13 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findLast +description: > + "findLast" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArray.prototype, "findLast", { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/findLast/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..55d0c94442b01ad9d1d8bf12ac0d6aca8e8fd5dc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + SendableTypedArray.p.findLast behaves correctly when receiver is backed by resizable + buffer that is grown mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLength.findLast(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLengthWithOffset.findLast(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTracking.findLast(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTrackingWithOffset.findLast(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/findLast/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..dd14ff285720ae28c2e79425d491f715ffad57e9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + SendableTypedArray.p.findLast behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLength.findLast(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLengthWithOffset.findLast(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTracking.findLast(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTrackingWithOffset.findLast(ResizeMidIteration), undefined); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/findLast/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9273ca06006c13abbf4fce615c9fd133568178b6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/resizable-buffer.js @@ -0,0 +1,115 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + SendableTypedArray.p.findLast behaves correctly when receiver is backed by resizable + buffer +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function isTwoOrFour(n) { + return n == 2 || n == 4; + } + assert.sameValue(Number(fixedLength.findLast(isTwoOrFour)), 4); + assert.sameValue(Number(fixedLengthWithOffset.findLast(isTwoOrFour)), 4); + assert.sameValue(Number(lengthTracking.findLast(isTwoOrFour)), 4); + assert.sameValue(Number(lengthTrackingWithOffset.findLast(isTwoOrFour)), 4); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.findLast(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.findLast(isTwoOrFour); + }); + + assert.sameValue(Number(lengthTracking.findLast(isTwoOrFour)), 4); + assert.sameValue(Number(lengthTrackingWithOffset.findLast(isTwoOrFour)), 4); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.findLast(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.findLast(isTwoOrFour); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.findLast(isTwoOrFour); + }); + + assert.sameValue(lengthTracking.findLast(isTwoOrFour), undefined); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.findLast(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.findLast(isTwoOrFour); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.findLast(isTwoOrFour); + }); + + assert.sameValue(lengthTracking.findLast(isTwoOrFour), undefined); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 0); + } + taWrite[4] = MayNeedBigInt(taWrite, 2); + taWrite[5] = MayNeedBigInt(taWrite, 4); + + // Orig. array: [0, 0, 0, 0, 2, 4] + // [0, 0, 0, 0] << fixedLength + // [0, 0] << fixedLengthWithOffset + // [0, 0, 0, 0, 2, 4, ...] << lengthTracking + // [0, 0, 2, 4, ...] << lengthTrackingWithOffset + + assert.sameValue(fixedLength.findLast(isTwoOrFour), undefined); + assert.sameValue(fixedLengthWithOffset.findLast(isTwoOrFour), undefined); + assert.sameValue(Number(lengthTracking.findLast(isTwoOrFour)), 4); + assert.sameValue(Number(lengthTrackingWithOffset.findLast(isTwoOrFour)), 4); +} diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/return-abrupt-from-predicate-call.js b/test/sendable/builtins/TypedArray/prototype/findLast/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..47ec28df260a3894bf5323b357fa93707ccf55cc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/return-abrupt-from-predicate-call.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Return abrupt from predicate call. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + var predicate = function() { + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + sample.findLast(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/findLast/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..46d77ea255d5d9b3dacec4fa300931eb6a76ae14 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer, array-find-from-last] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.findLast, + 'function', + 'implements SendableTypedArray.prototype.findLast' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.findLast(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.findLast(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the findLast operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.findLast(() => {}); + throw new Test262Error('findLast completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js b/test/sendable/builtins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..ea418aedcc3b115dcc4171e8c00dc3dd6521d6ec --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/return-found-value-predicate-result-is-true.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Return found value if predicate return a boolean true value. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 6. Repeat, while k ≥ 0, + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + d. If testResult is true, return kValue. + ... +includes: [sendableTypedArray.js] +features: [Symbol, SendableTypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([39, 2, 62]); + var called, result; + + called = 0; + result = sample.findLast(function() { + called++; + return true; + }); + assert.sameValue(result, 62, "returned true on sample[2]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.findLast(function(val) { + called++; + return val === 39; + }); + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 39, "returned true on sample[0]"); + + result = sample.findLast(function() { return "string"; }); + assert.sameValue(result, 62, "ToBoolean(string)"); + + result = sample.findLast(function() { return {}; }); + assert.sameValue(result, 62, "ToBoolean(object)"); + + result = sample.findLast(function() { return Symbol(""); }); + assert.sameValue(result, 62, "ToBoolean(symbol)"); + + result = sample.findLast(function() { return 1; }); + assert.sameValue(result, 62, "ToBoolean(number)"); + + result = sample.findLast(function() { return -1; }); + assert.sameValue(result, 62, "ToBoolean(negative number)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/return-undefined-if-predicate-returns-false-value.js b/test/sendable/builtins/TypedArray/prototype/findLast/return-undefined-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..30617e6f3fb3d7a0427bbb77920a876ec6fa51f2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/return-undefined-if-predicate-returns-false-value.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Return undefined if predicate always returns a boolean false value. +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + ... + 6. 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... + 7. Return undefined. +includes: [sendableTypedArray.js] +features: [Symbol, SendableTypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + var called = 0; + + var result = sample.findLast(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, undefined); + + result = sample.findLast(function() { return ""; }); + assert.sameValue(result, undefined, "ToBoolean(empty string)"); + + result = sample.findLast(function() { return undefined; }); + assert.sameValue(result, undefined, "ToBoolean(undefined)"); + + result = sample.findLast(function() { return null; }); + assert.sameValue(result, undefined, "ToBoolean(null)"); + + result = sample.findLast(function() { return 0; }); + assert.sameValue(result, undefined, "ToBoolean(0)"); + + result = sample.findLast(function() { return -0; }); + assert.sameValue(result, undefined, "ToBoolean(-0)"); + + result = sample.findLast(function() { return NaN; }); + assert.sameValue(result, undefined, "ToBoolean(NaN)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/findLast/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..41eb4bbabf667b74b872719b25fa97316ab71c58 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/this-is-not-object.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: Throws a TypeError exception when `this` is not Object +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, SendableTypedArray, array-find-from-last] +---*/ + +var findLast = SendableTypedArray.prototype.findLast; +var predicate = function() {}; + +assert.throws(TypeError, function() { + findLast.call(undefined, predicate); +}, "this is undefined"); + +assert.throws(TypeError, function() { + findLast.call(null, predicate); +}, "this is null"); + +assert.throws(TypeError, function() { + findLast.call(42, predicate); +}, "this is 42"); + +assert.throws(TypeError, function() { + findLast.call("1", predicate); +}, "this is a string"); + +assert.throws(TypeError, function() { + findLast.call(true, predicate); +}, "this is true"); + +assert.throws(TypeError, function() { + findLast.call(false, predicate); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + findLast.call(s, predicate); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/findLast/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/findLast/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..5f7b2c082cb3411aa4c668c4cb5129658fab879c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLast/this-is-not-typedarray-instance.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlast +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + %SendableTypedArray%.prototype.findLast (predicate [ , thisArg ] ) + + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +var findlast = SendableTypedArray.prototype.findlast; +var predicate = function() {}; + +assert.throws(TypeError, function() { + findlast.call({}, predicate); +}, "this is an Object"); + +assert.throws(TypeError, function() { + findlast.call([], predicate); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + findlast.call(ab, predicate); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + findlast.call(dv, predicate); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..142a22aea71188a908b2444df62ec777ece951cc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: Throws a TypeError if this has a detached buffer +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.findLastIndex(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..83ab55204854b9b6bb528da087a40f04d6294afb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/get-length-ignores-length-prop.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + [[Get]] of "length" uses [[ArrayLength]] +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 3. Let len be O.[[ArrayLength]]. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([42n]); + + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true + }); + + assert.sameValue( + sample.findLastIndex(function() { return true; }), + 0 + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-changes-value.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-changes-value.js new file mode 100644 index 0000000000000000000000000000000000000000..6ab335a31776d2015154cfc85572f81245b010a5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-changes-value.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Change values during predicate call +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var arr = [10n, 20n, 30n]; + var sample; + var result; + + sample = new TA(3); + sample.findLastIndex(function(val, i) { + sample[i] = arr[i]; + + assert.sameValue(val, 0n, "value is not mapped to instance"); + }); + assert(compareArray(sample, arr), "values set during each predicate call"); + + sample = new TA(arr); + result = sample.findLastIndex(function(val, i) { + if ( i === 2 ) { + sample[0] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, 0, "value found"); + + sample = new TA(arr); + result = sample.findLastIndex(function(val, i) { + if ( i === 2 ) { + sample[0] = 7n; + } + return val === 10n; + }); + assert.sameValue(result, -1, "value not found"); + + sample = new TA(arr); + result = sample.findLastIndex(function(val, i) { + if ( i < 2 ) { + sample[2] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, -1, "value not found - changed after call"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-parameters.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..9b8931ddb209f00239a482c08125819a0bd3ccae --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-parameters.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([39n, 2n, 62n]); + var results = []; + var result; + + sample.foo = "bar"; // Ignores non integer index properties + + sample.findLastIndex(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "predicate is called for each index"); + + result = results[0]; + assert.sameValue(result[0], 62n, "results[0][0] === 62, value"); + assert.sameValue(result[1], 2, "results[0][1] === 2, index"); + assert.sameValue(result[2], sample, "results[0][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[0].length === 3, arguments"); + + result = results[1]; + assert.sameValue(result[0], 2n, "results[1][0] === 2, value"); + assert.sameValue(result[1], 1, "results[1][1] === 1, index"); + assert.sameValue(result[2], sample, "results[1][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[1].length === 3, arguments"); + + result = results[2]; + assert.sameValue(result[0], 39n, "results[2][0] === 39, value"); + assert.sameValue(result[1], 0, "results[2][1] === 0, index"); + assert.sameValue(result[2], sample, "results[2][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[2].length === 3, arguments"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-non-strict.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..c0f5c75211e8d1f0d033029e0b37a028163691c9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-non-strict.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Verify predicate this on non-strict mode +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +flags: [noStrict] +includes: [sendableBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +var T = this; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findLastIndex(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.findLastIndex(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.findLastIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-strict.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..26fb4fad80ef9c58e50c15753ca35f27545ce768 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-call-this-strict.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findLastIndex(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.findLastIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..f5fa2aa1199dae48567f325b26ceec5422aaf2c1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-is-not-callable-throws.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Throws a TypeError exception if predicate is not callable. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 4. If IsCallable(predicate) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.findLastIndex({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.findLastIndex(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.findLastIndex(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.findLastIndex(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.findLastIndex(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.findLastIndex(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.findLastIndex(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.findLastIndex([]); + }, "[]"); + + assert.throws(TypeError, function() { + sample.findLastIndex(/./); + }, "/./"); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-may-detach-buffer.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-may-detach-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9c54800c24141c3f0264c89b2224e9d4b719b94b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-may-detach-buffer.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Predicate may detach the buffer +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 6. Repeat, while k ≥ 0, + a. Let Pk be ! ToString(𝔽(k)). + b. Let kValue be ! Get(O, Pk). + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... + + IntegerIndexedElementGet ( O, index ) + + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [sendableBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var loops = 0; + + sample.findLastIndex(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + assert.sameValue(loops, 2, "predicate is called once"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-not-called-on-empty-array.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..743f4b0099d33b7ee53d4691086274130c589d26 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/predicate-not-called-on-empty-array.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Predicate is not called on an empty instance +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... + 7. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + var called = false; + + var predicate = function() { + called = true; + return true; + }; + + var result = sample.findLastIndex(predicate); + + assert.sameValue( + called, false, + "does not call predicate" + ); + assert.sameValue( + result, -1, + "returns -1 on an empty instance" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-predicate-call.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..af348d5102635993fb0276642f09e0ecd0f91fb0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-predicate-call.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Return abrupt from predicate call. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + assert.throws(Test262Error, function() { + sample.findLastIndex(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..ff447347799e9016206d87a6a28f4ae9818d0c4e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, array-find-from-last, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.findLastIndex, + 'function', + 'implements SendableTypedArray.prototype.findLastIndex' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.findLastIndex(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.findLastIndex(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the findLastIndex operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.findLastIndex(() => {}); + throw new Test262Error('findLastIndex completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-index-predicate-result-is-true.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-index-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..e030426cdb64d8ced4194b7c723a83faef2be66b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-index-predicate-result-is-true.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Return index if predicate return a boolean true value. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + d. If testResult is true, return 𝔽(k). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([39n, 3n, 9n]); + var called = 0; + + var result = sample.findLastIndex(function() { + called++; + return true; + }); + + assert.sameValue(result, 2, "returned true on sample[2]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.findLastIndex(function(val) { + called++; + return val === 39n; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 0, "returned true on sample[0]"); + + result = sample.findLastIndex(function() { return "string"; }); + assert.sameValue(result, 2, "ToBoolean(string)"); + + result = sample.findLastIndex(function() { return {}; }); + assert.sameValue(result, 2, "ToBoolean(object)"); + + result = sample.findLastIndex(function() { return Symbol(""); }); + assert.sameValue(result, 2, "ToBoolean(symbol)"); + + result = sample.findLastIndex(function() { return 1; }); + assert.sameValue(result, 2, "ToBoolean(number)"); + + result = sample.findLastIndex(function() { return -1; }); + assert.sameValue(result, 2, "ToBoolean(negative number)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..cccc55af4590b3271f6d98715896faa28f4c58b0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Return -1 if predicate always returns a boolean false value. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... + 7. Return -1𝔽. +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, array-find-from-last] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 3n]); + var called = 0; + + var result = sample.findLastIndex(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, -1, "result is -1 when predicate returns are false"); + + result = sample.findLastIndex(function() { return ""; }); + assert.sameValue(result, -1, "ToBoolean(string)"); + + result = sample.findLastIndex(function() { return undefined; }); + assert.sameValue(result, -1, "ToBoolean(undefined)"); + + result = sample.findLastIndex(function() { return null; }); + assert.sameValue(result, -1, "ToBoolean(null)"); + + result = sample.findLastIndex(function() { return 0; }); + assert.sameValue(result, -1, "ToBoolean(0)"); + + result = sample.findLastIndex(function() { return -0; }); + assert.sameValue(result, -1, "ToBoolean(-0)"); + + result = sample.findLastIndex(function() { return NaN; }); + assert.sameValue(result, -1, "ToBoolean(NaN)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/callbackfn-resize.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/callbackfn-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..dbe04771c8c14f7b882df86c0676d769b6020a02 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/callbackfn-resize.js @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: Instance buffer can be resized during iteration +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var secondElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + + elements = []; + indices = []; + arrays = []; + result = sample.findLastIndex(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(BPE); + secondElement = undefined; + expectedElements = [0]; + expectedIndices = [0]; + expectedArrays = [sample]; + } catch (_) { + secondElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [2, 1, 0]; + expectedArrays = [sample, sample, sample]; + } + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + + assert.compareArray(elements, [0, secondElement, 0], 'elements (shrink)'); + assert.compareArray(indices, [2, 1, 0], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, -1, 'result (shrink)'); + + elements = []; + indices = []; + arrays = []; + result = sample.findLastIndex(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, -1, 'result (grow)'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..b5785c415bf7716956f89b0f634b9aa48a82000b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: Throws a TypeError if this has a detached buffer +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray, array-find-from-last] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.findLastIndex(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/get-length-ignores-length-prop.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/get-length-ignores-length-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..e7af0abb262ef7faf34e363160681f09ef5e45a4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/get-length-ignores-length-prop.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + [[Get]] of "length" uses [[ArrayLength]] +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 3. Let len be O.[[ArrayLength]]. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([42]); + + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true + }); + + assert.sameValue( + sample.findLastIndex(function() { return true; }), + 0 + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..5e7181daf3dd3d68638b9bb7472600818bdea9d3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: Throws a TypeError exception when invoked as a function +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +var findLastIndex = SendableTypedArray.prototype.findLastIndex; + +assert.sameValue(typeof findLastIndex, 'function'); + +assert.throws(TypeError, function() { + findLastIndex(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..09d714f99e1a409739a8c4a7b6921eae3f65d825 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: Requires a [[TypedArrayName]] internal slot. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.findLastIndex, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.findLastIndex(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/length.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/length.js new file mode 100644 index 0000000000000000000000000000000000000000..f5f11955a6b8dc11e02f6204988e7db5f0a5cb7b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/length.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + %SendableTypedArray%.prototype.findLastIndex.length is 1. +info: | + %SendableTypedArray%.prototype.findLastIndex (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +assert.sameValue(SendableTypedArray.prototype.findLastIndex.length, 1); + +verifyProperty(SendableTypedArray.prototype.findLastIndex, "length", { + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/name.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/name.js new file mode 100644 index 0000000000000000000000000000000000000000..197681cc5c1e0aff5acf6039a847f98e778cecb2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/name.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + %SendableTypedArray%.prototype.findLastIndex.name is "findLastIndex". +info: | + %SendableTypedArray%.prototype.findLastIndex (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +assert.sameValue(SendableTypedArray.prototype.findLastIndex.name, "findLastIndex"); + +verifyProperty(SendableTypedArray.prototype.findLastIndex, "name", { + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..19d76e64cd664c868ce6cc4149367cde5e1d566c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.findLastIndex does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, SendableTypedArray, array-find-from-last] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.findLastIndex), + false, + 'isConstructor(SendableTypedArray.prototype.findLastIndex) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.findLastIndex(() => {}); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-changes-value.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-changes-value.js new file mode 100644 index 0000000000000000000000000000000000000000..5643ced772a95d6e3c528d01254833c2479db377 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-changes-value.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Change values during predicate call +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var arr = [10, 20, 30]; + var sample; + var result; + + sample = new TA(3); + sample.findLastIndex(function(val, i) { + sample[i] = arr[i]; + + assert.sameValue(val, 0, "value is not mapped to instance"); + }); + assert(compareArray(sample, arr), "values set during each predicate call"); + + sample = new TA(arr); + result = sample.findLastIndex(function(val, i) { + if ( i === 2 ) { + sample[0] = 7; + } + return val === 7; + }); + assert.sameValue(result, 0, "value found"); + + sample = new TA(arr); + result = sample.findLastIndex(function(val, i) { + if ( i === 2 ) { + sample[0] = 7; + } + return val === 10; + }); + assert.sameValue(result, -1, "value not found"); + + sample = new TA(arr); + result = sample.findLastIndex(function(val, i) { + if ( i < 2) { + sample[2] = 7; + } + return val === 7; + }); + assert.sameValue(result, -1, "value not found - changed after call"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-parameters.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-parameters.js new file mode 100644 index 0000000000000000000000000000000000000000..9d9273af5f04e056c3fe556750ff0d439516cdbc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-parameters.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([39, 2, 62]); + var results = []; + var result; + + sample.foo = "bar"; // Ignores non integer index properties + + sample.findLastIndex(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "predicate is called for each index"); + + result = results[0]; + assert.sameValue(result[0], 62, "results[0][0] === 62, value"); + assert.sameValue(result[1], 2, "results[0][1] === 2, index"); + assert.sameValue(result[2], sample, "results[0][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[0].length === 3, arguments"); + + result = results[1]; + assert.sameValue(result[0], 2, "results[1][0] === 2, value"); + assert.sameValue(result[1], 1, "results[1][1] === 1, index"); + assert.sameValue(result[2], sample, "results[1][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[1].length === 3, arguments"); + + result = results[2]; + assert.sameValue(result[0], 39, "results[2][0] === 39, value"); + assert.sameValue(result[1], 0, "results[2][1] === 0, index"); + assert.sameValue(result[2], sample, "results[2][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[2].length === 3, arguments"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-this-non-strict.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-this-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..57831ea0dbd14d6e55383c58fdf0637587620b8a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-this-non-strict.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Verify predicate this on non-strict mode +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +flags: [noStrict] +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +var T = this; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findLastIndex(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.findLastIndex(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.findLastIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-this-strict.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-this-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..d2aa0491f905f37ef54169d5c1fbbaa32a026067 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-call-this-strict.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +flags: [onlyStrict] +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findLastIndex(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.findLastIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..dca0314d01c285b5e5b16ee20a53bd950e04f996 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-is-not-callable-throws.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Throws a TypeError exception if predicate is not callable. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 4. If IsCallable(predicate) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.findLastIndex({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.findLastIndex(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.findLastIndex(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.findLastIndex(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.findLastIndex(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.findLastIndex(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.findLastIndex(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.findLastIndex([]); + }, "[]"); + + assert.throws(TypeError, function() { + sample.findLastIndex(/./); + }, "/./"); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-may-detach-buffer.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-may-detach-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..c77e221ed8d51af384e394392d46d47e98b2dbd0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-may-detach-buffer.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Predicate may detach the buffer +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 6. Repeat, while k ≥ 0, + a. Let Pk be ! ToString(𝔽(k)). + b. Let kValue be ! Get(O, Pk). + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... + + IntegerIndexedElementGet ( O, index ) + + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var loops = 0; + + sample.findLastIndex(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + assert.sameValue(loops, 2, "predicate is called once"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-not-called-on-empty-array.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000000000000000000000000000000000..5ed8a79f735ade222e970ecaef480bc9ee48802d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/predicate-not-called-on-empty-array.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Predicate is not called on an empty instance +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... + 7. Return -1. +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var called = false; + + var predicate = function() { + called = true; + return true; + }; + + var result = sample.findLastIndex(predicate); + + assert.sameValue( + called, false, + "does not call predicate" + ); + assert.sameValue( + result, -1, + "returns -1 on an empty instance" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..e72787c51da251258a95f1360ee98e5d816d587f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + "findLastIndex" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArray.prototype, "findLastIndex", { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..cb6cb82c86090179466ee9887367fb5da245f093 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + SendableTypedArray.p.findLastIndex behaves correctly when receiver is backed by resizable + buffer that is grown mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLength.findLastIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLengthWithOffset.findLastIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTracking.findLastIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTrackingWithOffset.findLastIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..59acab440efadd76bd4476119ae32a2b76517b8b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,109 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + SendableTypedArray.p.findLastIndex behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLength.findLastIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(fixedLengthWithOffset.findLastIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTracking.findLastIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 1; + resizeTo = 2 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTracking.findLastIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + undefined, + 2, + 0 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert.sameValue(lengthTrackingWithOffset.findLastIndex(ResizeMidIteration), -1); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..c78c04848a215bce170b8c3017aa077757ab2cbc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/resizable-buffer.js @@ -0,0 +1,114 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + SendableTypedArray.p.findLastIndex behaves correctly when receiver is backed by resizable + buffer +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function isTwoOrFour(n) { + return n == 2 || n == 4; + } + assert.sameValue(fixedLength.findLastIndex(isTwoOrFour), 2); + assert.sameValue(fixedLengthWithOffset.findLastIndex(isTwoOrFour), 0); + assert.sameValue(lengthTracking.findLastIndex(isTwoOrFour), 2); + assert.sameValue(lengthTrackingWithOffset.findLastIndex(isTwoOrFour), 0); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.findLastIndex(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.findLastIndex(isTwoOrFour); + }); + + assert.sameValue(lengthTracking.findLastIndex(isTwoOrFour), 2); + assert.sameValue(lengthTrackingWithOffset.findLastIndex(isTwoOrFour), 0); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.findLastIndex(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.findLastIndex(isTwoOrFour); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.findLastIndex(isTwoOrFour); + }); + + assert.sameValue(lengthTracking.findLastIndex(isTwoOrFour), -1); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.findLastIndex(isTwoOrFour); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.findLastIndex(isTwoOrFour); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.findLastIndex(isTwoOrFour); + }); + assert.sameValue(lengthTracking.findLastIndex(isTwoOrFour), -1); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 0); + } + taWrite[4] = MayNeedBigInt(taWrite, 2); + taWrite[5] = MayNeedBigInt(taWrite, 4); + + // Orig. array: [0, 0, 0, 0, 2, 4] + // [0, 0, 0, 0] << fixedLength + // [0, 0] << fixedLengthWithOffset + // [0, 0, 0, 0, 2, 4, ...] << lengthTracking + // [0, 0, 2, 4, ...] << lengthTrackingWithOffset + + assert.sameValue(fixedLength.findLastIndex(isTwoOrFour), -1); + assert.sameValue(fixedLengthWithOffset.findLastIndex(isTwoOrFour), -1); + assert.sameValue(lengthTracking.findLastIndex(isTwoOrFour), 5); + assert.sameValue(lengthTrackingWithOffset.findLastIndex(isTwoOrFour), 3); +} diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-abrupt-from-predicate-call.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000000000000000000000000000000000..2d238777b312f728b83840ec804355ba4f735f15 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-abrupt-from-predicate-call.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Return abrupt from predicate call. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + assert.throws(Test262Error, function() { + sample.findLastIndex(predicate); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..fd2dcaf6ac8f23d46284a7ac5d9226a186854234 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer, array-find-from-last] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.findLastIndex, + 'function', + 'implements SendableTypedArray.prototype.findLastIndex' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.findLastIndex(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.findLastIndex(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the findLastIndex operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.findLastIndex(() => {}); + throw new Test262Error('findLastIndex completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-index-predicate-result-is-true.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-index-predicate-result-is-true.js new file mode 100644 index 0000000000000000000000000000000000000000..92d54a990409c32ac0a36827f28dfee85d086244 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-index-predicate-result-is-true.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Return index if predicate return a boolean true value. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + d. If testResult is true, return 𝔽(k). + ... +includes: [sendableTypedArray.js] +features: [Symbol, SendableTypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([39, 3, 9]); + var called = 0; + + var result = sample.findLastIndex(function() { + called++; + return true; + }); + + assert.sameValue(result, 2, "returned true on sample[2]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.findLastIndex(function(val) { + called++; + return val === 39; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 0, "returned true on sample[0]"); + + result = sample.findLastIndex(function() { return "string"; }); + assert.sameValue(result, 2, "ToBoolean(string)"); + + result = sample.findLastIndex(function() { return {}; }); + assert.sameValue(result, 2, "ToBoolean(object)"); + + result = sample.findLastIndex(function() { return Symbol(""); }); + assert.sameValue(result, 2, "ToBoolean(symbol)"); + + result = sample.findLastIndex(function() { return 1; }); + assert.sameValue(result, 2, "ToBoolean(number)"); + + result = sample.findLastIndex(function() { return -1; }); + assert.sameValue(result, 2, "ToBoolean(negative number)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-negative-one-if-predicate-returns-false-value.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-negative-one-if-predicate-returns-false-value.js new file mode 100644 index 0000000000000000000000000000000000000000..636f90ad558f45c9f23d5f651181888be245883a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/return-negative-one-if-predicate-returns-false-value.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Return -1 if predicate always returns a boolean false value. +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 5. Let k be len - 1. + 6. Repeat, while k ≥ 0 + ... + c. Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + ... + 7. Return -1𝔽. +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 2, 3]); + var called = 0; + + var result = sample.findLastIndex(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, -1, "result is -1 when predicate returns are false"); + + result = sample.findLastIndex(function() { return ""; }); + assert.sameValue(result, -1, "ToBoolean(string)"); + + result = sample.findLastIndex(function() { return undefined; }); + assert.sameValue(result, -1, "ToBoolean(undefined)"); + + result = sample.findLastIndex(function() { return null; }); + assert.sameValue(result, -1, "ToBoolean(null)"); + + result = sample.findLastIndex(function() { return 0; }); + assert.sameValue(result, -1, "ToBoolean(0)"); + + result = sample.findLastIndex(function() { return -0; }); + assert.sameValue(result, -1, "ToBoolean(-0)"); + + result = sample.findLastIndex(function() { return NaN; }); + assert.sameValue(result, -1, "ToBoolean(NaN)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..60a6022c5c2cae1a0444cf07f42edeef31766276 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/this-is-not-object.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: Throws a TypeError exception when `this` is not Object +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, SendableTypedArray, array-find-from-last] +---*/ + +var findLastIndex = SendableTypedArray.prototype.findLastIndex; +var predicate = function() {}; + +assert.throws(TypeError, function() { + findLastIndex.call(undefined, predicate); +}, "this is undefined"); + +assert.throws(TypeError, function() { + findLastIndex.call(null, predicate); +}, "this is null"); + +assert.throws(TypeError, function() { + findLastIndex.call(42, predicate); +}, "this is 42"); + +assert.throws(TypeError, function() { + findLastIndex.call("1", predicate); +}, "this is a string"); + +assert.throws(TypeError, function() { + findLastIndex.call(true, predicate); +}, "this is true"); + +assert.throws(TypeError, function() { + findLastIndex.call(false, predicate); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + findLastIndex.call(s, predicate); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/findLastIndex/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/findLastIndex/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..278a36dd06973d23aad5a0579a8d5d4334f4dc18 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/findLastIndex/this-is-not-typedarray-instance.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.findlastindex +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + %SendableTypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] ) + + ... + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, array-find-from-last] +---*/ + +var findLastIndex = SendableTypedArray.prototype.findLastIndex; +var predicate = function() {}; + +assert.throws(TypeError, function() { + findLastIndex.call({}, predicate); +}, "this is an Object"); + +assert.throws(TypeError, function() { + findLastIndex.call([], predicate); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + findLastIndex.call(ab, predicate); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + findLastIndex.call(dv, predicate); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..3eb40e69276aeaf09d172f419d876d1ff9ed03de --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/arraylength-internal.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + [[ArrayLength]] is accessed in place of performing a [[Get]] of "length" +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + var loop = 0; + + Object.defineProperty(sample1, "length", {value: 1}); + + sample1.forEach(function() { + loop++; + }); + + assert.sameValue(loop, 42, "data descriptor"); + + var sample2 = new TA(7); + loop = 0; + + Object.defineProperty(sample2, "length", { + get: function() { + throw new Test262Error( + "Does not return abrupt getting length property" + ); + } + }); + + sample2.forEach(function() { + loop++; + }); + + assert.sameValue(loop, 7, "accessor descriptor"); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-with-thisarg.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..41a58bb24696c5b11d9f4ce4e010ce5a337fea9f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.forEach(function() { + results.push(arguments); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-without-thisarg.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..84c798c2f6a9f33c98f0a41704b6ef37a42de3fb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + callbackfn arguments +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.forEach(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..a8bcab95e6e5f448dc1f2666c5bc6f54fdb1f2eb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.forEach(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-is-not-callable.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..3fc179f2f55418588484fa56c5b29ba7246ca193 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-is-not-callable.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + callbackfn is not callable +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(TypeError, function() { + sample.forEach(); + }); + + assert.throws(TypeError, function() { + sample.forEach(undefined); + }); + + assert.throws(TypeError, function() { + sample.forEach(null); + }); + + assert.throws(TypeError, function() { + sample.forEach({}); + }); + + assert.throws(TypeError, function() { + sample.forEach(1); + }); + + assert.throws(TypeError, function() { + sample.forEach(""); + }); + + assert.throws(TypeError, function() { + sample.forEach(false); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-no-interaction-over-non-integer.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 0000000000000000000000000000000000000000..d1d4946c69931f751893c53ff823aaba3d3e06be --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-no-interaction-over-non-integer.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Does not interact over non-integer properties +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.forEach(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + + assert.sameValue(results[0][0], 7n, "results[0][0] - kValue"); + assert.sameValue(results[1][0], 8n, "results[1][0] - kValue"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..2695f5843d9ef02c5f222c8d966ed3be8b402498 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().forEach(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..013d2f6f71d3d43e330ae41bcc608d16bb3e84ec --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(3); + + sample1[1] = 1n; + + sample1.forEach(function() { + return 42; + }); + + assert.sameValue(sample1[0], 0n, "[0] == 0"); + assert.sameValue(sample1[1], 1n, "[1] == 1"); + assert.sameValue(sample1[2], 0n, "[2] == 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..53024452bd6c1e38711b4b5cf37114d85bc3eaaa --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.forEach(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-set-value-during-interaction.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000000000000000000000000000000000..c06a2f8739fd1e3b1f6a7c01938dab088553f9d3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-set-value-during-interaction.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.forEach(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1n, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7n), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + }); + + assert.sameValue(sample[0], 7n, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1n, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2n, "changed values after iteration [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..7dd8ffa055459c8f703c47accad50850aa2dc7f9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/callbackfn-this.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + callbackfn `this` value +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.forEach(function() { + results1.push(this); + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.forEach(function() { + results2.push(this); + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..a1cb8a9cf5a5b02ca468d8e02d005e064f04c479 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.forEach(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..d53d05bd28b2766580d2a07e1c2bf34840e91edc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.forEach, + 'function', + 'implements SendableTypedArray.prototype.forEach' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.forEach(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.forEach(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the forEach operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.forEach(() => {}); + throw new Test262Error('forEach completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/returns-undefined.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/returns-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..1db950520aa0464ca27e806f44c04275435c242c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/returns-undefined.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Returns undefined +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + + var result1 = sample1.forEach(function() { + return 42; + }); + + assert.sameValue(result1, undefined, "result1"); + + var sample2 = new TA(1); + var result2 = sample2.forEach(function() { + return null; + }); + + assert.sameValue(result2, undefined, "result2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..93582128b1be095819f725b8c46aee39a37435bf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/BigInt/values-are-not-cached.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + sample.forEach(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42n; + } + + assert.sameValue( + v, 42n, "method does not cache values before callbackfn calls" + ); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/forEach/arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..2d5195e4e2cab99fcc6c69bce495afdc0e7e8ae4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/arraylength-internal.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + [[ArrayLength]] is accessed in place of performing a [[Get]] of "length" +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + var loop = 0; + + Object.defineProperty(sample1, "length", {value: 1}); + + sample1.forEach(function() { + loop++; + }); + + assert.sameValue(loop, 42, "data descriptor"); + + var sample2 = new TA(7); + loop = 0; + + Object.defineProperty(sample2, "length", { + get: function() { + throw new Test262Error( + "Does not return abrupt getting length property" + ); + } + }); + + sample2.forEach(function() { + loop++; + }); + + assert.sameValue(loop, 7, "accessor descriptor"); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-arguments-with-thisarg.js b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..513823583131f89b49386e31ea1ecb70d00b5d8a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.forEach(function() { + results.push(arguments); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-arguments-without-thisarg.js b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..263c1f2e9ecb30a5842fbcd4ffafce196c7943af --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + callbackfn arguments +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + + sample.forEach(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..51644ff01b3aa59986017d14d23092b0e7c8f80b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-detachbuffer.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [detachArrayBuffer.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.forEach(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-is-not-callable.js b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..d724c8b149f2a981904b8724c456ccd98eea891e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-is-not-callable.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + callbackfn is not callable +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(TypeError, function() { + sample.forEach(); + }); + + assert.throws(TypeError, function() { + sample.forEach(undefined); + }); + + assert.throws(TypeError, function() { + sample.forEach(null); + }); + + assert.throws(TypeError, function() { + sample.forEach({}); + }); + + assert.throws(TypeError, function() { + sample.forEach(1); + }); + + assert.throws(TypeError, function() { + sample.forEach(""); + }); + + assert.throws(TypeError, function() { + sample.forEach(false); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-no-interaction-over-non-integer.js b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 0000000000000000000000000000000000000000..f9155d7c52ee935ff7eee69ed0fdde9c8b925407 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-no-interaction-over-non-integer.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Does not interact over non-integer properties +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7, 8]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.forEach(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + + assert.sameValue(results[0][0], 7, "results[0][0] - kValue"); + assert.sameValue(results[1][0], 8, "results[1][0] - kValue"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..bfdd0c98d5240b294d8ee2dcffa45aa0e7aa63db --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-not-called-on-empty.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().forEach(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-resize.js b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..1142e1d5003d79a31ce7f866cfbb71a6dfe23696 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-resize.js @@ -0,0 +1,84 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.forEach +description: Instance buffer can be resized during iteration +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var finalElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + + elements = []; + indices = []; + arrays = []; + result = sample.forEach(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + finalElement = undefined; + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + finalElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + + elements.push(element); + indices.push(index); + arrays.push(array); + }); + + assert.compareArray(elements, [0, 0, finalElement], 'elements (shrink)'); + assert.compareArray(indices, [0, 1, 2], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, undefined, 'result (shrink)'); + + elements = []; + indices = []; + arrays = []; + result = sample.forEach(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + + elements.push(element); + indices.push(index); + arrays.push(array); + }); + + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, undefined, 'result (grow)'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..e4be72f28c02b9a48d74ea06683ea17abbc9c3be --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA(3); + + sample1[1] = 1; + + sample1.forEach(function() { + return 42; + }); + + assert.sameValue(sample1[0], 0, "[0] == 0"); + assert.sameValue(sample1[1], 1, "[1] == 1"); + assert.sameValue(sample1[2], 0, "[2] == 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..33fd1dbe1969a3da9acb3ba13be953d8ee874935 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-returns-abrupt.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.forEach(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-set-value-during-interaction.js b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000000000000000000000000000000000..f77348bf276d32393c9d5317b57f7c290c697d47 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-set-value-during-interaction.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [sendableTypedArray.js] +features: [Reflect.set, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + var newVal = 0; + + sample.forEach(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + }); + + assert.sameValue(sample[0], 7, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2, "changed values after iteration [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..4f21698338cd41e2d8bca086a61873a73deb711d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/callbackfn-this.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + callbackfn `this` value +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.forEach(function() { + results1.push(this); + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.forEach(function() { + results2.push(this); + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/forEach/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..93ff35ef94dac2adafdda1edbf65241a484311e6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.forEach(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/forEach/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..dcedeea0674fa5b0f8e1114c5051bc0f6fab6897 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var forEach = SendableTypedArray.prototype.forEach; + +assert.sameValue(typeof forEach, 'function'); + +assert.throws(TypeError, function() { + forEach(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/forEach/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..23aca02d06f61e84750b3c76fa869a106122c600 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.forEach, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.forEach(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/length.js b/test/sendable/builtins/TypedArray/prototype/forEach/length.js new file mode 100644 index 0000000000000000000000000000000000000000..a0b98e1a0f18c7a8fb7ee5a05cae8b0609c284fe --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + %SendableTypedArray%.prototype.forEach.length is 1. +info: | + %SendableTypedArray%.prototype.forEach (callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.forEach, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/name.js b/test/sendable/builtins/TypedArray/prototype/forEach/name.js new file mode 100644 index 0000000000000000000000000000000000000000..779d1dbbfde3635dea735c7df9e7aa04ceac7fa6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + %SendableTypedArray%.prototype.forEach.name is "forEach". +info: | + %SendableTypedArray%.prototype.forEach (callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.forEach, "name", { + value: "forEach", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/forEach/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..0d9f5795b803c79c56f794ddea57e3e09c8ddc3f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.forEach does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.forEach), + false, + 'isConstructor(SendableTypedArray.prototype.forEach) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.forEach(() => {}); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/forEach/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..575c259cbaf4a25c4561a4fc895c7f4274b2c75a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + "forEach" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'forEach', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/forEach/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..1bbcb172047065728ff7f4bd77d13646cfe07828 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + SendableTypedArray.p.forEach behaves correctly on SendableTypedArrays backed by resizable + buffers that are grown mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + fixedLength.forEach(ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.forEach(ResizeMidIteration); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + lengthTracking.forEach(ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.forEach(ResizeMidIteration); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/forEach/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..594cee451b61178a742de82eda255449c26d4949 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + SendableTypedArray.p.forEach behaves correctly on SendableTypedArrays backed by resizable + buffers that are shrunk mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLength.forEach(ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.forEach(ResizeMidIteration); + assert.compareArray(values, [ + 4, + undefined + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTracking.forEach(ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4, + undefined + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.forEach(ResizeMidIteration); + assert.compareArray(values, [ + 4, + undefined + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/forEach/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..8900ee3b3fd85456957a8cdd60430c6a77af1676 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/resizable-buffer.js @@ -0,0 +1,157 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + SendableTypedArray.p.forEach behaves correctly when on SendableTypedArrays backed by resizable + buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function Collect(array) { + const forEachValues = []; + array.forEach(n => { + forEachValues.push(n); + }); + return ToNumbers(forEachValues); + } + assert.compareArray(Collect(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(Collect(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(Collect(lengthTracking), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(Collect(lengthTrackingWithOffset), [ + 4, + 6 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + Collect(fixedLength); + }); + assert.throws(TypeError, () => { + Collect(fixedLengthWithOffset); + }); + + assert.compareArray(Collect(lengthTracking), [ + 0, + 2, + 4 + ]); + assert.compareArray(Collect(lengthTrackingWithOffset), [4]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + Collect(fixedLength); + }); + assert.throws(TypeError, () => { + Collect(fixedLengthWithOffset); + }); + assert.throws(TypeError, () => { + Collect(lengthTrackingWithOffset); + }); + + assert.compareArray(Collect(lengthTracking), [0]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + Collect(fixedLength); + }); + assert.throws(TypeError, () => { + Collect(fixedLengthWithOffset); + }); + assert.throws(TypeError, () => { + Collect(lengthTrackingWithOffset); + }); + + assert.compareArray(Collect(lengthTracking), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.compareArray(Collect(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(Collect(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(Collect(lengthTracking), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(Collect(lengthTrackingWithOffset), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/forEach/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..b6d4c91c67f84933b6214bf39725a5d99c4e17cf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.forEach, + 'function', + 'implements SendableTypedArray.prototype.forEach' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.forEach(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.forEach(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the forEach operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.forEach(() => {}); + throw new Test262Error('forEach completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/returns-undefined.js b/test/sendable/builtins/TypedArray/prototype/forEach/returns-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..a18761d26092c49867f2709c214964dfedf0213c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/returns-undefined.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Returns undefined +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + + var result1 = sample1.forEach(function() { + return 42; + }); + + assert.sameValue(result1, undefined, "result1"); + + var sample2 = new TA(1); + var result2 = sample2.forEach(function() { + return null; + }); + + assert.sameValue(result2, undefined, "result2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/forEach/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..82c0b88c750a57d1e03cbec6b426c1ca43d2e3a0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/this-is-not-object.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var forEach = SendableTypedArray.prototype.forEach; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + forEach.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + forEach.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + forEach.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + forEach.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + forEach.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + forEach.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + forEach.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/forEach/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..f5443367a3eb54f3a50e39050b651ea10ee43e87 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/this-is-not-typedarray-instance.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var forEach = SendableTypedArray.prototype.forEach; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + forEach.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + forEach.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + forEach.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + forEach.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/forEach/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/forEach/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..e43d209b0753a0e483f5cd2d10f18d869f779820 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/forEach/values-are-not-cached.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.foreach +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.12 %SendableTypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + sample.forEach(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42; + } + + assert.sameValue( + v, 42, "method does not cache values before callbackfn calls" + ); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-false-for-zero.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-false-for-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..e5b6d41965d32902ef89caa35cf017cb8148d130 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-false-for-zero.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Returns -1 if buffer is detached after ValidateSendableTypedArray +info: | + %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13. + + When the includes method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return false. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return false. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let elementK be the result of ! Get(O, ! ToString(F(k))). + If SameValueZero(searchElement, elementK) is true, return true. + Set k to k + 1. + Return false. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.includes(0n, fromIndex), false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-true-for-undefined.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-true-for-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..5b27672ab782c563695e0ee1bfdf47bc3f15eac1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/detached-buffer-during-fromIndex-returns-true-for-undefined.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + Returns false if buffer is detached after ValidateSendableTypedArray and searchElement is a value +info: | + %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13. + + When the includes method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return false. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return false. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let elementK be the result of ! Get(O, ! ToString(F(k))). + If SameValueZero(searchElement, elementK) is true, return true. + Set k to k + 1. + Return false. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.includes(undefined, fromIndex), true); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..ba07e0335f576288987f7d9dc9571a9e3517a352 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/detached-buffer.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.14 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.includes(0n); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/fromIndex-equal-or-greater-length-returns-false.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/fromIndex-equal-or-greater-length-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..057c9a679e31c03c60ac048217d517c76c4d4963 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/fromIndex-equal-or-greater-length-returns-false.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Return false if fromIndex >= ArrayLength +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + ... + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(42); + assert.sameValue(sample.includes(0n, 42), false); + assert.sameValue(sample.includes(0n, 43), false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/fromIndex-infinity.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/fromIndex-infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..0c045216f5da5ac0fdb58bd30fb55740e405901b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/fromIndex-infinity.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: handle Infinity values for fromIndex +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + ... + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 43n, 41n]); + + assert.sameValue( + sample.includes(43n, Infinity), + false, + "includes(43, Infinity)" + ); + assert.sameValue( + sample.includes(43n, -Infinity), + true, + "includes(43, -Infinity)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/fromIndex-minus-zero.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/fromIndex-minus-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..e7119d04b9c022657ab3effb0752277dd00db63d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/fromIndex-minus-zero.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: -0 fromIndex becomes 0 +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n]); + assert.sameValue(sample.includes(42n, -0), true, "-0 [0]"); + assert.sameValue(sample.includes(43n, -0), true, "-0 [1]"); + assert.sameValue(sample.includes(44n, -0), false, "-0 [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..9aae0af515fb8d583fa09040f5ccb77f80ee0a8a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", {value: 0}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n]); + + Object.defineProperty(TA.prototype, "length", {value: 0}); + Object.defineProperty(sample, "length", {value: 0}); + + assert.sameValue(sample.includes(7n), true); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/length-zero-returns-false.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/length-zero-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..90c0b8b01047096f4456ea01533148a6215e8441 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/length-zero-returns-false.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Returns false if length is 0 +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. If len is 0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.includes(0), false, "returns false"); + assert.sameValue(sample.includes(), false, "returns false - no arg"); + assert.sameValue( + sample.includes(0n, fromIndex), false, + "length is checked before ToInteger(fromIndex)" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..47e8b9feaff3878037eb7cfa676b7e3dc695f3f1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.includes, + 'function', + 'implements SendableTypedArray.prototype.includes' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.includes(0n); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.includes(0n); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the includes operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.includes(0n); + throw new Test262Error('includes completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex-symbol.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..a58d1bc0bf59866831265cdb867f6d30d8f2f05c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex-symbol.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var fromIndex = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n]); + + assert.throws(TypeError, function() { + sample.includes(7n, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..7e388beaab811408a3a6335476fcf29902b33ea2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n]); + + assert.throws(Test262Error, function() { + sample.includes(7n, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/search-found-returns-true.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/search-found-returns-true.js new file mode 100644 index 0000000000000000000000000000000000000000..1f3f9ed3923dc26b5d79a5a9859a5e5b190b0455 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/search-found-returns-true.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: returns true for found index +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 42n, 41n]); + assert.sameValue(sample.includes(42n), true, "includes(42)"); + assert.sameValue(sample.includes(43n), true, "includes(43)"); + assert.sameValue(sample.includes(43n, 1), true, "includes(43, 1)"); + assert.sameValue(sample.includes(42n, 1), true, "includes(42, 1)"); + assert.sameValue(sample.includes(42n, 2), true, "includes(42, 2)"); + + assert.sameValue(sample.includes(42n, -4), true, "includes(42, -4)"); + assert.sameValue(sample.includes(42n, -3), true, "includes(42, -3)"); + assert.sameValue(sample.includes(42n, -2), true, "includes(42, -2)"); + assert.sameValue(sample.includes(42n, -5), true, "includes(42, -5)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/search-not-found-returns-false.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/search-not-found-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..9171b1ffa95f462c196cce6f5be83e6bf63b4768 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/search-not-found-returns-false.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: returns false if the element is not found +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n, 42n, 41n]); + assert.sameValue(sample.includes(44n), false, "includes(44)"); + assert.sameValue(sample.includes(43n, 2), false, "includes(43, 2)"); + assert.sameValue(sample.includes(42n, 3), false, "includes(42, 3)"); + assert.sameValue(sample.includes(44n, -4), false, "includes(44, -4)"); + assert.sameValue(sample.includes(44n, -5), false, "includes(44, -5)"); + assert.sameValue(sample.includes(42n, -1), false, "includes(42, -1)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/BigInt/tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..e6105734b40ad60c27bda824e690d684976c0e40 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/BigInt/tointeger-fromindex.js @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: get the integer value from fromIndex +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n]); + assert.sameValue(sample.includes(42n, "1"), false, "string [0]"); + assert.sameValue(sample.includes(43n, "1"), true, "string [1]"); + + assert.sameValue(sample.includes(42n, true), false, "true [0]"); + assert.sameValue(sample.includes(43n, true), true, "true [1]"); + + assert.sameValue(sample.includes(42n, false), true, "false [0]"); + assert.sameValue(sample.includes(43n, false), true, "false [1]"); + + assert.sameValue(sample.includes(42n, NaN), true, "NaN [0]"); + assert.sameValue(sample.includes(43n, NaN), true, "NaN [1]"); + + assert.sameValue(sample.includes(42n, null), true, "null [0]"); + assert.sameValue(sample.includes(43n, null), true, "null [1]"); + + assert.sameValue(sample.includes(42n, undefined), true, "undefined [0]"); + assert.sameValue(sample.includes(43n, undefined), true, "undefined [1]"); + + assert.sameValue(sample.includes(42n, null), true, "null [0]"); + assert.sameValue(sample.includes(43n, null), true, "null [1]"); + + assert.sameValue(sample.includes(42n, obj), false, "object [0]"); + assert.sameValue(sample.includes(43n, obj), true, "object [1]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/coerced-searchelement-fromindex-resize.js b/test/sendable/builtins/TypedArray/prototype/includes/coerced-searchelement-fromindex-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..c01138d21901ab742579ea0b93a757d626295c2b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/coerced-searchelement-fromindex-resize.js @@ -0,0 +1,97 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + SendableTypedArray.p.includes behaves correctly on SendableTypedArrays backed by resizable + buffers that are resized during argument coercion. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer, Array.prototype.includes] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert(!fixedLength.includes(undefined)); + // The TA is OOB so it includes only "undefined". + assert(fixedLength.includes(undefined, evil)); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n0 = MayNeedBigInt(fixedLength, 0); + assert(fixedLength.includes(n0)); + // The TA is OOB so it includes only "undefined". + assert(!fixedLength.includes(n0, evil)); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert(!lengthTracking.includes(undefined)); + // "includes" iterates until the original length and sees "undefined"s. + assert(lengthTracking.includes(undefined, evil)); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, 1); + } + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n0 = MayNeedBigInt(lengthTracking, 0); + assert(!lengthTracking.includes(n0)); + // The TA grew but we only look at the data until the original length. + assert(!lengthTracking.includes(n0, evil)); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + lengthTracking[0] = MayNeedBigInt(lengthTracking, 1); + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return -4; + } + }; + let n1 = MayNeedBigInt(lengthTracking, 1); + assert(lengthTracking.includes(n1, -4)); + // The TA grew but the start index conversion is done based on the original + // length. + assert(lengthTracking.includes(n1, evil)); +} diff --git a/test/sendable/builtins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-false-for-zero.js b/test/sendable/builtins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-false-for-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..ff48b488feb6b501df540fda3c4465e951560a9d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-false-for-zero.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + Returns false if buffer is detached after ValidateSendableTypedArray and searchElement is a value +info: | + %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13. + + When the includes method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return false. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return false. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let elementK be the result of ! Get(O, ! ToString(F(k))). + If SameValueZero(searchElement, elementK) is true, return true. + Set k to k + 1. + Return false. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.includes(0, fromIndex), false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-true-for-undefined.js b/test/sendable/builtins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-true-for-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..e727bda2a03e86667763f8adcc82f381e673b211 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/detached-buffer-during-fromIndex-returns-true-for-undefined.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + Returns true if buffer is detached after ValidateSendableTypedArray and searchElement is undefined +info: | + %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.includes are the same as for Array.prototype.includes as defined in 22.1.3.13. + + When the includes method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return false. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return false. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let elementK be the result of ! Get(O, ! ToString(F(k))). + If SameValueZero(searchElement, elementK) is true, return true. + Set k to k + 1. + Return false. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.includes(undefined, fromIndex), true); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/includes/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..72864f11a2edf2beeadf1cc0d69635d2426af939 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/detached-buffer.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.14 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.includes(0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js b/test/sendable/builtins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..4918e9f578a0ed9806416e6f1855dfa6de8a41a1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/fromIndex-equal-or-greater-length-returns-false.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Return false if fromIndex >= ArrayLength +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + ... + 8. Return false. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(42); + assert.sameValue(sample.includes(0, 42), false); + assert.sameValue(sample.includes(0, 43), false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/fromIndex-infinity.js b/test/sendable/builtins/TypedArray/prototype/includes/fromIndex-infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..2d4f8d891e1c9598508f5beb5a51f85409f46ce8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/fromIndex-infinity.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: handle Infinity values for fromIndex +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + ... + 8. Return false. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 43, 41]); + + assert.sameValue( + sample.includes(43, Infinity), + false, + "includes(43, Infinity)" + ); + assert.sameValue( + sample.includes(43, -Infinity), + true, + "includes(43, -Infinity)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/fromIndex-minus-zero.js b/test/sendable/builtins/TypedArray/prototype/includes/fromIndex-minus-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..b4fdd744c0aa2a83aeda5f72e6311185350e5396 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/fromIndex-minus-zero.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: -0 fromIndex becomes 0 +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43]); + assert.sameValue(sample.includes(42, -0), true, "-0 [0]"); + assert.sameValue(sample.includes(43, -0), true, "-0 [1]"); + assert.sameValue(sample.includes(44, -0), false, "-0 [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..8e56b57e0e163d5d0efa558f774ba029fff52957 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/get-length-uses-internal-arraylength.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", {value: 0}); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7]); + + Object.defineProperty(TA.prototype, "length", {value: 0}); + Object.defineProperty(sample, "length", {value: 0}); + + assert.sameValue(sample.includes(7), true); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/index-compared-against-initial-length-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/includes/index-compared-against-initial-length-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..fcc2ff61a9fe9938ccffceec873d9101da9fad3b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/index-compared-against-initial-length-out-of-bounds.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + Index is compared against the initial length when typed array is made out-of-bounds. +info: | + %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let taRecord be ? ValidateSendableTypedArray(O, seq-cst). + 3. Let len be SendableTypedArrayLength(taRecord). + ... + 5. Let n be ? ToIntegerOrInfinity(fromIndex). + ... + 9. If n ≥ 0, then + a. Let k be n. + ... + 11. Repeat, while k < len, + ... + +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(4, {maxByteLength: 20}); + +// Uses byteOffset to make typed array out-of-bounds when shrinking size to zero. +let byteOffset = 1; + +let ta = new Int8Array(rab, byteOffset); + +let index = { + valueOf() { + // Shrink buffer to zero. + rab.resize(0); + + // Index is larger than the initial length. + return 10; + } +}; + +// Typed array is in-bounds. +assert.sameValue(ta.length, 3); + +let result = ta.includes(undefined, index); + +// Typed array is out-of-bounds. +assert.sameValue(ta.length, 0); + +assert.sameValue(result, false); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/index-compared-against-initial-length.js b/test/sendable/builtins/TypedArray/prototype/includes/index-compared-against-initial-length.js new file mode 100644 index 0000000000000000000000000000000000000000..041bf90cd819112ca92493ff011e5435bc7b4a68 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/index-compared-against-initial-length.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + Index is compared against the initial length. +info: | + %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let taRecord be ? ValidateSendableTypedArray(O, seq-cst). + 3. Let len be SendableTypedArrayLength(taRecord). + ... + 5. Let n be ? ToIntegerOrInfinity(fromIndex). + ... + 9. If n ≥ 0, then + a. Let k be n. + ... + 11. Repeat, while k < len, + ... + +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(4, {maxByteLength: 20}); +let ta = new Int8Array(rab); + +let index = { + valueOf() { + // Shrink buffer to zero. + rab.resize(0); + + // Index is larger than the initial length. + return 10; + } +}; + +// Auto-length is correctly tracked. +assert.sameValue(ta.length, 4); + +let result = ta.includes(undefined, index); + +// Auto-length is correctly set to zero. +assert.sameValue(ta.length, 0); + +assert.sameValue(result, false); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/includes/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..1fa063bad737851431a0b0e56c4269716f0e477b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.14 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var includes = SendableTypedArray.prototype.includes; + +assert.sameValue(typeof includes, "function"); + +assert.throws(TypeError, function() { + includes(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/includes/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..39c796d643b23688a108892cb0d6a8f0768f92ad --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.14 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.includes, "function"); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.includes(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/length-zero-returns-false.js b/test/sendable/builtins/TypedArray/prototype/includes/length-zero-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..d7b313aab9a2cf8e96a01512c41aec351c455f64 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/length-zero-returns-false.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Returns false if length is 0 +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. If len is 0, return false. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.includes(0), false, "returns false"); + assert.sameValue(sample.includes(), false, "returns false - no arg"); + assert.sameValue( + sample.includes(0, fromIndex), false, + "length is checked before ToInteger(fromIndex)" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/length.js b/test/sendable/builtins/TypedArray/prototype/includes/length.js new file mode 100644 index 0000000000000000000000000000000000000000..2b40cb2151904f6c14fc6ce10b986c14607a3885 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + %SendableTypedArray%.prototype.includes.length is 1. +info: | + %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.includes, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/name.js b/test/sendable/builtins/TypedArray/prototype/includes/name.js new file mode 100644 index 0000000000000000000000000000000000000000..69b8fc6556d19ca1c2bce7bad7bc51e6d0c1b524 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + %SendableTypedArray%.prototype.includes.name is "includes". +info: | + %SendableTypedArray%.prototype.includes (searchElement [ , fromIndex ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.includes, "name", { + value: "includes", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/includes/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..6959e33a2ccf7e733c8ef56f7655057a4dcace5d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.includes does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.includes), + false, + 'isConstructor(SendableTypedArray.prototype.includes) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.includes(1); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/includes/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/includes/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..09fb022432c9d0ba37615d92e03b8d206ea6e4c6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + "includes" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, "includes", { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/resizable-buffer-special-float-values.js b/test/sendable/builtins/TypedArray/prototype/includes/resizable-buffer-special-float-values.js new file mode 100644 index 0000000000000000000000000000000000000000..b48d15f0b5503ca1bba8b1c81bc44419cd1c16eb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/resizable-buffer-special-float-values.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + SendableTypedArray.p.includes behaves correctly for special float values when + receiver is a float SendableTypedArray backed by a resizable buffer. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer, Array.prototype.includes] +---*/ + +for (let ctor of floatCtors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + lengthTracking[0] = -Infinity; + lengthTracking[1] = Infinity; + lengthTracking[2] = NaN; + assert(lengthTracking.includes(-Infinity)); + assert(lengthTracking.includes(Infinity)); + assert(lengthTracking.includes(NaN)); +} diff --git a/test/sendable/builtins/TypedArray/prototype/includes/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/includes/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..e32bbbdf2dbbb82eed3556a809f8b481c34f4d6a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/resizable-buffer.js @@ -0,0 +1,149 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + SendableTypedArray.p.includes behaves correctly on SendableTypedArrays backed by resizable + buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer, Array.prototype.includes] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + // If fixedLength is a BigInt array, they all are BigInt Arrays. + let n2 = MayNeedBigInt(fixedLength, 2); + let n4 = MayNeedBigInt(fixedLength, 4); + + assert(fixedLength.includes(n2)); + assert(!fixedLength.includes(undefined)); + assert(fixedLength.includes(n2, 1)); + assert(!fixedLength.includes(n2, 2)); + assert(fixedLength.includes(n2, -3)); + assert(!fixedLength.includes(n2, -2)); + assert(!fixedLengthWithOffset.includes(n2)); + assert(fixedLengthWithOffset.includes(n4)); + assert(!fixedLengthWithOffset.includes(undefined)); + assert(fixedLengthWithOffset.includes(n4, 0)); + assert(!fixedLengthWithOffset.includes(n4, 1)); + assert(fixedLengthWithOffset.includes(n4, -2)); + assert(!fixedLengthWithOffset.includes(n4, -1)); + assert(lengthTracking.includes(n2)); + assert(!lengthTracking.includes(undefined)); + assert(lengthTracking.includes(n2, 1)); + assert(!lengthTracking.includes(n2, 2)); + assert(lengthTracking.includes(n2, -3)); + assert(!lengthTracking.includes(n2, -2)); + assert(!lengthTrackingWithOffset.includes(n2)); + assert(lengthTrackingWithOffset.includes(n4)); + assert(!lengthTrackingWithOffset.includes(undefined)); + assert(lengthTrackingWithOffset.includes(n4, 0)); + assert(!lengthTrackingWithOffset.includes(n4, 1)); + assert(lengthTrackingWithOffset.includes(n4, -2)); + assert(!lengthTrackingWithOffset.includes(n4, -1)); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.includes(n2); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.includes(n2); + }); + + assert(lengthTracking.includes(n2)); + assert(!lengthTracking.includes(undefined)); + assert(!lengthTrackingWithOffset.includes(n2)); + assert(lengthTrackingWithOffset.includes(n4)); + assert(!lengthTrackingWithOffset.includes(undefined)); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.includes(n2); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.includes(n2); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.includes(n2); + }); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.includes(n2); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.includes(n2); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.includes(n2); + }); + assert(!lengthTracking.includes(n2)); + assert(!lengthTracking.includes(undefined)); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + let n8 = MayNeedBigInt(fixedLength, 8); + + assert(fixedLength.includes(n2)); + assert(!fixedLength.includes(undefined)); + assert(!fixedLength.includes(n8)); + assert(!fixedLengthWithOffset.includes(n2)); + assert(fixedLengthWithOffset.includes(n4)); + assert(!fixedLengthWithOffset.includes(undefined)); + assert(!fixedLengthWithOffset.includes(n8)); + assert(lengthTracking.includes(n2)); + assert(!lengthTracking.includes(undefined)); + assert(lengthTracking.includes(n8)); + assert(!lengthTrackingWithOffset.includes(n2)); + assert(lengthTrackingWithOffset.includes(n4)); + assert(!lengthTrackingWithOffset.includes(undefined)); + assert(lengthTrackingWithOffset.includes(n8)); +} diff --git a/test/sendable/builtins/TypedArray/prototype/includes/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/includes/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..049726f535501178ddc14f3f7b78425dac458343 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.includes, + 'function', + 'implements SendableTypedArray.prototype.includes' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.includes(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.includes(0); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the includes operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.includes(0); + throw new Test262Error('includes completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js b/test/sendable/builtins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..7c05e3adab2b51e0a749d4556b91d416fe8a2384 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex-symbol.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var fromIndex = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7]); + + assert.throws(TypeError, function() { + sample.includes(7, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..ba1ede76a731676937b97624bf82d8bbd2a019b4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/return-abrupt-tointeger-fromindex.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7]); + + assert.throws(Test262Error, function() { + sample.includes(7, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/samevaluezero.js b/test/sendable/builtins/TypedArray/prototype/includes/samevaluezero.js new file mode 100644 index 0000000000000000000000000000000000000000..f5241ddc9a2ff2ba841fbcae811983d8fd42714f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/samevaluezero.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: search element is compared using SameValueZero +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 0, 1, undefined]); + assert.sameValue(sample.includes(), false, "no arg"); + assert.sameValue(sample.includes(undefined), false, "undefined"); + assert.sameValue(sample.includes("42"), false, "'42'"); + assert.sameValue(sample.includes([42]), false, "[42]"); + assert.sameValue(sample.includes(42.0), true, "42.0"); + assert.sameValue(sample.includes(-0), true, "-0"); + assert.sameValue(sample.includes(true), false, "true"); + assert.sameValue(sample.includes(false), false, "false"); + assert.sameValue(sample.includes(null), false, "null"); + assert.sameValue(sample.includes(""), false, "empty string"); +}); + +testWithTypedArrayConstructors(function(FloatArray) { + var sample = new FloatArray([42, 0, 1, undefined, NaN]); + assert.sameValue(sample.includes(NaN), true, "NaN"); +}, floatArrayConstructors); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/search-found-returns-true.js b/test/sendable/builtins/TypedArray/prototype/includes/search-found-returns-true.js new file mode 100644 index 0000000000000000000000000000000000000000..391944748c4c7dc9b8a2859ea090cb4e9bd5cfcf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/search-found-returns-true.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: returns true for found index +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 42, 41]); + assert.sameValue(sample.includes(42), true, "includes(42)"); + assert.sameValue(sample.includes(43), true, "includes(43)"); + assert.sameValue(sample.includes(43, 1), true, "includes(43, 1)"); + assert.sameValue(sample.includes(42, 1), true, "includes(42, 1)"); + assert.sameValue(sample.includes(42, 2), true, "includes(42, 2)"); + + assert.sameValue(sample.includes(42, -4), true, "includes(42, -4)"); + assert.sameValue(sample.includes(42, -3), true, "includes(42, -3)"); + assert.sameValue(sample.includes(42, -2), true, "includes(42, -2)"); + assert.sameValue(sample.includes(42, -5), true, "includes(42, -5)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/search-not-found-returns-false.js b/test/sendable/builtins/TypedArray/prototype/includes/search-not-found-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..bbff0974e33d7819aef891eced9b7bb0d8e4be3e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/search-not-found-returns-false.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: returns false if the element is not found +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + 8. Return false. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43, 42, 41]); + assert.sameValue(sample.includes(44), false, "includes(44)"); + assert.sameValue(sample.includes(43, 2), false, "includes(43, 2)"); + assert.sameValue(sample.includes(42, 3), false, "includes(42, 3)"); + assert.sameValue(sample.includes(44, -4), false, "includes(44, -4)"); + assert.sameValue(sample.includes(44, -5), false, "includes(44, -5)"); + assert.sameValue(sample.includes(42, -1), false, "includes(42, -1)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/searchelement-not-integer.js b/test/sendable/builtins/TypedArray/prototype/includes/searchelement-not-integer.js new file mode 100644 index 0000000000000000000000000000000000000000..0c52a7fc3eca85389077e81a9b47bdea6fe77dcd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/searchelement-not-integer.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Check that search element is not coerced if not an integer +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the same algorithm as Array.prototype.includes as defined in 22.1.3.13 + + 22.1.3.13 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + 8. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(10); + function throwFunc(){ + throw Test262Error() + return 0; + } + + assert.sameValue(sample.includes({valueOf : throwFunc}), false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/includes/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..109ec7831559cb23366cf0a22305c13d4117b2ae --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/this-is-not-object.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.14 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var includes = SendableTypedArray.prototype.includes; + +assert.throws(TypeError, function() { + includes.call(undefined, 42); +}, "this is undefined"); + +assert.throws(TypeError, function() { + includes.call(null, 42); +}, "this is null"); + +assert.throws(TypeError, function() { + includes.call(42, 42); +}, "this is 42"); + +assert.throws(TypeError, function() { + includes.call("1", 42); +}, "this is a string"); + +assert.throws(TypeError, function() { + includes.call(true, 42); +}, "this is true"); + +assert.throws(TypeError, function() { + includes.call(false, 42); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + includes.call(s, 42); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/includes/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..b46ff08af3e6eccc0f4fedc6adbe5b3720da7a7a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/this-is-not-typedarray-instance.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.14 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var includes = SendableTypedArray.prototype.includes; + +assert.throws(TypeError, function() { + includes.call({}, 42); +}, "this is an Object"); + +assert.throws(TypeError, function() { + includes.call([], 42); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + includes.call(ab, 42); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + includes.call(dv, 42); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/includes/tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/includes/tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..fc50f18adc9999799f9b37e572947af941e69380 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/includes/tointeger-fromindex.js @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.includes +description: get the integer value from fromIndex +info: | + 22.2.3.13 %SendableTypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + 8. Return false. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43]); + assert.sameValue(sample.includes(42, "1"), false, "string [0]"); + assert.sameValue(sample.includes(43, "1"), true, "string [1]"); + + assert.sameValue(sample.includes(42, true), false, "true [0]"); + assert.sameValue(sample.includes(43, true), true, "true [1]"); + + assert.sameValue(sample.includes(42, false), true, "false [0]"); + assert.sameValue(sample.includes(43, false), true, "false [1]"); + + assert.sameValue(sample.includes(42, NaN), true, "NaN [0]"); + assert.sameValue(sample.includes(43, NaN), true, "NaN [1]"); + + assert.sameValue(sample.includes(42, null), true, "null [0]"); + assert.sameValue(sample.includes(43, null), true, "null [1]"); + + assert.sameValue(sample.includes(42, undefined), true, "undefined [0]"); + assert.sameValue(sample.includes(43, undefined), true, "undefined [1]"); + + assert.sameValue(sample.includes(42, null), true, "null [0]"); + assert.sameValue(sample.includes(43, null), true, "null [1]"); + + assert.sameValue(sample.includes(42, obj), false, "object [0]"); + assert.sameValue(sample.includes(43, obj), true, "object [1]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..b7583199da8134a89655387951ed84ee6336cff9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Throws a TypeError if this has a detached buffer +info: | + %SendableTypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.indexOf are the same as for Array.prototype.indexOf as defined in 22.1.3.14. + + When the indexOf method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return -1F. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return -1F. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k + 1. + Return -1F. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.indexOf(undefined, fromIndex), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..dcee961c3ed1c2beb9cc8f1e677afba52bf4737c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Throws a TypeError if this has a detached buffer +info: | + %SendableTypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.indexOf are the same as for Array.prototype.indexOf as defined in 22.1.3.14. + + When the indexOf method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return -1F. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return -1F. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k + 1. + Return -1F. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.indexOf(0n, fromIndex), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..7dff374fcb9a39109e66335cf00f9ab8877937dd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/detached-buffer.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.indexOf(0n); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/fromIndex-equal-or-greater-length-returns-minus-one.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/fromIndex-equal-or-greater-length-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..53bf0823475a607ffbaa909c421cc0a5bfcdfcd2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/fromIndex-equal-or-greater-length-returns-minus-one.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Return -1 if fromIndex >= ArrayLength +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(42); + assert.sameValue(sample.indexOf(0n, 42), -1); + assert.sameValue(sample.indexOf(0n, 43), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/fromIndex-infinity.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/fromIndex-infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..5f05c472344097e623a05776166e7266f210bfcf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/fromIndex-infinity.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: handle Infinity values for fromIndex +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + 7. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 8. Repeat, while k < len + a. Let kPresent be ? HasProperty(O, ! ToString(k)). + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ii. Let same be the result of performing Strict Equality Comparison + searchElement === elementK. + iii. If same is true, return k. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 43n, 41n]); + + assert.sameValue(sample.indexOf(43n, Infinity), -1, "indexOf(43, Infinity)"); + assert.sameValue(sample.indexOf(43n, -Infinity), 1, "indexOf(43, -Infinity)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/fromIndex-minus-zero.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/fromIndex-minus-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..10b2364a8758263a8162e2defc06d03b6c388f18 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/fromIndex-minus-zero.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: -0 fromIndex becomes 0 +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n]); + assert.sameValue(sample.indexOf(42n, -0), 0, "-0 [0]"); + assert.sameValue(sample.indexOf(43n, -0), 1, "-0 [1]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..d1ad8ca9b3023858f6122f2a4193f4df05a5a20c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", {value: 0}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n]); + + Object.defineProperty(TA.prototype, "length", {value: 0}); + Object.defineProperty(sample, "length", {value: 0}); + + assert.sameValue(sample.indexOf(7n), 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/length-zero-returns-minus-one.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/length-zero-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..b7456ad2147c699900ed5e1fbae37512377b8118 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/length-zero-returns-minus-one.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Returns -1 if length is 0 +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. If len is 0, return -1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.indexOf(0n), -1, "returns -1"); + assert.sameValue( + sample.indexOf(0n, fromIndex), -1, + "length is checked before ToInteger(fromIndex)" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/no-arg.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/no-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..c134e2737335c73016c4370b6c10fcbddcaacefa --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/no-arg.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: > + If `searchElement` is not supplied, -1 is returned. +info: | + %SendableTypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements + the same algorithm as Array.prototype.indexOf as defined in 22.1.3.14 + except that the this value's [[ArrayLength]] internal slot is accessed + in place of performing a [[Get]] of "length". + + Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + [...] + 10. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.indexOf(), -1); + + var ta2 = new TA([0n, 1n, 2n]); + assert.sameValue(ta2.indexOf(), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..4a97e0688de7f5c30a7647ccc3e8d16187adc51d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.indexOf, + 'function', + 'implements SendableTypedArray.prototype.indexOf' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.indexOf(0n); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.indexOf(0n); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the indexOf operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.indexOf(0n); + throw new Test262Error('indexOf completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..71454a440d05f89e5cc3784220595e06197d93ee --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var fromIndex = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.indexOf(7n, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..37c559ea771cd9d4d7d009e47a7fdffd9b791f55 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(Test262Error, function() { + sample.indexOf(7n, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/search-found-returns-index.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/search-found-returns-index.js new file mode 100644 index 0000000000000000000000000000000000000000..491f73ca711de844882ba8ba8c972dee3d0a6792 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/search-found-returns-index.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: returns index for the first found element +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + 7. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 8. Repeat, while k < len + a. Let kPresent be ? HasProperty(O, ! ToString(k)). + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ii. Let same be the result of performing Strict Equality Comparison + searchElement === elementK. + iii. If same is true, return k. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 42n, 41n]); + assert.sameValue(sample.indexOf(42n), 0, "indexOf(42)"); + assert.sameValue(sample.indexOf(43n), 1, "indexOf(43)"); + assert.sameValue(sample.indexOf(43n, 1), 1, "indexOf(43, 1)"); + assert.sameValue(sample.indexOf(42n, 1), 2, "indexOf(42, 1)"); + assert.sameValue(sample.indexOf(42n, 2), 2, "indexOf(42, 2)"); + + assert.sameValue(sample.indexOf(42n, -4), 0, "indexOf(42, -4)"); + assert.sameValue(sample.indexOf(42n, -3), 2, "indexOf(42, -3)"); + assert.sameValue(sample.indexOf(42n, -2), 2, "indexOf(42, -2)"); + assert.sameValue(sample.indexOf(42n, -5), 0, "indexOf(42, -5)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/search-not-found-returns-minus-one.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/search-not-found-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..419db05fe23559e22e6291c522513825177fbcab --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/search-not-found-returns-minus-one.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: returns -1 if the element if not found +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + 7. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + ... + 9. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n, 42n, 41n]); + assert.sameValue(sample.indexOf(44n), -1, "indexOf(44)"); + assert.sameValue(sample.indexOf(43n, 2), -1, "indexOf(43, 2)"); + assert.sameValue(sample.indexOf(42n, 3), -1, "indexOf(42, 3)"); + assert.sameValue(sample.indexOf(44n, -4), -1, "indexOf(44, -4)"); + assert.sameValue(sample.indexOf(44n, -5), -1, "indexOf(44, -5)"); + assert.sameValue(sample.indexOf(42n, -1), -1, "indexOf(42, -1)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..28aea42a4657a8c5de6149c8fb7edc179e08cf60 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/BigInt/tointeger-fromindex.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Return -1 if fromIndex >= ArrayLength - converted values +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n]); + assert.sameValue(sample.indexOf(42n, "1"), -1, "string [0]"); + assert.sameValue(sample.indexOf(43n, "1"), 1, "string [1]"); + + assert.sameValue(sample.indexOf(42n, true), -1, "true [0]"); + assert.sameValue(sample.indexOf(43n, true), 1, "true [1]"); + + assert.sameValue(sample.indexOf(42n, false), 0, "false [0]"); + assert.sameValue(sample.indexOf(43n, false), 1, "false [1]"); + + assert.sameValue(sample.indexOf(42n, NaN), 0, "NaN [0]"); + assert.sameValue(sample.indexOf(43n, NaN), 1, "NaN [1]"); + + assert.sameValue(sample.indexOf(42n, null), 0, "null [0]"); + assert.sameValue(sample.indexOf(43n, null), 1, "null [1]"); + + assert.sameValue(sample.indexOf(42n, undefined), 0, "undefined [0]"); + assert.sameValue(sample.indexOf(43n, undefined), 1, "undefined [1]"); + + assert.sameValue(sample.indexOf(42n, null), 0, "null [0]"); + assert.sameValue(sample.indexOf(43n, null), 1, "null [1]"); + + assert.sameValue(sample.indexOf(42n, obj), -1, "object [0]"); + assert.sameValue(sample.indexOf(43n, obj), 1, "object [1]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/coerced-searchelement-fromindex-grow.js b/test/sendable/builtins/TypedArray/prototype/indexOf/coerced-searchelement-fromindex-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..2ba98305b7e5469ee82386b3a9505db8efc50efb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/coerced-searchelement-fromindex-grow.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: > + SendableTypedArray.p.indexOf behaves correctly when the backing resizable buffer is + grown during argument coercion. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Growing + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, 1); + } + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n0 = MayNeedBigInt(lengthTracking, 0); + assert.sameValue(lengthTracking.indexOf(n0), -1); + // The TA grew but we only look at the data until the original length. + assert.sameValue(lengthTracking.indexOf(n0, evil), -1); +} + +// Growing + length-tracking TA, index conversion. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + lengthTracking[0] = MayNeedBigInt(lengthTracking, 1); + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return -4; + } + }; + let n1 = MayNeedBigInt(lengthTracking, 1); + assert.sameValue(lengthTracking.indexOf(n1, -4), 0); + // The TA grew but the start index conversion is done based on the original + // length. + assert.sameValue(lengthTracking.indexOf(n1, evil), 0); +} diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/coerced-searchelement-fromindex-shrink.js b/test/sendable/builtins/TypedArray/prototype/indexOf/coerced-searchelement-fromindex-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..4ec4529b8f58bd77e2697c1b8823684ec5365092 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/coerced-searchelement-fromindex-shrink.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: > + SendableTypedArray.p.indexOf behaves correctly when receiver is shrunk + during argument coercion +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Shrinking + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n0 = MayNeedBigInt(fixedLength, 0); + assert.sameValue(fixedLength.indexOf(n0), 0); + // The TA is OOB so indexOf returns -1. + assert.sameValue(fixedLength.indexOf(n0, evil), -1); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n0 = MayNeedBigInt(fixedLength, 0); + assert.sameValue(fixedLength.indexOf(n0), 0); + // The TA is OOB so indexOf returns -1, also for undefined). + assert.sameValue(fixedLength.indexOf(undefined, evil), -1); +} + +// Shrinking + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i); + } + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + let n2 = MayNeedBigInt(lengthTracking, 2); + assert.sameValue(lengthTracking.indexOf(n2), 2); + // 2 no longer found. + assert.sameValue(lengthTracking.indexOf(n2, evil), -1); +} diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js b/test/sendable/builtins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..bbd45397d7b0ead8c63ffd846b6716714126392f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Returns -1 if buffer is detached after ValidateSendableTypedArray +info: | + %SendableTypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.indexOf are the same as for Array.prototype.indexOf as defined in 22.1.3.14. + + When the indexOf method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return -1F. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return -1F. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k + 1. + Return -1F. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.indexOf(undefined, fromIndex), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js b/test/sendable/builtins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..e7850c336b3272e177b2e4de4bdb3864b3a1c34d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Returns -1 if buffer is detached after ValidateSendableTypedArray +info: | + %SendableTypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.indexOf are the same as for Array.prototype.indexOf as defined in 22.1.3.14. + + When the indexOf method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return -1F. + Let n be ? ToIntegerOrInfinity(fromIndex). + Assert: If fromIndex is undefined, then n is 0. + If n is +∞, return -1F. + Else if n is -∞, set n to 0. + If n ≥ 0, then + Let k be n. + Else, + Let k be len + n. + If k < 0, set k to 0. + Repeat, while k < len, + Let kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k + 1. + Return -1F. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.indexOf(0, fromIndex), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/indexOf/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..5212d39db3d39b825c502c8fc9c85ae2384a4932 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/detached-buffer.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.indexOf(0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/fromIndex-equal-or-greater-length-returns-minus-one.js b/test/sendable/builtins/TypedArray/prototype/indexOf/fromIndex-equal-or-greater-length-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..515c22c36c77c34f5a941b8b4d8b5e8fac68a24b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/fromIndex-equal-or-greater-length-returns-minus-one.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Return -1 if fromIndex >= ArrayLength +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(42); + assert.sameValue(sample.indexOf(0, 42), -1); + assert.sameValue(sample.indexOf(0, 43), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/fromIndex-infinity.js b/test/sendable/builtins/TypedArray/prototype/indexOf/fromIndex-infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..77050bb0d1cd65fc82ac9bc378d77a684cba4c12 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/fromIndex-infinity.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: handle Infinity values for fromIndex +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + 7. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 8. Repeat, while k < len + a. Let kPresent be ? HasProperty(O, ! ToString(k)). + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ii. Let same be the result of performing Strict Equality Comparison + searchElement === elementK. + iii. If same is true, return k. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 43, 41]); + + assert.sameValue(sample.indexOf(43, Infinity), -1, "indexOf(43, Infinity)"); + assert.sameValue(sample.indexOf(43, -Infinity), 1, "indexOf(43, -Infinity)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/fromIndex-minus-zero.js b/test/sendable/builtins/TypedArray/prototype/indexOf/fromIndex-minus-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..bbfb99682281a5a1d10141d48ce3c3ddad4a45dd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/fromIndex-minus-zero.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: -0 fromIndex becomes 0 +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43]); + assert.sameValue(sample.indexOf(42, -0), 0, "-0 [0]"); + assert.sameValue(sample.indexOf(43, -0), 1, "-0 [1]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/indexOf/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..266c1ebde95deab7c9fceb85dc76a71cf625f739 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/get-length-uses-internal-arraylength.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", {value: 0}); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7]); + + Object.defineProperty(TA.prototype, "length", {value: 0}); + Object.defineProperty(sample, "length", {value: 0}); + + assert.sameValue(sample.indexOf(7), 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/indexOf/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..8be518f6821b610ee1f9b64253501c3287db27ca --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var indexOf = SendableTypedArray.prototype.indexOf; + +assert.sameValue(typeof indexOf, 'function'); + +assert.throws(TypeError, function() { + indexOf(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/indexOf/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..ad630abdb271bcccf0771d459cdcd2b91699d79e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.indexOf, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.indexOf(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/length-zero-returns-minus-one.js b/test/sendable/builtins/TypedArray/prototype/indexOf/length-zero-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..d5247fa14381a173de4e213703994df84453827a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/length-zero-returns-minus-one.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Returns -1 if length is 0 +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. If len is 0, return -1. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.indexOf(0), -1, "returns -1"); + assert.sameValue( + sample.indexOf(0, fromIndex), -1, + "length is checked before ToInteger(fromIndex)" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/length.js b/test/sendable/builtins/TypedArray/prototype/indexOf/length.js new file mode 100644 index 0000000000000000000000000000000000000000..3fa29accee6b8a11c01df634a208940244eb011f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: > + %SendableTypedArray%.prototype.indexOf.length is 1. +info: | + %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.indexOf, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/name.js b/test/sendable/builtins/TypedArray/prototype/indexOf/name.js new file mode 100644 index 0000000000000000000000000000000000000000..9253902753db861e78676a6740392fa10548b028 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: > + %SendableTypedArray%.prototype.indexOf.name is "indexOf". +info: | + %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.indexOf, "name", { + value: "indexOf", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/no-arg.js b/test/sendable/builtins/TypedArray/prototype/indexOf/no-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..35d5e2e3bb2007c2e02396ec5204880490adb173 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/no-arg.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: > + If `searchElement` is not supplied, -1 is returned. +info: | + %SendableTypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements + the same algorithm as Array.prototype.indexOf as defined in 22.1.3.14 + except that the this value's [[ArrayLength]] internal slot is accessed + in place of performing a [[Get]] of "length". + + Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + [...] + 10. Return -1. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.indexOf(), -1); + + var ta2 = new TA([0, 1, 2]); + assert.sameValue(ta2.indexOf(), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/indexOf/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..2fd697bfac4f829e5bc27872e4e4dd6899bb940b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.indexOf does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.indexOf), + false, + 'isConstructor(SendableTypedArray.prototype.indexOf) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.indexOf(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/indexOf/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..92f80b495ca946972bba17c9e590dfbf9832334d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: > + "indexOf" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'indexOf', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/resizable-buffer-special-float-values.js b/test/sendable/builtins/TypedArray/prototype/indexOf/resizable-buffer-special-float-values.js new file mode 100644 index 0000000000000000000000000000000000000000..6b6636795762a9261ccb342f57d93285aaa5431a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/resizable-buffer-special-float-values.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: > + SendableTypedArray.p.indexOf behaves correctly for special float values on float + SendableTypedArrays backed by resizable buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer, Array.prototype.includes] +---*/ + +for (let ctor of floatCtors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + lengthTracking[0] = -Infinity; + lengthTracking[1] = -Infinity; + lengthTracking[2] = Infinity; + lengthTracking[3] = Infinity; + lengthTracking[4] = NaN; + lengthTracking[5] = NaN; + assert.sameValue(lengthTracking.indexOf(-Infinity), 0); + assert.sameValue(lengthTracking.indexOf(Infinity), 2); + // NaN is never found. + assert.sameValue(lengthTracking.indexOf(NaN), -1); +} diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/indexOf/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..ca25edfa599a4d2eeb61c380ae891f251c955b11 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/resizable-buffer.js @@ -0,0 +1,149 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: > + SendableTypedArray.p.indexOf behaves correctly on SendableTypedArrays backed by resizable + buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, Math.floor(i / 2)); + } + + // Orig. array: [0, 0, 1, 1] + // [0, 0, 1, 1] << fixedLength + // [1, 1] << fixedLengthWithOffset + // [0, 0, 1, 1, ...] << lengthTracking + // [1, 1, ...] << lengthTrackingWithOffset + + // If fixedLength is a BigInt array, they all are BigInt Arrays. + let n0 = MayNeedBigInt(fixedLength, 0); + let n1 = MayNeedBigInt(fixedLength, 1); + + assert.sameValue(fixedLength.indexOf(n0), 0); + assert.sameValue(fixedLength.indexOf(n0, 1), 1); + assert.sameValue(fixedLength.indexOf(n0, 2), -1); + assert.sameValue(fixedLength.indexOf(n0, -2), -1); + assert.sameValue(fixedLength.indexOf(n0, -3), 1); + assert.sameValue(fixedLength.indexOf(n1, 1), 2); + assert.sameValue(fixedLength.indexOf(n1, -3), 2); + assert.sameValue(fixedLength.indexOf(n1, -2), 2); + assert.sameValue(fixedLength.indexOf(undefined), -1); + assert.sameValue(fixedLengthWithOffset.indexOf(n0), -1); + assert.sameValue(fixedLengthWithOffset.indexOf(n1), 0); + assert.sameValue(fixedLengthWithOffset.indexOf(n1, -2), 0); + assert.sameValue(fixedLengthWithOffset.indexOf(n1, -1), 1); + assert.sameValue(fixedLengthWithOffset.indexOf(undefined), -1); + assert.sameValue(lengthTracking.indexOf(n0), 0); + assert.sameValue(lengthTracking.indexOf(n0, 2), -1); + assert.sameValue(lengthTracking.indexOf(n1, -3), 2); + assert.sameValue(lengthTracking.indexOf(undefined), -1); + assert.sameValue(lengthTrackingWithOffset.indexOf(n0), -1); + assert.sameValue(lengthTrackingWithOffset.indexOf(n1), 0); + assert.sameValue(lengthTrackingWithOffset.indexOf(n1, 1), 1); + assert.sameValue(lengthTrackingWithOffset.indexOf(n1, -2), 0); + assert.sameValue(lengthTrackingWithOffset.indexOf(undefined), -1); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 0, 1] + // [0, 0, 1, ...] << lengthTracking + // [1, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.indexOf(n1); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.indexOf(n1); + }); + + assert.sameValue(lengthTracking.indexOf(n1), 2); + assert.sameValue(lengthTracking.indexOf(undefined), -1); + assert.sameValue(lengthTrackingWithOffset.indexOf(n0), -1); + assert.sameValue(lengthTrackingWithOffset.indexOf(n1), 0); + assert.sameValue(lengthTrackingWithOffset.indexOf(undefined), -1); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.indexOf(n0); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.indexOf(n0); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.indexOf(n0); + }); + + assert.sameValue(lengthTracking.indexOf(n0), 0); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.indexOf(n0); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.indexOf(n0); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.indexOf(n0); + }); + + assert.sameValue(lengthTracking.indexOf(n0), -1); + assert.sameValue(lengthTracking.indexOf(undefined), -1); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, Math.floor(i / 2)); + } + + // Orig. array: [0, 0, 1, 1, 2, 2] + // [0, 0, 1, 1] << fixedLength + // [1, 1] << fixedLengthWithOffset + // [0, 0, 1, 1, 2, 2, ...] << lengthTracking + // [1, 1, 2, 2, ...] << lengthTrackingWithOffset + + let n2 = MayNeedBigInt(fixedLength, 2); + + assert.sameValue(fixedLength.indexOf(n1), 2); + assert.sameValue(fixedLength.indexOf(n2), -1); + assert.sameValue(fixedLength.indexOf(undefined), -1); + assert.sameValue(fixedLengthWithOffset.indexOf(n0), -1); + assert.sameValue(fixedLengthWithOffset.indexOf(n1), 0); + assert.sameValue(fixedLengthWithOffset.indexOf(n2), -1); + assert.sameValue(fixedLengthWithOffset.indexOf(undefined), -1); + assert.sameValue(lengthTracking.indexOf(n1), 2); + assert.sameValue(lengthTracking.indexOf(n2), 4); + assert.sameValue(lengthTracking.indexOf(undefined), -1); + assert.sameValue(lengthTrackingWithOffset.indexOf(n0), -1); + assert.sameValue(lengthTrackingWithOffset.indexOf(n1), 0); + assert.sameValue(lengthTrackingWithOffset.indexOf(n2), 2); + assert.sameValue(lengthTrackingWithOffset.indexOf(undefined), -1); +} diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/indexOf/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..2d1c99bcdbc959910cf5bd3b55eec9f4da1c8784 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.indexOf, + 'function', + 'implements SendableTypedArray.prototype.indexOf' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.indexOf(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.indexOf(0); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the indexOf operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.indexOf(0); + throw new Test262Error('indexOf completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex-symbol.js b/test/sendable/builtins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..a295858461b8ee49a86db6c9a77ab81dca7b3b1e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex-symbol.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var fromIndex = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.indexOf(7, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..e9f54a3e300e08d70955016a1a505da923ce9e5c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/return-abrupt-tointeger-fromindex.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(Test262Error, function() { + sample.indexOf(7, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/search-found-returns-index.js b/test/sendable/builtins/TypedArray/prototype/indexOf/search-found-returns-index.js new file mode 100644 index 0000000000000000000000000000000000000000..bed0dfd26e08325ca125c44300cac170ed121c13 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/search-found-returns-index.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: returns index for the first found element +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + 7. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 8. Repeat, while k < len + a. Let kPresent be ? HasProperty(O, ! ToString(k)). + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ii. Let same be the result of performing Strict Equality Comparison + searchElement === elementK. + iii. If same is true, return k. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 42, 41]); + assert.sameValue(sample.indexOf(42), 0, "indexOf(42)"); + assert.sameValue(sample.indexOf(43), 1, "indexOf(43)"); + assert.sameValue(sample.indexOf(43, 1), 1, "indexOf(43, 1)"); + assert.sameValue(sample.indexOf(42, 1), 2, "indexOf(42, 1)"); + assert.sameValue(sample.indexOf(42, 2), 2, "indexOf(42, 2)"); + + assert.sameValue(sample.indexOf(42, -4), 0, "indexOf(42, -4)"); + assert.sameValue(sample.indexOf(42, -3), 2, "indexOf(42, -3)"); + assert.sameValue(sample.indexOf(42, -2), 2, "indexOf(42, -2)"); + assert.sameValue(sample.indexOf(42, -5), 0, "indexOf(42, -5)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/search-not-found-returns-minus-one.js b/test/sendable/builtins/TypedArray/prototype/indexOf/search-not-found-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..4571abfb0b36fb32b84844ba80e2d9378dd86fe6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/search-not-found-returns-minus-one.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: returns -1 if the element if not found +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + 7. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + ... + 9. Return -1. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43, 42, 41]); + assert.sameValue(sample.indexOf(44), -1, "indexOf(44)"); + assert.sameValue(sample.indexOf(43, 2), -1, "indexOf(43, 2)"); + assert.sameValue(sample.indexOf(42, 3), -1, "indexOf(42, 3)"); + assert.sameValue(sample.indexOf(44, -4), -1, "indexOf(44, -4)"); + assert.sameValue(sample.indexOf(44, -5), -1, "indexOf(44, -5)"); + assert.sameValue(sample.indexOf(42, -1), -1, "indexOf(42, -1)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/strict-comparison.js b/test/sendable/builtins/TypedArray/prototype/indexOf/strict-comparison.js new file mode 100644 index 0000000000000000000000000000000000000000..140bcff7a27892a975132c790d440108391f54f0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/strict-comparison.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: search element is compared using strict comparing (===) +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 8. Repeat, while k < len + ... + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ii. Let same be the result of performing Strict Equality Comparison + searchElement === elementK. + iii. If same is true, return k. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 0, 1, undefined, NaN]); + assert.sameValue(sample.indexOf("42"), -1, "'42'"); + assert.sameValue(sample.indexOf([42]), -1, "[42]"); + assert.sameValue(sample.indexOf(42.0), 0, "42.0"); + assert.sameValue(sample.indexOf(-0), 1, "-0"); + assert.sameValue(sample.indexOf(true), -1, "true"); + assert.sameValue(sample.indexOf(false), -1, "false"); + assert.sameValue(sample.indexOf(NaN), -1, "NaN === NaN is false"); + assert.sameValue(sample.indexOf(null), -1, "null"); + assert.sameValue(sample.indexOf(undefined), -1, "undefined"); + assert.sameValue(sample.indexOf(""), -1, "empty string"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/indexOf/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..77c7d137c1aa141f8f44d36972f1202f21d3ce8c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/this-is-not-object.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var indexOf = SendableTypedArray.prototype.indexOf; + +assert.throws(TypeError, function() { + indexOf.call(undefined, 42); +}, "this is undefined"); + +assert.throws(TypeError, function() { + indexOf.call(null, 42); +}, "this is null"); + +assert.throws(TypeError, function() { + indexOf.call(42, 42); +}, "this is 42"); + +assert.throws(TypeError, function() { + indexOf.call("1", 42); +}, "this is a string"); + +assert.throws(TypeError, function() { + indexOf.call(true, 42); +}, "this is true"); + +assert.throws(TypeError, function() { + indexOf.call(false, 42); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + indexOf.call(s, 42); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/indexOf/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..477eae884950de29e781aafde5bbe50232eb78aa --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/this-is-not-typedarray-instance.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var indexOf = SendableTypedArray.prototype.indexOf; + +assert.throws(TypeError, function() { + indexOf.call({}, 42); +}, "this is an Object"); + +assert.throws(TypeError, function() { + indexOf.call([], 42); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + indexOf.call(ab, 42); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + indexOf.call(dv, 42); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/indexOf/tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/indexOf/tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..bd4af01513b348e843f9b61639f2de65e55ea0f4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/indexOf/tointeger-fromindex.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.indexof +description: Return -1 if fromIndex >= ArrayLength - converted values +info: | + 22.2.3.13 %SendableTypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43]); + assert.sameValue(sample.indexOf(42, "1"), -1, "string [0]"); + assert.sameValue(sample.indexOf(43, "1"), 1, "string [1]"); + + assert.sameValue(sample.indexOf(42, true), -1, "true [0]"); + assert.sameValue(sample.indexOf(43, true), 1, "true [1]"); + + assert.sameValue(sample.indexOf(42, false), 0, "false [0]"); + assert.sameValue(sample.indexOf(43, false), 1, "false [1]"); + + assert.sameValue(sample.indexOf(42, NaN), 0, "NaN [0]"); + assert.sameValue(sample.indexOf(43, NaN), 1, "NaN [1]"); + + assert.sameValue(sample.indexOf(42, null), 0, "null [0]"); + assert.sameValue(sample.indexOf(43, null), 1, "null [1]"); + + assert.sameValue(sample.indexOf(42, undefined), 0, "undefined [0]"); + assert.sameValue(sample.indexOf(43, undefined), 1, "undefined [1]"); + + assert.sameValue(sample.indexOf(42, null), 0, "null [0]"); + assert.sameValue(sample.indexOf(43, null), 1, "null [1]"); + + assert.sameValue(sample.indexOf(42, obj), -1, "object [0]"); + assert.sameValue(sample.indexOf(43, obj), 1, "object [1]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/BigInt/custom-separator-result-from-tostring-on-each-simple-value.js b/test/sendable/builtins/TypedArray/prototype/join/BigInt/custom-separator-result-from-tostring-on-each-simple-value.js new file mode 100644 index 0000000000000000000000000000000000000000..44e4de57e00d4eed7d44ba584c96a7b6e5a704a5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/BigInt/custom-separator-result-from-tostring-on-each-simple-value.js @@ -0,0 +1,91 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: > + Concatenates the result of toString for each value with custom separator +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 7. If element0 is undefined or null, let R be the empty String; otherwise, let + R be ? ToString(element0). + 8. Let k be 1. + 9. Repeat, while k < len + a. Let S be the String value produced by concatenating R and sep. + b. Let element be ? Get(O, ! ToString(k)). + c. If element is undefined or null, let next be the empty String; otherwise, + let next be ? ToString(element). + d. Let R be a String value produced by concatenating S and next. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 0n, 2n, 3n, 42n, 127n]); + + var result; + + result = sample.join(","); + assert.sameValue(result, "1,0,2,3,42,127"); + + result = sample.join(undefined); + assert.sameValue(result, "1,0,2,3,42,127"); + + result = sample.join(null); + assert.sameValue(result, "1null0null2null3null42null127"); + + result = sample.join(",,"); + assert.sameValue(result, "1,,0,,2,,3,,42,,127"); + + result = sample.join(0); + assert.sameValue(result, "10002030420127"); + + result = sample.join(""); + assert.sameValue(result, "102342127"); + + result = sample.join(" a b c "); + assert.sameValue(result, "1 a b c 0 a b c 2 a b c 3 a b c 42 a b c 127"); + + result = sample.join({}); + assert.sameValue(result, "1[object Object]0[object Object]2[object Object]3[object Object]42[object Object]127"); + + result = sample.join(true); + assert.sameValue(result, "1true0true2true3true42true127"); + + result = sample.join({ toString: function() { return "foo"; }}); + assert.sameValue(result, "1foo0foo2foo3foo42foo127"); + + result = sample.join({ toString: undefined, valueOf: function() { return "bar"; }}); + assert.sameValue(result, "1bar0bar2bar3bar42bar127"); + + result = sample.join(false); + assert.sameValue(result, "1false0false2false3false42false127"); + + result = sample.join(-1); + assert.sameValue(result, "1-10-12-13-142-1127"); + + result = sample.join(-0); + assert.sameValue(result, "10002030420127"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/BigInt/detached-buffer-during-fromIndex-returns-single-comma.js b/test/sendable/builtins/TypedArray/prototype/join/BigInt/detached-buffer-during-fromIndex-returns-single-comma.js new file mode 100644 index 0000000000000000000000000000000000000000..dfd691cad218986ddda6fbd01692739463046f27 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/BigInt/detached-buffer-during-fromIndex-returns-single-comma.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Returns single separator if buffer is detached after ValidateSendableTypedArray +info: | + %SendableTypedArray%.prototype.join ( separator ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15. + + When the join method is called with one argument separator, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If separator is undefined, let sep be the single-element String ",". + Else, let sep be ? ToString(separator). + Let R be the empty String. + Let k be 0. + Repeat, while k < len, + If k > 0, set R to the string-concatenation of R and sep. + Let element be ! Get(O, ! ToString(𝔽(k))). + If element is undefined or null, let next be the empty String; otherwise, let next be ! ToString(element). + Set R to the string-concatenation of R and next. + Set k to k + 1. + Return R. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA([1n,2n,3n]); + const separator = { + toString() { + $DETACHBUFFER(sample.buffer); + return ','; + } + }; + + assert.sameValue(sample.join(separator), ',,'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/join/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..21e774f050f55c706d0e8aab87dbcdebc02b5742 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/BigInt/detached-buffer.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Throws a TypeError if this has a detached buffer +info: | + %SendableTypedArray%.prototype.join ( separator ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15. + + When the join method is called with one argument separator, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +let obj = { + toString() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, () => { + sample.join(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/BigInt/empty-instance-empty-string.js b/test/sendable/builtins/TypedArray/prototype/join/BigInt/empty-instance-empty-string.js new file mode 100644 index 0000000000000000000000000000000000000000..102e17aaac4a1dfc1a8af0ec28c17bd36904aeb2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/BigInt/empty-instance-empty-string.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Return the empty String if length is 0 +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.sameValue(sample.join(), ""); + assert.sameValue(sample.join("test262"), ""); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/BigInt/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/join/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..6861141572a534a836c21e8fdd67d2ab4633d1d6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... + 5. If len is zero, return the empty String. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.join(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.notSameValue(result, "", "result is not affected but custom length 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/BigInt/result-from-tostring-on-each-simple-value.js b/test/sendable/builtins/TypedArray/prototype/join/BigInt/result-from-tostring-on-each-simple-value.js new file mode 100644 index 0000000000000000000000000000000000000000..aa6721fcf88abf56e3628876d6e20478a62d6373 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/BigInt/result-from-tostring-on-each-simple-value.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Concatenates the result of toString for each simple value +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 7. If element0 is undefined or null, let R be the empty String; otherwise, let + R be ? ToString(element0). + 8. Let k be 1. + 9. Repeat, while k < len + a. Let S be the String value produced by concatenating R and sep. + b. Let element be ? Get(O, ! ToString(k)). + c. If element is undefined or null, let next be the empty String; otherwise, + let next be ? ToString(element). + d. Let R be a String value produced by concatenating S and next. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 0n, 2n, 3n, 42n, 127n]); + + var result = sample.join(); + + assert.sameValue(result, "1,0,2,3,42,127"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator-symbol.js b/test/sendable/builtins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..5bf3e211819e48eedd91b2a811898e38b621dbac --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator-symbol.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Return abrupt from ToString(Symbol separator) +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol(""); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.join(s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator.js b/test/sendable/builtins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator.js new file mode 100644 index 0000000000000000000000000000000000000000..88722e7bd82d01b64251c24a60eb9f4aa57d9c7d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Return abrupt from ToString(separator) +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.join(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/join/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..c8ea76d95d515e24b59e4ea30482e014a84770cc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.join, + 'function', + 'implements SendableTypedArray.prototype.join' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.join(','); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.join(','); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the join operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.join(','); + throw new Test262Error('join completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/coerced-separator-grow.js b/test/sendable/builtins/TypedArray/prototype/join/coerced-separator-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..bad18fa5a288fdd7c62c667619a39d7346f8ca6b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/coerced-separator-grow.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: > + SendableTypedArray.p.join behaves correctly when the receiver is grown during + argument coercion +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Growing + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + toString: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return '.'; + } + }; + assert.sameValue(fixedLength.join(evil), '0.0.0.0'); +} + +// Growing + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let evil = { + toString: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return '.'; + } + }; + // We iterate 4 elements, since it was the starting length. + assert.sameValue(lengthTracking.join(evil), '0.0.0.0'); +} diff --git a/test/sendable/builtins/TypedArray/prototype/join/coerced-separator-shrink.js b/test/sendable/builtins/TypedArray/prototype/join/coerced-separator-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..da86fd705c232c72753182b65708feea2784f21d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/coerced-separator-shrink.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: > + SendableTypedArray.p.join behaves correctly when the receiver is shrunk during + argument coercion +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Shrinking + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + toString: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return '.'; + } + }; + // We iterate 4 elements, since it was the starting length, but the TA is + // OOB right after parameter conversion, so all elements are converted to + // the empty string. + assert.sameValue(fixedLength.join(evil), '...'); +} + +// Shrinking + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let evil = { + toString: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return '.'; + } + }; + // We iterate 4 elements, since it was the starting length. Elements beyond + // the new length are converted to the empty string. + assert.sameValue(lengthTracking.join(evil), '0.0..'); +} diff --git a/test/sendable/builtins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-simple-value.js b/test/sendable/builtins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-simple-value.js new file mode 100644 index 0000000000000000000000000000000000000000..210736cb79560b37b3071b918372c0db078b3043 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-simple-value.js @@ -0,0 +1,91 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: > + Concatenates the result of toString for each value with custom separator +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 7. If element0 is undefined or null, let R be the empty String; otherwise, let + R be ? ToString(element0). + 8. Let k be 1. + 9. Repeat, while k < len + a. Let S be the String value produced by concatenating R and sep. + b. Let element be ? Get(O, ! ToString(k)). + c. If element is undefined or null, let next be the empty String; otherwise, + let next be ? ToString(element). + d. Let R be a String value produced by concatenating S and next. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 0, 2, 3, 42, 127]); + + var result; + + result = sample.join(","); + assert.sameValue(result, "1,0,2,3,42,127"); + + result = sample.join(undefined); + assert.sameValue(result, "1,0,2,3,42,127"); + + result = sample.join(null); + assert.sameValue(result, "1null0null2null3null42null127"); + + result = sample.join(",,"); + assert.sameValue(result, "1,,0,,2,,3,,42,,127"); + + result = sample.join(0); + assert.sameValue(result, "10002030420127"); + + result = sample.join(""); + assert.sameValue(result, "102342127"); + + result = sample.join(" a b c "); + assert.sameValue(result, "1 a b c 0 a b c 2 a b c 3 a b c 42 a b c 127"); + + result = sample.join({}); + assert.sameValue(result, "1[object Object]0[object Object]2[object Object]3[object Object]42[object Object]127"); + + result = sample.join(true); + assert.sameValue(result, "1true0true2true3true42true127"); + + result = sample.join({ toString: function() { return "foo"; }}); + assert.sameValue(result, "1foo0foo2foo3foo42foo127"); + + result = sample.join({ toString: undefined, valueOf: function() { return "bar"; }}); + assert.sameValue(result, "1bar0bar2bar3bar42bar127"); + + result = sample.join(false); + assert.sameValue(result, "1false0false2false3false42false127"); + + result = sample.join(-1); + assert.sameValue(result, "1-10-12-13-142-1127"); + + result = sample.join(-0); + assert.sameValue(result, "10002030420127"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js b/test/sendable/builtins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js new file mode 100644 index 0000000000000000000000000000000000000000..049eda599a958ea8c46538acf494ec7fd2d66c91 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js @@ -0,0 +1,148 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: > + Concatenates the result of toString for each value with custom separator +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 7. If element0 is undefined or null, let R be the empty String; otherwise, let + R be ? ToString(element0). + 8. Let k be 1. + 9. Repeat, while k < len + a. Let S be the String value produced by concatenating R and sep. + b. Let element be ? Get(O, ! ToString(k)). + c. If element is undefined or null, let next be the empty String; otherwise, + let next be ? ToString(element). + d. Let R be a String value produced by concatenating S and next. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var arr = [-2, Infinity, NaN, -Infinity, 0.6, 9007199254740992]; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(arr); + var result, separator, expected; + + separator = ","; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected); + + separator = undefined; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = null; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = ",,"; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = 0; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = ""; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = " a b c "; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = {}; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = { toString: function() { return "foo"; }}; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = { toString: undefined, valueOf: function() { return "bar"; }}; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = true; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = false; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = 1; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); + + separator = 0; + expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(separator); + result = sample.join(separator); + assert.sameValue(result, expected, "using: " + separator); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/detached-buffer-during-fromIndex-returns-single-comma.js b/test/sendable/builtins/TypedArray/prototype/join/detached-buffer-during-fromIndex-returns-single-comma.js new file mode 100644 index 0000000000000000000000000000000000000000..4bc4e7b4b88e604a28e749805c264178598fba1f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/detached-buffer-during-fromIndex-returns-single-comma.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Returns single separator if buffer is detached after ValidateSendableTypedArray +info: | + %SendableTypedArray%.prototype.join ( separator ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15. + + When the join method is called with one argument separator, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If separator is undefined, let sep be the single-element String ",". + Else, let sep be ? ToString(separator). + Let R be the empty String. + Let k be 0. + Repeat, while k < len, + If k > 0, set R to the string-concatenation of R and sep. + Let element be ! Get(O, ! ToString(𝔽(k))). + If element is undefined or null, let next be the empty String; otherwise, let next be ! ToString(element). + Set R to the string-concatenation of R and next. + Set k to k + 1. + Return R. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA([1,2,3]); + const separator = { + toString() { + $DETACHBUFFER(sample.buffer); + return ','; + } + }; + + assert.sameValue(sample.join(separator), ',,'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/join/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..e325fc1e152fe83b3984f942dc630fe2914a74a1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/detached-buffer.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Throws a TypeError if this has a detached buffer +info: | + %SendableTypedArray%.prototype.join ( separator ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.join are the same as for Array.prototype.join as defined in 22.1.3.15. + + When the join method is called with one argument separator, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + ... + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +let obj = { + toString() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, () => { + sample.join(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/empty-instance-empty-string.js b/test/sendable/builtins/TypedArray/prototype/join/empty-instance-empty-string.js new file mode 100644 index 0000000000000000000000000000000000000000..967173927db35de5387eac6dbee7bebe77debb09 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/empty-instance-empty-string.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Return the empty String if length is 0 +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.sameValue(sample.join(), ""); + assert.sameValue(sample.join("test262"), ""); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/join/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..667f0f47916af16a286667964b2645a9208f73db --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/get-length-uses-internal-arraylength.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... + 5. If len is zero, return the empty String. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.join(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.notSameValue(result, "", "result is not affected but custom length 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/join/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..e6255fad161c3f1286b6f09c39391a23b952909a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.14 %SendableTypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var join = SendableTypedArray.prototype.join; + +assert.sameValue(typeof join, 'function'); + +assert.throws(TypeError, function() { + join(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/join/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..a51df5cbf19e513a774711468c0c13f8bafb3d1e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.14 %SendableTypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.join, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.join(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/length.js b/test/sendable/builtins/TypedArray/prototype/join/length.js new file mode 100644 index 0000000000000000000000000000000000000000..394f2eb18a919be30ba05fa1af53d7bf6e0ee781 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: > + %SendableTypedArray%.prototype.join.length is 1. +info: | + %SendableTypedArray%.prototype.join ( separator ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.join, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/name.js b/test/sendable/builtins/TypedArray/prototype/join/name.js new file mode 100644 index 0000000000000000000000000000000000000000..a224be2804ae6d95b4f5623205e98ab93e98e45f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: > + %SendableTypedArray%.prototype.join.name is "join". +info: | + %SendableTypedArray%.prototype.join ( separator ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.join, "name", { + value: "join", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/join/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..fa5232e0d17eed94c163e0576b9de9d8b3c14df1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.join does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.join), + false, + 'isConstructor(SendableTypedArray.prototype.join) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.join(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/join/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/join/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..459c69aae5851da566e8fde149a058b68f8cc7fd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: > + "join" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'join', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/join/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..3cabaaa34710fe8d72710a648c68ba9e7b56c175 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/resizable-buffer.js @@ -0,0 +1,110 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: > + SendableTypedArray.p.join behaves correctly when the receiver is backed by resizable + buffer +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const taWrite = new ctor(rab); + + // Write some data into the array. + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + assert.sameValue(fixedLength.join(), '0,2,4,6'); + assert.sameValue(fixedLengthWithOffset.join(), '4,6'); + assert.sameValue(lengthTracking.join(), '0,2,4,6'); + assert.sameValue(lengthTrackingWithOffset.join(), '4,6'); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.join(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.join(); + }); + + assert.sameValue(lengthTracking.join(), '0,2,4'); + assert.sameValue(lengthTrackingWithOffset.join(), '4'); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.join(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.join(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.join(); + }); + + assert.sameValue(lengthTracking.join(), '0'); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.join(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.join(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.join(); + }); + + assert.sameValue(lengthTracking.join(), ''); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.sameValue(fixedLength.join(), '0,2,4,6'); + assert.sameValue(fixedLengthWithOffset.join(), '4,6'); + assert.sameValue(lengthTracking.join(), '0,2,4,6,8,10'); + assert.sameValue(lengthTrackingWithOffset.join(), '4,6,8,10'); +} diff --git a/test/sendable/builtins/TypedArray/prototype/join/result-from-tostring-on-each-simple-value.js b/test/sendable/builtins/TypedArray/prototype/join/result-from-tostring-on-each-simple-value.js new file mode 100644 index 0000000000000000000000000000000000000000..95eadb5deb56f8f9436efd3a0daca7e7abd3e94e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/result-from-tostring-on-each-simple-value.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Concatenates the result of toString for each simple value +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 7. If element0 is undefined or null, let R be the empty String; otherwise, let + R be ? ToString(element0). + 8. Let k be 1. + 9. Repeat, while k < len + a. Let S be the String value produced by concatenating R and sep. + b. Let element be ? Get(O, ! ToString(k)). + c. If element is undefined or null, let next be the empty String; otherwise, + let next be ? ToString(element). + d. Let R be a String value produced by concatenating S and next. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 0, 2, 3, 42, 127]); + + var result = sample.join(); + + assert.sameValue(result, "1,0,2,3,42,127"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/result-from-tostring-on-each-value.js b/test/sendable/builtins/TypedArray/prototype/join/result-from-tostring-on-each-value.js new file mode 100644 index 0000000000000000000000000000000000000000..94f6731c0c1e215c868a99aa43fe55e37221b7c4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/result-from-tostring-on-each-value.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Concatenates the result of toString for each value +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 7. If element0 is undefined or null, let R be the empty String; otherwise, let + R be ? ToString(element0). + 8. Let k be 1. + 9. Repeat, while k < len + a. Let S be the String value produced by concatenating R and sep. + b. Let element be ? Get(O, ! ToString(k)). + c. If element is undefined or null, let next be the empty String; otherwise, + let next be ? ToString(element). + d. Let R be a String value produced by concatenating S and next. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var arr = [-2, Infinity, NaN, -Infinity, 0.6, 9007199254740992]; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(arr); + + // Use converted values using Array methods as helpers + var expected = arr.map(function(_, i) { + return sample[i].toString(); + }).join(); + + var result = sample.join(); + + assert.sameValue(result, expected); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/return-abrupt-from-separator-symbol.js b/test/sendable/builtins/TypedArray/prototype/join/return-abrupt-from-separator-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..b8209c0aa1e24ed6c871cedc310b424c36da19cc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/return-abrupt-from-separator-symbol.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Return abrupt from ToString(Symbol separator) +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol(""); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.join(s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/return-abrupt-from-separator.js b/test/sendable/builtins/TypedArray/prototype/join/return-abrupt-from-separator.js new file mode 100644 index 0000000000000000000000000000000000000000..b31520e1c219f7fcc6aa5bc31f52d1167446bb0b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/return-abrupt-from-separator.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Return abrupt from ToString(separator) +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + %SendableTypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.join(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/join/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..2a5aec3405091f3de2192efcaa0d6f4a2274ddab --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.join, + 'function', + 'implements SendableTypedArray.prototype.join' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.join(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.join(0); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the join operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.join(0); + throw new Test262Error('join completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/join/separator-tostring-once-after-resized.js b/test/sendable/builtins/TypedArray/prototype/join/separator-tostring-once-after-resized.js new file mode 100644 index 0000000000000000000000000000000000000000..0d2627a14ef74b7c66735a038c8c4b3f016f4aeb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/separator-tostring-once-after-resized.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: > + ToString is called once when the array is resized. +info: | + %SendableTypedArray%.prototype.join ( separator ) + + ... + 2. Let taRecord be ? ValidateSendableTypedArray(O, seq-cst). + 3. Let len be SendableTypedArrayLength(taRecord). + ... + 5. Else, let sep be ? ToString(separator). + ... + +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(3, {maxByteLength: 5}); +let ta = new Int8Array(rab); + +let callCount = 0; + +let index = { + toString() { + callCount++; + rab.resize(0); + return "-"; + } +}; + +assert.sameValue(callCount, 0); + +let r = ta.join(index); + +assert.sameValue(callCount, 1); +assert.sameValue(r, "--"); diff --git a/test/sendable/builtins/TypedArray/prototype/join/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/join/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..e1ef6b70da958f1d3aa5dcd27c51342362d7b22e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/this-is-not-object.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var join = SendableTypedArray.prototype.join; + +assert.throws(TypeError, function() { + join.call(undefined, ""); +}, "this is undefined"); + +assert.throws(TypeError, function() { + join.call(null, ""); +}, "this is null"); + +assert.throws(TypeError, function() { + join.call(42, ""); +}, "this is 42"); + +assert.throws(TypeError, function() { + join.call("1", ""); +}, "this is a string"); + +assert.throws(TypeError, function() { + join.call(true, ""); +}, "this is true"); + +assert.throws(TypeError, function() { + join.call(false, ""); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + join.call(s, ""); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/join/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/join/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..895b8ad2018fa3bb5bdbb0261d13d375e9b5cd03 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/join/this-is-not-typedarray-instance.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.join +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var join = SendableTypedArray.prototype.join; + +assert.throws(TypeError, function() { + join.call({}, ""); +}, "this is an Object"); + +assert.throws(TypeError, function() { + join.call([], ""); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + join.call(ab, ""); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + join.call(dv, ""); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/keys/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..fd4069f1d12022cf97bd525647a0cdb85e27c697 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/BigInt/detached-buffer.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.16 %SendableTypedArray%.prototype.keys ( ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.keys(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/BigInt/iter-prototype.js b/test/sendable/builtins/TypedArray/prototype/keys/BigInt/iter-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..97b254c93eb561f6510412bcb6cd6a3f5bedb39b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/BigInt/iter-prototype.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: > + The prototype of the returned iterator is ArrayIteratorPrototype +info: | + 22.2.3.16 %SendableTypedArray%.prototype.keys ( ) + + ... + 3. Return CreateArrayIterator(O, "key"). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n, 42n, 64n]); + var iter = sample.keys(); + + assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/keys/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..88ff9fe98e65d16e1aae7b120dc1bfb11fafb078 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.keys, + 'function', + 'implements SendableTypedArray.prototype.keys' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.keys(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.keys(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the keys operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.keys(); + throw new Test262Error('keys completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/BigInt/return-itor.js b/test/sendable/builtins/TypedArray/prototype/keys/BigInt/return-itor.js new file mode 100644 index 0000000000000000000000000000000000000000..f5d9fd6c7ad7825584a99b358ebbad1258dab216 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/BigInt/return-itor.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: Return an iterator for the keys. +info: | + 22.2.3.16 %SendableTypedArray%.prototype.keys ( ) + + ... + 3. Return CreateArrayIterator(O, "key"). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var sample = [0n, 42n, 64n]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(sample); + var itor = typedArray.keys(); + + var next = itor.next(); + assert.sameValue(next.value, 0); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, 1); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, 2); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, undefined); + assert.sameValue(next.done, true); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/keys/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..dc63c92e2e4c5a9320c35be7c9d053363a47585d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/detached-buffer.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.16 %SendableTypedArray%.prototype.keys ( ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.keys(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/keys/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..7ed10b376e2bee76611a2768465ee97ca531310b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/invoked-as-func.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.15 %SendableTypedArray%.prototype.keys ( ) + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var keys = SendableTypedArray.prototype.keys; + +assert.sameValue(typeof keys, 'function'); + +assert.throws(TypeError, function() { + keys(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/keys/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..f919361711bc7bf9be1d79ce378189ad2406eae4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/invoked-as-method.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.15 %SendableTypedArray%.prototype.keys ( ) + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.keys, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.keys(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/iter-prototype.js b/test/sendable/builtins/TypedArray/prototype/keys/iter-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..0dceba5b92387c5143e25e25f5bc1123a7075893 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/iter-prototype.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: > + The prototype of the returned iterator is ArrayIteratorPrototype +info: | + 22.2.3.16 %SendableTypedArray%.prototype.keys ( ) + + ... + 3. Return CreateArrayIterator(O, "key"). +includes: [sendableTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0, 42, 64]); + var iter = sample.keys(); + + assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/length.js b/test/sendable/builtins/TypedArray/prototype/keys/length.js new file mode 100644 index 0000000000000000000000000000000000000000..e64582fd5a54ae0333fb06391bfa95151c4e6492 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: > + %SendableTypedArray%.prototype.keys.length is 0. +info: | + %SendableTypedArray%.prototype.keys ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.keys, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/name.js b/test/sendable/builtins/TypedArray/prototype/keys/name.js new file mode 100644 index 0000000000000000000000000000000000000000..169d7c942d7216e9f9148597f6c73d0b0fa006df --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: > + %SendableTypedArray%.prototype.keys.name is "keys". +info: | + %SendableTypedArray%.prototype.keys ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.keys, "name", { + value: "keys", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/keys/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..19108ce1569b97441d2e88aa81b37ea4bbfd5b32 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.keys does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.keys), + false, + 'isConstructor(SendableTypedArray.prototype.keys) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.keys(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/keys/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/keys/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..23d43f32af60176238b603ef8ed31062d6ad8e85 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: > + "keys" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'keys', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/keys/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..78c3c81a7962e74d97ac3d66a4d712aa76e8ad77 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: > + SendableTypedArray.p.keys behaves correctly when receiver is backed by a resizable + buffer and is grown mid-iteration +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + // The fixed length array is not affected by resizing. + TestIterationAndResize(fixedLength.keys(), [ + 0, + 1, + 2, + 3 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + // The fixed length array is not affected by resizing. + TestIterationAndResize(fixedLengthWithOffset.keys(), [ + 0, + 1 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(lengthTracking.keys(), [ + 0, + 1, + 2, + 3, + 4, + 5 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + TestIterationAndResize(lengthTrackingWithOffset.keys(), [ + 0, + 1, + 2, + 3 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/keys/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/keys/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..a18237137a43ee6d2548c33791f88d7c9885ed12 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: > + SendableTypedArray.p.keys behaves correctly when receiver is backed by resizable + buffer that is shrunk mid-iteration +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + + // The fixed length array goes out of bounds when the RAB is resized. + assert.throws(TypeError, () => { + TestIterationAndResize(fixedLength.keys(), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + + // The fixed length array goes out of bounds when the RAB is resized. + assert.throws(TypeError, () => { + TestIterationAndResize(fixedLengthWithOffset.keys(), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(lengthTracking.keys(), [ + 0, + 1, + 2 + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + TestIterationAndResize(lengthTrackingWithOffset.keys(), [ + 0, + 1 + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/keys/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/keys/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..807666f2068c1807bc60d086e2f71dae54de62ce --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/resizable-buffer.js @@ -0,0 +1,153 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: > + SendableTypedArray.p.keys behaves correctly when receiver is backed by resizable + buffer +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + assert.compareArray(Array.from(fixedLength.keys()), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(Array.from(fixedLengthWithOffset.keys()), [ + 0, + 1 + ]); + assert.compareArray(Array.from(lengthTracking.keys()), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(Array.from(lengthTrackingWithOffset.keys()), [ + 0, + 1 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + // SendableTypedArray.prototype.{entries, keys, values} throw right away when + // called. Array.prototype.{entries, keys, values} don't throw, but when + // we try to iterate the returned ArrayIterator, that throws. + assert.throws(TypeError, () => { + fixedLength.keys(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.keys(); + }); + + assert.compareArray(Array.from(lengthTracking.keys()), [ + 0, + 1, + 2 + ]); + assert.compareArray(Array.from(lengthTrackingWithOffset.keys()), [0]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.keys(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.keys(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.keys(); + }); + + assert.compareArray(Array.from(lengthTracking.keys()), [0]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.keys(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.keys(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.keys(); + }); + + assert.compareArray(Array.from(lengthTracking.keys()), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.compareArray(Array.from(fixedLength.keys()), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(Array.from(fixedLengthWithOffset.keys()), [ + 0, + 1 + ]); + assert.compareArray(Array.from(lengthTracking.keys()), [ + 0, + 1, + 2, + 3, + 4, + 5 + ]); + assert.compareArray(Array.from(lengthTrackingWithOffset.keys()), [ + 0, + 1, + 2, + 3 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/keys/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/keys/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..c17683919b58020302de6b1340ad4c1e031f85c4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.keys, + 'function', + 'implements SendableTypedArray.prototype.keys' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.keys(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.keys(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the keys operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.keys(); + throw new Test262Error('keys completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/return-itor.js b/test/sendable/builtins/TypedArray/prototype/keys/return-itor.js new file mode 100644 index 0000000000000000000000000000000000000000..16f0fbd18d6d31df918cbfd46255458ce290e97f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/return-itor.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: Return an iterator for the keys. +info: | + 22.2.3.16 %SendableTypedArray%.prototype.keys ( ) + + ... + 3. Return CreateArrayIterator(O, "key"). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var sample = [0, 42, 64]; + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(sample); + var itor = typedArray.keys(); + + var next = itor.next(); + assert.sameValue(next.value, 0); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, 1); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, 2); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, undefined); + assert.sameValue(next.done, true); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/keys/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..4a193527be05537a57b142b614b3c91235c9f38c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/this-is-not-object.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.16 %SendableTypedArray%.prototype.keys ( ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var keys = SendableTypedArray.prototype.keys; + +assert.throws(TypeError, function() { + keys.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + keys.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + keys.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + keys.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + keys.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + keys.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + keys.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/keys/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/keys/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..95e30291f0798042baf07f1121d2c1ef54dcfb0b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/keys/this-is-not-typedarray-instance.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.keys +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.16 %SendableTypedArray%.prototype.keys ( ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var keys = SendableTypedArray.prototype.keys; + +assert.throws(TypeError, function() { + keys.call({}); +}, "this is an Object"); + +assert.throws(TypeError, function() { + keys.call([]); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + keys.call(ab); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + keys.call(dv); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..e67cca0064e0fc348bd9953a63af601537968981 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Returns -1 if buffer is detached after ValidateSendableTypedArray +info: | + %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.lastIndexOf are the same as for Array.prototype.lastIndexOf as defined in 22.1.3.17. + + When the lastIndexOf method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return -1F. + If fromIndex is present, let n be ? ToIntegerOrInfinity(fromIndex); else let n be len - 1. + If n is -∞, return -1F. + If n ≥ 0, then + Let k be min(n, len - 1). + Else, + Let k be len + n. + Repeat, while k ≥ 0, + Let kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k - 1. + Return -1F. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.lastIndexOf(undefined, fromIndex), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..37d9bf93dbfbb64bb5c97edf0f9ea6a339e3d14f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Returns -1 if buffer is detached after ValidateSendableTypedArray +info: | + %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.lastIndexOf are the same as for Array.prototype.lastIndexOf as defined in 22.1.3.17. + + When the lastIndexOf method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return -1F. + If fromIndex is present, let n be ? ToIntegerOrInfinity(fromIndex); else let n be len - 1. + If n is -∞, return -1F. + If n ≥ 0, then + Let k be min(n, len - 1). + Else, + Let k be len + n. + Repeat, while k ≥ 0, + Let kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k - 1. + Return -1F. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.lastIndexOf(0n, fromIndex), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f44633e29619709d32256db82a8e0f948d216413 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.lastIndexOf(0n); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-infinity.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..e8d7520ecef93d2c263315cd90f1d59b39191068 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-infinity.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: handle Infinity values for fromIndex +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + 6. Else n < 0, + a. Let k be len + n. + 7. Repeat, while k ≥ 0 + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 43n, 41n]); + + assert.sameValue(sample.lastIndexOf(43n, Infinity), 2, "lastIndexOf(43, Infinity)"); + assert.sameValue(sample.lastIndexOf(43n, -Infinity), -1, "lastIndexOf(43, -Infinity)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-minus-zero.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-minus-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..94ff4ef2d7ebf6661bc8211d6775feb90866194c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-minus-zero.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: -0 fromIndex becomes 0 +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n]); + assert.sameValue(sample.lastIndexOf(42n, -0), 0, "-0 [0]"); + assert.sameValue(sample.lastIndexOf(43n, -0), -1, "-0 [1]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..bc3d26febb5666489b895edc768231ddf6c8d370 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", {value: 0}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n]); + + Object.defineProperty(TA.prototype, "length", {value: 0}); + Object.defineProperty(sample, "length", {value: 0}); + + assert.sameValue(sample.lastIndexOf(7n), 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/length-zero-returns-minus-one.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/length-zero-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..5fc5afd8ee502e8e3abcab66dfd6e2bb30d8206b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/length-zero-returns-minus-one.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Returns -1 if length is 0 +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. If len is 0, return -1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.lastIndexOf(0), -1, "returns -1"); + assert.sameValue( + sample.lastIndexOf(0n, fromIndex), -1, + "length is checked before ToInteger(fromIndex)" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/no-arg.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/no-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..d6080337a43938442fab3e38f42af9e58ebf54d5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/no-arg.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: > + If `searchElement` is not supplied, -1 is returned. +info: | + %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements + the same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.17 + except that the this value's [[ArrayLength]] internal slot is accessed + in place of performing a [[Get]] of "length". + + Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + [...] + 8. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.lastIndexOf(), -1); + + var ta2 = new TA([0n, 1n, 2n]); + assert.sameValue(ta2.lastIndexOf(), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..9fba59dbfb510f81256fb7a37acd1978594e804f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.lastIndexOf, + 'function', + 'implements SendableTypedArray.prototype.lastIndexOf' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.lastIndexOf(0n); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.lastIndexOf(0n); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the lastIndexOf operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.lastIndexOf(0n); + throw new Test262Error('lastIndexOf completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..4a2f5ce214c20a7de1594c86865567366a4bbb1b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let + n be len-1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var fromIndex = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.lastIndexOf(7n, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..dd37f4d30c498583615c8abe2ec6f0cd1b205302 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let + n be len-1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(Test262Error, function() { + sample.lastIndexOf(7n, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/search-found-returns-index.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/search-found-returns-index.js new file mode 100644 index 0000000000000000000000000000000000000000..58b841a9ed21cdfb6d3e0e2129afae8205bd763b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/search-found-returns-index.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: returns index for the first found element +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + 6. Else n < 0, + a. Let k be len + n. + 7. Repeat, while k ≥ 0 + a. Let kPresent be ? HasProperty(O, ! ToString(k)). + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ii. Let same be the result of performing Strict Equality Comparison + searchElement === elementK. + iii. If same is true, return k. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 42n, 41n]); + assert.sameValue(sample.lastIndexOf(42n), 2, "lastIndexOf(42)"); + assert.sameValue(sample.lastIndexOf(43n), 1, "lastIndexOf(43)"); + assert.sameValue(sample.lastIndexOf(41n), 3, "lastIndexOf(41)"); + assert.sameValue(sample.lastIndexOf(41n, 3), 3, "lastIndexOf(41, 3)"); + assert.sameValue(sample.lastIndexOf(41n, 4), 3, "lastIndexOf(41, 4)"); + assert.sameValue(sample.lastIndexOf(43n, 1), 1, "lastIndexOf(43, 1)"); + assert.sameValue(sample.lastIndexOf(43n, 2), 1, "lastIndexOf(43, 2)"); + assert.sameValue(sample.lastIndexOf(43n, 3), 1, "lastIndexOf(43, 3)"); + assert.sameValue(sample.lastIndexOf(43n, 4), 1, "lastIndexOf(43, 4)"); + assert.sameValue(sample.lastIndexOf(42n, 0), 0, "lastIndexOf(42, 0)"); + assert.sameValue(sample.lastIndexOf(42n, 1), 0, "lastIndexOf(42, 1)"); + assert.sameValue(sample.lastIndexOf(42n, 2), 2, "lastIndexOf(42, 2)"); + assert.sameValue(sample.lastIndexOf(42n, 3), 2, "lastIndexOf(42, 3)"); + assert.sameValue(sample.lastIndexOf(42n, 4), 2, "lastIndexOf(42, 4)"); + assert.sameValue(sample.lastIndexOf(42n, -4), 0, "lastIndexOf(42, -4)"); + assert.sameValue(sample.lastIndexOf(42n, -3), 0, "lastIndexOf(42, -3)"); + assert.sameValue(sample.lastIndexOf(42n, -2), 2, "lastIndexOf(42, -2)"); + assert.sameValue(sample.lastIndexOf(42n, -1), 2, "lastIndexOf(42, -1)"); + assert.sameValue(sample.lastIndexOf(43n, -3), 1, "lastIndexOf(43, -3)"); + assert.sameValue(sample.lastIndexOf(43n, -2), 1, "lastIndexOf(43, -2)"); + assert.sameValue(sample.lastIndexOf(43n, -1), 1, "lastIndexOf(43, -1)"); + assert.sameValue(sample.lastIndexOf(41n, -1), 3, "lastIndexOf(41, -1)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/search-not-found-returns-minus-one.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/search-not-found-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..bace53fa44bfd5c40d0affe903db713c67d8f7c5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/search-not-found-returns-minus-one.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: returns -1 if the element if not found +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + 6. Else n < 0, + a. Let k be len + n. + 7. Repeat, while k ≥ 0 + ... + 8. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n, 42n, 41n]); + assert.sameValue(sample.lastIndexOf(44n), -1, "lastIndexOf(44)"); + assert.sameValue(sample.lastIndexOf(44n, -4), -1, "lastIndexOf(44, -4)"); + assert.sameValue(sample.lastIndexOf(44n, -5), -1, "lastIndexOf(44, -5)"); + assert.sameValue(sample.lastIndexOf(42n, -5), -1, "lastIndexOf(42, -5)"); + assert.sameValue(sample.lastIndexOf(43n, -4), -1, "lastIndexOf(43, -4)"); + assert.sameValue(sample.lastIndexOf(43n, -5), -1, "lastIndexOf(43, -5)"); + assert.sameValue(sample.lastIndexOf(41n, 0), -1, "lastIndexOf(41, 0)"); + assert.sameValue(sample.lastIndexOf(41n, 1), -1, "lastIndexOf(41, 1)"); + assert.sameValue(sample.lastIndexOf(41n, 2), -1, "lastIndexOf(41, 2)"); + assert.sameValue(sample.lastIndexOf(43n, 0), -1, "lastIndexOf(43, 0)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..e8ebf61b2dac4509b60ce6afed522aea667ca3db --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/BigInt/tointeger-fromindex.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Return -1 if fromIndex >= ArrayLength - converted values +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let + n be len-1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42n, 43n]); + assert.sameValue(sample.lastIndexOf(42n, "1"), 0, "string [0]"); + assert.sameValue(sample.lastIndexOf(43n, "1"), 1, "string [1]"); + + assert.sameValue(sample.lastIndexOf(42n, true), 0, "true [0]"); + assert.sameValue(sample.lastIndexOf(43n, true), 1, "true [1]"); + + assert.sameValue(sample.lastIndexOf(42n, false), 0, "false [0]"); + assert.sameValue(sample.lastIndexOf(43n, false), -1, "false [1]"); + + assert.sameValue(sample.lastIndexOf(42n, NaN), 0, "NaN [0]"); + assert.sameValue(sample.lastIndexOf(43n, NaN), -1, "NaN [1]"); + + assert.sameValue(sample.lastIndexOf(42n, null), 0, "null [0]"); + assert.sameValue(sample.lastIndexOf(43n, null), -1, "null [1]"); + + assert.sameValue(sample.lastIndexOf(42n, undefined), 0, "undefined [0]"); + assert.sameValue(sample.lastIndexOf(43n, undefined), -1, "undefined [1]"); + + assert.sameValue(sample.lastIndexOf(42n, null), 0, "null [0]"); + assert.sameValue(sample.lastIndexOf(43n, null), -1, "null [1]"); + + assert.sameValue(sample.lastIndexOf(42n, obj), 0, "object [0]"); + assert.sameValue(sample.lastIndexOf(43n, obj), 1, "object [1]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/coerced-position-grow.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/coerced-position-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..f99802a95a1b9470a854dc36d18858b6fa2307ca --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/coerced-position-grow.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: > + SendableTypedArray.p.lastIndexOf behaves correctly on SendableTypedArrays backed by resizable + buffers that are grown by argument coercion. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Growing + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, 1); + } + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return -1; + } + }; + let n0 = MayNeedBigInt(lengthTracking, 0); + assert.sameValue(lengthTracking.lastIndexOf(n0), -1); + // Because lastIndexOf iterates from the given index downwards, it's not + // possible to test that "we only look at the data until the original + // length" without also testing that the index conversion happening with the + // original length. + assert.sameValue(lengthTracking.lastIndexOf(n0, evil), -1); +} + +// Growing + length-tracking TA, index conversion. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return -4; + } + }; + let n0 = MayNeedBigInt(lengthTracking, 0); + assert.sameValue(lengthTracking.lastIndexOf(n0, -4), 0); + // The TA grew but the start index conversion is done based on the original + // length. + assert.sameValue(lengthTracking.lastIndexOf(n0, evil), 0); +} diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/coerced-position-shrink.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/coerced-position-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..5da326a35c76de0817edc1153a34f565d409e8ad --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/coerced-position-shrink.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: > + SendableTypedArray.p.lastIndexOf behaves correctly on SendableTypedArrays backed by resizable + buffers that are shrunk by argument coercion. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Shrinking + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 2; + } + }; + let n0 = MayNeedBigInt(fixedLength, 0); + assert.sameValue(fixedLength.lastIndexOf(n0), 3); + // The TA is OOB so lastIndexOf returns -1. + assert.sameValue(fixedLength.lastIndexOf(n0, evil), -1); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 2; + } + }; + let n0 = MayNeedBigInt(fixedLength, 0); + assert.sameValue(fixedLength.lastIndexOf(n0), 3); + // The TA is OOB so lastIndexOf returns -1, also for undefined). + assert.sameValue(fixedLength.lastIndexOf(undefined, evil), -1); +} + +// Shrinking + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i); + } + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 2; + } + }; + let n2 = MayNeedBigInt(lengthTracking, 2); + assert.sameValue(lengthTracking.lastIndexOf(n2), 2); + // 2 no longer found. + assert.sameValue(lengthTracking.lastIndexOf(n2, evil), -1); +} diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..16632902f43988eca5b606def49fb114dd8e9430 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-undefined.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Returns -1 if buffer is detached after ValidateSendableTypedArray +info: | + %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.lastIndexOf are the same as for Array.prototype.lastIndexOf as defined in 22.1.3.17. + + When the lastIndexOf method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return -1F. + If fromIndex is present, let n be ? ToIntegerOrInfinity(fromIndex); else let n be len - 1. + If n is -∞, return -1F. + If n ≥ 0, then + Let k be min(n, len - 1). + Else, + Let k be len + n. + Repeat, while k ≥ 0, + Let kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k - 1. + Return -1F. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.lastIndexOf(undefined, fromIndex), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..1046b224f835ac444381275f9f75b963c887f62e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/detached-buffer-during-fromIndex-returns-minus-one-for-zero.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Returns -1 if buffer is detached after ValidateSendableTypedArray +info: | + %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + The interpretation and use of the arguments of %SendableTypedArray%.prototype.lastIndexOf are the same as for Array.prototype.lastIndexOf as defined in 22.1.3.17. + + When the lastIndexOf method is called with one or two arguments, the following steps are taken: + + Let O be the this value. + Perform ? ValidateSendableTypedArray(O). + Let len be O.[[ArrayLength]]. + If len is 0, return -1F. + If fromIndex is present, let n be ? ToIntegerOrInfinity(fromIndex); else let n be len - 1. + If n is -∞, return -1F. + If n ≥ 0, then + Let k be min(n, len - 1). + Else, + Let k be len + n. + Repeat, while k ≥ 0, + Let kPresent be ! HasProperty(O, ! ToString(F(k))). + If kPresent is true, then + Let elementK be ! Get(O, ! ToString(F(k))). + Let same be the result of performing Strict Equality Comparison searchElement === elementK. + If same is true, return F(k). + Set k to k - 1. + Return -1F. + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA(1); + const fromIndex = { + valueOf() { + $DETACHBUFFER(sample.buffer); + return 0; + } + }; + + assert.sameValue(sample.lastIndexOf(0, fromIndex), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..ae736b1bdefd8363579028177df5b40d09745ccf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/detached-buffer.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.lastIndexOf(0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/fromIndex-infinity.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/fromIndex-infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..f597a58382c29bc14fa4989cb4eac58f70abb866 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/fromIndex-infinity.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: handle Infinity values for fromIndex +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + 6. Else n < 0, + a. Let k be len + n. + 7. Repeat, while k ≥ 0 + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 43, 41]); + + assert.sameValue(sample.lastIndexOf(43, Infinity), 2, "lastIndexOf(43, Infinity)"); + assert.sameValue(sample.lastIndexOf(43, -Infinity), -1, "lastIndexOf(43, -Infinity)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/fromIndex-minus-zero.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/fromIndex-minus-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..6dc1c72c512444894d4bc11b528f048e591f832e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/fromIndex-minus-zero.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: -0 fromIndex becomes 0 +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43]); + assert.sameValue(sample.lastIndexOf(42, -0), 0, "-0 [0]"); + assert.sameValue(sample.lastIndexOf(43, -0), -1, "-0 [1]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..ca37ffcbcd4ee99eb4d6bd67babb59f33359c798 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/get-length-uses-internal-arraylength.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +Object.defineProperty(SendableTypedArray.prototype, "length", {value: 0}); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7]); + + Object.defineProperty(TA.prototype, "length", {value: 0}); + Object.defineProperty(sample, "length", {value: 0}); + + assert.sameValue(sample.lastIndexOf(7), 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..8b3255cccf8244ce13ab2f261308697c4b6c9c16 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.16 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var lastIndexOf = SendableTypedArray.prototype.lastIndexOf; + +assert.sameValue(typeof lastIndexOf, 'function'); + +assert.throws(TypeError, function() { + lastIndexOf(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..7609a7387a23df09ce30dbfc0758843ff9292771 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.16 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.lastIndexOf, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.lastIndexOf(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/length-zero-returns-minus-one.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/length-zero-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..01744d0ed45fe41594205859143bfe4bb9b53232 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/length-zero-returns-minus-one.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Returns -1 if length is 0 +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. If len is 0, return -1. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.lastIndexOf(0), -1, "returns -1"); + assert.sameValue( + sample.lastIndexOf(0, fromIndex), -1, + "length is checked before ToInteger(fromIndex)" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/length.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/length.js new file mode 100644 index 0000000000000000000000000000000000000000..739bd6c8b1cb293eb21442a8304702ff117de7a7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: > + %SendableTypedArray%.prototype.lastIndexOf.length is 1. +info: | + %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.lastIndexOf, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/name.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/name.js new file mode 100644 index 0000000000000000000000000000000000000000..bcc29d1166d2cd0240d798f7a50466efed6bb5b3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: > + %SendableTypedArray%.prototype.lastIndexOf.name is "lastIndexOf". +info: | + %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.lastIndexOf, "name", { + value: "lastIndexOf", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/no-arg.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/no-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..dc22ec6ffabb9b33aa9d00b9cda5fc50eeb49fd6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/no-arg.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: > + If `searchElement` is not supplied, -1 is returned. +info: | + %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements + the same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.17 + except that the this value's [[ArrayLength]] internal slot is accessed + in place of performing a [[Get]] of "length". + + Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + [...] + 8. Return -1. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.lastIndexOf(), -1); + + var ta2 = new TA([0, 1, 2]); + assert.sameValue(ta2.lastIndexOf(), -1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..be2b02464ec7bdc53b8e8ca1a4abfe626d1ef650 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.lastIndexOf does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.lastIndexOf), + false, + 'isConstructor(SendableTypedArray.prototype.lastIndexOf) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.lastIndexOf(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..85d0b04fa801c19f5f5bf7db1eae1846a1558b6b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: > + "lastIndexOf" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'lastIndexOf', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/resizable-buffer-special-float-values.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/resizable-buffer-special-float-values.js new file mode 100644 index 0000000000000000000000000000000000000000..31041e957ddd58d8ada7d100b663e4086b3a6316 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/resizable-buffer-special-float-values.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: > + SendableTypedArray.p.lastIndexOf behaves correctly for special float values on float + SendableTypedArrays backed by resizable buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer, Array.prototype.includes] +---*/ + +for (let ctor of floatCtors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + lengthTracking[0] = -Infinity; + lengthTracking[1] = -Infinity; + lengthTracking[2] = Infinity; + lengthTracking[3] = Infinity; + lengthTracking[4] = NaN; + lengthTracking[5] = NaN; + assert.sameValue(lengthTracking.lastIndexOf(-Infinity), 1); + assert.sameValue(lengthTracking.lastIndexOf(Infinity), 3); + // NaN is never found. + assert.sameValue(lengthTracking.lastIndexOf(NaN), -1); +} diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..131f1fab0260fd38a50ab8a2e2928dde41f94a4a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/resizable-buffer.js @@ -0,0 +1,153 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: > + SendableTypedArray.p.lastIndexOf behaves correctly on SendableTypedArrays backed by resizable + buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, Math.floor(i / 2)); + } + + // Orig. array: [0, 0, 1, 1] + // [0, 0, 1, 1] << fixedLength + // [1, 1] << fixedLengthWithOffset + // [0, 0, 1, 1, ...] << lengthTracking + // [1, 1, ...] << lengthTrackingWithOffset + + // If fixedLength is a BigInt array, they all are BigInt Arrays. + let n0 = MayNeedBigInt(fixedLength, 0); + let n1 = MayNeedBigInt(fixedLength, 1); + + assert.sameValue(fixedLength.lastIndexOf(n0), 1); + assert.sameValue(fixedLength.lastIndexOf(n0, 1), 1); + assert.sameValue(fixedLength.lastIndexOf(n0, 2), 1); + assert.sameValue(fixedLength.lastIndexOf(n0, -2), 1); + assert.sameValue(fixedLength.lastIndexOf(n0, -3), 1); + assert.sameValue(fixedLength.lastIndexOf(n1, 1), -1); + assert.sameValue(fixedLength.lastIndexOf(n1, -2), 2); + assert.sameValue(fixedLength.lastIndexOf(n1, -3), -1); + assert.sameValue(fixedLength.lastIndexOf(undefined), -1); + assert.sameValue(fixedLengthWithOffset.lastIndexOf(n0), -1); + assert.sameValue(fixedLengthWithOffset.lastIndexOf(n1), 1); + assert.sameValue(fixedLengthWithOffset.lastIndexOf(n1, -2), 0); + assert.sameValue(fixedLengthWithOffset.lastIndexOf(n1, -1), 1); + assert.sameValue(fixedLengthWithOffset.lastIndexOf(undefined), -1); + assert.sameValue(lengthTracking.lastIndexOf(n0), 1); + assert.sameValue(lengthTracking.lastIndexOf(n0, 2), 1); + assert.sameValue(lengthTracking.lastIndexOf(n0, -3), 1); + assert.sameValue(lengthTracking.lastIndexOf(n1, 1), -1); + assert.sameValue(lengthTracking.lastIndexOf(n1, 2), 2); + assert.sameValue(lengthTracking.lastIndexOf(n1, -3), -1); + assert.sameValue(lengthTracking.lastIndexOf(undefined), -1); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(n0), -1); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(n1), 1); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(n1, 1), 1); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(n1, -2), 0); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(n1, -1), 1); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(undefined), -1); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 0, 1] + // [0, 0, 1, ...] << lengthTracking + // [1, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.lastIndexOf(n1); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.lastIndexOf(n1); + }); + + assert.sameValue(lengthTracking.lastIndexOf(n0), 1); + assert.sameValue(lengthTracking.lastIndexOf(undefined), -1); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(n0), -1); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(n1), 0); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(undefined), -1); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.lastIndexOf(n0); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.lastIndexOf(n0); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.lastIndexOf(n0); + }); + + assert.sameValue(lengthTracking.lastIndexOf(n0), 0); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.lastIndexOf(n0); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.lastIndexOf(n0); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.lastIndexOf(n0); + }); + + assert.sameValue(lengthTracking.lastIndexOf(n0), -1); + assert.sameValue(lengthTracking.lastIndexOf(undefined), -1); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, Math.floor(i / 2)); + } + + // Orig. array: [0, 0, 1, 1, 2, 2] + // [0, 0, 1, 1] << fixedLength + // [1, 1] << fixedLengthWithOffset + // [0, 0, 1, 1, 2, 2, ...] << lengthTracking + // [1, 1, 2, 2, ...] << lengthTrackingWithOffset + + let n2 = MayNeedBigInt(fixedLength, 2); + + assert.sameValue(fixedLength.lastIndexOf(n1), 3); + assert.sameValue(fixedLength.lastIndexOf(n2), -1); + assert.sameValue(fixedLength.lastIndexOf(undefined), -1); + assert.sameValue(fixedLengthWithOffset.lastIndexOf(n0), -1); + assert.sameValue(fixedLengthWithOffset.lastIndexOf(n1), 1); + assert.sameValue(fixedLengthWithOffset.lastIndexOf(n2), -1); + assert.sameValue(fixedLengthWithOffset.lastIndexOf(undefined), -1); + assert.sameValue(lengthTracking.lastIndexOf(n1), 3); + assert.sameValue(lengthTracking.lastIndexOf(n2), 5); + assert.sameValue(lengthTracking.lastIndexOf(undefined), -1); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(n0), -1); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(n1), 1); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(n2), 3); + assert.sameValue(lengthTrackingWithOffset.lastIndexOf(undefined), -1); +} diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..46f2d7575428a3c47c25bc75d1e4a2e8daea8d86 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [ArrayBuffer, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.lastIndexOf, + 'function', + 'implements SendableTypedArray.prototype.lastIndexOf' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.lastIndexOf(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.lastIndexOf(0); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the lastIndexOf operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.lastIndexOf(0); + throw new Test262Error('lastIndexOf completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/return-abrupt-tointeger-fromindex-symbol.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..c8f46281f9ee9ddbc334364aa7a429f17e09f2cd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/return-abrupt-tointeger-fromindex-symbol.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let + n be len-1. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var fromIndex = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.lastIndexOf(7, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/return-abrupt-tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/return-abrupt-tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..e5640164afa5fb388c3b45e51a83d04f2bb962bd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/return-abrupt-tointeger-fromindex.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let + n be len-1. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(Test262Error, function() { + sample.lastIndexOf(7, fromIndex); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/search-found-returns-index.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/search-found-returns-index.js new file mode 100644 index 0000000000000000000000000000000000000000..0748c0d9a7d6a80660f3392aba94f7150d401d0c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/search-found-returns-index.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: returns index for the first found element +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + 6. Else n < 0, + a. Let k be len + n. + 7. Repeat, while k ≥ 0 + a. Let kPresent be ? HasProperty(O, ! ToString(k)). + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ii. Let same be the result of performing Strict Equality Comparison + searchElement === elementK. + iii. If same is true, return k. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 42, 41]); + assert.sameValue(sample.lastIndexOf(42), 2, "lastIndexOf(42)"); + assert.sameValue(sample.lastIndexOf(43), 1, "lastIndexOf(43)"); + assert.sameValue(sample.lastIndexOf(41), 3, "lastIndexOf(41)"); + assert.sameValue(sample.lastIndexOf(41, 3), 3, "lastIndexOf(41, 3)"); + assert.sameValue(sample.lastIndexOf(41, 4), 3, "lastIndexOf(41, 4)"); + assert.sameValue(sample.lastIndexOf(43, 1), 1, "lastIndexOf(43, 1)"); + assert.sameValue(sample.lastIndexOf(43, 2), 1, "lastIndexOf(43, 2)"); + assert.sameValue(sample.lastIndexOf(43, 3), 1, "lastIndexOf(43, 3)"); + assert.sameValue(sample.lastIndexOf(43, 4), 1, "lastIndexOf(43, 4)"); + assert.sameValue(sample.lastIndexOf(42, 0), 0, "lastIndexOf(42, 0)"); + assert.sameValue(sample.lastIndexOf(42, 1), 0, "lastIndexOf(42, 1)"); + assert.sameValue(sample.lastIndexOf(42, 2), 2, "lastIndexOf(42, 2)"); + assert.sameValue(sample.lastIndexOf(42, 3), 2, "lastIndexOf(42, 3)"); + assert.sameValue(sample.lastIndexOf(42, 4), 2, "lastIndexOf(42, 4)"); + assert.sameValue(sample.lastIndexOf(42, -4), 0, "lastIndexOf(42, -4)"); + assert.sameValue(sample.lastIndexOf(42, -3), 0, "lastIndexOf(42, -3)"); + assert.sameValue(sample.lastIndexOf(42, -2), 2, "lastIndexOf(42, -2)"); + assert.sameValue(sample.lastIndexOf(42, -1), 2, "lastIndexOf(42, -1)"); + assert.sameValue(sample.lastIndexOf(43, -3), 1, "lastIndexOf(43, -3)"); + assert.sameValue(sample.lastIndexOf(43, -2), 1, "lastIndexOf(43, -2)"); + assert.sameValue(sample.lastIndexOf(43, -1), 1, "lastIndexOf(43, -1)"); + assert.sameValue(sample.lastIndexOf(41, -1), 3, "lastIndexOf(41, -1)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/search-not-found-returns-minus-one.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/search-not-found-returns-minus-one.js new file mode 100644 index 0000000000000000000000000000000000000000..5e78e05be7c28c74b8e571ead7a613ac85b7f22f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/search-not-found-returns-minus-one.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: returns -1 if the element if not found +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + 6. Else n < 0, + a. Let k be len + n. + 7. Repeat, while k ≥ 0 + ... + 8. Return -1. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43, 42, 41]); + assert.sameValue(sample.lastIndexOf(44), -1, "lastIndexOf(44)"); + assert.sameValue(sample.lastIndexOf(44, -4), -1, "lastIndexOf(44, -4)"); + assert.sameValue(sample.lastIndexOf(44, -5), -1, "lastIndexOf(44, -5)"); + assert.sameValue(sample.lastIndexOf(42, -5), -1, "lastIndexOf(42, -5)"); + assert.sameValue(sample.lastIndexOf(43, -4), -1, "lastIndexOf(43, -4)"); + assert.sameValue(sample.lastIndexOf(43, -5), -1, "lastIndexOf(43, -5)"); + assert.sameValue(sample.lastIndexOf(41, 0), -1, "lastIndexOf(41, 0)"); + assert.sameValue(sample.lastIndexOf(41, 1), -1, "lastIndexOf(41, 1)"); + assert.sameValue(sample.lastIndexOf(41, 2), -1, "lastIndexOf(41, 2)"); + assert.sameValue(sample.lastIndexOf(43, 0), -1, "lastIndexOf(43, 0)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/strict-comparison.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/strict-comparison.js new file mode 100644 index 0000000000000000000000000000000000000000..83ca8b0370808f2842b8602eed2c28a37161b9d9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/strict-comparison.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: search element is compared using strict comparing (===) +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 7. Repeat, while k ≥ 0 + ... + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ii. Let same be the result of performing Strict Equality Comparison + searchElement === elementK. + iii. If same is true, return k. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, undefined, NaN, 0, 1]); + assert.sameValue(sample.lastIndexOf("42"), -1, "'42'"); + assert.sameValue(sample.lastIndexOf([42]), -1, "[42]"); + assert.sameValue(sample.lastIndexOf(42.0), 0, "42.0"); + assert.sameValue(sample.lastIndexOf(-0), 3, "-0"); + assert.sameValue(sample.lastIndexOf(true), -1, "true"); + assert.sameValue(sample.lastIndexOf(false), -1, "false"); + assert.sameValue(sample.lastIndexOf(NaN), -1, "NaN === NaN is false"); + assert.sameValue(sample.lastIndexOf(null), -1, "null"); + assert.sameValue(sample.lastIndexOf(undefined), -1, "undefined"); + assert.sameValue(sample.lastIndexOf(""), -1, "empty string"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..b811c08ffe5f1cda5f18030e7dbb8537c13ac7d3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/this-is-not-object.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var lastIndexOf = SendableTypedArray.prototype.lastIndexOf; + +assert.throws(TypeError, function() { + lastIndexOf.call(undefined, 42); +}, "this is undefined"); + +assert.throws(TypeError, function() { + lastIndexOf.call(null, 42); +}, "this is null"); + +assert.throws(TypeError, function() { + lastIndexOf.call(42, 42); +}, "this is 42"); + +assert.throws(TypeError, function() { + lastIndexOf.call("1", 42); +}, "this is a string"); + +assert.throws(TypeError, function() { + lastIndexOf.call(true, 42); +}, "this is true"); + +assert.throws(TypeError, function() { + lastIndexOf.call(false, 42); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + lastIndexOf.call(s, 42); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..143fe04243cbc7c25659f02820dcb544d605e076 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/this-is-not-typedarray-instance.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var lastIndexOf = SendableTypedArray.prototype.lastIndexOf; + +assert.throws(TypeError, function() { + lastIndexOf.call({}, 42); +}, "this is an Object"); + +assert.throws(TypeError, function() { + lastIndexOf.call([], 42); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + lastIndexOf.call(ab, 42); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + lastIndexOf.call(dv, 42); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/lastIndexOf/tointeger-fromindex.js b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/tointeger-fromindex.js new file mode 100644 index 0000000000000000000000000000000000000000..c61acaec018ba275cd65fb74fd6de7222b4f1dec --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/lastIndexOf/tointeger-fromindex.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.lastindexof +description: Return -1 if fromIndex >= ArrayLength - converted values +info: | + 22.2.3.17 %SendableTypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %SendableTypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let + n be len-1. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([42, 43]); + assert.sameValue(sample.lastIndexOf(42, "1"), 0, "string [0]"); + assert.sameValue(sample.lastIndexOf(43, "1"), 1, "string [1]"); + + assert.sameValue(sample.lastIndexOf(42, true), 0, "true [0]"); + assert.sameValue(sample.lastIndexOf(43, true), 1, "true [1]"); + + assert.sameValue(sample.lastIndexOf(42, false), 0, "false [0]"); + assert.sameValue(sample.lastIndexOf(43, false), -1, "false [1]"); + + assert.sameValue(sample.lastIndexOf(42, NaN), 0, "NaN [0]"); + assert.sameValue(sample.lastIndexOf(43, NaN), -1, "NaN [1]"); + + assert.sameValue(sample.lastIndexOf(42, null), 0, "null [0]"); + assert.sameValue(sample.lastIndexOf(43, null), -1, "null [1]"); + + assert.sameValue(sample.lastIndexOf(42, undefined), 0, "undefined [0]"); + assert.sameValue(sample.lastIndexOf(43, undefined), -1, "undefined [1]"); + + assert.sameValue(sample.lastIndexOf(42, null), 0, "null [0]"); + assert.sameValue(sample.lastIndexOf(43, null), -1, "null [1]"); + + assert.sameValue(sample.lastIndexOf(42, obj), 0, "object [0]"); + assert.sameValue(sample.lastIndexOf(43, obj), 1, "object [1]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/length/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..666ef39e92efb7601c881fd14d56e350465f2916 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/BigInt/detached-buffer.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: Returns 0 if the instance has a detached buffer +info: | + 22.2.3.18 get %SendableTypedArray%.prototype.length + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.length, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/BigInt/resizable-array-buffer-auto.js b/test/sendable/builtins/TypedArray/prototype/length/BigInt/resizable-array-buffer-auto.js new file mode 100644 index 0000000000000000000000000000000000000000..5016ca9b66627506901a69b03416d1f336ad358c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/BigInt/resizable-array-buffer-auto.js @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the dynamically-sized SendableTypedArray instance +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE); + var expected = 3; + + assert.sameValue(array.length, expected, "initial value"); + + try { + ab.resize(BPE * 5); + expected = 4; + } catch (_) {} + + assert.sameValue(array.length, expected, "following grow"); + + try { + ab.resize(BPE * 3); + expected = 2; + } catch (_) {} + + assert.sameValue(array.length, expected, "following shrink (within bounds)"); + + try { + ab.resize(BPE * 3 - 1); + expected = 1; + } catch (_) {} + + assert.sameValue(array.length, expected, "following shrink (partial element)"); + + try { + ab.resize(BPE); + expected = 0; + } catch (_) {} + + assert.sameValue(array.length, expected, "following shrink (on boundary)"); + + try { + ab.resize(0); + expected = 0; + } catch (_) {} + + assert.sameValue(array.length, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/BigInt/resizable-array-buffer-fixed.js b/test/sendable/builtins/TypedArray/prototype/length/BigInt/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000000000000000000000000000000000..d76ed7a649d99e330fc917c42ac0df3e7ad2d768 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/BigInt/resizable-array-buffer-fixed.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the fixed-sized SendableTypedArray instance +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + assert.sameValue(array.length, 2, "initial value"); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(array.length, 2, "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue(array.length, 2, "following shrink (within bounds)"); + + var expected; + try { + ab.resize(BPE * 3 - 1); + expected = 0; + } catch (_) { + expected = 2; + } + + assert.sameValue(array.length, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/BigInt/return-length.js b/test/sendable/builtins/TypedArray/prototype/length/BigInt/return-length.js new file mode 100644 index 0000000000000000000000000000000000000000..cdb44e28d1a9e0c3d4cffcc8efa8bd088d1b61c6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/BigInt/return-length.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: > + Return value from the [[ArrayLength]] internal slot +info: | + 22.2.3.18 get %SendableTypedArray%.prototype.length + + ... + 6. Let length be the value of O's [[ArrayLength]] internal slot. + 7. Return length. + + --- + + The current tests on `prop-desc.js` and `length.js` already assert `length` is + not a dynamic property as in regular arrays. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.length, 0); + + var ta2 = new TA(42); + assert.sameValue(ta2.length, 42); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/length/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..11b500e509406c904e58e769c2974b8870d7c75e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/detached-buffer.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: Returns 0 if the instance has a detached buffer +info: | + 22.2.3.18 get %SendableTypedArray%.prototype.length + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.length, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/invoked-as-accessor.js b/test/sendable/builtins/TypedArray/prototype/length/invoked-as-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..3d7039bb951c3c5520063167a3f3151827e56084 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/invoked-as-accessor.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: > + Requires this value to have a [[ViewedArrayBuffer]] internal slot +info: | + 22.2.3.17 get %SendableTypedArray%.prototype.length + + 1. Let O be the this value. + ... + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.length; +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/length/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..2fea06044e24b9f60b7a771550641f1940df7277 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/invoked-as-func.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.17 get %SendableTypedArray%.prototype.length + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, 'length' +).get; + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/length.js b/test/sendable/builtins/TypedArray/prototype/length/length.js new file mode 100644 index 0000000000000000000000000000000000000000..9dd3afd110dc13eef83de02468a766a7fa81a86b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: > + get %SendableTypedArray%.prototype.length.length is 0. +info: | + get %SendableTypedArray%.prototype.length + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, "length"); + +verifyProperty(desc.get, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/name.js b/test/sendable/builtins/TypedArray/prototype/length/name.js new file mode 100644 index 0000000000000000000000000000000000000000..29b75b0c52b0b93095bdc6f18bae303a67f68a66 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/name.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: > + get %SendableTypedArray%.prototype.length.name is "get length". +info: | + get %SendableTypedArray%.prototype.length + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SendableTypedArray.prototype, "length"); + +verifyProperty(desc.get, "name", { + value: "get length", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/length/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..5aee4d817a04eb21c5c4e92cdc8376b2653b88d7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/prop-desc.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: > + "length" property of SendableTypedArrayPrototype +info: | + %SendableTypedArray%.prototype.length is an accessor property whose set accessor + function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var desc = Object.getOwnPropertyDescriptor(SendableTypedArrayPrototype, "length"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(SendableTypedArrayPrototype, "length"); +verifyConfigurable(SendableTypedArrayPrototype, "length"); diff --git a/test/sendable/builtins/TypedArray/prototype/length/resizable-array-buffer-auto.js b/test/sendable/builtins/TypedArray/prototype/length/resizable-array-buffer-auto.js new file mode 100644 index 0000000000000000000000000000000000000000..112c6af285914f357f770cf6c5b307163d411ec0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/resizable-array-buffer-auto.js @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the dynamically-sized SendableTypedArray instance +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE); + var expected = 3; + + assert.sameValue(array.length, expected, "initial value"); + + try { + ab.resize(BPE * 5); + expected = 4; + } catch (_) {} + + assert.sameValue(array.length, expected, "following grow"); + + try { + ab.resize(BPE * 3); + expected = 2; + } catch (_) {} + + assert.sameValue(array.length, expected, "following shrink (within bounds)"); + + try { + ab.resize(BPE * 3 - 1); + expected = 1; + } catch (_) {} + + assert.sameValue(array.length, expected, "following shrink (partial element)"); + + try { + ab.resize(BPE); + expected = 0; + } catch (_) {} + + assert.sameValue(array.length, expected, "following shrink (on boundary)"); + + try { + ab.resize(0); + expected = 0; + } catch (_) {} + + assert.sameValue(array.length, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/resizable-array-buffer-fixed.js b/test/sendable/builtins/TypedArray/prototype/length/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000000000000000000000000000000000..563e40056cdf6a19d9730db03316e6fde41658d1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/resizable-array-buffer-fixed.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: | + reset to 0 if the underlying ArrayBuffer is resized beyond the boundary of + the fixed-sized SendableTypedArray instance +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + assert.sameValue(array.length, 2, "initial value"); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(array.length, 2, "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue(array.length, 2, "following shrink (within bounds)"); + + var expected; + try { + ab.resize(BPE * 3 - 1); + expected = 0; + } catch (_) { + expected = 2; + } + + assert.sameValue(array.length, expected, "following shrink (out of bounds)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/resizable-buffer-assorted.js b/test/sendable/builtins/TypedArray/prototype/length/resizable-buffer-assorted.js new file mode 100644 index 0000000000000000000000000000000000000000..4831e2d5775935c70192f4932465c168bac02c05 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/resizable-buffer-assorted.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: > + SendableTypedArray.p.length behaves correctly on SendableTypedArrays backed by resizable + buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const rab = CreateResizableArrayBuffer(40, 80); +for (let ctor of ctors) { + const ta = new ctor(rab, 0, 3); + assert.compareArray(ta.buffer, rab); + assert.sameValue(ta.length, 3); + const empty_ta = new ctor(rab, 0, 0); + assert.compareArray(empty_ta.buffer, rab); + assert.sameValue(empty_ta.length, 0); + const ta_with_offset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 3); + assert.compareArray(ta_with_offset.buffer, rab); + assert.sameValue(ta_with_offset.length, 3); + const empty_ta_with_offset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 0); + assert.compareArray(empty_ta_with_offset.buffer, rab); + assert.sameValue(empty_ta_with_offset.length, 0); + const length_tracking_ta = new ctor(rab); + assert.compareArray(length_tracking_ta.buffer, rab); + assert.sameValue(length_tracking_ta.length, 40 / ctor.BYTES_PER_ELEMENT); + const offset = 8; + const length_tracking_ta_with_offset = new ctor(rab, offset); + assert.compareArray(length_tracking_ta_with_offset.buffer, rab); + assert.sameValue(length_tracking_ta_with_offset.length, (40 - offset) / ctor.BYTES_PER_ELEMENT); + const empty_length_tracking_ta_with_offset = new ctor(rab, 40); + assert.compareArray(empty_length_tracking_ta_with_offset.buffer, rab); + assert.sameValue(empty_length_tracking_ta_with_offset.length, 0); +} diff --git a/test/sendable/builtins/TypedArray/prototype/length/resized-out-of-bounds-1.js b/test/sendable/builtins/TypedArray/prototype/length/resized-out-of-bounds-1.js new file mode 100644 index 0000000000000000000000000000000000000000..0d4e1f8b36f92d993df7b0c96107c6b5c11e6cde --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/resized-out-of-bounds-1.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: > + SendableTypedArray.p.length behaves correctly when the underlying resizable buffer is + resized such that the SendableTypedArray becomes out of bounds. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const rab = CreateResizableArrayBuffer(16, 40); + +// Create TAs which cover the bytes 0-7. +let tas_and_lengths = []; +for (let ctor of ctors) { + const length = 8 / ctor.BYTES_PER_ELEMENT; + tas_and_lengths.push([ + new ctor(rab, 0, length), + length + ]); +} +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.length, length); +} +rab.resize(2); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.length, 0); +} +// Resize the rab so that it just barely covers the needed 8 bytes. +rab.resize(8); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.length, length); +} +rab.resize(40); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.length, length); +} diff --git a/test/sendable/builtins/TypedArray/prototype/length/resized-out-of-bounds-2.js b/test/sendable/builtins/TypedArray/prototype/length/resized-out-of-bounds-2.js new file mode 100644 index 0000000000000000000000000000000000000000..853f639161635a0a458fa97f2c4c5a6adac06e16 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/resized-out-of-bounds-2.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: > + SendableTypedArray.p.length behaves correctly when the underlying resizable buffer is + resized such that the SendableTypedArray becomes out of bounds. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Like resized-out-of-bounds-1.js but with offsets. + +const rab = CreateResizableArrayBuffer(20, 40); + +// Create TAs with offset, which cover the bytes 8-15. +let tas_and_lengths = []; +for (let ctor of ctors) { + const length = 8 / ctor.BYTES_PER_ELEMENT; + tas_and_lengths.push([ + new ctor(rab, 8, length), + length + ]); +} +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.length, length); +} +rab.resize(10); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.length, 0); +} +// Resize the rab so that it just barely covers the needed 8 bytes. +rab.resize(16); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.length, length); +} +rab.resize(40); +for (let [ta, length] of tas_and_lengths) { + assert.sameValue(ta.length, length); +} diff --git a/test/sendable/builtins/TypedArray/prototype/length/return-length.js b/test/sendable/builtins/TypedArray/prototype/length/return-length.js new file mode 100644 index 0000000000000000000000000000000000000000..0a499aafd69e9ff0db695e7f87fe7d30642e7c3d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/return-length.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: > + Return value from the [[ArrayLength]] internal slot +info: | + 22.2.3.18 get %SendableTypedArray%.prototype.length + + ... + 6. Let length be the value of O's [[ArrayLength]] internal slot. + 7. Return length. + + --- + + The current tests on `prop-desc.js` and `length.js` already assert `length` is + not a dynamic property as in regular arrays. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.length, 0); + + var ta2 = new TA(42); + assert.sameValue(ta2.length, 42); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/this-has-no-typedarrayname-internal.js b/test/sendable/builtins/TypedArray/prototype/length/this-has-no-typedarrayname-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..95b39f24f922e236b627e8170e288a94142938da --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/this-has-no-typedarrayname-internal.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: > + Throws a TypeError exception when `this` does not have a [[TypedArrayName]] + internal slot +info: | + 22.2.3.18 get %SendableTypedArray%.prototype.length + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [DataView, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, "length" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}); + +var dv = new DataView(new ArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/length/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/length/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..89d05331cf7dd7dc2bf0799fdb7009e5217cce53 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/length/this-is-not-object.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-get-%typedarray%.prototype.length +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.18 get %SendableTypedArray%.prototype.length + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + SendableTypedArrayPrototype, "length" +).get; + + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "number"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..95c798bb1ac437928671c541982f7d83240aac02 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/arraylength-internal.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + [[ArrayLength]] is accessed in place of performing a [[Get]] of "length" +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + var loop = 0; + + Object.defineProperty(sample1, "length", {value: 1}); + + sample1.map(function() { + loop++; + return 0n; + }); + assert.sameValue(loop, 42, "data descriptor"); + + loop = 0; + var sample2 = new TA(4); + Object.defineProperty(sample2, "length", { + get: function() { + throw new Test262Error( + "Does not return abrupt getting length property" + ); + } + }); + + sample2.map(function() { + loop++; + return 0n; + }); + assert.sameValue(loop, 4, "accessor descriptor"); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-arguments-with-thisarg.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..e1f07b5073d240512cb00205dff122d2a21337b9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.map(function() { + results.push(arguments); + return 0n; + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-arguments-without-thisarg.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..076915e77707e7c88184c7bf7fe00752767c78f7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + callbackfn arguments +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.map(function() { + results.push(arguments); + return 0n; + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..4233a03f1ea25cee4198aa02906890dee51dcef3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.map(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return true; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-is-not-callable.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..58ff9345b58a96c651721c9dcc41411bead1f4e9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-is-not-callable.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + callbackfn is not callable +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(TypeError, function() { + sample.map(); + }); + + assert.throws(TypeError, function() { + sample.map(undefined); + }); + + assert.throws(TypeError, function() { + sample.map(null); + }); + + assert.throws(TypeError, function() { + sample.map({}); + }); + + assert.throws(TypeError, function() { + sample.map(1); + }); + + assert.throws(TypeError, function() { + sample.map(""); + }); + + assert.throws(TypeError, function() { + sample.map(false); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-no-interaction-over-non-integer-properties.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-no-interaction-over-non-integer-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..f6025e8a64eb286e19082c3ec7b214e48bbfc8c0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-no-interaction-over-non-integer-properties.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Does not interact over non-integer properties +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.map(function() { + results.push(arguments); + return 0n; + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + + assert.sameValue(results[0][0], 7n, "results[0][0] - kValue"); + assert.sameValue(results[1][0], 8n, "results[1][0] - kValue"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..b67f086aea7b7ef4584ed096225fea58ab27150e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().map(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-return-affects-returned-object.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-return-affects-returned-object.js new file mode 100644 index 0000000000000000000000000000000000000000..91abe46191bafbfd38d17513a5c87ba0456c9fbd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-return-affects-returned-object.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + The callbackfn returned values are applied to the new instance +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + d. Perform ? Set(A, Pk, mappedValue, true). + ... + 9. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 4n]); + var result = sample.map(function(v) { + return v * 3n; + }); + + assert.sameValue(result[0], 3n, "result[0] == 3"); + assert.sameValue(result[1], 6n, "result[1] == 6"); + assert.sameValue(result[2], 12n, "result[2] == 12"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..394a4895f8f1c6a1aa5ebc997444dc53579364d2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + The callbackfn return does not change the `this` instance +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(3); + + sample1[1] = 1n; + + sample1.map(function() { + return 42n; + }); + + assert.sameValue(sample1[0], 0n, "[0] == 0"); + assert.sameValue(sample1[1], 1n, "[1] == 1"); + assert.sameValue(sample1[2], 0n, "[2] == 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-copy-non-integer-properties.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-copy-non-integer-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..e176bc5b6fc01205d0be396178aa356b42b6c0b8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-copy-non-integer-properties.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Does not copy non-integer properties to returned value +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + var bar = Symbol("1"); + + sample.foo = 42; + sample[bar] = 1; + + var result = sample.map(function() { + return 0n; + }); + + assert.sameValue(result.length, 2, "result.length"); + assert.sameValue( + Object.getOwnPropertyDescriptor(result, "foo"), + undefined, + "foo" + ); + assert.sameValue( + Object.getOwnPropertyDescriptor(result, bar), + undefined, + "bar" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..b995c01245ab60af3c4a8f8a883f41f7cbe1bc70 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.map(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-set-value-during-interaction.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000000000000000000000000000000000..d141ad44d32de3ceebe5c5af826c624a26a3083e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-set-value-during-interaction.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.map(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1n, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7n), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + return 0n; + }); + + assert.sameValue(sample[0], 7n, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1n, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2n, "changed values after iteration [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..3704267d1865b68e9be9e53938a7ab9689d4d25b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/callbackfn-this.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + callbackfn `this` value +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.map(function() { + results1.push(this); + return 0n; + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.map(function() { + results2.push(this); + return 0n; + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..403b0973a600c88f83e10203b541c529647d7c0c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.map(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..e8651c86ef16f5ee4382222215c7c3b5cd6df8a5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.map, + 'function', + 'implements SendableTypedArray.prototype.map' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.map(() => 0n); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.map(() => 0n); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the map operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.map(() => 0n); + throw new Test262Error('map completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-empty-length.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-empty-length.js new file mode 100644 index 0000000000000000000000000000000000000000..8291a90554654d12f88b38c3c680f5b5983ebcdf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-empty-length.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Returns a new typedArray instance from the same constructor with the same + length and a new buffer object - testing on an instance with length == 0 +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... + 9. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(0); + + var result = sample.map(function() {}); + + assert.notSameValue(result, sample, "new typedArray object"); + assert.sameValue(result.constructor, TA, "same constructor"); + assert(result instanceof TA, "result is an instance of " + TA.name); + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "result has the same prototype of sample" + ); + assert.sameValue(result.length, 0, "same length"); + assert.notSameValue(result.buffer, sample.buffer, "new buffer"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-positive-length.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-positive-length.js new file mode 100644 index 0000000000000000000000000000000000000000..71e6a77048eb466c0919fb71741002d52c5e7af9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-positive-length.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Returns a new typedArray instance from the same constructor with the same + length and a new buffer object - testing on an instance with length > 0 +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... + 9. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var result = sample.map(function(v) { + return v; + }); + + assert.notSameValue(result, sample, "new typedArray object"); + assert.sameValue(result.constructor, sample.constructor, "same constructor"); + assert.sameValue(result.length, 3, "same length"); + assert.notSameValue(result.buffer, sample.buffer, "new buffer"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-destination-resizable.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-destination-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..65abd0e870b6c1872af37096e8489cd79a1858f0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-destination-resizable.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Throws a TypeError if new typedArray's length < count +info: | + 22.2.3.22 %SendableTypedArray%.prototype.map ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const rab1 = new ArrayBuffer(8, {maxByteLength: 100}); + const ta = new TA(rab1); + const rab2 = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab2); + rab2.resize(0); + ta.constructor = { [Symbol.species]: function() { return lengthTracking; } }; + assert.throws(TypeError, function() { + ta.map(() => {}); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-abrupt.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..6b43292e06704015caa06bb2f2b9411180a15fa1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var callCount = 0; + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.map(function() { + callCount++; + }); + }); + assert.sameValue(callCount, 0, "callback should not be called"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-inherited.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000000000000000000000000000000000..d4f8221bc1145c4f5d6a3a460732edbd301ff2b4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-inherited.js @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var calls = 0; + var result; + + Object.defineProperty(TA.prototype, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.map(function() { + return 0n; + }); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + undefined, + "used defaultCtor but still checks the inherited .constructor" + ); + + calls = 6; + result.constructor; + assert.sameValue( + calls, + 7, + "result.constructor triggers the inherited accessor property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..2ed299f9a3ad28a021edfe1a7914eff75110617e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var callbackfn = function() { return 0n; }; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..1945cc1db7428fba21d56112990f0f0e972e4d94 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: get constructor on SpeciesConstructor +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var calls = 0; + var result; + + Object.defineProperty(sample, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.map(function() { return 0n; }); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + TA, + "use defaultCtor on an undefined return - .constructor check" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-abrupt.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..f79442c3ec34a688fdd0ad97d278bd8f7257a09a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-abrupt.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.map(function() { return 0n; }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-invocation.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000000000000000000000000000000000..7b61bb19b011f9303b0245096153d34b1060191f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 42n, 42n]); + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + result = arguments; + ctorThis = this; + return new TA(count); + }; + + sample.map(function(v) { return v === 42n; }); + + assert.sameValue(result.length, 1, "called with 1 argument"); + assert.sameValue(result[0], 3, "[0] is the length"); + + assert( + ctorThis instanceof sample.constructor[Symbol.species], + "`this` value in the @@species fn is an instance of the function itself" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..d923aa603339dc64587b2099a32d2cecd4a12cef --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Throws a TypeError if new typedArray's length < count +info: | + 22.2.3.22 %SendableTypedArray%.prototype.map ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA(2); + const rab = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab); + rab.resize(0); + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return lengthTracking; + }; + assert.throws(TypeError, function() { + sample.map(() => {}); + }); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length-throws.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..0dc42863d4d968f6cb4bbbe6d0d5878fb31665ce --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length-throws.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Throws a TypeError if new typedArray's length < len +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(); + }; + + assert.throws(TypeError, function() { + sample.map(function() { return 0; }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length.js new file mode 100644 index 0000000000000000000000000000000000000000..07a33b218ccac960e7bde12d71fdee46fd79504b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Does not throw a TypeError if new typedArray's length >= len +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var customCount, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(customCount); + }; + + customCount = 2; + result = sample.map(function() { return 0n; }); + assert.sameValue(result.length, customCount, "length == count"); + + customCount = 5; + result = sample.map(function() { return 0n; }); + assert.sameValue(result.length, customCount, "length > count"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..c2896edc63470728d0a604dbc4a956f5da3624ba --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Custom @@species constructor may return a different SendableTypedArray +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n]); + var otherTA = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var other = new otherTA([1n, 0n, 1n]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.map(function(a) { return a + 7n; }); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [47n, 0n, 1n]), "values are set on returned typedarray"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-throws.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..33b1e0075915ecf3f880e012500e51c4557f350a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = Array; + + assert.throws(TypeError, function() { + sample.map(function() {}); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..f8d44b67de6323ddc2a0cc9c16faeb142a1ec4a2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Use custom @@species constructor if available +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + var calls = 0; + var other, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(len) { + calls++; + other = new TA(len); + return other; + }; + + result = sample.map(function(a) { return a + 7n; }); + + assert.sameValue(calls, 1, "ctor called once"); + assert.sameValue(result, other, "return is instance of custom constructor"); + assert(compareArray(result, [47n, 48n, 49n]), "values are set on the new obj"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..3a1ce20eb6283d22f7ee48af820312520c2c2ee8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-returns-throws.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + sample.constructor[Symbol.species] = 0; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "true"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-use-default-ctor.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..beda5e72df635fbf44f12422573a1b03c549cbca --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var result; + + sample.constructor = {}; + + result = sample.map(function() { return 0n; }); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "undefined @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "undefined @@species - ctor check"); + + sample.constructor[Symbol.species] = null; + result = sample.map(function() { return 0n; }); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "null @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "null @@species - ctor check"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species.js new file mode 100644 index 0000000000000000000000000000000000000000..e6b0fc66a47d4ddab00246e82822326b857c9a5f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/speciesctor-get-species.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + get @@species from found constructor +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calls = 0; + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + calls++; + } + }); + + sample.map(function() { return 0n; }); + + assert.sameValue(calls, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/BigInt/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/map/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..8227f925f35c9b49abfa081fd2d4208434a28418 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/BigInt/values-are-not-cached.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + sample.map(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42n; + } + + assert.sameValue( + v, 42n, "method does not cache values before callbackfn calls" + ); + + return 0n; + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/map/arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..5ace72176aca8757a742d378e5afa7a25536b859 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/arraylength-internal.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + [[ArrayLength]] is accessed in place of performing a [[Get]] of "length" +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + var loop = 0; + + Object.defineProperty(sample1, "length", {value: 1}); + + sample1.map(function() { + loop++; + return 0; + }); + assert.sameValue(loop, 42, "data descriptor"); + + loop = 0; + var sample2 = new TA(4); + Object.defineProperty(sample2, "length", { + get: function() { + throw new Test262Error( + "Does not return abrupt getting length property" + ); + } + }); + + sample2.map(function() { + loop++; + return 0; + }); + assert.sameValue(loop, 4, "accessor descriptor"); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-arguments-with-thisarg.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..a5e06dc2707f64d6c44ea6dd1492572c04a8da24 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.map(function() { + results.push(arguments); + return 0; + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-arguments-without-thisarg.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..2ed4dbac600c2d09ea0431c5d9514e849ae5e5db --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + callbackfn arguments +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + + sample.map(function() { + results.push(arguments); + return 0; + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..40c52ae618a8a4bd978a1904a06add8bb68e1f41 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-detachbuffer.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [detachArrayBuffer.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.map(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return true; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-is-not-callable.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-is-not-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..9b4aee28fcd6e4f6d7cc0a012c599625dcd14066 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-is-not-callable.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + callbackfn is not callable +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(TypeError, function() { + sample.map(); + }); + + assert.throws(TypeError, function() { + sample.map(undefined); + }); + + assert.throws(TypeError, function() { + sample.map(null); + }); + + assert.throws(TypeError, function() { + sample.map({}); + }); + + assert.throws(TypeError, function() { + sample.map(1); + }); + + assert.throws(TypeError, function() { + sample.map(""); + }); + + assert.throws(TypeError, function() { + sample.map(false); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..a651ad781d43d429794913360fa51de22616f219 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Does not interact over non-integer properties +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7, 8]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.map(function() { + results.push(arguments); + return 0; + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + + assert.sameValue(results[0][0], 7, "results[0][0] - kValue"); + assert.sameValue(results[1][0], 8, "results[1][0] - kValue"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..aea6c268c62b7ddf31e4543ee322a1dfbd6077b4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-not-called-on-empty.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().map(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-resize.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..016042ab7e36432765062d49100bcf1b628b09d7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-resize.js @@ -0,0 +1,89 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: Instance buffer can be resized during iteration +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var NaNvalue = isFloatSendableTypedArrayConstructor(TA) ? NaN : 0; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var finalElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + + elements = []; + indices = []; + arrays = []; + result = sample.map(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + finalElement = undefined; + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + finalElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + + elements.push(element); + indices.push(index); + arrays.push(array); + + return index; + }); + + assert.compareArray(elements, [0, 0, finalElement], 'elements (shrink)'); + assert.compareArray(indices, [0, 1, 2], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.compareArray(result, [0, 1, 2], 'result (shrink)'); + + elements = []; + indices = []; + arrays = []; + result = sample.map(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + + elements.push(element); + indices.push(index); + arrays.push(array); + + return index; + }); + + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.compareArray(result, expectedIndices, 'result (grow)'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-return-affects-returned-object.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-return-affects-returned-object.js new file mode 100644 index 0000000000000000000000000000000000000000..31bf3c1cd3b6020ba4741b2ba73e290240dfeb58 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-return-affects-returned-object.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + The callbackfn returned values are applied to the new instance +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + d. Perform ? Set(A, Pk, mappedValue, true). + ... + 9. Return A. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 2, 4]); + var result = sample.map(function(v) { + return v * 3; + }); + + assert.sameValue(result[0], 3, "result[0] == 3"); + assert.sameValue(result[1], 6, "result[1] == 6"); + assert.sameValue(result[2], 12, "result[2] == 12"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..5f9ca8f4d07840f1942a575aa2c2e4c73bde2ea7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + The callbackfn return does not change the `this` instance +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA(3); + + sample1[1] = 1; + + sample1.map(function() { + return 42; + }); + + assert.sameValue(sample1[0], 0, "[0] == 0"); + assert.sameValue(sample1[1], 1, "[1] == 1"); + assert.sameValue(sample1[2], 0, "[2] == 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-return-does-not-copy-non-integer-properties.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-return-does-not-copy-non-integer-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..d20b9c0d60f0ebc0b073ae1938b57a29a31fd673 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-return-does-not-copy-non-integer-properties.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Does not copy non-integer properties to returned value +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7, 8]); + var bar = Symbol("1"); + + sample.foo = 42; + sample[bar] = 1; + + var result = sample.map(function() { + return 0; + }); + + assert.sameValue(result.length, 2, "result.length"); + assert.sameValue( + Object.getOwnPropertyDescriptor(result, "foo"), + undefined, + "foo" + ); + assert.sameValue( + Object.getOwnPropertyDescriptor(result, bar), + undefined, + "bar" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..47099d9d9fe9dd8134d0510a39a6875c73d54207 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-returns-abrupt.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.map(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-set-value-during-interaction.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000000000000000000000000000000000..61849f85bd480185fe563118c69bf9214ba2e8be --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-set-value-during-interaction.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [sendableTypedArray.js] +features: [Reflect.set, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + var newVal = 0; + + sample.map(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + return 0; + }); + + assert.sameValue(sample[0], 7, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2, "changed values after iteration [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..53386c3caa80de81b850d72dab507a00d09ec033 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/callbackfn-this.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + callbackfn `this` value +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.map(function() { + results1.push(this); + return 0; + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.map(function() { + results2.push(this); + return 0; + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/map/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..8eb571a0efe13c88f4e23745667d9279aa5cfde5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.map(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/map/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..9436c20998019bd674ebad4c5bc53a5c34ce76a9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/invoked-as-func.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.18 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var map = SendableTypedArray.prototype.map; + +assert.sameValue(typeof map, 'function'); + +assert.throws(TypeError, function() { + map(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/map/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..0dcaf80db1ad6ae2499608d07ea5c16d63e2af14 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/invoked-as-method.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.18 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.map, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.map(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/length.js b/test/sendable/builtins/TypedArray/prototype/map/length.js new file mode 100644 index 0000000000000000000000000000000000000000..85c6cbf58597c48787bbe0dc67146d1e368223d8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + %SendableTypedArray%.prototype.map.length is 1. +info: | + %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.map, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/name.js b/test/sendable/builtins/TypedArray/prototype/map/name.js new file mode 100644 index 0000000000000000000000000000000000000000..44cba371a4b1c3fa4bae49e24332a551e4181844 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + %SendableTypedArray%.prototype.map.name is "map". +info: | + %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.map, "name", { + value: "map", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/map/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..8c5ac0f080822be0ce289ea940d8483863f5dc0e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.map does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.map), + false, + 'isConstructor(SendableTypedArray.prototype.map) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.map(() => {}); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/map/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/map/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..d0c0e7e98ea66e386e39ef5b26b96a380a972aaa --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + "map" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'map', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/map/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..643fbc5e0e91d4000b81349bb1222dc7fd25f425 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + SendableTypedArray.p.map behaves correctly on SendableTypedArrays backed by resizable buffers + that are grown mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return n; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + fixedLength.map(ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.map(ResizeMidIteration); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + lengthTracking.map(ResizeMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.map(ResizeMidIteration); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/map/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/map/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..98c0f61d4a000513293723973f8e21ed91573cef --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,101 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + SendableTypedArray.p.map behaves correctly on SendableTypedArrays backed by resizable buffers + that are shrunk mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. This version can deal with the undefined values +// resulting by shrinking rab. +function ShrinkMidIteration(n, ix, ta) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + // We still need to return a valid BigInt / non-BigInt, even if + // n is `undefined`. + if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) { + return 0n; + } + return 0; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLength.map(ShrinkMidIteration); + assert.compareArray(values, [ + 0, + 2, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.map(ShrinkMidIteration); + assert.compareArray(values, [ + 4, + undefined + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTracking.map(ShrinkMidIteration); + assert.compareArray(values, [ + 0, + 2, + 4, + undefined + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.map(ShrinkMidIteration); + assert.compareArray(values, [ + 4, + undefined + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/map/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/map/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..0dbff508023c5ca3ecdb5f2d9f88adfbfb4bc0a0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/resizable-buffer.js @@ -0,0 +1,170 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + SendableTypedArray.p.map behaves as expected on SendableTypedArrays backed by resizable + buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < taWrite.length; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function MapGathering(array) { + const values = []; + function GatherValues(n, ix) { + assert.sameValue(ix, values.length); + values.push(n); + if (typeof n == 'bigint') { + return n + 1n; + } + return n + 1; + } + const newValues = array.map(GatherValues); + for (let i = 0; i < values.length; ++i) { + if (typeof values[i] == 'bigint') { + assert.sameValue(values[i] + 1n, newValues[i]); + } else { + assert.sameValue(values[i] + 1, newValues[i]); + } + } + return ToNumbers(values); + } + assert.compareArray(MapGathering(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(MapGathering(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(MapGathering(lengthTracking), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(MapGathering(lengthTrackingWithOffset), [ + 4, + 6 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + MapGathering(fixedLength); + }); + assert.throws(TypeError, () => { + MapGathering(fixedLengthWithOffset); + }); + + assert.compareArray(MapGathering(lengthTracking), [ + 0, + 2, + 4 + ]); + assert.compareArray(MapGathering(lengthTrackingWithOffset), [4]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + MapGathering(fixedLength); + }); + assert.throws(TypeError, () => { + MapGathering(fixedLengthWithOffset); + }); + assert.throws(TypeError, () => { + MapGathering(lengthTrackingWithOffset); + }); + + assert.compareArray(MapGathering(lengthTracking), [0]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + MapGathering(fixedLength); + }); + assert.throws(TypeError, () => { + MapGathering(fixedLengthWithOffset); + }); + assert.throws(TypeError, () => { + MapGathering(lengthTrackingWithOffset); + }); + + assert.compareArray(MapGathering(lengthTracking), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.compareArray(MapGathering(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(MapGathering(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(MapGathering(lengthTracking), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(MapGathering(lengthTrackingWithOffset), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/map/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/map/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..d0da518825e4f370ad516b407498efc6d731c450 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [ArrayBuffer, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.map, + 'function', + 'implements SendableTypedArray.prototype.map' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.map(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.map(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the map operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.map(() => {}); + throw new Test262Error('map completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-conversion-operation-consistent-nan.js b/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-conversion-operation-consistent-nan.js new file mode 100644 index 0000000000000000000000000000000000000000..5c4dcdcc094b0ddb09e14c3c0afedca69ef27d55 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-conversion-operation-consistent-nan.js @@ -0,0 +1,84 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: Consistent canonicalization of NaN values +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Perform ? Set(A, Pk, mappedValue, true). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + a. Set rawBytes to a List containing the 4 bytes that are the result + of converting value to IEEE 754-2008 binary32 format using “Round to + nearest, ties to even” rounding mode. If isLittleEndian is false, the + bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number + encoding. An implementation must always choose the same encoding for + each implementation distinguishable NaN value. + 9. Else, if type is "Float64", then + a. Set rawBytes to a List containing the 8 bytes that are the IEEE + 754-2008 binary64 format encoding of value. If isLittleEndian is false, + the bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary32 format Not-a-Number + encoding. An implementation must always choose the same encoding for + each implementation distinguishable NaN value. + ... +includes: [nans.js, sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +function body(FloatArray) { + var sample = new FloatArray(NaNs); + var sampleBytes, resultBytes; + var i = 0; + + var result = sample.map(function() { + return NaNs[i++]; + }); + + sampleBytes = new Uint8Array(sample.buffer); + resultBytes = new Uint8Array(result.buffer); + + assert(compareArray(sampleBytes, resultBytes)); +} + +testWithTypedArrayConstructors(body, floatArrayConstructors); diff --git a/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-conversion-operation.js b/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-conversion-operation.js new file mode 100644 index 0000000000000000000000000000000000000000..9f24d6e826d97bc3a3344a58f159bf322a52deb8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-conversion-operation.js @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Verify conversion values on returned instance +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Perform ? Set(A, Pk, mappedValue, true). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + ... + 9. Else, if type is "Float64", then + ... + 10. Else, + ... + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 50 for Element Type type. + c. Let intValue be convOp(value). + d. If intValue ≥ 0, then + ... + e. Else, + ... +includes: [byteConversionValues.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + var result = sample.map(function() { + return value; + }); + + assert.sameValue(result[0], expected, value + " converts to " + expected); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-from-empty-length.js b/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-from-empty-length.js new file mode 100644 index 0000000000000000000000000000000000000000..cb37026256bbe3d298f43afa49c926f1ea73ef6a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-from-empty-length.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Returns a new typedArray instance from the same constructor with the same + length and a new buffer object - testing on an instance with length == 0 +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... + 9. Return A. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(0); + + var result = sample.map(function() {}); + + assert.notSameValue(result, sample, "new typedArray object"); + assert.sameValue(result.constructor, TA, "same constructor"); + assert(result instanceof TA, "result is an instance of " + TA.name); + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "result has the same prototype of sample" + ); + assert.sameValue(result.length, 0, "same length"); + assert.notSameValue(result.buffer, sample.buffer, "new buffer"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-from-positive-length.js b/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-from-positive-length.js new file mode 100644 index 0000000000000000000000000000000000000000..8d4fe80fe41ef74fb92683c59df035d5bd0016e1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/return-new-typedarray-from-positive-length.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Returns a new typedArray instance from the same constructor with the same + length and a new buffer object - testing on an instance with length > 0 +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... + 9. Return A. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var result = sample.map(function(v) { + return v; + }); + + assert.notSameValue(result, sample, "new typedArray object"); + assert.sameValue(result.constructor, sample.constructor, "same constructor"); + assert.sameValue(result.length, 3, "same length"); + assert.notSameValue(result.buffer, sample.buffer, "new buffer"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-destination-resizable.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-destination-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..e9d955df3a70f2235956ada8372d14c574690475 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-destination-resizable.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Throws a TypeError if new typedArray's length < count +info: | + 22.2.3.22 %SendableTypedArray%.prototype.map ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const rab1 = new ArrayBuffer(8, {maxByteLength: 100}); + const ta = new TA(rab1); + const rab2 = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab2); + rab2.resize(0); + ta.constructor = { [Symbol.species]: function() { return lengthTracking; } }; + assert.throws(TypeError, function() { + ta.map(() => {}); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor-abrupt.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..c3a7a058309c33f9d81322f117df856ac60f2122 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var callCount = 0; + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.map(function() { + callCount++; + }); + }); + assert.sameValue(callCount, 0, "callback should not be called"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor-inherited.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000000000000000000000000000000000..e04fcc7b0da7ead65d3db5d5d0b5aa976e29f40e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor-inherited.js @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var calls = 0; + var result; + + Object.defineProperty(TA.prototype, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.map(function() { + return 0; + }); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + undefined, + "used defaultCtor but still checks the inherited .constructor" + ); + + calls = 6; + result.constructor; + assert.sameValue( + calls, + 7, + "result.constructor triggers the inherited accessor property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..a7d7bb5d091a564104da0c9796c5b523bba49afe --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var callbackfn = function() { return 0; }; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..f459e2c979843bdf9b562bcab8701039486f60f2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: get constructor on SpeciesConstructor +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var calls = 0; + var result; + + Object.defineProperty(sample, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.map(function() { return 0; }); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + TA, + "use defaultCtor on an undefined return - .constructor check" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-abrupt.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..99a6e918482348aaeb1a73f97ab5b5e0ec0d9e8c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-abrupt.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.map(function() { return 0; }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-invocation.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000000000000000000000000000000000..5f835479a295cbe797b33c64cd1a4a987d61c8be --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 42, 42]); + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + result = arguments; + ctorThis = this; + return new TA(count); + }; + + sample.map(function(v) { return v === 42; }); + + assert.sameValue(result.length, 1, "called with 1 argument"); + assert.sameValue(result[0], 3, "[0] is the length"); + + assert( + ctorThis instanceof sample.constructor[Symbol.species], + "`this` value in the @@species fn is an instance of the function itself" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9cfd8c942c1a3c8aab9e2ad305636a2aaef7aac4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Throws a TypeError if new typedArray's length < count +info: | + 22.2.3.22 %SendableTypedArray%.prototype.map ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA(2); + const rab = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab); + rab.resize(0); + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return lengthTracking; + }; + assert.throws(TypeError, function() { + sample.map(() => {}); + }); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length-throws.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..032613fe244766f9cc751bc7c07a67bb6b75d804 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length-throws.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Throws a TypeError if new typedArray's length < len +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(); + }; + + assert.throws(TypeError, function() { + sample.map(function() { return 0; }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length.js new file mode 100644 index 0000000000000000000000000000000000000000..853f632aed1092d3c31a6e22541f41c870f8aef3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Does not throw a TypeError if new typedArray's length >= len +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var customCount, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(customCount); + }; + + customCount = 2; + result = sample.map(function() { return 0; }); + assert.sameValue(result.length, customCount, "length == count"); + + customCount = 5; + result = sample.map(function() { return 0; }); + assert.sameValue(result.length, customCount, "length > count"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-returns-another-instance.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..6073927ac8b4e248b4f6772e693db2d7d6fcc0c3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Custom @@species constructor may return a different SendableTypedArray +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js, compareArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40]); + var otherTA = TA === Int8Array ? Int16Array : Int8Array; + var other = new otherTA([1, 0, 1]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.map(function(a) { return a + 7; }); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [47, 0, 1]), "values are set on returned typedarray"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-throws.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..324308f7e2e3ba9d8af2d84b2a5488bfb48e2266 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = Array; + + assert.throws(TypeError, function() { + sample.map(function() {}); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..5ecbfcb91fd9a17a30dbf3a28529e1fc37742db6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Use custom @@species constructor if available +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js, compareArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42]); + var calls = 0; + var other, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(len) { + calls++; + other = new TA(len); + return other; + }; + + result = sample.map(function(a) { return a + 7; }); + + assert.sameValue(calls, 1, "ctor called once"); + assert.sameValue(result, other, "return is instance of custom constructor"); + assert(compareArray(result, [47, 48, 49]), "values are set on the new obj"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..8a21bcc83e310d75195822b9c95fc3c8551b4ce5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-returns-throws.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + sample.constructor[Symbol.species] = 0; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "true"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-use-default-ctor.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..1b30dd1d3a7528a2bda7d0608c9dfd514fa5d74c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var result; + + sample.constructor = {}; + + result = sample.map(function() {}); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "undefined @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "undefined @@species - ctor check"); + + sample.constructor[Symbol.species] = null; + result = sample.map(function() {}); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "null @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "null @@species - ctor check"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species.js new file mode 100644 index 0000000000000000000000000000000000000000..fa19189c3b7c166f88d731d28b4e01437848f853 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-get-species.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + get @@species from found constructor +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? SendableTypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calls = 0; + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + calls++; + } + }); + + sample.map(function() {}); + + assert.sameValue(calls, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-resizable-buffer-grow.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-resizable-buffer-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..81e9ddbd63c43e623a19e5bed41cc8d8011964b1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-resizable-buffer-grow.js @@ -0,0 +1,97 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + SendableTypedArray.p.map behaves correctly on SendableTypedArrays backed by resizable buffers + that are grown by the species constructor. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Returns a function that collects an appropriate typed array into values. Such +// a result can be used as an argument to .map. +function CollectWithUndefined(values) { + return (n, ix, ta) => { + if (typeof n == 'bigint') { + values.push(Number(n)); + } else { + values.push(n); + } + if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) { + // We still need to return a valid BigInt / non-BigInt, even if + // n is `undefined`. + return 0n; + } + return 0; + } +} + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + let resizeWhenConstructorCalled = false; + class MyArray extends ctor { + constructor(...params) { + super(...params); + if (resizeWhenConstructorCalled) { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + } + } + }; + const fixedLength = new MyArray(rab, 0, 4); + resizeWhenConstructorCalled = true; + const values = []; + fixedLength.map(CollectWithUndefined(values)); + assert.compareArray(values, [ + 0, + 1, + 2, + 3 + ]); + assert.sameValue(rab.byteLength, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + let resizeWhenConstructorCalled = false; + class MyArray extends ctor { + constructor(...params) { + super(...params); + if (resizeWhenConstructorCalled) { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + } + } + } + ; + const lengthTracking = new MyArray(rab); + resizeWhenConstructorCalled = true; + const values = []; + lengthTracking.map(CollectWithUndefined(values)); + assert.compareArray(values, [ + 0, + 1, + 2, + 3 + ]); + assert.sameValue(rab.byteLength, 6 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/map/speciesctor-resizable-buffer-shrink.js b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-resizable-buffer-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..fc2eba27e6ac58fad6614a440355bfbebcb956b6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/speciesctor-resizable-buffer-shrink.js @@ -0,0 +1,94 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + SendableTypedArray.p.map behaves correctly on SendableTypedArrays backed by resizable buffers + that are shrunk by the species constructor. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Returns a function that collects an appropriate typed array into values. Such +// a result can be used as an argument to .map. +function CollectWithUndefined(values) { + return (n, ix, ta) => { + if (typeof n == 'bigint') { + values.push(Number(n)); + } else { + values.push(n); + } + if (ta instanceof BigInt64Array || ta instanceof BigUint64Array) { + // We still need to return a valid BigInt / non-BigInt, even if + // n is `undefined`. + return 0n; + } + return 0; + } +} + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + let resizeWhenConstructorCalled = false; + class MyArray extends ctor { + constructor(...params) { + super(...params); + if (resizeWhenConstructorCalled) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + } + } + ; + const fixedLength = new MyArray(rab, 0, 4); + resizeWhenConstructorCalled = true; + const values = []; + fixedLength.map(CollectWithUndefined(values)); + assert.compareArray(values, [ + undefined, + undefined, + undefined, + undefined + ]); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + let resizeWhenConstructorCalled = false; + class MyArray extends ctor { + constructor(...params) { + super(...params); + if (resizeWhenConstructorCalled) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + } + } + ; + const lengthTracking = new MyArray(rab); + resizeWhenConstructorCalled = true; + const values = []; + lengthTracking.map(CollectWithUndefined(values)); + assert.compareArray(values, [ + 0, + 1, + undefined, + undefined + ]); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/map/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/map/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..5746c84911c5f3d14495b190de920279b1a2c66f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/this-is-not-object.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var map = SendableTypedArray.prototype.map; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + map.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + map.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + map.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + map.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + map.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + map.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + map.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/map/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/map/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..80670dfe0ba47a48a7914b4089bd7656ea16677f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/this-is-not-typedarray-instance.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var map = SendableTypedArray.prototype.map; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + map.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + map.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + map.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + map.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/map/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/map/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..8fa34cfcb6208cee0a538e8df6d79fe0f33da013 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/map/values-are-not-cached.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.map +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.19 %SendableTypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + sample.map(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42; + } + + assert.sameValue( + v, 42, "method does not cache values before callbackfn calls" + ); + + return 0; + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-custom-accumulator.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-custom-accumulator.js new file mode 100644 index 0000000000000000000000000000000000000000..25d92c990d3963dfb63b67b0b8b3e5ec19e6b69d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-custom-accumulator.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + callbackfn arguments using custom accumulator +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.reduce(function(accumulator) { + results.push(arguments); + return accumulator + 1; + }, 7); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 4, "results[0].length"); + assert.sameValue(results[0][0], 7, "results[0][0] - accumulator"); + assert.sameValue(results[0][1], 42n, "results[0][1] - kValue"); + assert.sameValue(results[0][2], 0, "results[0][2] - k"); + assert.sameValue(results[0][3], sample, "results[0][3] - this"); + + assert.sameValue(results[1].length, 4, "results[1].length"); + assert.sameValue(results[1][0], 8, "results[1][0] - accumulator"); + assert.sameValue(results[1][1], 43n, "results[1][1] - kValue"); + assert.sameValue(results[1][2], 1, "results[1][2] - k"); + assert.sameValue(results[1][3], sample, "results[1][3] - this"); + + assert.sameValue(results[2].length, 4, "results[2].length"); + assert.sameValue(results[2][0], 9, "results[2][0] - accumulator"); + assert.sameValue(results[2][1], 44n, "results[2][1] - kValue"); + assert.sameValue(results[2][2], 2, "results[2][2] - k"); + assert.sameValue(results[2][3], sample, "results[2][3] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-default-accumulator.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-default-accumulator.js new file mode 100644 index 0000000000000000000000000000000000000000..f02383a61126cf16fa6a03aa0ace1fa39dd0585a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-default-accumulator.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + callbackfn arguments using default accumulator (value at index 0) +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + a. Let kPresent be false. + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.reduce(function(accumulator) { + results.push(arguments); + return accumulator - 1n; + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0].length, 4, "results[1].length"); + assert.sameValue(results[0][0], 42n, "results[1][0] - accumulator"); + assert.sameValue(results[0][1], 43n, "results[1][1] - kValue"); + assert.sameValue(results[0][2], 1, "results[1][2] - k"); + assert.sameValue(results[0][3], sample, "results[1][3] - this"); + + assert.sameValue(results[1].length, 4, "results[2].length"); + assert.sameValue(results[1][0], 41n, "results[2][0] - accumulator"); + assert.sameValue(results[1][1], 44n, "results[2][1] - kValue"); + assert.sameValue(results[1][2], 2, "results[2][2] - k"); + assert.sameValue(results[1][3], sample, "results[2][3] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..2ac487bd7d878878afd1adb73ae892e91fbb88c2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.reduce(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return true; + }, 0); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..be3833c4d84a1ac1ce06d5c9883b4ba409b8d3b3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-is-not-callable-throws.js @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Throws TypeError if callbackfn is not callable +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.reduce(); + }, "no arg"); + + assert.throws(TypeError, function() { + sample.reduce(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.reduce(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.reduce({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.reduce(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.reduce(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.reduce(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.reduce(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.reduce(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.reduce(Symbol("")); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-no-iteration-over-non-integer-properties.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-no-iteration-over-non-integer-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..ccc8362d3157b94d2ae53e52458d764850776e11 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-no-iteration-over-non-integer-properties.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Does not iterate over non-integer properties +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.reduce(function() { + results.push(arguments); + }, 0); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][2], 0, "results[0][2] - k"); + assert.sameValue(results[1][2], 1, "results[1][2] - k"); + + assert.sameValue(results[0][1], 7n, "results[0][1] - kValue"); + assert.sameValue(results[1][1], 8n, "results[1][1] - kValue"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..e2a6d206096d5272fd3428a4fc3c8a8c8b90096a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().reduce(function() { + called++; + }, undefined); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..7c981ac565dee75e28aea6e292859fda80f4221e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + The callbackfn return does not change the `this` instance +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n, 1n, 0n]); + + sample.reduce(function() { + return 42; + }, 7); + + assert.sameValue(sample[0], 0n, "[0] == 0"); + assert.sameValue(sample[1], 1n, "[1] == 1"); + assert.sameValue(sample[2], 0n, "[2] == 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..59847f4d87930b3c7ec1f70de7e9e532bea296ee --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(Test262Error, function() { + sample.reduce(function() { + throw new Test262Error(); + }); + }); + + assert.throws(Test262Error, function() { + sample.reduce(function() { + throw new Test262Error(); + }, 0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-set-value-during-iteration.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-set-value-during-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..ad9b9bf5217ff6d952600f4e0d0a7c81908be864 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-set-value-during-iteration.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.reduce(function(acc, val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1n, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7n), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + }, 0); + + assert.sameValue(sample[0], 7n, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1n, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2n, "changed values after iteration [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..fa1d277ce8b484b683a5776075efe210e52ca563 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/callbackfn-this.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + callbackfn `this` value +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results = []; + + sample.reduce(function() { + results.push(this); + }, 0); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(results[0], expected, "[0]"); + assert.sameValue(results[1], expected, "[1]"); + assert.sameValue(results[2], expected, "[2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..e772df9a52efa495adf97c0959193a8f3d37d7c3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reduce(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/empty-instance-return-initialvalue.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/empty-instance-return-initialvalue.js new file mode 100644 index 0000000000000000000000000000000000000000..20a7bfb845ffcf98e743500d50ef36bc71839b79 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/empty-instance-return-initialvalue.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Returns given initialValue on empty instances without calling callbackfn +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA().reduce(function() { + called = true; + }, 42); + + assert.sameValue(result, 42); + assert.sameValue(called, false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/empty-instance-with-no-initialvalue-throws.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/empty-instance-with-no-initialvalue-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..2ff522b5834c424f7a863c78f035bd0c5cb5160a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/empty-instance-with-no-initialvalue-throws.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + If len is 0 and initialValue is not present, throw a TypeError exception. +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + assert.throws(TypeError, function() { + new TA().reduce(function() { + called++; + }); + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..28c9c6a0c74b9bfd4e46c4740cf1dd0a131b64bf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.reduce(function() { + calls++; + }, 0); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/result-is-last-callbackfn-return.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/result-is-last-callbackfn-return.js new file mode 100644 index 0000000000000000000000000000000000000000..47f53bcf4b4de57c2b907dddefdb73c0a84d46d2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/result-is-last-callbackfn-return.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Returns last accumulator value +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var calls, result; + + calls = 0; + result = new TA([1n, 2n, 3n]).reduce(function() { + calls++; + + if (calls == 2) { + return 42; + } + }); + assert.sameValue(result, 42, "using default accumulator"); + + calls = 0; + result = new TA([1n, 2n, 3n]).reduce(function() { + calls++; + + if (calls == 3) { + return 7; + } + }, 0); + assert.sameValue(result, 7, "using custom accumulator"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/result-of-any-type.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/result-of-any-type.js new file mode 100644 index 0000000000000000000000000000000000000000..d7b088f8d2673c2995fd73755b7f86ddf80df188 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/result-of-any-type.js @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Result can be of any type without any number conversions +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + [ + ["test262", "string"], + ["", "empty string"], + [undefined, "undefined"], + [null, "null"], + [-0, "-0"], + [42, "integer"], + [NaN, "NaN"], + [Infinity, "Infinity"], + [0.6, "float number"], + [true, "true"], + [false, "false"], + [Symbol(""), "symbol"], + [{}, "object"] + ].forEach(function(item) { + var result; + + result = sample.reduce(function() { + return item[0]; + }); + assert.sameValue(result, item[0], item[1] + " - using default accumulator"); + + result = sample.reduce(function() { + return item[0]; + }, 0); + + assert.sameValue(result, item[0], item[1] + " - using custom accumulator"); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..bda78b32384ca2d241d255de8291d2af792b2ef8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.reduce, + 'function', + 'implements SendableTypedArray.prototype.reduce' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.reduce(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.reduce(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the reduce operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.reduce(() => {}); + throw new Test262Error('reduce completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/return-first-value-without-callbackfn.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/return-first-value-without-callbackfn.js new file mode 100644 index 0000000000000000000000000000000000000000..be1526999f04271de09d669055f45e548ededd2e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/return-first-value-without-callbackfn.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Returns [0] without calling callbackfn if length is 1 and initialValue is not + present. +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA([42n]).reduce(function() { + called = true; + }); + + assert.sameValue(result, 42n); + assert.sameValue(called, false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..ac8b5b4310bf6f66e5f6502e5359879f8d83ffae --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/BigInt/values-are-not-cached.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + sample.reduce(function(a, v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42n; + } + + assert.sameValue( + v, 42n, "method does not cache values before callbackfn calls" + ); + }, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-arguments-custom-accumulator.js b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-arguments-custom-accumulator.js new file mode 100644 index 0000000000000000000000000000000000000000..9c50eb8b468f5e8f24256ad64ddd2dffe467d1e9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-arguments-custom-accumulator.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + callbackfn arguments using custom accumulator +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + + sample.reduce(function(accumulator) { + results.push(arguments); + return accumulator + 1; + }, 7); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 4, "results[0].length"); + assert.sameValue(results[0][0], 7, "results[0][0] - accumulator"); + assert.sameValue(results[0][1], 42, "results[0][1] - kValue"); + assert.sameValue(results[0][2], 0, "results[0][2] - k"); + assert.sameValue(results[0][3], sample, "results[0][3] - this"); + + assert.sameValue(results[1].length, 4, "results[1].length"); + assert.sameValue(results[1][0], 8, "results[1][0] - accumulator"); + assert.sameValue(results[1][1], 43, "results[1][1] - kValue"); + assert.sameValue(results[1][2], 1, "results[1][2] - k"); + assert.sameValue(results[1][3], sample, "results[1][3] - this"); + + assert.sameValue(results[2].length, 4, "results[2].length"); + assert.sameValue(results[2][0], 9, "results[2][0] - accumulator"); + assert.sameValue(results[2][1], 44, "results[2][1] - kValue"); + assert.sameValue(results[2][2], 2, "results[2][2] - k"); + assert.sameValue(results[2][3], sample, "results[2][3] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-arguments-default-accumulator.js b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-arguments-default-accumulator.js new file mode 100644 index 0000000000000000000000000000000000000000..de4b3e4f9b722715deafed8d714fa285c33557bb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-arguments-default-accumulator.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + callbackfn arguments using default accumulator (value at index 0) +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + a. Let kPresent be false. + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + + sample.reduce(function(accumulator) { + results.push(arguments); + return accumulator - 1; + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0].length, 4, "results[1].length"); + assert.sameValue(results[0][0], 42, "results[1][0] - accumulator"); + assert.sameValue(results[0][1], 43, "results[1][1] - kValue"); + assert.sameValue(results[0][2], 1, "results[1][2] - k"); + assert.sameValue(results[0][3], sample, "results[1][3] - this"); + + assert.sameValue(results[1].length, 4, "results[2].length"); + assert.sameValue(results[1][0], 41, "results[2][0] - accumulator"); + assert.sameValue(results[1][1], 44, "results[2][1] - kValue"); + assert.sameValue(results[1][2], 2, "results[2][2] - k"); + assert.sameValue(results[1][3], sample, "results[2][3] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..83031d8b413c3a29ea926b9d4a35f059e9d4bfb8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-detachbuffer.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [detachArrayBuffer.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.reduce(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return true; + }, 0); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..51057e59d24725c6b4aecd27ebfc7e90be2ea574 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-is-not-callable-throws.js @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Throws TypeError if callbackfn is not callable +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.reduce(); + }, "no arg"); + + assert.throws(TypeError, function() { + sample.reduce(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.reduce(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.reduce({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.reduce(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.reduce(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.reduce(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.reduce(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.reduce(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.reduce(Symbol("")); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-no-iteration-over-non-integer-properties.js b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-no-iteration-over-non-integer-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..9fe1430d4d64187bcf53ef093dad0de830bfa429 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-no-iteration-over-non-integer-properties.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Does not iterate over non-integer properties +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7, 8]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.reduce(function() { + results.push(arguments); + }, 0); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][2], 0, "results[0][2] - k"); + assert.sameValue(results[1][2], 1, "results[1][2] - k"); + + assert.sameValue(results[0][1], 7, "results[0][1] - kValue"); + assert.sameValue(results[1][1], 8, "results[1][1] - kValue"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..b24b31e0d63366fb94278424177506cdc7f680d4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-not-called-on-empty.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().reduce(function() { + called++; + }, undefined); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-resize.js b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..332a18655ba76eafea276bd08577133462cce57e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-resize.js @@ -0,0 +1,88 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: Instance buffer can be resized during iteration +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 3}); + var sample = new TA(buffer); + var finalNext, expectedPrevs, expectedNexts, expectedIndices, expectedArrays; + var prevs, nexts, indices, arrays, result; + + prevs = []; + nexts = []; + indices = []; + arrays = []; + result = sample.reduce(function(prev, next, index, array) { + if (prevs.length === 0) { + try { + buffer.resize(2 * BPE); + finalNext = undefined; + expectedPrevs = [262, 0]; + expectedNexts = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + finalNext = 0; + expectedPrevs = [262, 0, 1]; + expectedNexts = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + + prevs.push(prev); + nexts.push(next); + indices.push(index); + arrays.push(array); + return index; + }, 262); + + assert.compareArray(prevs, [262, 0, 1], 'prevs (shrink)'); + assert.compareArray(nexts, [0, 0, finalNext], 'nexts (shrink)'); + assert.compareArray(indices, [0, 1, 2], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, 2, 'result (shrink)'); + + prevs = []; + nexts = []; + indices = []; + arrays = []; + result = sample.reduce(function(prev, next, index, array) { + if (prevs.length === 0) { + try { + buffer.resize(3 * BPE); + } catch (_) {} + } + + prevs.push(prev); + nexts.push(next); + indices.push(index); + arrays.push(array); + return index; + }, 262); + + assert.compareArray(prevs, expectedPrevs, 'prevs (grow)'); + assert.compareArray(nexts, expectedNexts, 'nexts (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, expectedIndices[expectedIndices.length - 1], 'result (grow)'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..8002b4aab57332c7e0e93ca98e97e4f1346f9081 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + The callbackfn return does not change the `this` instance +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0, 1, 0]); + + sample.reduce(function() { + return 42; + }, 7); + + assert.sameValue(sample[0], 0, "[0] == 0"); + assert.sameValue(sample[1], 1, "[1] == 1"); + assert.sameValue(sample[2], 0, "[2] == 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..6c86a10ebbe893aca441be689ffabc5dbcffd910 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-returns-abrupt.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(Test262Error, function() { + sample.reduce(function() { + throw new Test262Error(); + }); + }); + + assert.throws(Test262Error, function() { + sample.reduce(function() { + throw new Test262Error(); + }, 0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-set-value-during-iteration.js b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-set-value-during-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..376ac43c9a95b76f7b95e880b033e66aeb34b1b4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-set-value-during-iteration.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) +includes: [sendableTypedArray.js] +features: [Reflect.set, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + var newVal = 0; + + sample.reduce(function(acc, val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + }, 0); + + assert.sameValue(sample[0], 7, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2, "changed values after iteration [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..499f842b46760808ac5499d8ebd5e737eeb4eac5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/callbackfn-this.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + callbackfn `this` value +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var expected = (function() { return this; })(); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results = []; + + sample.reduce(function() { + results.push(this); + }, 0); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(results[0], expected, "[0]"); + assert.sameValue(results[1], expected, "[1]"); + assert.sameValue(results[2], expected, "[2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/reduce/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9d20a7c607720f6fce4808d4a029dd7ac69ecc34 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reduce(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/empty-instance-return-initialvalue.js b/test/sendable/builtins/TypedArray/prototype/reduce/empty-instance-return-initialvalue.js new file mode 100644 index 0000000000000000000000000000000000000000..743ef93ebff35a0210649b4d6ccc38d1c5e302a1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/empty-instance-return-initialvalue.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Returns given initialValue on empty instances without calling callbackfn +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + 9. Return accumulator. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA().reduce(function() { + called = true; + }, 42); + + assert.sameValue(result, 42); + assert.sameValue(called, false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/empty-instance-with-no-initialvalue-throws.js b/test/sendable/builtins/TypedArray/prototype/reduce/empty-instance-with-no-initialvalue-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..3076bd55f9e65c4ca155cd0675ae9ac83ec34eb8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/empty-instance-with-no-initialvalue-throws.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + If len is 0 and initialValue is not present, throw a TypeError exception. +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + assert.throws(TypeError, function() { + new TA().reduce(function() { + called++; + }); + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/reduce/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..ef5744a9bd384f879b2a92dbd61e2e2e76b2a695 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/get-length-uses-internal-arraylength.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.reduce(function() { + calls++; + }, 0); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/reduce/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..98b9478975fe52b1426681a5e53acd65b2387ce1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/invoked-as-func.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.19 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var reduce = SendableTypedArray.prototype.reduce; + +assert.sameValue(typeof reduce, 'function'); + +assert.throws(TypeError, function() { + reduce(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/reduce/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..312945c803a9407f2fc10688b8afa9431aa9ebd6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/invoked-as-method.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.19 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.reduce, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.reduce(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/length.js b/test/sendable/builtins/TypedArray/prototype/reduce/length.js new file mode 100644 index 0000000000000000000000000000000000000000..6ca4664047142f90707ca554acaa57beb3b8e65b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + %SendableTypedArray%.prototype.reduce.length is 1. +info: | + %SendableTypedArray%.prototype.reduce ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.reduce, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/name.js b/test/sendable/builtins/TypedArray/prototype/reduce/name.js new file mode 100644 index 0000000000000000000000000000000000000000..ce94b7f2f98a7ecde50332edae09be2b8d00c228 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + %SendableTypedArray%.prototype.reduce.name is "reduce". +info: | + %SendableTypedArray%.prototype.reduce ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.reduce, "name", { + value: "reduce", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/reduce/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..7196707e2fea498596b66c361d87a65c873208dc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.reduce does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.reduce), + false, + 'isConstructor(SendableTypedArray.prototype.reduce) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.reduce(() => {}, []); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/reduce/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..099b8219faebbd42cc23b319b0da9ceadb1a73bd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + "reduce" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'reduce', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/reduce/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..3654de54054710f1572def63a189e51930f4b415 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + SendableTypedArray.p.reduce behaves correctly on SendableTypedArrays backed by resizable + buffers that are grown mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(acc, n) { + // Returns true by default. + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + fixedLength.reduce(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.reduce(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + lengthTracking.reduce(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.reduce(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/reduce/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..6b269bfd57a0ef02275749b3b1e771b1c983a0c9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + SendableTypedArray.p.reduce behaves correctly on SendableTypedArrays backed by resizable + buffers that are shrunk mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset +// before calling this. +function ResizeMidIteration(acc, n) { + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLength.reduce(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 0, + 2, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.reduce(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 4, + undefined + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTracking.reduce(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 0, + 2, + 4, + undefined + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.reduce(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 4, + undefined + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/reduce/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..78be73db3ff1dc9b4f90174aadba0704465fb986 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/resizable-buffer.js @@ -0,0 +1,157 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + SendableTypedArray.p.reduce behaves correctly on SendableTypedArrays backed by resizable + buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function ReduceCollecting(array) { + const reduceValues = []; + array.reduce((acc, n) => { + reduceValues.push(n); + }, 'initial value'); + return ToNumbers(reduceValues); + } + assert.compareArray(ReduceCollecting(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceCollecting(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ReduceCollecting(lengthTracking), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceCollecting(lengthTrackingWithOffset), [ + 4, + 6 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + ReduceCollecting(fixedLength); + }); + assert.throws(TypeError, () => { + ReduceCollecting(fixedLengthWithOffset); + }); + + assert.compareArray(ReduceCollecting(lengthTracking), [ + 0, + 2, + 4 + ]); + assert.compareArray(ReduceCollecting(lengthTrackingWithOffset), [4]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + ReduceCollecting(fixedLength); + }); + assert.throws(TypeError, () => { + ReduceCollecting(fixedLengthWithOffset); + }); + assert.throws(TypeError, () => { + ReduceCollecting(lengthTrackingWithOffset); + }); + + assert.compareArray(ReduceCollecting(lengthTracking), [0]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + ReduceCollecting(fixedLength); + }); + assert.throws(TypeError, () => { + ReduceCollecting(fixedLengthWithOffset); + }); + assert.throws(TypeError, () => { + ReduceCollecting(lengthTrackingWithOffset); + }); + + assert.compareArray(ReduceCollecting(lengthTracking), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.compareArray(ReduceCollecting(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceCollecting(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ReduceCollecting(lengthTracking), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(ReduceCollecting(lengthTrackingWithOffset), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/result-is-last-callbackfn-return.js b/test/sendable/builtins/TypedArray/prototype/reduce/result-is-last-callbackfn-return.js new file mode 100644 index 0000000000000000000000000000000000000000..f47896b82a24056eeb712d7ac57620f68dcecb0b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/result-is-last-callbackfn-return.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Returns last accumulator value +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + 9. Return accumulator. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var calls, result; + + calls = 0; + result = new TA([1, 2, 3]).reduce(function() { + calls++; + + if (calls == 2) { + return 42; + } + }); + assert.sameValue(result, 42, "using default accumulator"); + + calls = 0; + result = new TA([1, 2, 3]).reduce(function() { + calls++; + + if (calls == 3) { + return 7; + } + }, 0); + assert.sameValue(result, 7, "using custom accumulator"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/result-of-any-type.js b/test/sendable/builtins/TypedArray/prototype/reduce/result-of-any-type.js new file mode 100644 index 0000000000000000000000000000000000000000..67a450afed7100ac3032bb72d4abefc423a14c08 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/result-of-any-type.js @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Result can be of any type without any number conversions +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + 9. Return accumulator. +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + [ + ["test262", "string"], + ["", "empty string"], + [undefined, "undefined"], + [null, "null"], + [-0, "-0"], + [42, "integer"], + [NaN, "NaN"], + [Infinity, "Infinity"], + [0.6, "float number"], + [true, "true"], + [false, "false"], + [Symbol(""), "symbol"], + [{}, "object"] + ].forEach(function(item) { + var result; + + result = sample.reduce(function() { + return item[0]; + }); + assert.sameValue(result, item[0], item[1] + " - using default accumulator"); + + result = sample.reduce(function() { + return item[0]; + }, 0); + + assert.sameValue(result, item[0], item[1] + " - using custom accumulator"); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/reduce/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..72ccd36930c71e6915f6c61eda4fd61b8ad8aea7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [ArrayBuffer, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.reduce, + 'function', + 'implements SendableTypedArray.prototype.reduce' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.reduce(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.reduce(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the reduce operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.reduce(() => {}); + throw new Test262Error('reduce completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/return-first-value-without-callbackfn.js b/test/sendable/builtins/TypedArray/prototype/reduce/return-first-value-without-callbackfn.js new file mode 100644 index 0000000000000000000000000000000000000000..939b25c86d6fad03aad6e0f6bfe987a520edc342 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/return-first-value-without-callbackfn.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Returns [0] without calling callbackfn if length is 1 and initialValue is not + present. +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + 9. Return accumulator. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA([42]).reduce(function() { + called = true; + }); + + assert.sameValue(result, 42); + assert.sameValue(called, false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/reduce/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..02b96d775f959687183d58abd44bd38300162ce2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/this-is-not-object.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var reduce = SendableTypedArray.prototype.reduce; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + reduce.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + reduce.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + reduce.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + reduce.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + reduce.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + reduce.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + reduce.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/reduce/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..3c7fd694b39fbb0ee2572bb15ce13dd51f224f42 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/this-is-not-typedarray-instance.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var reduce = SendableTypedArray.prototype.reduce; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + reduce.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + reduce.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + reduce.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + reduce.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/reduce/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/reduce/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..698e2986ffe56bb1438ef6d67bab32311709aa65 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduce/values-are-not-cached.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduce +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + sample.reduce(function(a, v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42; + } + + assert.sameValue( + v, 42, "method does not cache values before callbackfn calls" + ); + }, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-custom-accumulator.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-custom-accumulator.js new file mode 100644 index 0000000000000000000000000000000000000000..0f3b520f278bdfd466f0e7c2d00063f79c587d31 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-custom-accumulator.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + callbackfn arguments using custom accumulator +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.reduceRight(function(accumulator) { + results.push(arguments); + return accumulator + 1; + }, 7); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 4, "results[0].length"); + assert.sameValue(results[0][0], 7, "results[0][0] - accumulator"); + assert.sameValue(results[0][1], 44n, "results[0][1] - kValue"); + assert.sameValue(results[0][2], 2, "results[0][2] - k"); + assert.sameValue(results[0][3], sample, "results[0][3] - this"); + + assert.sameValue(results[1].length, 4, "results[1].length"); + assert.sameValue(results[1][0], 8, "results[1][0] - accumulator"); + assert.sameValue(results[1][1], 43n, "results[1][1] - kValue"); + assert.sameValue(results[1][2], 1, "results[1][2] - k"); + assert.sameValue(results[1][3], sample, "results[1][3] - this"); + + assert.sameValue(results[2].length, 4, "results[2].length"); + assert.sameValue(results[2][0], 9, "results[2][0] - accumulator"); + assert.sameValue(results[2][1], 42n, "results[2][1] - kValue"); + assert.sameValue(results[2][2], 0, "results[2][2] - k"); + assert.sameValue(results[2][3], sample, "results[2][3] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-default-accumulator.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-default-accumulator.js new file mode 100644 index 0000000000000000000000000000000000000000..1d0626f56afd061e6e47e3b235d25866fbb7da48 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-default-accumulator.js @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + callbackfn arguments using default accumulator (value at last index) +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.reduceRight(function(accumulator) { + results.push(arguments); + return accumulator + 1n; + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0].length, 4, "results[1].length"); + assert.sameValue(results[0][0], 44n, "results[1][0] - accumulator"); + assert.sameValue(results[0][1], 43n, "results[1][1] - kValue"); + assert.sameValue(results[0][2], 1, "results[1][2] - k"); + assert.sameValue(results[0][3], sample, "results[1][3] - this"); + + assert.sameValue(results[1].length, 4, "results[2].length"); + assert.sameValue(results[1][0], 45n, "results[2][0] - accumulator"); + assert.sameValue(results[1][1], 42n, "results[2][1] - kValue"); + assert.sameValue(results[1][2], 0, "results[2][2] - k"); + assert.sameValue(results[1][3], sample, "results[2][3] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..cc3a270e5fbc85baea8aa63151fdf44437a1a373 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.reduceRight(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return true; + }, 0); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..708277c12c2215767b8c231e1504ce57a6a4c35d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-is-not-callable-throws.js @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Throws TypeError if callbackfn is not callable +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.reduceRight(); + }, "no arg"); + + assert.throws(TypeError, function() { + sample.reduceRight(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.reduceRight(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.reduceRight({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.reduceRight(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.reduceRight(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.reduceRight(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.reduceRight(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.reduceRight(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.reduceRight(Symbol("")); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-no-iteration-over-non-integer-properties.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-no-iteration-over-non-integer-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..ca28b55c7f18ed5af02ce04bdb3bfe2b0a3e58e8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-no-iteration-over-non-integer-properties.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Does not iterate over non-integer properties +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.reduceRight(function() { + results.push(arguments); + }, 0); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][2], 1, "results[0][2] - k"); + assert.sameValue(results[1][2], 0, "results[1][2] - k"); + + assert.sameValue(results[0][1], 8n, "results[0][1] - kValue"); + assert.sameValue(results[1][1], 7n, "results[1][1] - kValue"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..9286bffbefc6baeb5486f17c6ec0156896e11b5a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().reduceRight(function() { + called++; + }, undefined); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..2048de957f16847a20bed98a9cdfececc49cdf0b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + The callbackfn return does not change the `this` instance +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n, 1n, 0n]); + + sample.reduceRight(function() { + return 42; + }, 7); + + assert.sameValue(sample[0], 0n, "[0] == 0"); + assert.sameValue(sample[1], 1n, "[1] == 1"); + assert.sameValue(sample[2], 0n, "[2] == 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..afa4fb77083745962b00f52655cabc891377d021 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(Test262Error, function() { + sample.reduceRight(function() { + throw new Test262Error(); + }); + }); + + assert.throws(Test262Error, function() { + sample.reduceRight(function() { + throw new Test262Error(); + }, 0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-set-value-during-iteration.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-set-value-during-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..f9761399a706c692a6004bb821c4bcc76c719196 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-set-value-during-iteration.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.reduceRight(function(acc, val, i) { + if (i < sample.length - 1) { + assert.sameValue( + sample[i + 1], newVal - 1n, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 2, 7n), + true, + "re-set a value for sample[2]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + }, 0); + + assert.sameValue(sample[0], 2n, "changed values after iteration [0] == 2"); + assert.sameValue(sample[1], 1n, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 7n, "changed values after iteration [2] == 7"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..58ea6af60c262f61721d869144289c0cc7f41f1c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/callbackfn-this.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + callbackfn `this` value +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results = []; + + sample.reduceRight(function() { + results.push(this); + }, 0); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(results[0], expected, "[0]"); + assert.sameValue(results[1], expected, "[1]"); + assert.sameValue(results[2], expected, "[2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..4574c7e43c46f61d3b28f8532d43915cdebf20a3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reduceRight(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/empty-instance-return-initialvalue.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/empty-instance-return-initialvalue.js new file mode 100644 index 0000000000000000000000000000000000000000..8cac4a855ce23c1df905fbc177852611a45cf066 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/empty-instance-return-initialvalue.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Returns given initialValue on empty instances without calling callbackfn +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA().reduceRight(function() { + called = true; + }, 42); + + assert.sameValue(result, 42); + assert.sameValue(called, false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/empty-instance-with-no-initialvalue-throws.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/empty-instance-with-no-initialvalue-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..a5ca021869de94ab1f63830419d9d91ba79ea68f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/empty-instance-with-no-initialvalue-throws.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + If len is 0 and initialValue is not present, throw a TypeError exception. +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + assert.throws(TypeError, function() { + new TA().reduceRight(function() { + called++; + }); + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..ad37cbd354e5e54d2cd5797bdbb1124032d13da7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.reduceRight(function() { + calls++; + }, 0); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/result-is-last-callbackfn-return.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/result-is-last-callbackfn-return.js new file mode 100644 index 0000000000000000000000000000000000000000..badaefc1dadd3e9d6fee55d5f71a780cdf244532 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/result-is-last-callbackfn-return.js @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Returns last accumulator value +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var calls, result; + + calls = 0; + result = new TA([1n, 2n, 3n]).reduceRight(function() { + calls++; + + if (calls == 2) { + return 42; + } + }); + assert.sameValue(result, 42, "using default accumulator"); + + calls = 0; + result = new TA([1n, 2n, 3n]).reduceRight(function() { + calls++; + + if (calls == 3) { + return 7; + } + }, 0); + assert.sameValue(result, 7, "using custom accumulator"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/result-of-any-type.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/result-of-any-type.js new file mode 100644 index 0000000000000000000000000000000000000000..066294989df88a8beaeae236dd1a749f6902a83b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/result-of-any-type.js @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Result can be of any type without any number conversions +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + [ + ["test262", "string"], + ["", "empty string"], + [undefined, "undefined"], + [null, "null"], + [-0, "-0"], + [42, "integer"], + [NaN, "NaN"], + [Infinity, "Infinity"], + [0.6, "float number"], + [true, "true"], + [false, "false"], + [Symbol(""), "symbol"], + [{}, "object"] + ].forEach(function(item) { + var result; + + result = sample.reduceRight(function() { + return item[0]; + }); + assert.sameValue(result, item[0], item[1] + " - using default accumulator"); + + result = sample.reduceRight(function() { + return item[0]; + }, 0); + + assert.sameValue(result, item[0], item[1] + " - using custom accumulator"); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..4b1b983bdfeeadba63b00d3f0ebe3a50381f360c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.reduceRight, + 'function', + 'implements SendableTypedArray.prototype.reduceRight' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.reduceRight(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.reduceRight(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the reduceRight operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.reduceRight(() => {}); + throw new Test262Error('reduceRight completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/return-first-value-without-callbackfn.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/return-first-value-without-callbackfn.js new file mode 100644 index 0000000000000000000000000000000000000000..2b0e3108ee03e1a11fad428c79fe8ef919038a9c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/return-first-value-without-callbackfn.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Returns [0] without calling callbackfn if length is 1 and initialValue is not + present. +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA([42n]).reduceRight(function() { + called = true; + }); + + assert.sameValue(result, 42n); + assert.sameValue(called, false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..48cf996f29248b9e4389a438c75eafcb482d0584 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/BigInt/values-are-not-cached.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([44n, 43n, 42n]); + + sample.reduceRight(function(a, v, i) { + if (i > 0) { + sample[i-1] = 42n; + } + + assert.sameValue( + v, 42n, "method does not cache values before callbackfn calls" + ); + }, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-arguments-custom-accumulator.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-arguments-custom-accumulator.js new file mode 100644 index 0000000000000000000000000000000000000000..dc6cfb2c8b6847416c245ddd06e3bff9bb6b313a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-arguments-custom-accumulator.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + callbackfn arguments using custom accumulator +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + + sample.reduceRight(function(accumulator) { + results.push(arguments); + return accumulator + 1; + }, 7); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 4, "results[0].length"); + assert.sameValue(results[0][0], 7, "results[0][0] - accumulator"); + assert.sameValue(results[0][1], 44, "results[0][1] - kValue"); + assert.sameValue(results[0][2], 2, "results[0][2] - k"); + assert.sameValue(results[0][3], sample, "results[0][3] - this"); + + assert.sameValue(results[1].length, 4, "results[1].length"); + assert.sameValue(results[1][0], 8, "results[1][0] - accumulator"); + assert.sameValue(results[1][1], 43, "results[1][1] - kValue"); + assert.sameValue(results[1][2], 1, "results[1][2] - k"); + assert.sameValue(results[1][3], sample, "results[1][3] - this"); + + assert.sameValue(results[2].length, 4, "results[2].length"); + assert.sameValue(results[2][0], 9, "results[2][0] - accumulator"); + assert.sameValue(results[2][1], 42, "results[2][1] - kValue"); + assert.sameValue(results[2][2], 0, "results[2][2] - k"); + assert.sameValue(results[2][3], sample, "results[2][3] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-arguments-default-accumulator.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-arguments-default-accumulator.js new file mode 100644 index 0000000000000000000000000000000000000000..db0cb5cee4825fc2c4f7083f86e81ef614c514f1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-arguments-default-accumulator.js @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + callbackfn arguments using default accumulator (value at last index) +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + + sample.reduceRight(function(accumulator) { + results.push(arguments); + return accumulator + 1; + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0].length, 4, "results[1].length"); + assert.sameValue(results[0][0], 44, "results[1][0] - accumulator"); + assert.sameValue(results[0][1], 43, "results[1][1] - kValue"); + assert.sameValue(results[0][2], 1, "results[1][2] - k"); + assert.sameValue(results[0][3], sample, "results[1][3] - this"); + + assert.sameValue(results[1].length, 4, "results[2].length"); + assert.sameValue(results[1][0], 45, "results[2][0] - accumulator"); + assert.sameValue(results[1][1], 42, "results[2][1] - kValue"); + assert.sameValue(results[1][2], 0, "results[2][2] - k"); + assert.sameValue(results[1][3], sample, "results[2][3] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..488c785420db8bf9459808810736b5ead93bdbf6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-detachbuffer.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [detachArrayBuffer.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.reduceRight(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return true; + }, 0); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-is-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-is-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..02d4e03fd6d651b435616907f22beb5f716ce345 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-is-not-callable-throws.js @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Throws TypeError if callbackfn is not callable +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.reduceRight(); + }, "no arg"); + + assert.throws(TypeError, function() { + sample.reduceRight(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.reduceRight(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.reduceRight({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.reduceRight(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.reduceRight(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.reduceRight(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.reduceRight(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.reduceRight(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.reduceRight(Symbol("")); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-no-iteration-over-non-integer-properties.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-no-iteration-over-non-integer-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..e5599b69468dcf2291e5e425f936759cba886c3f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-no-iteration-over-non-integer-properties.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Does not iterate over non-integer properties +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7, 8]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.reduceRight(function() { + results.push(arguments); + }, 0); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][2], 1, "results[0][2] - k"); + assert.sameValue(results[1][2], 0, "results[1][2] - k"); + + assert.sameValue(results[0][1], 8, "results[0][1] - kValue"); + assert.sameValue(results[1][1], 7, "results[1][1] - kValue"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..4c195858cd440730545b25bb2d4455c067ad1770 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-not-called-on-empty.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().reduceRight(function() { + called++; + }, undefined); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-resize.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..fe577f2e56424dee40751379a62937f44c55d1a3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-resize.js @@ -0,0 +1,88 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: Instance buffer can be resized during iteration +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 3}); + var sample = new TA(buffer); + var secondNext, expectedPrevs, expectedNexts, expectedIndices, expectedArrays; + var prevs, nexts, indices, arrays, result; + + prevs = []; + nexts = []; + indices = []; + arrays = []; + result = sample.reduceRight(function(prev, next, index, array) { + if (prevs.length === 0) { + try { + buffer.resize(BPE); + secondNext = undefined; + expectedPrevs = [262]; + expectedNexts = [0]; + expectedIndices = [0]; + expectedArrays = [sample]; + } catch (_) { + secondNext = 0; + expectedPrevs = [262, 2, 1]; + expectedNexts = [0, 0, 0]; + expectedIndices = [2, 1, 0]; + expectedArrays = [sample, sample, sample]; + } + } + + prevs.push(prev); + nexts.push(next); + indices.push(index); + arrays.push(array); + return index; + }, 262); + + assert.compareArray(prevs, [262, 2, 1], 'prevs (shrink)'); + assert.compareArray(nexts, [0, secondNext, 0], 'nexts (shrink)'); + assert.compareArray(indices, [2, 1, 0], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, 0, 'result (shrink)'); + + prevs = []; + nexts = []; + indices = []; + arrays = []; + result = sample.reduceRight(function(prev, next, index, array) { + if (prevs.length === 0) { + try { + buffer.resize(3 * BPE); + } catch (_) {} + } + + prevs.push(prev); + nexts.push(next); + indices.push(index); + arrays.push(array); + return index; + }, 262); + + assert.compareArray(prevs, expectedPrevs, 'prevs (grow)'); + assert.compareArray(nexts, expectedNexts, 'nexts (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, expectedIndices[expectedIndices.length - 1], 'result (grow)'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..6804f8124b0c35e86e1d73088bf3b783bbe30db4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + The callbackfn return does not change the `this` instance +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0, 1, 0]); + + sample.reduceRight(function() { + return 42; + }, 7); + + assert.sameValue(sample[0], 0, "[0] == 0"); + assert.sameValue(sample[1], 1, "[1] == 1"); + assert.sameValue(sample[2], 0, "[2] == 0"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..d2c8766a49d487998bc37cb86d192e9e94d47845 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-returns-abrupt.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(Test262Error, function() { + sample.reduceRight(function() { + throw new Test262Error(); + }); + }); + + assert.throws(Test262Error, function() { + sample.reduceRight(function() { + throw new Test262Error(); + }, 0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-set-value-during-iteration.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-set-value-during-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..fb8cb4fc9e5a55d7bba8b11f31611090230caf50 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-set-value-during-iteration.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) +includes: [sendableTypedArray.js] +features: [Reflect.set, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + var newVal = 0; + + sample.reduceRight(function(acc, val, i) { + if (i < sample.length - 1) { + assert.sameValue( + sample[i + 1], newVal - 1, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 2, 7), + true, + "re-set a value for sample[2]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + }, 0); + + assert.sameValue(sample[0], 2, "changed values after iteration [0] == 2"); + assert.sameValue(sample[1], 1, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 7, "changed values after iteration [2] == 7"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..b276379ddebd44376e08c3857f3d30f11e377ca8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/callbackfn-this.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + callbackfn `this` value +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var expected = (function() { return this; })(); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results = []; + + sample.reduceRight(function() { + results.push(this); + }, 0); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(results[0], expected, "[0]"); + assert.sameValue(results[1], expected, "[1]"); + assert.sameValue(results[2], expected, "[2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..e1a04ea57f6eb4e27ec8c2f2900d7f5d995e53fd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reduceRight(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/empty-instance-return-initialvalue.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/empty-instance-return-initialvalue.js new file mode 100644 index 0000000000000000000000000000000000000000..ec6d34c545f1d6720e766b7e26c324bb3294c301 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/empty-instance-return-initialvalue.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Returns given initialValue on empty instances without calling callbackfn +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + 9. Return accumulator. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA().reduceRight(function() { + called = true; + }, 42); + + assert.sameValue(result, 42); + assert.sameValue(called, false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/empty-instance-with-no-initialvalue-throws.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/empty-instance-with-no-initialvalue-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..48d390ba4025e29dd82f2db741b293184afae708 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/empty-instance-with-no-initialvalue-throws.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + If len is 0 and initialValue is not present, throw a TypeError exception. +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + assert.throws(TypeError, function() { + new TA().reduceRight(function() { + called++; + }); + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..68a9136a6da2688f4508b6cf90d6fa49478c40a4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/get-length-uses-internal-arraylength.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.reduceRight(function() { + calls++; + }, 0); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..4daacf026a44ed4aa82663ef69e8b269469f2f1d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/invoked-as-func.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var reduceRight = SendableTypedArray.prototype.reduceRight; + +assert.sameValue(typeof reduceRight, 'function'); + +assert.throws(TypeError, function() { + reduceRight(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..ab4abd40970e8d483cb2893bbab0896ad9f90843 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/invoked-as-method.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.20 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.reduceRight, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.reduceRight(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/length.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/length.js new file mode 100644 index 0000000000000000000000000000000000000000..84a4c4f236b3ef99eeb19407e8297b05cb6a4b73 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + %SendableTypedArray%.prototype.reduceRight.length is 1. +info: | + %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.reduceRight, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/name.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/name.js new file mode 100644 index 0000000000000000000000000000000000000000..cdf762bfddc453f8cb0632ee74ba69f67ee58c7b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + %SendableTypedArray%.prototype.reduceRight.name is "reduceRight". +info: | + %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.reduceRight, "name", { + value: "reduceRight", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..c8f5bf96d2b75e3febb46d5bf908834be1fc68cc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.reduceRight does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.reduceRight), + false, + 'isConstructor(SendableTypedArray.prototype.reduceRight) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.reduceRight(() => {}, []); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..f662546970c524ee962b990dcb6b57c6ad6e3a17 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + "reduceRight" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'reduceRight', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..4af576661348c73e66144796313566744b580557 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,97 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + SendableTypedArray.p.reduceRight behaves correctly on SendableTypedArrays backed by resizable + buffers that are grown mid-iteration. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(acc, n) { + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +// Test for reduceRight. + +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + fixedLength.reduceRight(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.reduceRight(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + lengthTracking.reduceRight(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.reduceRight(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..160989602a897c0e6adadcc2ce182b3bf2c904e5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,113 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + SendableTypedArray.p.reduceRight behaves correctly on SendableTypedArrays backed by resizable + buffer that is shrunk mid-iteration +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Collects the view of the resizable array buffer rab into values, with an +// iteration during which, after resizeAfter steps, rab is resized to length +// resizeTo. To be called by a method of the view being collected. +// Note that rab, values, resizeAfter, and resizeTo may need to be reset before +// calling this. +function ResizeMidIteration(acc, n) { + return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +// Tests for reduceRight. + +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLength.reduceRight(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.reduceRight(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + undefined + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + // Unaffected by the shrinking, since we've already iterated past the point. + lengthTracking.reduceRight(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4, + 2, + 0 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + resizeAfter = 1; + resizeTo = 2 * ctor.BYTES_PER_ELEMENT; + lengthTracking.reduceRight(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + undefined, + 2, + 0 + ]); +} +for (let ctor of ctors) { + values = []; + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + // Unaffected by the shrinking, since we've already iterated past the point. + lengthTrackingWithOffset.reduceRight(ResizeMidIteration, 'initial value'); + assert.compareArray(values, [ + 6, + 4 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f2d4358b68ec069abbe63e37e2571b01d9718a8c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/resizable-buffer.js @@ -0,0 +1,158 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + SendableTypedArray.p.reduceRight behaves correctly on SendableTypedArrays backed by resizable + buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function ReduceRightCollecting(array) { + const reduceRightValues = []; + array.reduceRight((acc, n) => { + reduceRightValues.push(n); + }, 'initial value'); + reduceRightValues.reverse(); + return ToNumbers(reduceRightValues); + } + assert.compareArray(ReduceRightCollecting(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceRightCollecting(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ReduceRightCollecting(lengthTracking), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceRightCollecting(lengthTrackingWithOffset), [ + 4, + 6 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + ReduceRightCollecting(fixedLength); + }); + assert.throws(TypeError, () => { + ReduceRightCollecting(fixedLengthWithOffset); + }); + + assert.compareArray(ReduceRightCollecting(lengthTracking), [ + 0, + 2, + 4 + ]); + assert.compareArray(ReduceRightCollecting(lengthTrackingWithOffset), [4]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + ReduceRightCollecting(fixedLength); + }); + assert.throws(TypeError, () => { + ReduceRightCollecting(fixedLengthWithOffset); + }); + assert.throws(TypeError, () => { + ReduceRightCollecting(lengthTrackingWithOffset); + }); + + assert.compareArray(ReduceRightCollecting(lengthTracking), [0]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + ReduceRightCollecting(fixedLength); + }); + assert.throws(TypeError, () => { + ReduceRightCollecting(fixedLengthWithOffset); + }); + assert.throws(TypeError, () => { + ReduceRightCollecting(lengthTrackingWithOffset); + }); + + assert.compareArray(ReduceRightCollecting(lengthTracking), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.compareArray(ReduceRightCollecting(fixedLength), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ReduceRightCollecting(fixedLengthWithOffset), [ + 4, + 6 + ]); + assert.compareArray(ReduceRightCollecting(lengthTracking), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(ReduceRightCollecting(lengthTrackingWithOffset), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/result-is-last-callbackfn-return.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/result-is-last-callbackfn-return.js new file mode 100644 index 0000000000000000000000000000000000000000..dfdd3bd287791e9b98a8bba6e2eda0d4dead0683 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/result-is-last-callbackfn-return.js @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Returns last accumulator value +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + 9. Return accumulator. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var calls, result; + + calls = 0; + result = new TA([1, 2, 3]).reduceRight(function() { + calls++; + + if (calls == 2) { + return 42; + } + }); + assert.sameValue(result, 42, "using default accumulator"); + + calls = 0; + result = new TA([1, 2, 3]).reduceRight(function() { + calls++; + + if (calls == 3) { + return 7; + } + }, 0); + assert.sameValue(result, 7, "using custom accumulator"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/result-of-any-type.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/result-of-any-type.js new file mode 100644 index 0000000000000000000000000000000000000000..cf15636fd47283589acc0e5148d2974f9a6f1bbb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/result-of-any-type.js @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Result can be of any type without any number conversions +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + 9. Return accumulator. +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + [ + ["test262", "string"], + ["", "empty string"], + [undefined, "undefined"], + [null, "null"], + [-0, "-0"], + [42, "integer"], + [NaN, "NaN"], + [Infinity, "Infinity"], + [0.6, "float number"], + [true, "true"], + [false, "false"], + [Symbol(""), "symbol"], + [{}, "object"] + ].forEach(function(item) { + var result; + + result = sample.reduceRight(function() { + return item[0]; + }); + assert.sameValue(result, item[0], item[1] + " - using default accumulator"); + + result = sample.reduceRight(function() { + return item[0]; + }, 0); + + assert.sameValue(result, item[0], item[1] + " - using custom accumulator"); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..d25c832774321da3a0efe839378b8301251d6864 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [ArrayBuffer, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.reduceRight, + 'function', + 'implements SendableTypedArray.prototype.reduceRight' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.reduceRight(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.reduceRight(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the reduceRight operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.reduceRight(() => {}); + throw new Test262Error('reduceRight completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/return-first-value-without-callbackfn.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/return-first-value-without-callbackfn.js new file mode 100644 index 0000000000000000000000000000000000000000..d437405c0d5062c67a4ea6a4c585022214c63d1d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/return-first-value-without-callbackfn.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Returns [0] without calling callbackfn if length is 1 and initialValue is not + present. +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + 9. Return accumulator. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA([42]).reduceRight(function() { + called = true; + }); + + assert.sameValue(result, 42); + assert.sameValue(called, false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..2cf546cfc789a3b622c11fdf58e8c768b15928d3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/this-is-not-object.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var reduceRight = SendableTypedArray.prototype.reduceRight; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + reduceRight.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + reduceRight.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + reduceRight.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + reduceRight.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + reduceRight.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + reduceRight.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + reduceRight.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..418bdeb8af4587a6d137713d34558895def5c7e3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/this-is-not-typedarray-instance.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var reduceRight = SendableTypedArray.prototype.reduceRight; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + reduceRight.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + reduceRight.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + reduceRight.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + reduceRight.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/reduceRight/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/reduceRight/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..573e25ca9014349ec0907fcfc56ee81d0f3d4178 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reduceRight/values-are-not-cached.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reduceright +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %SendableTypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([44, 43, 42]); + + sample.reduceRight(function(a, v, i) { + if (i > 0) { + sample[i-1] = 42; + } + + assert.sameValue( + v, 42, "method does not cache values before callbackfn calls" + ); + }, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/resizable-and-fixed-have-same-prototype.js b/test/sendable/builtins/TypedArray/prototype/resizable-and-fixed-have-same-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..ab5b3e85cb1796e9523ef74c4f2147000294dd62 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/resizable-and-fixed-have-same-prototype.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype +description: > + SendableTypedArrays that are backed by resizable buffers have the same prototypes + as those backed by fixed-length buffers +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const rab = CreateResizableArrayBuffer(40, 80); +const ab = new ArrayBuffer(80); +for (let ctor of ctors) { + const ta_rab = new ctor(rab, 0, 3); + const ta_ab = new ctor(ab, 0, 3); + assert.sameValue(ta_ab.__proto__, ta_rab.__proto__); +} diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..524d78e34202f5119345e7a1556c078f296706fe --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/detached-buffer.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reverse(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..9da6f23792c9ac217c777b8f28e1d005a59dcd5f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + %SendableTypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.reverse(); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/preserves-non-numeric-properties.js b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/preserves-non-numeric-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..4297785b1d09919efd3427c547af2e7c7cd5fd91 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/preserves-non-numeric-properties.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Preserves non numeric properties +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + %SendableTypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + ... + 6. Return O. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result; + + sample = new TA(2); + sample.foo = 42; + sample.bar = "bar"; + sample[s] = 1; + result = sample.reverse(); + assert.sameValue(result.foo, 42, "sample.foo === 42"); + assert.sameValue(result.bar, "bar", "sample.bar === 'bar'"); + assert.sameValue(result[s], 1, "sample[s] === 1"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..98a2944c5e83c21d0184d71b690f33da40306c42 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.reverse, + 'function', + 'implements SendableTypedArray.prototype.reverse' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.reverse(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.reverse(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the reverse operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.reverse(); + throw new Test262Error('reverse completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/returns-original-object.js b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/returns-original-object.js new file mode 100644 index 0000000000000000000000000000000000000000..ec2c26cf1cadc5395acbc8f354e2033098193f8d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/returns-original-object.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Returns the same object +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + %SendableTypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + ... + 6. Return O. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(64); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result, expectedLength; + + sample = new TA(buffer, 0); + expectedLength = sample.length; + result = sample.reverse(); + assert.sameValue(result, sample, "returns the same object"); + assert.sameValue(sample.buffer, buffer, "keeps the same buffer"); + assert.sameValue(sample.length, expectedLength, "length is preserved"); + + sample = new TA(buffer, 0, 0); + result = sample.reverse(); + assert.sameValue(result, sample, "returns the same object (empty instance)"); + assert.sameValue(sample.buffer, buffer, "keeps the same buffer (empty instance)"); + assert.sameValue(sample.length, 0, "length is preserved (empty instance)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/reverts.js b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/reverts.js new file mode 100644 index 0000000000000000000000000000000000000000..869ced4576abe20ad8cb091a801357fb7407e890 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/BigInt/reverts.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Reverts values +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + %SendableTypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + ... + 6. Return O. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(64); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(buffer, 0, 4); + var other = new TA(buffer, 0, 5); + + sample[0] = 42n; + sample[1] = 43n; + sample[2] = 2n; + sample[3] = 1n; + other[4] = 7n; + + sample.reverse(); + assert( + compareArray(sample, [1n, 2n, 43n, 42n]) + ); + + assert( + compareArray(other, [1n, 2n, 43n, 42n, 7n]) + ); + + sample[0] = 7n; + sample[1] = 17n; + sample[2] = 1n; + sample[3] = 0n; + other[4] = 42n; + + other.reverse(); + assert( + compareArray(other, [42n, 0n, 1n, 17n, 7n]) + ); + + assert( + compareArray(sample, [42n, 0n, 1n, 17n]) + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/reverse/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..75576a1a55856c0965cc2350dfe0d855a142994d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/detached-buffer.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reverse(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/reverse/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..b30e790f7b1c9cc2a3e482ed601febdd66240d0e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/get-length-uses-internal-arraylength.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + %SendableTypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.reverse(); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/reverse/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..cbfdf8b8755a49dc3737f68290963972d56c8bea --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/invoked-as-func.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reverse ( ) + + ... + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var reverse = SendableTypedArray.prototype.reverse; + +assert.sameValue(typeof reverse, 'function'); + +assert.throws(TypeError, function() { + reverse(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/reverse/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..5e928f57a449fe50e0dcb15cc70ef5678bac9040 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/invoked-as-method.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.21 %SendableTypedArray%.prototype.reverse ( ) + + ... + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.reverse, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.reverse(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/length.js b/test/sendable/builtins/TypedArray/prototype/reverse/length.js new file mode 100644 index 0000000000000000000000000000000000000000..c534eaa2f4db39df02f364a1e0eb26881b42ed85 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: > + %SendableTypedArray%.prototype.reverse.length is 0. +info: | + %SendableTypedArray%.prototype.reverse ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.reverse, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/name.js b/test/sendable/builtins/TypedArray/prototype/reverse/name.js new file mode 100644 index 0000000000000000000000000000000000000000..4ff13767cecb466a2f8e0ec71e1e3f161e70ab45 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: > + %SendableTypedArray%.prototype.reverse.name is "reverse". +info: | + %SendableTypedArray%.prototype.reverse ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.reverse, "name", { + value: "reverse", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/reverse/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..fcb48ba3e25118901a973a872372508dbd4c7db9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.reverse does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.reverse), + false, + 'isConstructor(SendableTypedArray.prototype.reverse) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.reverse(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/preserves-non-numeric-properties.js b/test/sendable/builtins/TypedArray/prototype/reverse/preserves-non-numeric-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..5ec51918286685f22280a79103d987c99c5874ed --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/preserves-non-numeric-properties.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Preserves non numeric properties +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + %SendableTypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + ... + 6. Return O. +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample, result; + + sample = new TA(2); + sample.foo = 42; + sample.bar = "bar"; + sample[s] = 1; + result = sample.reverse(); + assert.sameValue(result.foo, 42, "sample.foo === 42"); + assert.sameValue(result.bar, "bar", "sample.bar === 'bar'"); + assert.sameValue(result[s], 1, "sample[s] === 1"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/reverse/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..b018e37aa5c3cb91174040460e47832ebdbd475a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: > + "reverse" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'reverse', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/reverse/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..8d61aeb82ab46eaa95cef14a8d21bb84ab40c102 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/resizable-buffer.js @@ -0,0 +1,177 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: > + SendableTypedArray.p.reverse behaves correctly on SendableTypedArrays backed by resizable + buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const wholeArrayView = new ctor(rab); + function WriteData() { + // Write some data into the array. + for (let i = 0; i < wholeArrayView.length; ++i) { + wholeArrayView[i] = MayNeedBigInt(wholeArrayView, 2 * i); + } + } + WriteData(); + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + fixedLength.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), [ + 6, + 4, + 2, + 0 + ]); + fixedLengthWithOffset.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), [ + 6, + 4, + 0, + 2 + ]); + lengthTracking.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), [ + 2, + 0, + 4, + 6 + ]); + lengthTrackingWithOffset.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), [ + 2, + 0, + 6, + 4 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + WriteData(); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.reverse(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.reverse(); + }); + lengthTracking.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), [ + 4, + 2, + 0 + ]); + lengthTrackingWithOffset.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), [ + 4, + 2, + 0 + ]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + WriteData(); + assert.throws(TypeError, () => { + fixedLength.reverse(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.reverse(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.reverse(); + }); + lengthTracking.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), [0]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.reverse(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.reverse(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.reverse(); + }); + lengthTracking.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + WriteData(); + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + fixedLength.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), [ + 6, + 4, + 2, + 0, + 8, + 10 + ]); + fixedLengthWithOffset.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), [ + 6, + 4, + 0, + 2, + 8, + 10 + ]); + lengthTracking.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), [ + 10, + 8, + 2, + 0, + 4, + 6 + ]); + lengthTrackingWithOffset.reverse(); + assert.compareArray(ToNumbers(wholeArrayView), [ + 10, + 8, + 6, + 4, + 0, + 2 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/reverse/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..02fc6d306d8391528d0a4a39413439c0e15c1059 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.reverse, + 'function', + 'implements SendableTypedArray.prototype.reverse' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.reverse(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.reverse(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the reverse operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.reverse(); + throw new Test262Error('reverse completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/returns-original-object.js b/test/sendable/builtins/TypedArray/prototype/reverse/returns-original-object.js new file mode 100644 index 0000000000000000000000000000000000000000..57f11a13d4a87611330db8c1946a6beba5b8520e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/returns-original-object.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Returns the same object +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + %SendableTypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + ... + 6. Return O. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var buffer = new ArrayBuffer(64); + +testWithTypedArrayConstructors(function(TA) { + var sample, result, expectedLength; + + sample = new TA(buffer, 0); + expectedLength = sample.length; + result = sample.reverse(); + assert.sameValue(result, sample, "returns the same object"); + assert.sameValue(sample.buffer, buffer, "keeps the same buffer"); + assert.sameValue(sample.length, expectedLength, "length is preserved"); + + sample = new TA(buffer, 0, 0); + result = sample.reverse(); + assert.sameValue(result, sample, "returns the same object (empty instance)"); + assert.sameValue(sample.buffer, buffer, "keeps the same buffer (empty instance)"); + assert.sameValue(sample.length, 0, "length is preserved (empty instance)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/reverts.js b/test/sendable/builtins/TypedArray/prototype/reverse/reverts.js new file mode 100644 index 0000000000000000000000000000000000000000..cf06ec92b267cd5dedd4dcc477c896f92d74ce7c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/reverts.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Reverts values +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + %SendableTypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + ... + 6. Return O. +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var buffer = new ArrayBuffer(64); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(buffer, 0, 4); + var other = new TA(buffer, 0, 5); + + sample[0] = 42; + sample[1] = 43; + sample[2] = 2; + sample[3] = 1; + other[4] = 7; + + sample.reverse(); + assert( + compareArray(sample, [1, 2, 43, 42]) + ); + + assert( + compareArray(other, [1, 2, 43, 42, 7]) + ); + + sample[0] = 7; + sample[1] = 17; + sample[2] = 1; + sample[3] = 0; + other[4] = 42; + + other.reverse(); + assert( + compareArray(other, [42, 0, 1, 17, 7]) + ); + + assert( + compareArray(sample, [42, 0, 1, 17]) + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/reverse/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..61137c227562d6404142a1b428df498c375392b9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/this-is-not-object.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var reverse = SendableTypedArray.prototype.reverse; + +assert.throws(TypeError, function() { + reverse.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + reverse.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + reverse.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + reverse.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + reverse.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + reverse.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + reverse.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/reverse/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/reverse/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..181786d03eef6cd164dc468f17217ff7369bd9cd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/reverse/this-is-not-typedarray-instance.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.reverse +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.22 %SendableTypedArray%.prototype.reverse ( ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var reverse = SendableTypedArray.prototype.reverse; + +assert.throws(TypeError, function() { + reverse.call({}); +}, "this is an Object"); + +assert.throws(TypeError, function() { + reverse.call([]); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + reverse.call(ab); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + reverse.call(dv); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..2dc8d381c8e917f9de25a7a75c43a31da5cbed80 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Throw a RangeError exception if targetOffset < 0 +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert.throws(RangeError, function() { + sample.set([1n], -1); + }, "-1"); + + assert.throws(RangeError, function() { + sample.set([1n], -1.00001); + }, "-1.00001"); + + assert.throws(RangeError, function() { + sample.set([1n], -Infinity); + }, "-Infinity"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js new file mode 100644 index 0000000000000000000000000000000000000000..89bd0951372bd9c89c2938916759a1472dd4572a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js @@ -0,0 +1,108 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + ToInteger(offset) operations +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([1n, 2n]); + sample.set([42n], ""); + assert(compareArray(sample, [42n, 2n]), "the empty string"); + + sample = new TA([1n, 2n]); + sample.set([42n], "0"); + assert(compareArray(sample, [42n, 2n]), "'0'"); + + sample = new TA([1n, 2n]); + sample.set([42n], false); + assert(compareArray(sample, [42n, 2n]), "false"); + + sample = new TA([1n, 2n]); + sample.set([42n], 0.1); + assert(compareArray(sample, [42n, 2n]), "0.1"); + + sample = new TA([1n, 2n]); + sample.set([42n], 0.9); + assert(compareArray(sample, [42n, 2n]), "0.9"); + + sample = new TA([1n, 2n]); + sample.set([42n], -0.5); + assert(compareArray(sample, [42n, 2n]), "-0.5"); + + sample = new TA([1n, 2n]); + sample.set([42n], 1.1); + assert(compareArray(sample, [1n, 42n]), "1.1"); + + sample = new TA([1n, 2n]); + sample.set([42n], NaN); + assert(compareArray(sample, [42n, 2n]), "NaN"); + + sample = new TA([1n, 2n]); + sample.set([42n], null); + assert(compareArray(sample, [42n, 2n]), "null"); + + sample = new TA([1n, 2n]); + sample.set([42n], undefined); + assert(compareArray(sample, [42n, 2n]), "undefined"); + + sample = new TA([1n, 2n]); + sample.set([42n], {}); + assert(compareArray(sample, [42n, 2n]), "{}"); + + sample = new TA([1n, 2n]); + sample.set([42n], []); + assert(compareArray(sample, [42n, 2n]), "[]"); + + sample = new TA([1n, 2n]); + sample.set([42n], [0]); + assert(compareArray(sample, [42n, 2n]), "[0]"); + + sample = new TA([1n, 2n]); + sample.set([42n], true); + assert(compareArray(sample, [1n, 42n]), "true"); + + sample = new TA([1n, 2n]); + sample.set([42n], "1"); + assert(compareArray(sample, [1n, 42n]), "'1'"); + + sample = new TA([1n, 2n]); + sample.set([42n], [1]); + assert(compareArray(sample, [1n, 42n]), "[1]"); + + sample = new TA([1n, 2n]); + sample.set([42n], { valueOf: function() {return 1;} }); + assert(compareArray(sample, [1n, 42n]), "valueOf"); + + sample = new TA([1n, 2n]); + sample.set([42n], { toString: function() {return 1;} }); + assert(compareArray(sample, [1n, 42n]), "toString"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-primitive-toobject.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-primitive-toobject.js new file mode 100644 index 0000000000000000000000000000000000000000..fd5776362e7bdf07f61fff7a1b711051e8697df7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-primitive-toobject.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Primitive `array` argument is coerced to an object. +info: | + %SendableTypedArray%.prototype.set ( typedArray [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object + with a [[TypedArrayName]] internal slot. If it is such an Object, + the definition in 22.2.3.23.2 applies. + [...] + 14. Let src be ? ToObject(array). + 15. Let srcLength be ? LengthOfArrayLike(src). + [...] + 19. Let limit be targetByteIndex + targetElementSize × srcLength. + 20. Repeat, while targetByteIndex < limit, + a. Let Pk be ! ToString(k). + b. Let value be ? Get(src, Pk). + c. If target.[[ContentType]] is BigInt, set value to ? ToBigInt(value). + [...] + f. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, value, true, Unordered). + [...] +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, SendableTypedArray, Symbol] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta1 = new TA([1n, 2n, 3n, 4n]); + ta1.set("567"); + assert.compareArray(ta1, [5n, 6n, 7n, 4n], "string"); + + var ta2 = new TA([1n, 2n, 3n]); + ta2.set(-10, 2); + assert.compareArray(ta2, [1n, 2n, 3n], "number"); + + var ta3 = new TA([1n]); + ta3.set(false); + assert.compareArray(ta3, [1n], "boolean"); + + var ta4 = new TA([1n, 2n]); + ta4.set(Symbol("desc"), 0); + assert.compareArray(ta4, [1n, 2n], "symbol"); + + var ta5 = new TA([1n, 2n]); + ta5.set(4n, 1); + assert.compareArray(ta5, [1n, 2n], "bigint"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-length.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-length.js new file mode 100644 index 0000000000000000000000000000000000000000..b8285ea456de8d2ccc8bcf7d5de19c380f391496 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-length.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt getting src "length" +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 3n]); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-value.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-value.js new file mode 100644 index 0000000000000000000000000000000000000000..31bda64db7636cd5289eb875857d006577f211cf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-value.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from getting src property value +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": 42n, + "1": 43n, + "3": 44n + }; + Object.defineProperty(obj, "2", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([1n, 2n, 3n, 4n]); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, [42n, 43n, 3n, 4n]), + "values are set until exception" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length-symbol.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..4b74474955ad7341e75d38b2ba1ceed9b5c69e99 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length-symbol.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt getting src "length" as symbol +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var obj = { + length: Symbol("1") +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 3n]); + + assert.throws(TypeError, function() { + sample.set(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length.js new file mode 100644 index 0000000000000000000000000000000000000000..b54286ab708e6aa53c500b7fb92ebac0c763a2bb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToLength(src "length") +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj1 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; + +var obj2 = { + length: { + toString: function() { + throw new Test262Error(); + } + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 3n]); + + assert.throws(Test262Error, function() { + sample.set(obj1); + }, "valueOf"); + + assert.throws(Test262Error, function() { + sample.set(obj2); + }, "toString"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value-symbol.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..c1f03ee64abe694c01d467f15c7765046d2f67f5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value-symbol.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToNumber(src property symbol value) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": 42n, + "1": 43n, + "2": Symbol("1"), + "3": 44n + }; + + var sample = new TA([1n, 2n, 3n, 4n]); + + assert.throws(TypeError, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, [42n, 43n, 3n, 4n]), + "values are set until exception" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value.js new file mode 100644 index 0000000000000000000000000000000000000000..7f9769098a5067d4c1a698a0bf233c3e49be2990 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToNumber(src property value) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": 42n, + "1": 43n, + "2": { + valueOf: function() { + throw new Test262Error(); + } + }, + "3": 44n + }; + + var sample = new TA([1n, 2n, 3n, 4n]); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, [42n, 43n, 3n, 4n]), + "values are set until exception" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..8ea6f3cc3431ad9f66062e5338c935fd83bb7d88 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToInteger(Symbol offset) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.set([1n], s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset.js new file mode 100644 index 0000000000000000000000000000000000000000..045b8b5cb484b7895da0518ceed0800990d08f38 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToInteger(offset) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.set([], obj1); + }, "abrupt from valueOf"); + + assert.throws(Test262Error, function() { + sample.set([], obj2); + }, "abrupt from toString"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-toobject-offset.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-toobject-offset.js new file mode 100644 index 0000000000000000000000000000000000000000..0f96928606a9428f49972b812df76bf3a14f4534 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-toobject-offset.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToObject(array) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 15. Let src be ? ToObject(array). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 3n]); + + assert.throws(TypeError, function() { + sample.set(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.set(null); + }, "null"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-set-values-in-order.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-set-values-in-order.js new file mode 100644 index 0000000000000000000000000000000000000000..15de4ceb8f66f1b95e7d6ac1eaf0567f7cbc5770 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-set-values-in-order.js @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Get and set each value in order +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(5); + var calls = []; + var obj = { + length: 3 + }; + Object.defineProperty(obj, 0, { + get: function() { + calls.push(0); + calls.push(sample.join()); + return 42n; + } + }); + + Object.defineProperty(obj, 1, { + get: function() { + calls.push(1); + calls.push(sample.join()); + return 43n; + } + }); + + Object.defineProperty(obj, 2, { + get: function() { + calls.push(2); + calls.push(sample.join()); + return 44n; + } + }); + + Object.defineProperty(obj, 3, { + get: function() { + throw new Test262Error("Should not call obj[3]"); + } + }); + + sample.set(obj, 1); + + assert( + compareArray(sample, [0n, 42n, 43n, 44n, 0n]), + "values are set for src length" + ); + + assert( + compareArray(calls, [0, "0,0,0,0,0", 1, "0,42,0,0,0", 2, "0,42,43,0,0"]), + "values are set in order" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-set-values.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-set-values.js new file mode 100644 index 0000000000000000000000000000000000000000..b3b65a13dc15f2b383db024c722a4f851b9591b4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-set-values.js @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Set values to target and return undefined +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + Let Pk be ! ToString(k). + Let kNumber be ? ToNumber(? Get(src, Pk)). + If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, kNumber). + ... + 22. Return undefined. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var src = [42n, 43n]; + var srcObj = { + length: 2, + '0': 7n, + '1': 17n + }; + var sample, result; + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(srcObj, 0); + assert(compareArray(sample, [7n, 17n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(srcObj, 1); + assert(compareArray(sample, [1n, 7n, 17n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(srcObj, 2); + assert(compareArray(sample, [1n, 2n, 7n, 17n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-type-conversions.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-type-conversions.js new file mode 100644 index 0000000000000000000000000000000000000000..93c85671ccd6226419b032b6a927001bd1d2840c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-type-conversions.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Type conversions on ToNumber(src property value) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj1 = { + valueOf: function() { + return 42n; + } + }; + + var obj2 = { + toString: function() { + return "42"; + } + }; + + var arr = [false, true, obj1, [], [1]]; + + var sample = new TA(arr.length); + var expected = new TA([0n, 1n, 42n, 0n, 1n]); + + sample.set(arr); + + assert( + compareArray(sample, expected), + "sample: [" + sample + "], expected: [" + expected + "]" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-src-values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-src-values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..b9f8c02f5bdc2363e048093c59d96baf47441db6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-src-values-are-not-cached.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Values from src array are not cached +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(5); + var obj = { + length: 5, + '1': 7n, + '2': 7n, + '3': 7n, + '4': 7n + }; + Object.defineProperty(obj, 0, { + get: function() { + obj[1] = 43n; + obj[2] = 44n; + obj[3] = 45n; + obj[4] = 46n; + return 42n; + } + }); + + sample.set(obj); + + assert(compareArray(sample, [42n, 43n, 44n, 45n, 46n])); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-target-arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-target-arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..ac8eeb1468179b2848d064e1eb60bab295be219c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-target-arraylength-internal.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 17. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.set([42n, 43n]); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..e8ab57c1c15bdcb337e56fb6047abc10c6f489db --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Throws a TypeError if targetBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(sample.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set([1n], obj); + }); + + assert.sameValue(calledOffset, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..0d6ed6647992c5badbbf4d04bf4565f8c83f502f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Throws a TypeError if targetBuffer is detached +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... + 15. Let src be ? ToObject(array). + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample.set([1n]); + }, "regular check"); + + assert.throws(TypeError, function() { + sample.set(obj); + }, "IsDetachedBuffer happens before Get(src.length)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/bigint-tobigint64.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/bigint-tobigint64.js new file mode 100644 index 0000000000000000000000000000000000000000..aba9285ff3ce56b71336f0b5d034255366ce28b5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/bigint-tobigint64.js @@ -0,0 +1,101 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Behavior for input array of BigInts +info: | + %SendableTypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + SendableTypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isSendableTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The SendableTypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The SendableTypedArray Constructors + Element Type: BigInt64 + Conversion Operation: ToBigInt64 + + ToBigInt64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. If int64bit ≥ 2^63, return int64bit - 2^64; otherwise return int64bit. + +features: [BigInt, TypedArray] +---*/ + +var vals = [ + 18446744073709551618n, // 2n ** 64n + 2n + 9223372036854775810n, // 2n ** 63n + 2n + 2n, + 0n, + -2n, + -9223372036854775810n, // -(2n ** 63n) - 2n + -18446744073709551618n, // -(2n ** 64n) - 2n +]; + +var typedArray = new BigInt64Array(vals.length); +typedArray.set(vals); + +assert.sameValue(typedArray[0], 2n, + "ToBigInt64(2n ** 64n + 2n) => 2n"); + +assert.sameValue(typedArray[1], -9223372036854775806n, // 2n - 2n ** 63n + "ToBigInt64(2n ** 63n + 2n) => -9223372036854775806n"); + +assert.sameValue(typedArray[2], 2n, + "ToBigInt64(2n) => 2n"); + +assert.sameValue(typedArray[3], 0n, + "ToBigInt64(0n) => 0n"); + +assert.sameValue(typedArray[4], -2n, + "ToBigInt64( -2n) => -2n"); + +assert.sameValue(typedArray[5], 9223372036854775806n, // 2n ** 63n - 2 + "ToBigInt64( -(2n ** 64n) - 2n) => 9223372036854775806n"); + +assert.sameValue(typedArray[6], -2n, + "ToBigInt64( -(2n ** 64n) - 2n) => -2n"); + diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js new file mode 100644 index 0000000000000000000000000000000000000000..5cff1148bf1e4c5a310311eeaf39acf336eb3fca --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/bigint-tobiguint64.js @@ -0,0 +1,100 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Behavior for input array of BigInts +info: | + %SendableTypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + SendableTypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isSendableTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The SendableTypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The SendableTypedArray Constructors + Element Type: BigUint64 + Conversion Operation: ToBigUint64 + + ToBigUint64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. Return int64bit. + +features: [BigInt, TypedArray] +---*/ + +var vals = [ + 18446744073709551618n, // 2n ** 64n + 2n + 9223372036854775810n, // 2n ** 63n + 2n + 2n, + 0n, + -2n, + -9223372036854775810n, // -(2n ** 63n) - 2n + -18446744073709551618n, // -(2n ** 64n) - 2n +]; + +var typedArray = new BigUint64Array(vals.length); +typedArray.set(vals); + +assert.sameValue(typedArray[0], 2n, + "ToBigUint64(2n ** 64n + 2n) => 2n"); + +assert.sameValue(typedArray[1], 9223372036854775810n, // 2n ** 63n + 2n + "ToBigUint64(2n ** 63n + 2n) => 9223372036854775810"); + +assert.sameValue(typedArray[2], 2n, + "ToBigUint64(2n) => 2n"); + +assert.sameValue(typedArray[3], 0n, + "ToBigUint64(0n) => 0n"); + +assert.sameValue(typedArray[4], 18446744073709551614n, // 2n ** 64n - 2n + "ToBigUint64( -2n) => 18446744073709551614n"); + +assert.sameValue(typedArray[5], 9223372036854775806n, // 2n ** 63n - 2n + "ToBigUint64( -(2n ** 63n) - 2n) => 9223372036854775806n"); + +assert.sameValue(typedArray[6], 18446744073709551614n, // 2n ** 64n - 2n + "ToBigUint64( -(2n ** 64n) - 2n) => 18446744073709551614n"); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/boolean-tobigint.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/boolean-tobigint.js new file mode 100644 index 0000000000000000000000000000000000000000..8cc77e7e895004fc4cf7be253056527f1e4ffb22 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/boolean-tobigint.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Behavior for input array of Booleans +info: | + %SendableTypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + SendableTypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Boolean + Result: Return 1n if prim is true and 0n if prim is false. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(2); + typedArray.set([false, true]) + + assert.sameValue(typedArray[0], 0n, "False converts to BigInt"); + assert.sameValue(typedArray[1], 1n, "True converts to BigInt"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/null-tobigint.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/null-tobigint.js new file mode 100644 index 0000000000000000000000000000000000000000..4f127c55796790c70168cbe74dcab605010ddf3d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/null-tobigint.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt on null +info: | + %SendableTypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + SendableTypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Null + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray.set([null]); + }, "abrupt completion from Null"); + +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/number-tobigint.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/number-tobigint.js new file mode 100644 index 0000000000000000000000000000000000000000..e7316a118a790ea9cb1518fd5df4217170e75ad8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/number-tobigint.js @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt on Number +info: | + %SendableTypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + SendableTypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Number + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray.set([1]); + }, "abrupt completion from Number: 1"); + + assert.throws(TypeError, function() { + typedArray.set([Math.pow(2, 63)]); + }, "abrupt completion from Number: 2**63"); + + assert.throws(TypeError, function() { + typedArray.set([+0]); + }, "abrupt completion from Number: +0"); + + assert.throws(TypeError, function() { + typedArray.set([-0]); + }, "abrupt completion from Number: -0"); + + assert.throws(TypeError, function() { + typedArray.set([Infinity]); + }, "abrupt completion from Number: Infinity"); + + assert.throws(TypeError, function() { + typedArray.set([-Infinity]); + }, "abrupt completion from Number: -Infinity"); + + assert.throws(TypeError, function() { + typedArray.set([NaN]); + }, "abrupt completion from Number: NaN"); + +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/src-typedarray-big.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/src-typedarray-big.js new file mode 100644 index 0000000000000000000000000000000000000000..078707835bd51ed02f2cfee4ddada278dd74f0e5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/src-typedarray-big.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + If typedArray constructor argument is a Big(U)Int, succeed in set +info: | + %SendableTypedArray%.prototype.set( typedArray [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the + typedArray argument object. The optional offset value indicates the first + element index in this SendableTypedArray where values are written. If omitted, it + is assumed to be 0. + ... + 23. If one of srcType and targetType contains the substring "Big" and the + other does not, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var srcSendableTypedArray; +var targetSendableTypedArray; +var testValue = 42n; + +testWithBigIntTypedArrayConstructors(function(BTA1) { + + srcSendableTypedArray = new BTA1([testValue]); + + testWithBigIntTypedArrayConstructors(function(BTA2) { + + targetSendableTypedArray = new BTA2(1); + targetSendableTypedArray.set(srcSendableTypedArray); + assert.sameValue(targetSendableTypedArray[0], testValue, + "Setting BigInt SendableTypedArray with BigInt SendableTypedArray should succeed.") + }); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/src-typedarray-not-big-throws.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/src-typedarray-not-big-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..e17953faef603b5066e8431b19e5f654e6235861 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/src-typedarray-not-big-throws.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + If typedArray set argument is not a Big(U)Int, and target is "Big", throw +info: | + %SendableTypedArray%.prototype.set( typedArray [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the + typedArray argument object. The optional offset value indicates the first + element index in this SendableTypedArray where values are written. If omitted, it + is assumed to be 0. + ... + 23. If one of srcType and targetType contains the substring "Big" and the + other does not, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, sendableTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var bigSendableTypedArray; +var littleSendableTypedArray; + +testWithTypedArrayConstructors(function(TA) { + + littleSendableTypedArray = new TA([1]); + + testWithBigIntTypedArrayConstructors(function(BTA) { + + bigSendableTypedArray = new BTA(1); + assert.throws(TypeError, function() { + bigSendableTypedArray.set(littleSendableTypedArray); + }); + }); + +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/string-nan-tobigint.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/string-nan-tobigint.js new file mode 100644 index 0000000000000000000000000000000000000000..a2e46efd6c9ae3fcd9c726364ebf6430fb4de7d2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/string-nan-tobigint.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt String, when StringToBigInt returns NaN +info: | + %SendableTypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + SendableTypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(SyntaxError, function() { + typedArray.set(["definately not a number"]); + }, "StringToBigInt(prim) == NaN"); + +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/string-tobigint.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/string-tobigint.js new file mode 100644 index 0000000000000000000000000000000000000000..04995724aefdac252e84a56d496cb0cf9e685dcc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/string-tobigint.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Behavior for input array of Strings, successful conversion +info: | + %SendableTypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + SendableTypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(2); + typedArray.set(['', '1']) + + assert.sameValue(typedArray[0], 0n); + assert.sameValue(typedArray[1], 1n); + + assert.throws(SyntaxError, function() { + typedArray.set(['1n']); + }, "A StringNumericLiteral may not include a BigIntLiteralSuffix."); + + assert.throws(SyntaxError, function() { + typedArray.set(["Infinity"]); + }, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity.."); + + assert.throws(SyntaxError, function() { + typedArray.set(["1.1"]); + }, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow... decimal points..."); + + assert.throws(SyntaxError, function() { + typedArray.set(["1e7"]); + }, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow... exponents..."); + +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/symbol-tobigint.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/symbol-tobigint.js new file mode 100644 index 0000000000000000000000000000000000000000..701d050344477d9c717b35b8d1ef1c38b9718c96 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/symbol-tobigint.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt on Symbol +info: | + %SendableTypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + SendableTypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Symbol + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, Symbol] +---*/ + +var s = Symbol() + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1) + + assert.throws(TypeError, function() { + typedArray.set([s]); + }, "abrupt completion from Symbol"); + +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-negative-integer-offset-throws.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-negative-integer-offset-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..cbf5812efb7eb7d2187e5f41680123f130c7c00d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-negative-integer-offset-throws.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Throw a RangeError exception if targetOffset < 0 +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(RangeError, function() { + sample.set(sample, -1); + }, "-1"); + + assert.throws(RangeError, function() { + sample.set(sample, -1.00001); + }, "-1.00001"); + + assert.throws(RangeError, function() { + sample.set(sample, -Infinity); + }, "-Infinity"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-offset-tointeger.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-offset-tointeger.js new file mode 100644 index 0000000000000000000000000000000000000000..8b41c64771ec81bbda558392dd78bec4eb14ba9e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-offset-tointeger.js @@ -0,0 +1,106 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + ToInteger(offset) operations +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + var src = new TA([42n]); + + sample = new TA([1n, 2n]); + sample.set(src, ""); + assert(compareArray(sample, [42n, 2n]), "the empty string"); + + sample = new TA([1n, 2n]); + sample.set(src, "0"); + assert(compareArray(sample, [42n, 2n]), "'0'"); + + sample = new TA([1n, 2n]); + sample.set(src, false); + assert(compareArray(sample, [42n, 2n]), "false"); + + sample = new TA([1n, 2n]); + sample.set(src, 0.1); + assert(compareArray(sample, [42n, 2n]), "0.1"); + + sample = new TA([1n, 2n]); + sample.set(src, 0.9); + assert(compareArray(sample, [42n, 2n]), "0.9"); + + sample = new TA([1n, 2n]); + sample.set(src, -0.5); + assert(compareArray(sample, [42n, 2n]), "-0.5"); + + sample = new TA([1n, 2n]); + sample.set(src, 1.1); + assert(compareArray(sample, [1n, 42n]), "1.1"); + + sample = new TA([1n, 2n]); + sample.set(src, NaN); + assert(compareArray(sample, [42n, 2n]), "NaN"); + + sample = new TA([1n, 2n]); + sample.set(src, null); + assert(compareArray(sample, [42n, 2n]), "null"); + + sample = new TA([1n, 2n]); + sample.set(src, undefined); + assert(compareArray(sample, [42n, 2n]), "undefined"); + + sample = new TA([1n, 2n]); + sample.set(src, {}); + assert(compareArray(sample, [42n, 2n]), "{}"); + + sample = new TA([1n, 2n]); + sample.set(src, []); + assert(compareArray(sample, [42n, 2n]), "[]"); + + sample = new TA([1n, 2n]); + sample.set(src, [0]); + assert(compareArray(sample, [42n, 2n]), "[0]"); + + sample = new TA([1n, 2n]); + sample.set(src, true); + assert(compareArray(sample, [1n, 42n]), "true"); + + sample = new TA([1n, 2n]); + sample.set(src, "1"); + assert(compareArray(sample, [1n, 42n]), "'1'"); + + sample = new TA([1n, 2n]); + sample.set(src, [1]); + assert(compareArray(sample, [1n, 42n]), "[1]"); + + sample = new TA([1n, 2n]); + sample.set(src, { valueOf: function() {return 1;} }); + assert(compareArray(sample, [1n, 42n]), "valueOf"); + + sample = new TA([1n, 2n]); + sample.set(src, { toString: function() {return 1;} }); + assert(compareArray(sample, [1n, 42n]), "toString"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..c482cfdd0bccfeba03bc0e6b2bbd5e574470ee99 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Return abrupt from ToInteger(Symbol offset) +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.set(sample, s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset.js new file mode 100644 index 0000000000000000000000000000000000000000..cebac1155c73ec83ef7894996f1355d20ada95ad --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Return abrupt from ToInteger(offset) +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.set(sample, obj1); + }, "abrupt from valueOf"); + + assert.throws(Test262Error, function() { + sample.set(sample, obj2); + }, "abrupt from toString"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-sab.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..ce890267aa15cec74b2159382f453c9d602b84b3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-sab.js @@ -0,0 +1,115 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and different + type. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sab = new SharedArrayBuffer(2 * BigInt64Array.BYTES_PER_ELEMENT); + var otherCtor = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var src = new otherCtor(sab); + src[0] = 42n; + src[1] = 43n; + var sample, result; + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "src is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "src is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "src is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + src = new BigInt64Array([42n, 43n]); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "sample is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "sample is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "sample is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + var sab1 = new SharedArrayBuffer(2 * BigInt64Array.BYTES_PER_ELEMENT); + src = new BigInt64Array(sab1); + src[0] = 42n; + src[1] = 43n; + + var sab2; + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "src and sample are SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "src and sample are SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "src and sample are SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type.js new file mode 100644 index 0000000000000000000000000000000000000000..3ebeb20ff5c4e7321d33361ecc6aa78b9a1fbeb4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and different + type. +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + ... + 24. Else, let srcByteIndex be srcByteOffset. + ... + 27. If SameValue(srcType, targetType) is true, then, + ... + 28. Else, + a. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + value). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var src = new other([42n, 43n]); + var sample, result; + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type-sab.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..a4c7c59d8a02c5e9056057aa95329f8796c0dcd5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type-sab.js @@ -0,0 +1,116 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and same + constructor. srcBuffer values are cached. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result; + + var sab = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); + var src = new TA(sab); + src[0] = 42n; + src[1] = 43n; + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "src is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "src is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "src is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + src = new TA([42n, 43n]); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "sample is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "sample is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "sample is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + + var sab1 = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); + src = new TA(sab1); + src[0] = 42n; + src[1] = 43n; + + var sab2; + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "src and sample are SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "src and sample are SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "src and sample are SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type.js new file mode 100644 index 0000000000000000000000000000000000000000..a350c0dacb3e0fee54913ba56ec877c412d4e7da --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and same + constructor. srcBuffer values are cached. +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + ... + 24. Else, let srcByteIndex be srcByteOffset. + ... + 27. If SameValue(srcType, targetType) is true, then, + a. NOTE: If srcType and targetType are the same, the transfer must be + performed in a manner that preserves the bit-level encoding of the source + data. + b. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). + ... + 29. Return undefined. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result; + var src = new TA([42n, 43n]); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 42n, 43n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 0); + assert(compareArray(sample, [42n, 43n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 42n, 43n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-resized.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-resized.js new file mode 100644 index 0000000000000000000000000000000000000000..6a5d3f5079cd23955688e4fa77408e14f4cf2e2d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-resized.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor when underlying ArrayBuffer has been resized +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, SendableTypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var source = new TA(ab); + var target = new TA(ab); + var expected = [10, 20, 30, 40]; + + source[0] = 10n; + source[1] = 20n; + source[2] = 30n; + source[3] = 40n; + + try { + ab.resize(BPE * 5); + expected = [10n, 20n, 30n, 40n, 0n]; + } catch (_) {} + + target.set(source); + assert(compareArray(target, expected), 'following grow'); + + try { + ab.resize(BPE * 3); + expected = [10n, 20n, 30n]; + } catch (_) {} + + target.set(source); + assert(compareArray(target, expected), 'following shrink'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-sab.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..f1f1971c28f2894364667a8183443f00f2a52203 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-sab.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor. srcBuffer values are cached. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, src, result, sab; + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 0); + assert(compareArray(sample, [1n, 2n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 1n, 2n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1n; + sample[1] = 2n; + sample[2] = 3n; + sample[3] = 4n; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 1n, 2n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type.js new file mode 100644 index 0000000000000000000000000000000000000000..3a2330441be4e58cf9795346d0cb4262864b1abb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor. srcBuffer values are cached. +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + a. Let srcBuffer be ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcLength, + %ArrayBuffer%). + b. NOTE: %ArrayBuffer% is used to clone srcBuffer because is it known to not + have any observable side-effects. + ... + ... + 27. If SameValue(srcType, targetType) is true, then, + a. NOTE: If srcType and targetType are the same, the transfer must be + performed in a manner that preserves the bit-level encoding of the source + data. + b. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, src, result; + + sample = new TA([1n, 2n, 3n, 4n]); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 0); + assert(compareArray(sample, [1n, 2n, 3n, 4n]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 1); + assert(compareArray(sample, [1n, 1n, 2n, 4n]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1n, 2n, 3n, 4n]); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 2); + assert(compareArray(sample, [1n, 2n, 1n, 2n]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-src-arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-src-arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..7815db525bd889ec31048303cf4391a556c8bcb0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-src-arraylength-internal.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Uses typedArray's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 20. Let srcLength be the value of typedArray's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 42; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42n, 43n]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(src, "length", desc); + + sample.set(src); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-src-byteoffset-internal.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-src-byteoffset-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..802f04b72a103da7fc3d98f6ead334c82b980fa5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-src-byteoffset-internal.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Uses typedArray's internal [[ByteOffset]] +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 21. Let srcByteOffset be typedArray.[[ByteOffset]]. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "byteOffset", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42n, 43n]); + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var src2 = new other([42n, 43n]); + var src3 = new other(sample.buffer, 0, 2); + + Object.defineProperty(TA.prototype, "byteOffset", desc); + Object.defineProperty(src, "byteOffset", desc); + Object.defineProperty(src2, "byteOffset", desc); + Object.defineProperty(src3, "byteOffset", desc); + + sample.set(src); + sample.set(src2); + sample.set(src3); + + assert.sameValue(getCalls, 0, "ignores byteOffset properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js new file mode 100644 index 0000000000000000000000000000000000000000..d3d51c4e762cc40f2ffa833a986efba9990c4809 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + If srcLength + targetOffset > targetLength, throw a RangeError exception. +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 20. Let srcLength be the value of typedArray's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, src; + + sample = new TA(2); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, 1); + }, "2 + 1 > 2"); + + sample = new TA(1); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, 0); + }, "2 + 0 > 1"); + + sample = new TA(1); + src = new TA(0); + assert.throws(RangeError, function() { + sample.set(src, 2); + }, "0 + 2 > 1"); + + sample = new TA(2); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, Infinity); + }, "2 + Infinity > 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..0f52982d4df5beced8b819eca25faa7f4a636f17 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Throws a TypeError if srcBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 11. Let srcBuffer be the value of typedArray's [[ViewedArrayBuffer]] internal + slot. + 12. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + var target = new TA(); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(target.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set(target, obj); + }); + + assert.sameValue(calledOffset, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-target-arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-target-arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..952dc624e655edc13b367d425cf0fd1d60fa1848 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-target-arraylength-internal.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + 2. Let target be the this value. + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42n, 43n]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.set(src); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-target-byteoffset-internal.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-target-byteoffset-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..eb4df9be008ffad2caea8cb608ee6121c29f6b8b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-target-byteoffset-internal.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + 2. Let target be the this value. + ... + 16. Let targetByteOffset be target.[[ByteOffset]]. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "byteOffset", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42n, 43n]); + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var src2 = new other([42n, 43n]); + var src3 = new other(sample.buffer, 0, 2); + + Object.defineProperty(TA.prototype, "byteOffset", desc); + Object.defineProperty(sample, "byteOffset", desc); + + sample.set(src); + sample.set(src2); + sample.set(src3); + + assert.sameValue(getCalls, 0, "ignores byteoffset properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-target-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-target-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..94ba23e5d7657934b8e4301df1353430ee7af936 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-target-out-of-bounds.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: Error when target SendableTypedArray fails boundary checks +includes: [sendableBigIntTypedArray.js] +features: [BigInt, SendableTypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.set, + 'function', + 'implements SendableTypedArray.prototype.set' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 4}); + var target = new TA(ab, 0, 4); + var source = new TA(new ArrayBuffer(BPE * 4)); + + var expectedError; + try { + ab.resize(BPE * 3); + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the reverse operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + target.set(source, 0); + throw new Test262Error('The `set` operation completed successfully.'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..b6dbd2cfe3baa4a1da5ea9e141f30c3955e9a62e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Throws a TypeError if targetBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA(1); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(sample.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set(src, obj); + }); + + assert.sameValue(calledOffset, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/BigInt/undefined-tobigint.js b/test/sendable/builtins/TypedArray/prototype/set/BigInt/undefined-tobigint.js new file mode 100644 index 0000000000000000000000000000000000000000..40637c41daf2aeb6df757d622bad2ae2354f01d0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/BigInt/undefined-tobigint.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Return abrupt on undefined +info: | + %SendableTypedArray%.prototype.set ( array [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the object + array. The optional offset value indicates the first element index in this + SendableTypedArray where values are written. If omitted, it is assumed to be 0. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. Let value be ? Get(src, Pk). + d. If target.[[TypedArrayName]] is "BigUint64Array" or "BigInt64Array", + let value be ? ToBigInt(value). + e. Otherwise, let value be ? ToNumber(value). + f. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + g. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumbervalue, true, "Unordered"). + h. Set k to k + 1. + i. Set targetByteIndex to targetByteIndex + targetElementSize. + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Undefined + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray.set([undefined]); + }, "abrupt completion from undefined"); + +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-negative-integer-offset-throws.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-negative-integer-offset-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..6c8e351d97feb40659170a454b35ca16508ceed2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-negative-integer-offset-throws.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Throw a RangeError exception if targetOffset < 0 +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert.throws(RangeError, function() { + sample.set([1], -1); + }, "-1"); + + assert.throws(RangeError, function() { + sample.set([1], -1.00001); + }, "-1.00001"); + + assert.throws(RangeError, function() { + sample.set([1], -Infinity); + }, "-Infinity"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-offset-tointeger.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-offset-tointeger.js new file mode 100644 index 0000000000000000000000000000000000000000..b93975f732045b007056aa03e31899ebaf807583 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-offset-tointeger.js @@ -0,0 +1,108 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + ToInteger(offset) operations +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([1, 2]); + sample.set([42], ""); + assert(compareArray(sample, [42, 2]), "the empty string"); + + sample = new TA([1, 2]); + sample.set([42], "0"); + assert(compareArray(sample, [42, 2]), "'0'"); + + sample = new TA([1, 2]); + sample.set([42], false); + assert(compareArray(sample, [42, 2]), "false"); + + sample = new TA([1, 2]); + sample.set([42], 0.1); + assert(compareArray(sample, [42, 2]), "0.1"); + + sample = new TA([1, 2]); + sample.set([42], 0.9); + assert(compareArray(sample, [42, 2]), "0.9"); + + sample = new TA([1, 2]); + sample.set([42], -0.5); + assert(compareArray(sample, [42, 2]), "-0.5"); + + sample = new TA([1, 2]); + sample.set([42], 1.1); + assert(compareArray(sample, [1, 42]), "1.1"); + + sample = new TA([1, 2]); + sample.set([42], NaN); + assert(compareArray(sample, [42, 2]), "NaN"); + + sample = new TA([1, 2]); + sample.set([42], null); + assert(compareArray(sample, [42, 2]), "null"); + + sample = new TA([1, 2]); + sample.set([42], undefined); + assert(compareArray(sample, [42, 2]), "undefined"); + + sample = new TA([1, 2]); + sample.set([42], {}); + assert(compareArray(sample, [42, 2]), "{}"); + + sample = new TA([1, 2]); + sample.set([42], []); + assert(compareArray(sample, [42, 2]), "[]"); + + sample = new TA([1, 2]); + sample.set([42], [0]); + assert(compareArray(sample, [42, 2]), "[0]"); + + sample = new TA([1, 2]); + sample.set([42], true); + assert(compareArray(sample, [1, 42]), "true"); + + sample = new TA([1, 2]); + sample.set([42], "1"); + assert(compareArray(sample, [1, 42]), "'1'"); + + sample = new TA([1, 2]); + sample.set([42], [1]); + assert(compareArray(sample, [1, 42]), "[1]"); + + sample = new TA([1, 2]); + sample.set([42], { valueOf: function() {return 1;} }); + assert(compareArray(sample, [1, 42]), "valueOf"); + + sample = new TA([1, 2]); + sample.set([42], { toString: function() {return 1;} }); + assert(compareArray(sample, [1, 42]), "toString"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-primitive-toobject.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-primitive-toobject.js new file mode 100644 index 0000000000000000000000000000000000000000..091708762fc78da93e345d08b82f699259c1f096 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-primitive-toobject.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Primitive `array` argument is coerced to an object. +info: | + %SendableTypedArray%.prototype.set ( typedArray [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object + with a [[TypedArrayName]] internal slot. If it is such an Object, + the definition in 22.2.3.23.2 applies. + [...] + 14. Let src be ? ToObject(array). + 15. Let srcLength be ? LengthOfArrayLike(src). + [...] + 19. Let limit be targetByteIndex + targetElementSize × srcLength. + 20. Repeat, while targetByteIndex < limit, + a. Let Pk be ! ToString(k). + b. Let value be ? Get(src, Pk). + [...] + d. Otherwise, set value to ? ToNumber(value). + [...] + f. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, value, true, Unordered). + [...] +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, Symbol] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta1 = new TA([1, 2, 3, 4, 5]); + ta1.set("678", 1); + assert.compareArray(ta1, [1, 6, 7, 8, 5], "string"); + + var ta2 = new TA([1, 2, 3]); + ta2.set(0); + assert.compareArray(ta2, [1, 2, 3], "number"); + + var ta3 = new TA([1, 2, 3]); + ta3.set(true, 2); + assert.compareArray(ta3, [1, 2, 3], "boolean"); + + var ta4 = new TA([1]); + ta4.set(Symbol()); + assert.compareArray(ta4, [1], "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-length.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-length.js new file mode 100644 index 0000000000000000000000000000000000000000..38220a8a0926b00d9b499428249409ef38014b95 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-length.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt getting src "length" +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 2, 3]); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-value.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-value.js new file mode 100644 index 0000000000000000000000000000000000000000..cfc6a9992c9b51ef9bc43ac7ade1cf6dc3fd287e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-get-value.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from getting src property value +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": 42, + "1": 43, + "3": 44 + }; + Object.defineProperty(obj, "2", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([1, 2, 3, 4]); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, [42, 43, 3, 4]), + "values are set until exception" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length-symbol.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..59b860c0a245c36735236fb20069e23acf3bcc81 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length-symbol.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt getting src "length" as symbol +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var obj = { + length: Symbol("1") +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 2, 3]); + + assert.throws(TypeError, function() { + sample.set(obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length.js new file mode 100644 index 0000000000000000000000000000000000000000..563bdb5733028a37f99d0d199ddc2d0a2f15afe3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-length.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToLength(src "length") +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var obj1 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; + +var obj2 = { + length: { + toString: function() { + throw new Test262Error(); + } + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 2, 3]); + + assert.throws(Test262Error, function() { + sample.set(obj1); + }, "valueOf"); + + assert.throws(Test262Error, function() { + sample.set(obj2); + }, "toString"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value-symbol.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..8d56547e78685d0bfd9cd12350f97189ce17ca69 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value-symbol.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToNumber(src property symbol value) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": 42, + "1": 43, + "2": Symbol("1"), + "3": 44 + }; + + var sample = new TA([1, 2, 3, 4]); + + assert.throws(TypeError, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, [42, 43, 3, 4]), + "values are set until exception" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value.js new file mode 100644 index 0000000000000000000000000000000000000000..aa617efffbbc8d4eafbc37e25bde6364a57494f6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-src-tonumber-value.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToNumber(src property value) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": 42, + "1": 43, + "2": { + valueOf: function() { + throw new Test262Error(); + } + }, + "3": 44 + }; + + var sample = new TA([1, 2, 3, 4]); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, [42, 43, 3, 4]), + "values are set until exception" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset-symbol.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..c38eb4a7b90c0369488d4d9056ba59c72d6511e3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset-symbol.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToInteger(Symbol offset) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.set([1], s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset.js new file mode 100644 index 0000000000000000000000000000000000000000..5a2efbd837fc2f0e76f17828008882754e0f7c5f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-tointeger-offset.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToInteger(offset) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.set([], obj1); + }, "abrupt from valueOf"); + + assert.throws(Test262Error, function() { + sample.set([], obj2); + }, "abrupt from toString"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-toobject-offset.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-toobject-offset.js new file mode 100644 index 0000000000000000000000000000000000000000..29f04bcac0a28ea771289a012b80b7394709b168 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-return-abrupt-from-toobject-offset.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Return abrupt from ToObject(array) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 15. Let src be ? ToObject(array). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 2, 3]); + + assert.throws(TypeError, function() { + sample.set(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.set(null); + }, "null"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-set-values-in-order.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-set-values-in-order.js new file mode 100644 index 0000000000000000000000000000000000000000..1af010172670c0eb780160c4a9e20506610a57da --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-set-values-in-order.js @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Get and set each value in order +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(5); + var calls = []; + var obj = { + length: 3 + }; + Object.defineProperty(obj, 0, { + get: function() { + calls.push(0); + calls.push(sample.join()); + return 42; + } + }); + + Object.defineProperty(obj, 1, { + get: function() { + calls.push(1); + calls.push(sample.join()); + return 43; + } + }); + + Object.defineProperty(obj, 2, { + get: function() { + calls.push(2); + calls.push(sample.join()); + return 44; + } + }); + + Object.defineProperty(obj, 3, { + get: function() { + throw new Test262Error("Should not call obj[3]"); + } + }); + + sample.set(obj, 1); + + assert( + compareArray(sample, [0, 42, 43, 44, 0]), + "values are set for src length" + ); + + assert( + compareArray(calls, [0, "0,0,0,0,0", 1, "0,42,0,0,0", 2, "0,42,43,0,0"]), + "values are set in order" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-set-values.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-set-values.js new file mode 100644 index 0000000000000000000000000000000000000000..eab47870d714c0f9809f0d1bda8e47f9dcf885b5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-set-values.js @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Set values to target and return undefined +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + Let Pk be ! ToString(k). + Let kNumber be ? ToNumber(? Get(src, Pk)). + If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, kNumber). + ... + 22. Return undefined. +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var src = [42, 43]; + var srcObj = { + length: 2, + '0': 7, + '1': 17 + }; + var sample, result; + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(srcObj, 0); + assert(compareArray(sample, [7, 17, 3, 4]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(srcObj, 1); + assert(compareArray(sample, [1, 7, 17, 4]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(srcObj, 2); + assert(compareArray(sample, [1, 2, 7, 17]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-src-tonumber-value-conversions.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-src-tonumber-value-conversions.js new file mode 100644 index 0000000000000000000000000000000000000000..12210bf264b774ab8dc04d71828a16bbddac13da --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-src-tonumber-value-conversions.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Values conversions on ToNumber(src property value) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [byteConversionValues.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + sample.set([value]); + + assert.sameValue(sample[0], expected, "["+value+"] => ["+expected +"]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-src-tonumber-value-type-conversions.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-src-tonumber-value-type-conversions.js new file mode 100644 index 0000000000000000000000000000000000000000..bf144b505966c9eca33ce4d1b51e798cd341251c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-src-tonumber-value-type-conversions.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Type conversions on ToNumber(src property value) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var obj1 = { + valueOf: function() { + return 42; + } + }; + + var obj2 = { + toString: function() { + return "42"; + } + }; + + var arr = ["1", "", false, true, null, obj1, obj2, [], [1]]; + + var sample = new TA(arr.length); + var expected = new TA([1, 0, 0, 1, 0, 42, 42, 0, 1]); + + sample.set(arr); + + assert( + compareArray(sample, expected), + "sample: [" + sample + "], expected: [" + expected + "]" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-src-values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-src-values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..c3234ffd511390257322c830dde5c20a24ce540c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-src-values-are-not-cached.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Values from src array are not cached +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(5); + var obj = { + length: 5, + '1': 7, + '2': 7, + '3': 7, + '4': 7 + }; + Object.defineProperty(obj, 0, { + get: function() { + obj[1] = 43; + obj[2] = 44; + obj[3] = 45; + obj[4] = 46; + return 42; + } + }); + + sample.set(obj); + + assert(compareArray(sample, [42, 43, 44, 45, 46])); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-target-arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-target-arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..98883f7f2f5b159baaee8f8512f29c0c0a90de04 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-target-arraylength-internal.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 17. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.set([42, 43]); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-get-src-value-no-throw.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-get-src-value-no-throw.js new file mode 100644 index 0000000000000000000000000000000000000000..05be276b05a29b7d85fc425aa69ac3eb66707921 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-get-src-value-no-throw.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Does not throw if target TA is detached mid-iteration +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 2, 3]); + var obj = { + length: 3, + "0": 42 + }; + Object.defineProperty(obj, 1, { + get: function() { + $DETACHBUFFER(sample.buffer); + } + }); + let get2Called = false; + Object.defineProperty(obj, 2, { + get: function() { + get2Called = true; + return 2; + } + }); + + sample.set(obj); + + assert.sameValue(true, get2Called); + assert.sameValue(0, sample.byteLength); + assert.sameValue(0, sample.byteOffset); + assert.sameValue(0, sample.length); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..d88b3b87c90c23555653676f198ab0bb1d8162df --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Throws a TypeError if targetBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(sample.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set([1], obj); + }); + + assert.sameValue(calledOffset, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-targetbuffer-detached-throws.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-targetbuffer-detached-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..59ba2779e6e03f03e793b571fa47fee2b50e93a0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-targetbuffer-detached-throws.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-array-offset +description: > + Throws a TypeError if targetBuffer is detached +info: | + 22.2.3.23.1 %SendableTypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... + 15. Let src be ? ToObject(array). + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample.set([1]); + }, "regular check"); + + assert.throws(TypeError, function() { + sample.set(obj); + }, "IsDetachedBuffer happens before Get(src.length)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/array-arg-value-conversion-resizes-array-buffer.js b/test/sendable/builtins/TypedArray/prototype/set/array-arg-value-conversion-resizes-array-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..0257f7853813115aeced2ac985e775fc58b4b5da --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/array-arg-value-conversion-resizes-array-buffer.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-settypedarrayfromarraylike +description: > + Value conversion shrinks and then grows the array buffer. +info: | + 23.2.3.26.2 SetSendableTypedArrayFromArrayLike ( target, targetOffset, source ) + ... + 9. Repeat, while k < srcLength, + a. Let Pk be ! ToString(𝔽(k)). + b. Let value be ? Get(src, Pk). + c. Let targetIndex be 𝔽(targetOffset + k). + d. Perform ? SendableTypedArraySetElement(target, targetIndex, value). + e. Set k to k + 1. + +features: [resizable-arraybuffer] +includes: [compareArray.js] +---*/ + +var rab = new ArrayBuffer(5, {maxByteLength: 10}); +var typedArray = new Int8Array(rab); + +var log = []; + +var growNumber = 0 + +var grow = { + valueOf() { + log.push("grow"); + rab.resize(rab.byteLength + 1); + return --growNumber; + } +}; + +var shrinkNumber = 0 + +var shrink = { + valueOf() { + log.push("shrink"); + rab.resize(rab.byteLength - 1); + return ++shrinkNumber; + } +}; + +var array = { + get length() { + return 5; + }, + 0: shrink, + 1: shrink, + 2: shrink, + 3: grow, + 4: grow, +} + +typedArray.set(array); + +assert.compareArray(log, [ + "shrink", "shrink", "shrink", "grow", "grow", +]); + +assert.compareArray(typedArray, [ + 1, 2, 0, 0 +]); diff --git a/test/sendable/builtins/TypedArray/prototype/set/bit-precision.js b/test/sendable/builtins/TypedArray/prototype/set/bit-precision.js new file mode 100644 index 0000000000000000000000000000000000000000..95dbeedb2b814691760ca8738e463f6f7d2be452 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/bit-precision.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set.2 +description: Preservation of bit-level encoding +info: | + [...] + 28. Else, + a. NOTE: If srcType and targetType are the same, the transfer must be + performed in a manner that preserves the bit-level encoding of the + source data. + b. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). + iii. Set srcByteIndex to srcByteIndex + 1. + iv. Set targetByteIndex to targetByteIndex + 1. +includes: [nans.js, compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +function body(FA) { + var source = new FA(NaNs); + var target = new FA(NaNs.length); + var sourceBytes, targetBytes; + + target.set(source); + + sourceBytes = new Uint8Array(source.buffer); + targetBytes = new Uint8Array(target.buffer); + + assert(compareArray(sourceBytes, targetBytes)) +} + +testWithTypedArrayConstructors(body, floatArrayConstructors); diff --git a/test/sendable/builtins/TypedArray/prototype/set/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/set/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..70c4ded319e1a856a7014c4e2856a5d2a272bae4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/invoked-as-func.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.22 %SendableTypedArray%.prototype.set ( overloaded [ , offset ]) + + This function is not generic. The this value must be an object with a + [[TypedArrayName]] internal slot. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var set = SendableTypedArray.prototype.set; + +assert.sameValue(typeof set, 'function'); + +assert.throws(TypeError, function() { + set(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/set/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..0f3d25833afc85002dad0760b5cac6f0ff2ef986 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/invoked-as-method.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.22 %SendableTypedArray%.prototype.set ( overloaded [ , offset ]) + + This function is not generic. The this value must be an object with a + [[TypedArrayName]] internal slot. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.set, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.set(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/length.js b/test/sendable/builtins/TypedArray/prototype/set/length.js new file mode 100644 index 0000000000000000000000000000000000000000..df9f4d10162d6ec6297444bdda13d3579823b121 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set +description: > + %SendableTypedArray%.prototype.set.length is 1. +info: | + %SendableTypedArray%.prototype.set ( overloaded [ , offset ]) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.set, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/name.js b/test/sendable/builtins/TypedArray/prototype/set/name.js new file mode 100644 index 0000000000000000000000000000000000000000..514c2aeebca6ffd4d1d2eef1d2237d5ac02b9e58 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set +description: > + %SendableTypedArray%.prototype.set.name is "set". +info: | + %SendableTypedArray%.prototype.set ( overloaded [ , offset ]) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.set, "name", { + value: "set", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/set/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..92e16e1715972fdfca69df467f9a8fed8639fe06 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.set does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.set), + false, + 'isConstructor(SendableTypedArray.prototype.set) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.set([0], 0); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/set/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/set/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..fb187164f1cd2dd919bb334d60808ac37e686ac3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set +description: > + "set" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'set', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/src-typedarray-big-throws.js b/test/sendable/builtins/TypedArray/prototype/set/src-typedarray-big-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..6d6067377d06cd8f4d1a8e74ff5e6c34519027f7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/src-typedarray-big-throws.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + If typedArray set argument is a Big(U)Int, and target not "Big", throw +info: | + %SendableTypedArray%.prototype.set( typedArray [ , offset ] ) + Sets multiple values in this SendableTypedArray, reading the values from the + typedArray argument object. The optional offset value indicates the first + element index in this SendableTypedArray where values are written. If omitted, it + is assumed to be 0. + ... + 23. If one of srcType and targetType contains the substring "Big" and the + other does not, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, sendableTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var bigSendableTypedArray; +var littleSendableTypedArray; + +testWithBigIntTypedArrayConstructors(function(BTA) { + + bigSendableTypedArray = new BTA([1n]); + + testWithTypedArrayConstructors(function(TA) { + + littleSendableTypedArray = new TA(1); + assert.throws(TypeError, function() { + littleSendableTypedArray.set(bigSendableTypedArray); + }); + }); + +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/target-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/set/target-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..a073096efa8012ca6894c4ba59de597e1dcf48ba --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/target-grow-mid-iteration.js @@ -0,0 +1,125 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set +description: > + SendableTypedArray.p.set behaves correctly on SendableTypedArrays backed by resizable buffers + that are grown mid-iteration due to a Proxy source. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Resizing will happen when we're calling Get for the `resizeAt`:th data +// element, but we haven't yet written it to the target. +function CreateSourceProxy(length, rab, resizeAt, resizeTo) { + let requestedIndices = []; + return new Proxy({}, { + get(target, prop, receiver) { + if (prop == 'length') { + return length; + } + requestedIndices.push(prop); + if (requestedIndices.length == resizeAt) { + rab.resize(resizeTo); + } + return true; // Can be converted to both BigInt and Number. + } + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + const resizeAt = 2; + const resizeTo = 6 * ctor.BYTES_PER_ELEMENT; + fixedLength.set(CreateSourceProxy(4, rab, resizeAt, resizeTo)); + assert.compareArray(ToNumbers(fixedLength), [ + 1, + 1, + 1, + 1 + ]); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 1, + 1, + 1, + 1, + 0, + 0 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const resizeAt = 1; + const resizeTo = 6 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.set(CreateSourceProxy(2, rab, resizeAt, resizeTo)); + assert.compareArray(ToNumbers(fixedLengthWithOffset), [ + 1, + 1 + ]); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 1, + 1, + 0, + 0 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + const resizeAt = 2; + const resizeTo = 6 * ctor.BYTES_PER_ELEMENT; + lengthTracking.set(CreateSourceProxy(2, rab, resizeAt, resizeTo)); + assert.compareArray(ToNumbers(lengthTracking), [ + 1, + 1, + 4, + 6, + 0, + 0 + ]); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 1, + 1, + 4, + 6, + 0, + 0 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const resizeAt = 1; + const resizeTo = 6 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.set(CreateSourceProxy(2, rab, resizeAt, resizeTo)); + assert.compareArray(ToNumbers(lengthTrackingWithOffset), [ + 1, + 1, + 0, + 0 + ]); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 1, + 1, + 0, + 0 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/set/target-grow-source-length-getter.js b/test/sendable/builtins/TypedArray/prototype/set/target-grow-source-length-getter.js new file mode 100644 index 0000000000000000000000000000000000000000..3bcb6e7fdb040f9e1dac2fb76c17893fc5d2af05 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/target-grow-source-length-getter.js @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set +description: > + SendableTypedArray.p.set behaves correctly on SendableTypedArrays backed by a + resizable buffer is grown due to the source's length getter +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +function CreateSourceProxy(length, rab, resizeTo) { + return new Proxy({}, { + get(target, prop, receiver) { + if (prop == 'length') { + rab.resize(resizeTo); + return length; + } + return true; // Can be converted to both BigInt and Number. + } + }); +} + +// Test that we still throw for lengthTracking TAs if the source length is +// too large, even though we resized in the length getter (we check against +// the original length). +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + const resizeTo = 6 * ctor.BYTES_PER_ELEMENT; + assert.throws(RangeError, () => { + lengthTracking.set(CreateSourceProxy(6, rab, resizeTo)); + }); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 4, + 6, + 0, + 0 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 6 * ctor.BYTES_PER_ELEMENT; + assert.throws(RangeError, () => { + lengthTrackingWithOffset.set(CreateSourceProxy(4, rab, resizeTo)); + }); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 4, + 6, + 0, + 0 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/set/target-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/set/target-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..858245e23f7de41bcb314c3c3ccbf6b296db3a31 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/target-shrink-mid-iteration.js @@ -0,0 +1,111 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set +description: > + SendableTypedArray.p.set behaves correctly on SendableTypedArrays backed by resizable buffers + that are shrunk mid-iteration due to a Proxy source. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +// Resizing will happen when we're calling Get for the `resizeAt`:th data +// element, but we haven't yet written it to the target. +function CreateSourceProxy(length, rab, resizeAt, resizeTo) { + let requestedIndices = []; + return new Proxy({}, { + get(target, prop, receiver) { + if (prop == 'length') { + return length; + } + requestedIndices.push(prop); + if (requestedIndices.length == resizeAt) { + rab.resize(resizeTo); + } + return true; // Can be converted to both BigInt and Number. + } + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + const resizeAt = 2; + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLength.set(CreateSourceProxy(4, rab, resizeAt, resizeTo)); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 1, + 2, + 4 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const resizeAt = 2; + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.set(CreateSourceProxy(2, rab, resizeAt, resizeTo)); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 1 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + const resizeAt = 2; + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTracking.set(CreateSourceProxy(2, rab, resizeAt, resizeTo)); + assert.compareArray(ToNumbers(lengthTracking), [ + 1, + 1, + 4 + ]); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 1, + 1, + 4 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const resizeAt = 2; + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.set(CreateSourceProxy(2, rab, resizeAt, resizeTo)); + assert.compareArray(ToNumbers(lengthTrackingWithOffset), [1]); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 1 + ]); +} + +// Length-tracking TA goes OOB because of the offset. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const resizeAt = 1; + const resizeTo = 1 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.set(CreateSourceProxy(2, rab, resizeAt, resizeTo)); + assert.compareArray(ToNumbers(new ctor(rab)), [0]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/set/target-shrink-source-length-getter.js b/test/sendable/builtins/TypedArray/prototype/set/target-shrink-source-length-getter.js new file mode 100644 index 0000000000000000000000000000000000000000..d7e6dafaeaef63f97a4ad09b9ccc2ae2458b41b0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/target-shrink-source-length-getter.js @@ -0,0 +1,159 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set +description: > + SendableTypedArray.p.set behaves correctly on SendableTypedArrays backed by resizable buffers + that are shrunk due to the source's length getter. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +function CreateSourceProxy(length, rab, resizeTo) { + return new Proxy({}, { + get(target, prop, receiver) { + if (prop == 'length') { + rab.resize(resizeTo); + return length; + } + return true; // Can be converted to both BigInt and Number. + } + }); +} + +// Tests where the length getter returns a non-zero value -> these are nop if +// the TA went OOB. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLength.set(CreateSourceProxy(1, rab, resizeTo)); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 4 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.set(CreateSourceProxy(1, rab, resizeTo)); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 4 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTracking.set(CreateSourceProxy(1, rab, resizeTo)); + assert.compareArray(ToNumbers(lengthTracking), [ + 1, + 2, + 4 + ]); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 1, + 2, + 4 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.set(CreateSourceProxy(1, rab, resizeTo)); + assert.compareArray(ToNumbers(lengthTrackingWithOffset), [1]); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 1 + ]); +} + +// Length-tracking TA goes OOB because of the offset. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 1 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.set(CreateSourceProxy(1, rab, resizeTo)); + assert.compareArray(ToNumbers(new ctor(rab)), [0]); +} + +// Tests where the length getter returns a zero -> these don't throw even if +// the TA went OOB. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLength.set(CreateSourceProxy(0, rab, resizeTo)); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 4 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + fixedLengthWithOffset.set(CreateSourceProxy(0, rab, resizeTo)); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 4 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTracking.set(CreateSourceProxy(0, rab, resizeTo)); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 4 + ]); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.set(CreateSourceProxy(0, rab, resizeTo)); + assert.compareArray(ToNumbers(new ctor(rab)), [ + 0, + 2, + 4 + ]); +} + +// Length-tracking TA goes OOB because of the offset. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 1 * ctor.BYTES_PER_ELEMENT; + lengthTrackingWithOffset.set(CreateSourceProxy(0, rab, resizeTo)); + assert.compareArray(ToNumbers(new ctor(rab)), [0]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/set/this-backed-by-resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/set/this-backed-by-resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..e1a667906688b0bef437af1c1f1c9cb60780d0c9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/this-backed-by-resizable-buffer.js @@ -0,0 +1,537 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set +description: > + SendableTypedArray.p.set behaves correctly on SendableTypedArrays backed by resizable buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function SetNumOrBigInt(target, source, offset) { + if (target instanceof BigInt64Array || target instanceof BigUint64Array) { + const bigIntSource = []; + for (const s of source) { + bigIntSource.push(BigInt(s)); + } + source = bigIntSource; + } + if (offset == undefined) { + return target.set(source); + } + return target.set(source, offset); +} + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const taFull = new ctor(rab); + + // Orig. array: [0, 0, 0, 0] + // [0, 0, 0, 0] << fixedLength + // [0, 0] << fixedLengthWithOffset + // [0, 0, 0, 0, ...] << lengthTracking + // [0, 0, ...] << lengthTrackingWithOffset + + // For making sure we're not calling the source length or element getters + // if the target is OOB. + const throwingProxy = new Proxy({}, { + get(target, prop, receiver) { + throw new Error('Called getter for ' + prop); + } + }); + SetNumOrBigInt(fixedLength, [ + 1, + 2 + ]); + assert.compareArray(ToNumbers(taFull), [ + 1, + 2, + 0, + 0 + ]); + SetNumOrBigInt(fixedLength, [ + 3, + 4 + ], 1); + assert.compareArray(ToNumbers(taFull), [ + 1, + 3, + 4, + 0 + ]); + assert.throws(RangeError, () => { + SetNumOrBigInt(fixedLength, [ + 0, + 0, + 0, + 0, + 0 + ]); + }); + assert.throws(RangeError, () => { + SetNumOrBigInt(fixedLength, [ + 0, + 0, + 0, + 0 + ], 1); + }); + assert.compareArray(ToNumbers(taFull), [ + 1, + 3, + 4, + 0 + ]); + SetNumOrBigInt(fixedLengthWithOffset, [ + 5, + 6 + ]); + assert.compareArray(ToNumbers(taFull), [ + 1, + 3, + 5, + 6 + ]); + SetNumOrBigInt(fixedLengthWithOffset, [7], 1); + assert.compareArray(ToNumbers(taFull), [ + 1, + 3, + 5, + 7 + ]); + assert.throws(RangeError, () => { + SetNumOrBigInt(fixedLengthWithOffset, [ + 0, + 0, + 0 + ]); + }); + assert.throws(RangeError, () => { + SetNumOrBigInt(fixedLengthWithOffset, [ + 0, + 0 + ], 1); + }); + assert.compareArray(ToNumbers(taFull), [ + 1, + 3, + 5, + 7 + ]); + SetNumOrBigInt(lengthTracking, [ + 8, + 9 + ]); + assert.compareArray(ToNumbers(taFull), [ + 8, + 9, + 5, + 7 + ]); + SetNumOrBigInt(lengthTracking, [ + 10, + 11 + ], 1); + assert.compareArray(ToNumbers(taFull), [ + 8, + 10, + 11, + 7 + ]); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTracking, [ + 0, + 0, + 0, + 0, + 0 + ]); + }); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTracking, [ + 0, + 0, + 0, + 0 + ], 1); + }); + assert.compareArray(ToNumbers(taFull), [ + 8, + 10, + 11, + 7 + ]); + SetNumOrBigInt(lengthTrackingWithOffset, [ + 12, + 13 + ]); + assert.compareArray(ToNumbers(taFull), [ + 8, + 10, + 12, + 13 + ]); + SetNumOrBigInt(lengthTrackingWithOffset, [14], 1); + assert.compareArray(ToNumbers(taFull), [ + 8, + 10, + 12, + 14 + ]); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTrackingWithOffset, [ + 0, + 0, + 0 + ]); + }); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTrackingWithOffset, [ + 0, + 0 + ], 1); + }); + assert.compareArray(ToNumbers(taFull), [ + 8, + 10, + 12, + 14 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [8, 10, 12] + // [8, 10, 12, ...] << lengthTracking + // [12, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + SetNumOrBigInt(fixedLength, throwingProxy); + }); + assert.throws(TypeError, () => { + SetNumOrBigInt(fixedLengthWithOffset, throwingProxy); + }); + assert.compareArray(ToNumbers(taFull), [ + 8, + 10, + 12 + ]); + SetNumOrBigInt(lengthTracking, [ + 15, + 16 + ]); + assert.compareArray(ToNumbers(taFull), [ + 15, + 16, + 12 + ]); + SetNumOrBigInt(lengthTracking, [ + 17, + 18 + ], 1); + assert.compareArray(ToNumbers(taFull), [ + 15, + 17, + 18 + ]); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTracking, [ + 0, + 0, + 0, + 0 + ]); + }); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTracking, [ + 0, + 0, + 0 + ], 1); + }); + assert.compareArray(ToNumbers(taFull), [ + 15, + 17, + 18 + ]); + SetNumOrBigInt(lengthTrackingWithOffset, [19]); + assert.compareArray(ToNumbers(taFull), [ + 15, + 17, + 19 + ]); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTrackingWithOffset, [ + 0, + 0 + ]); + }); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTrackingWithOffset, [0], 1); + }); + assert.compareArray(ToNumbers(taFull), [ + 15, + 17, + 19 + ]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + SetNumOrBigInt(fixedLength, throwingProxy); + }); + assert.throws(TypeError, () => { + SetNumOrBigInt(fixedLengthWithOffset, throwingProxy); + }); + assert.throws(TypeError, () => { + SetNumOrBigInt(lengthTrackingWithOffset, throwingProxy); + }); + assert.compareArray(ToNumbers(taFull), [15]); + SetNumOrBigInt(lengthTracking, [20]); + assert.compareArray(ToNumbers(taFull), [20]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + SetNumOrBigInt(fixedLength, throwingProxy); + }); + assert.throws(TypeError, () => { + SetNumOrBigInt(fixedLengthWithOffset, throwingProxy); + }); + assert.throws(TypeError, () => { + SetNumOrBigInt(lengthTrackingWithOffset, throwingProxy); + }); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTracking, [0]); + }); + assert.compareArray(ToNumbers(taFull), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 0, 0, 0, 0, 0] + // [0, 0, 0, 0] << fixedLength + // [0, 0] << fixedLengthWithOffset + // [0, 0, 0, 0, 0, 0, ...] << lengthTracking + // [0, 0, 0, 0, ...] << lengthTrackingWithOffset + SetNumOrBigInt(fixedLength, [ + 21, + 22 + ]); + assert.compareArray(ToNumbers(taFull), [ + 21, + 22, + 0, + 0, + 0, + 0 + ]); + SetNumOrBigInt(fixedLength, [ + 23, + 24 + ], 1); + assert.compareArray(ToNumbers(taFull), [ + 21, + 23, + 24, + 0, + 0, + 0 + ]); + assert.throws(RangeError, () => { + SetNumOrBigInt(fixedLength, [ + 0, + 0, + 0, + 0, + 0 + ]); + }); + assert.throws(RangeError, () => { + SetNumOrBigInt(fixedLength, [ + 0, + 0, + 0, + 0 + ], 1); + }); + assert.compareArray(ToNumbers(taFull), [ + 21, + 23, + 24, + 0, + 0, + 0 + ]); + SetNumOrBigInt(fixedLengthWithOffset, [ + 25, + 26 + ]); + assert.compareArray(ToNumbers(taFull), [ + 21, + 23, + 25, + 26, + 0, + 0 + ]); + SetNumOrBigInt(fixedLengthWithOffset, [27], 1); + assert.compareArray(ToNumbers(taFull), [ + 21, + 23, + 25, + 27, + 0, + 0 + ]); + assert.throws(RangeError, () => { + SetNumOrBigInt(fixedLengthWithOffset, [ + 0, + 0, + 0 + ]); + }); + assert.throws(RangeError, () => { + SetNumOrBigInt(fixedLengthWithOffset, [ + 0, + 0 + ], 1); + }); + assert.compareArray(ToNumbers(taFull), [ + 21, + 23, + 25, + 27, + 0, + 0 + ]); + SetNumOrBigInt(lengthTracking, [ + 28, + 29, + 30, + 31, + 32, + 33 + ]); + assert.compareArray(ToNumbers(taFull), [ + 28, + 29, + 30, + 31, + 32, + 33 + ]); + SetNumOrBigInt(lengthTracking, [ + 34, + 35, + 36, + 37, + 38 + ], 1); + assert.compareArray(ToNumbers(taFull), [ + 28, + 34, + 35, + 36, + 37, + 38 + ]); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTracking, [ + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ]); + }); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTracking, [ + 0, + 0, + 0, + 0, + 0, + 0 + ], 1); + }); + assert.compareArray(ToNumbers(taFull), [ + 28, + 34, + 35, + 36, + 37, + 38 + ]); + SetNumOrBigInt(lengthTrackingWithOffset, [ + 39, + 40, + 41, + 42 + ]); + assert.compareArray(ToNumbers(taFull), [ + 28, + 34, + 39, + 40, + 41, + 42 + ]); + SetNumOrBigInt(lengthTrackingWithOffset, [ + 43, + 44, + 45 + ], 1); + assert.compareArray(ToNumbers(taFull), [ + 28, + 34, + 39, + 43, + 44, + 45 + ]); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTrackingWithOffset, [ + 0, + 0, + 0, + 0, + 0 + ]); + }); + assert.throws(RangeError, () => { + SetNumOrBigInt(lengthTrackingWithOffset, [ + 0, + 0, + 0, + 0 + ], 1); + }); + assert.compareArray(ToNumbers(taFull), [ + 28, + 34, + 39, + 43, + 44, + 45 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/set/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/set/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..de02094cef8e901c6c93e245d5bd232cc9e0f286 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/this-is-not-object.js @@ -0,0 +1,88 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-overloaded-offset +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.23 %SendableTypedArray%.prototype.set + + ... + 2. Let target be the this value. + 3. If Type(target) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var set = SendableTypedArray.prototype.set; + +assert.throws(TypeError, function() { + set.call(undefined, []); +}, "this is undefined"); + +assert.throws(TypeError, function() { + set.call(null, []); +}, "this is null"); + +assert.throws(TypeError, function() { + set.call(undefined, new Int8Array()); +}, "this is undefined"); + +assert.throws(TypeError, function() { + set.call(null, new Int8Array()); +}, "this is null"); + +assert.throws(TypeError, function() { + set.call(42, []); +}, "this is 42"); + +assert.throws(TypeError, function() { + set.call("1", []); +}, "this is a string"); + +assert.throws(TypeError, function() { + set.call(true, []); +}, "this is true"); + +assert.throws(TypeError, function() { + set.call(false, []); +}, "this is false"); + +var s1 = Symbol("s"); +assert.throws(TypeError, function() { + set.call(s1, []); +}, "this is a Symbol"); + +assert.throws(TypeError, function() { + set.call(42, new Int8Array(1)); +}, "this is 42"); + +assert.throws(TypeError, function() { + set.call("1", new Int8Array(1)); +}, "this is a string"); + +assert.throws(TypeError, function() { + set.call(true, new Int8Array(1)); +}, "this is true"); + +assert.throws(TypeError, function() { + set.call(false, new Int8Array(1)); +}, "this is false"); + +var s2 = Symbol("s"); +assert.throws(TypeError, function() { + set.call(s2, new Int8Array(1)); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/set/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/set/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..41cc0bd041901ab08ee384bc6beb60ad8c1e119a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/this-is-not-typedarray-instance.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-overloaded-offset +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.23 %SendableTypedArray%.prototype.set + + ... + 2. Let target be the this value. + 3. If Type(target) is not Object, throw a TypeError exception. + 4. If target does not have a [[TypedArrayName]] internal slot, throw a + TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var set = SendableTypedArray.prototype.set; + +assert.throws(TypeError, function() { + set.call({}, []); +}, "this is an Object"); + +assert.throws(TypeError, function() { + set.call([], []); +}, "this is an Array"); + +var ab1 = new ArrayBuffer(8); +assert.throws(TypeError, function() { + set.call(ab1, []); +}, "this is an ArrayBuffer instance"); + +var dv1 = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + set.call(dv1, []); +}, "this is a DataView instance"); + +assert.throws(TypeError, function() { + set.call({}, new Int8Array()); +}, "this is an Object"); + +assert.throws(TypeError, function() { + set.call([], new Int8Array()); +}, "this is an Array"); + +var ab2 = new ArrayBuffer(8); +assert.throws(TypeError, function() { + set.call(ab2, new Int8Array()); +}, "this is an ArrayBuffer instance"); + +var dv2 = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + set.call(dv2, new Int8Array()); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-negative-integer-offset-throws.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-negative-integer-offset-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..480e4ab832c77b71edef612723f29715691fe252 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-negative-integer-offset-throws.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Throw a RangeError exception if targetOffset < 0 +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(RangeError, function() { + sample.set(sample, -1); + }, "-1"); + + assert.throws(RangeError, function() { + sample.set(sample, -1.00001); + }, "-1.00001"); + + assert.throws(RangeError, function() { + sample.set(sample, -Infinity); + }, "-Infinity"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-offset-tointeger.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-offset-tointeger.js new file mode 100644 index 0000000000000000000000000000000000000000..7e55d86fd87887ea3b9f23c6aed280702e8f65eb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-offset-tointeger.js @@ -0,0 +1,106 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + ToInteger(offset) operations +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + var src = new TA([42]); + + sample = new TA([1, 2]); + sample.set(src, ""); + assert(compareArray(sample, [42, 2]), "the empty string"); + + sample = new TA([1, 2]); + sample.set(src, "0"); + assert(compareArray(sample, [42, 2]), "'0'"); + + sample = new TA([1, 2]); + sample.set(src, false); + assert(compareArray(sample, [42, 2]), "false"); + + sample = new TA([1, 2]); + sample.set(src, 0.1); + assert(compareArray(sample, [42, 2]), "0.1"); + + sample = new TA([1, 2]); + sample.set(src, 0.9); + assert(compareArray(sample, [42, 2]), "0.9"); + + sample = new TA([1, 2]); + sample.set(src, -0.5); + assert(compareArray(sample, [42, 2]), "-0.5"); + + sample = new TA([1, 2]); + sample.set(src, 1.1); + assert(compareArray(sample, [1, 42]), "1.1"); + + sample = new TA([1, 2]); + sample.set(src, NaN); + assert(compareArray(sample, [42, 2]), "NaN"); + + sample = new TA([1, 2]); + sample.set(src, null); + assert(compareArray(sample, [42, 2]), "null"); + + sample = new TA([1, 2]); + sample.set(src, undefined); + assert(compareArray(sample, [42, 2]), "undefined"); + + sample = new TA([1, 2]); + sample.set(src, {}); + assert(compareArray(sample, [42, 2]), "{}"); + + sample = new TA([1, 2]); + sample.set(src, []); + assert(compareArray(sample, [42, 2]), "[]"); + + sample = new TA([1, 2]); + sample.set(src, [0]); + assert(compareArray(sample, [42, 2]), "[0]"); + + sample = new TA([1, 2]); + sample.set(src, true); + assert(compareArray(sample, [1, 42]), "true"); + + sample = new TA([1, 2]); + sample.set(src, "1"); + assert(compareArray(sample, [1, 42]), "'1'"); + + sample = new TA([1, 2]); + sample.set(src, [1]); + assert(compareArray(sample, [1, 42]), "[1]"); + + sample = new TA([1, 2]); + sample.set(src, { valueOf: function() {return 1;} }); + assert(compareArray(sample, [1, 42]), "valueOf"); + + sample = new TA([1, 2]); + sample.set(src, { toString: function() {return 1;} }); + assert(compareArray(sample, [1, 42]), "toString"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..1a38335e7b2f34452721468a2adbb189c63bbb9a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Return abrupt from ToInteger(Symbol offset) +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.set(sample, s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset.js new file mode 100644 index 0000000000000000000000000000000000000000..7da3899fd531c34ebb55e29d42937e8d4b72be43 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-return-abrupt-from-tointeger-offset.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Return abrupt from ToInteger(offset) +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.set(sample, obj1); + }, "abrupt from valueOf"); + + assert.throws(Test262Error, function() { + sample.set(sample, obj2); + }, "abrupt from toString"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..bec1dc659294edb69f980299181a86dc784b6487 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set converted values from different buffer of different types and different type instances +includes: [byteConversionValues.js, sendableTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + if (TA === Float64Array || TA === Float32Array || (typeof Float16Array !== 'undefined' && TA === Float16Array) || TA === Uint8ClampedArray) { + return; + } + if (TA === Int32Array) { + return; + } + + var sab, src, target; + + sab = new SharedArrayBuffer(4); + src = new Int32Array(sab); + src[0] = value; + target = new TA([initial]); + + target.set(src); + + assert.sameValue(target[0], expected, "src is SAB-backed"); + + sab = new SharedArrayBuffer(4); + src = new Int32Array([value]); + target = new TA(sab); + target[0] = initial; + + target.set(src); + + assert.sameValue(target[0], expected, "target is SAB-backed"); + + var sab1 = new SharedArrayBuffer(4); + var sab2 = new SharedArrayBuffer(4); + src = new Int32Array(sab1); + src[0] = value; + target = new TA(sab2); + target[0] = initial; + + target.set(src); + + assert.sameValue(target[0], expected, "src and target are SAB-backed"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions.js new file mode 100644 index 0000000000000000000000000000000000000000..508598fdcc346459de917e99e96fcb3beb09a29e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set converted values from different buffer and different type instances +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + ... + 24. Else, let srcByteIndex be srcByteOffset. + ... + 27. If SameValue(srcType, targetType) is true, then, + ... + 28. Else, + a. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + value). +includes: [byteConversionValues.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + if (TA === Float64Array) { + return; + } + var src = new Float64Array([value]); + var target = new TA([initial]); + + target.set(src); + + assert.sameValue(target[0], expected); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-sab.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..696b23868721c0fbe6ea354693c9901b8c11fc41 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-sab.js @@ -0,0 +1,118 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and different + type. +includes: [sendableTypedArray.js, compareArray.js] +features: [SharedArrayBuffer, TypedArray] +---*/ + +var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; + +testWithTypedArrayConstructors(function(TA) { + var other = Int32Array; + var sab = new SharedArrayBuffer(2 * other.BYTES_PER_ELEMENT); + var src = new other(sab); + src[0] = 42; + src[1] = 43; + var sample, result; + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + + src = new other([42, 43]); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "sample is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "sample is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "sample is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + var sab1 = new SharedArrayBuffer(2 * other.BYTES_PER_ELEMENT); + src = new other(sab1); + src[0] = 42; + src[1] = 43; + + var sab2; + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src and sample are SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src and sample are SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src and sample are SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}, int_views); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type.js new file mode 100644 index 0000000000000000000000000000000000000000..8b942a118800e18a18f3dfae4149ecfabca485cc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and different + type. +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + ... + 24. Else, let srcByteIndex be srcByteOffset. + ... + 27. If SameValue(srcType, targetType) is true, then, + ... + 28. Else, + a. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + value). +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var other = TA === Float32Array ? Float64Array : Float32Array; + var src = new other([42, 43]); + var sample, result; + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type-sab.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..b67a665f0e7630413eb6d1b07bc19a0e48300522 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type-sab.js @@ -0,0 +1,119 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and same + constructor. srcBuffer values are cached. +includes: [sendableTypedArray.js, compareArray.js] +features: [SharedArrayBuffer, TypedArray] +---*/ + +var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; + +testWithTypedArrayConstructors(function(TA) { + var sample, result; + + var sab = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); + var src = new TA(sab); + src[0] = 42; + src[1] = 43; + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + + src = new TA([42, 43]); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "sample is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "sample is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "sample is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + + var sab1 = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); + src = new TA(sab1); + src[0] = 42; + src[1] = 43; + + var sab2; + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src and sample are SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src and sample are SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src and sample are SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}, int_views); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type.js new file mode 100644 index 0000000000000000000000000000000000000000..065c3d6e870e0a4865dd253a8caa7efd4589ef60 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and same + constructor. srcBuffer values are cached. +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + ... + 24. Else, let srcByteIndex be srcByteOffset. + ... + 27. If SameValue(srcType, targetType) is true, then, + a. NOTE: If srcType and targetType are the same, the transfer must be + performed in a manner that preserves the bit-level encoding of the source + data. + b. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). + ... + 29. Return undefined. +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample, result; + var src = new TA([42, 43]); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js new file mode 100644 index 0000000000000000000000000000000000000000..7f2630cd55d37b54075c680dc72857ca17ffa781 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the same buffer and different + constructor. +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + a. Let srcBuffer be ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcLength, + %ArrayBuffer%). + b. NOTE: %ArrayBuffer% is used to clone srcBuffer because is it known to not + have any observable side-effects. + ... + ... + 27. If SameValue(srcType, targetType) is true, then, + ... + 28. Else, + a. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + value). + ... + 29. Return undefined. +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var expected = { + Float64Array: [1.0000002464512363, 42, 1.875, 4, 5, 6, 7, 8], + Float32Array: [0, 42, 512.0001220703125, 4, 5, 6, 7, 8], + Float16Array: [0, 42, 513, 4, 5, 6, 7, 8], + Int32Array: [1109917696, 42, 0, 4, 5, 6, 7, 8], + Int16Array: [0, 42, 0, 4, 5, 6, 7, 8], + Int8Array: [0, 42, 0, 66, 5, 6, 7, 8], + Uint32Array: [1109917696, 42, 0, 4, 5, 6, 7, 8], + Uint16Array: [0, 42, 0, 4, 5, 6, 7, 8], + Uint8Array: [0, 42, 0, 66, 5, 6, 7, 8], + Uint8ClampedArray: [0, 42, 0, 66, 5, 6, 7, 8] +}; + +testWithTypedArrayConstructors(function(TA) { + var other = TA === Float32Array ? Float64Array : Float32Array; + + var sample = new TA([1, 2, 3, 4, 5, 6, 7, 8]); + var src = new other(sample.buffer, 0, 2); + + // Reflect changes on sample object + src[0] = 42; + + var result = sample.set(src, 1); + + assert(compareArray(sample, expected[TA.name]), sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-resized.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-resized.js new file mode 100644 index 0000000000000000000000000000000000000000..7a0029aa7db033bc3a3add3c2ee12d5aeb11b05e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-resized.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor when underlying ArrayBuffer has been resized +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var source = new TA(ab); + var target = new TA(ab); + var expected = [10, 20, 30, 40]; + + source[0] = 10; + source[1] = 20; + source[2] = 30; + source[3] = 40; + + try { + ab.resize(BPE * 5); + expected = [10, 20, 30, 40, 0]; + } catch (_) {} + + target.set(source); + assert(compareArray(target, expected), 'following grow'); + + try { + ab.resize(BPE * 3); + expected = [10, 20, 30]; + } catch (_) {} + + target.set(source); + assert(compareArray(target, expected), 'following shrink'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-sab.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..82b188d05349962b94f8aa69d8bdc6b96b1c35b0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-sab.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor. srcBuffer values are cached. +includes: [sendableTypedArray.js, compareArray.js] +features: [SharedArrayBuffer, TypedArray] +---*/ + +var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; + +testWithTypedArrayConstructors(function(TA) { + var sample, src, result, sab; + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 0); + assert(compareArray(sample, [1, 2, 3, 4]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 1, 2, 4]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 1, 2]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}, int_views); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type.js new file mode 100644 index 0000000000000000000000000000000000000000..7346c563b6f5ce1f160f11297bca9a35d95e9bc8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor. srcBuffer values are cached. +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + a. Let srcBuffer be ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcLength, + %ArrayBuffer%). + b. NOTE: %ArrayBuffer% is used to clone srcBuffer because is it known to not + have any observable side-effects. + ... + ... + 27. If SameValue(srcType, targetType) is true, then, + a. NOTE: If srcType and targetType are the same, the transfer must be + performed in a manner that preserves the bit-level encoding of the source + data. + b. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample, src, result; + + sample = new TA([1, 2, 3, 4]); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 0); + assert(compareArray(sample, [1, 2, 3, 4]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 1, 2, 4]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 1, 2]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..de1c84fb36d5d2f4a1e6d89319720773d27d2913 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-arraylength-internal.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Uses typedArray's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 20. Let srcLength be the value of typedArray's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 42; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42, 43]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(src, "length", desc); + + sample.set(src); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-backed-by-resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-backed-by-resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..8ad1ccf7d7f97b54ea989823d0295f507d9baeb1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-backed-by-resizable-buffer.js @@ -0,0 +1,241 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set +description: > + SendableTypedArray.p.set behaves correctly on SendableTypedArrays backed by resizable buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function IsBigIntSendableTypedArray(ta) { + return ta instanceof BigInt64Array || ta instanceof BigUint64Array; +} + +function SetNumOrBigInt(target, source, offset) { + if (IsBigIntSendableTypedArray(target)) { + const bigIntSource = []; + for (const s of source) { + bigIntSource.push(BigInt(s)); + } + source = bigIntSource; + } + if (offset == undefined) { + return target.set(source); + } + return target.set(source, offset); +} + +for (let targetIsResizable of [ + false, + true + ]) { + for (let targetCtor of ctors) { + for (let sourceCtor of ctors) { + const rab = CreateResizableArrayBuffer(4 * sourceCtor.BYTES_PER_ELEMENT, 8 * sourceCtor.BYTES_PER_ELEMENT); + const fixedLength = new sourceCtor(rab, 0, 4); + const fixedLengthWithOffset = new sourceCtor(rab, 2 * sourceCtor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new sourceCtor(rab, 0); + const lengthTrackingWithOffset = new sourceCtor(rab, 2 * sourceCtor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taFull = new sourceCtor(rab); + for (let i = 0; i < 4; ++i) { + taFull[i] = MayNeedBigInt(taFull, i + 1); + } + + // Orig. array: [1, 2, 3, 4] + // [1, 2, 3, 4] << fixedLength + // [3, 4] << fixedLengthWithOffset + // [1, 2, 3, 4, ...] << lengthTracking + // [3, 4, ...] << lengthTrackingWithOffset + + const targetAb = targetIsResizable ? new ArrayBuffer(6 * targetCtor.BYTES_PER_ELEMENT) : new ArrayBuffer(6 * targetCtor.BYTES_PER_ELEMENT, { maxByteLength: 8 * targetCtor.BYTES_PER_ELEMENT }); + const target = new targetCtor(targetAb); + if (IsBigIntSendableTypedArray(target) != IsBigIntSendableTypedArray(taFull)) { + // Can't mix BigInt and non-BigInt types. + continue; + } + SetNumOrBigInt(target, fixedLength); + assert.compareArray(ToNumbers(target), [ + 1, + 2, + 3, + 4, + 0, + 0 + ]); + SetNumOrBigInt(target, fixedLengthWithOffset); + assert.compareArray(ToNumbers(target), [ + 3, + 4, + 3, + 4, + 0, + 0 + ]); + SetNumOrBigInt(target, lengthTracking, 1); + assert.compareArray(ToNumbers(target), [ + 3, + 1, + 2, + 3, + 4, + 0 + ]); + SetNumOrBigInt(target, lengthTrackingWithOffset, 1); + assert.compareArray(ToNumbers(target), [ + 3, + 3, + 4, + 3, + 4, + 0 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * sourceCtor.BYTES_PER_ELEMENT); + + // Orig. array: [1, 2, 3] + // [1, 2, 3, ...] << lengthTracking + // [3, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + SetNumOrBigInt(target, fixedLength); + }); + assert.throws(TypeError, () => { + SetNumOrBigInt(target, fixedLengthWithOffset); + }); + assert.compareArray(ToNumbers(target), [ + 3, + 3, + 4, + 3, + 4, + 0 + ]); + SetNumOrBigInt(target, lengthTracking); + assert.compareArray(ToNumbers(target), [ + 1, + 2, + 3, + 3, + 4, + 0 + ]); + SetNumOrBigInt(target, lengthTrackingWithOffset); + assert.compareArray(ToNumbers(target), [ + 3, + 2, + 3, + 3, + 4, + 0 + ]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * sourceCtor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + SetNumOrBigInt(target, fixedLength); + }); + assert.throws(TypeError, () => { + SetNumOrBigInt(target, fixedLengthWithOffset); + }); + assert.throws(TypeError, () => { + SetNumOrBigInt(target, lengthTrackingWithOffset); + }); + SetNumOrBigInt(target, lengthTracking, 3); + assert.compareArray(ToNumbers(target), [ + 3, + 2, + 3, + 1, + 4, + 0 + ]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + SetNumOrBigInt(target, fixedLength); + }); + assert.throws(TypeError, () => { + SetNumOrBigInt(target, fixedLengthWithOffset); + }); + assert.throws(TypeError, () => { + SetNumOrBigInt(target, lengthTrackingWithOffset); + }); + SetNumOrBigInt(target, lengthTracking, 4); + assert.compareArray(ToNumbers(target), [ + 3, + 2, + 3, + 1, + 4, + 0 + ]); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * sourceCtor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taFull[i] = MayNeedBigInt(taFull, i + 1); + } + + // Orig. array: [1, 2, 3, 4, 5, 6] + // [1, 2, 3, 4] << fixedLength + // [3, 4] << fixedLengthWithOffset + // [1, 2, 3, 4, 5, 6, ...] << lengthTracking + // [3, 4, 5, 6, ...] << lengthTrackingWithOffset + + SetNumOrBigInt(target, fixedLength); + assert.compareArray(ToNumbers(target), [ + 1, + 2, + 3, + 4, + 4, + 0 + ]); + SetNumOrBigInt(target, fixedLengthWithOffset); + assert.compareArray(ToNumbers(target), [ + 3, + 4, + 3, + 4, + 4, + 0 + ]); + SetNumOrBigInt(target, lengthTracking, 0); + assert.compareArray(ToNumbers(target), [ + 1, + 2, + 3, + 4, + 5, + 6 + ]); + SetNumOrBigInt(target, lengthTrackingWithOffset, 1); + assert.compareArray(ToNumbers(target), [ + 1, + 3, + 4, + 5, + 6, + 6 + ]); + } + } +} diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-byteoffset-internal.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-byteoffset-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..f718938a27846dd8e6e5fc2cb1ab28db29876edf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-byteoffset-internal.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Uses typedArray's internal [[ByteOffset]] +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 21. Let srcByteOffset be typedArray.[[ByteOffset]]. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "byteOffset", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42, 43]); + var differentTA = TA === Uint8Array ? Int8Array : Uint8Array; + var src2 = new differentTA([42, 43]); + var src3 = new differentTA(sample.buffer, 0, 2); + + Object.defineProperty(TA.prototype, "byteOffset", desc); + Object.defineProperty(src, "byteOffset", desc); + Object.defineProperty(src2, "byteOffset", desc); + Object.defineProperty(src3, "byteOffset", desc); + + sample.set(src); + sample.set(src2); + sample.set(src3); + + assert.sameValue(getCalls, 0, "ignores byteOffset properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js new file mode 100644 index 0000000000000000000000000000000000000000..a4c446732b8680d78bc860ba5616f92064ba72c2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + If srcLength + targetOffset > targetLength, throw a RangeError exception. +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 20. Let srcLength be the value of typedArray's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample, src; + + sample = new TA(2); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, 1); + }, "2 + 1 > 2"); + + sample = new TA(1); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, 0); + }, "2 + 0 > 1"); + + sample = new TA(1); + src = new TA(0); + assert.throws(RangeError, function() { + sample.set(src, 2); + }, "0 + 2 > 1"); + + sample = new TA(2); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, Infinity); + }, "2 + Infinity > 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9a8bba4483714e28c9671ebd3bb1f3cdde95a645 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Throws a TypeError if srcBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 11. Let srcBuffer be the value of typedArray's [[ViewedArrayBuffer]] internal + slot. + 12. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var target = new TA(); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(target.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set(target, obj); + }); + + assert.sameValue(calledOffset, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-target-arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-target-arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..870fb7bcfc8c0d164f695e71bd351e6888fe408c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-target-arraylength-internal.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + 2. Let target be the this value. + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42, 43]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.set(src); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-target-byteoffset-internal.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-target-byteoffset-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..90b79f25c4daebace0503ead02bd3b0a9e2103f8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-target-byteoffset-internal.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + 2. Let target be the this value. + ... + 16. Let targetByteOffset be target.[[ByteOffset]]. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "byteOffset", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA([42, 43]); + var differentTA = TA === Uint8Array ? Int8Array : Uint8Array; + var src2 = new differentTA([42, 43]); + var src3 = new differentTA(sample.buffer, 0, 2); + + Object.defineProperty(TA.prototype, "byteOffset", desc); + Object.defineProperty(sample, "byteOffset", desc); + + sample.set(src); + sample.set(src2); + sample.set(src3); + + assert.sameValue(getCalls, 0, "ignores byteoffset properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-target-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-target-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..f324949ce9c6ae2dc4a4d855fdf4b0734b722f8b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-target-out-of-bounds.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: Error when target SendableTypedArray fails boundary checks +includes: [sendableTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.set, + 'function', + 'implements SendableTypedArray.prototype.set' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 4}); + var target = new TA(ab, 0, 4); + var source = new TA(new ArrayBuffer(BPE * 4)); + + var expectedError; + try { + ab.resize(BPE * 3); + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the reverse operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + target.set(source, 0); + throw new Test262Error('The `set` operation completed successfully.'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..666376581fff3ebde0787db2bb41869462d5320f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/set/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.set-typedarray-offset +description: > + Throws a TypeError if targetBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.2 %SendableTypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA(1); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(sample.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set(src, obj); + }); + + assert.sameValue(calledOffset, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..6bdd03bc2e9240114812ceeb4704ae5fe35236c2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/arraylength-internal.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Use internal ArrayLength instead of getting a length property +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.slice(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(result[0], 42n); + assert.sameValue(result[1], 43n); + assert.sameValue(result.hasOwnProperty(2), false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js new file mode 100644 index 0000000000000000000000000000000000000000..a38e7534c9e859299754bfd9173fe8937593eb40 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached during create with custom constructor (other targetType) +info: | + %SendableTypedArray%.prototype.slice ( start, end ) + + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + + SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + SendableTypedArrayCreate ( constructor, argumentList ) + + Let newSendableTypedArray be ? Construct(constructor, argumentList). + Perform ? ValidateSendableTypedArray(newSendableTypedArray). + + ValidateSendableTypedArray ( O ) + The abstract operation ValidateSendableTypedArray takes argument O. It performs the following steps when called: + + Perform ? RequireInternalSlot(O, [[TypedArrayName]]). + Assert: O has a [[ViewedArrayBuffer]] internal slot. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + var sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + counter++; + $DETACHBUFFER(sample.buffer); + return new other(count); + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js new file mode 100644 index 0000000000000000000000000000000000000000..723f4eca227231cf15b1d8c123761ac9e371b330 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached during create with custom constructor. +info: | + %SendableTypedArray%.prototype.slice ( start, end ) + + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + + SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + SendableTypedArrayCreate ( constructor, argumentList ) + + Let newSendableTypedArray be ? Construct(constructor, argumentList). + Perform ? ValidateSendableTypedArray(newSendableTypedArray). + + ValidateSendableTypedArray ( O ) + The abstract operation ValidateSendableTypedArray takes argument O. It performs the following steps when called: + + Perform ? RequireInternalSlot(O, [[TypedArrayName]]). + Assert: O has a [[ViewedArrayBuffer]] internal slot. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + counter++; + $DETACHBUFFER(sample.buffer); + return new TA(count); + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..1d31d4a51ce3289beff582dd0333d4eeea9f13d1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached during Get custom constructor. +info: | + %SendableTypedArray%.prototype.slice ( start, end ) + + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + + SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + SendableTypedArrayCreate ( constructor, argumentList ) + + Let newSendableTypedArray be ? Construct(constructor, argumentList). + Perform ? ValidateSendableTypedArray(newSendableTypedArray). + + ValidateSendableTypedArray ( O ) + The abstract operation ValidateSendableTypedArray takes argument O. It performs the following steps when called: + + Perform ? RequireInternalSlot(O, [[TypedArrayName]]). + Assert: O has a [[ViewedArrayBuffer]] internal slot. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + Object.defineProperty(sample, "constructor", { + get() { + counter++; + $DETACHBUFFER(sample.buffer); + } + }); + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..bc18e14a582977ad21df98e63d1a5383d14577ca --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Throws a TypeError if buffer of object created by custom constructor is detached. +info: | + %SendableTypedArray%.prototype.slice ( start, end ) + + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + + SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + SendableTypedArrayCreate ( constructor, argumentList ) + + Let newSendableTypedArray be ? Construct(constructor, argumentList). + Perform ? ValidateSendableTypedArray(newSendableTypedArray). + + ValidateSendableTypedArray ( O ) + The abstract operation ValidateSendableTypedArray takes argument O. It performs the following steps when called: + + Perform ? RequireInternalSlot(O, [[TypedArrayName]]). + Assert: O has a [[ViewedArrayBuffer]] internal slot. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + let other = new TA(count); + counter++; + $DETACHBUFFER(other.buffer); + return other; + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.js new file mode 100644 index 0000000000000000000000000000000000000000..14027137080b2a6b2efae5377fe9f7314508cf80 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Does not throw a TypeError if buffer is detached on custom constructor and + count <= 0. Using other targetType. +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + If count > 0, then + ... + Return A + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + let sample, result, Other, other; + let ctor = {}; + ctor[Symbol.species] = function(count) { + counter++; + Other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + $DETACHBUFFER(sample.buffer); + other = new Other(count); + return other; + }; + + sample = new TA(0); + sample.constructor = ctor; + result = sample.slice(); + assert.sameValue(result.length, 0, 'The value of result.length is 0'); + assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`'); + assert.sameValue(result.constructor, Other, 'The value of result.constructor is expected to equal the value of Other'); + assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other'); + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + + sample = new TA(4); + sample.constructor = ctor; + sample.slice(1, 1); // count = 0; + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js new file mode 100644 index 0000000000000000000000000000000000000000..4019654e39a8433cedf2789ecb5a170b9dfd0424 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Does not throw a TypeError if buffer is detached on custom constructor and + count <= 0. Using same targetType. +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + If count > 0, then + ... + Return A +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + let sample, result, other; + let ctor = {}; + ctor[Symbol.species] = function(count) { + counter++; + $DETACHBUFFER(sample.buffer); + other = new TA(count); + return other; + }; + + sample = new TA(0); + sample.constructor = ctor; + result = sample.slice(); + assert.sameValue(result.length, 0, 'The value of result.length is 0'); + assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`'); + assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other'); + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + + sample = new TA(4); + sample.constructor = ctor; + result = sample.slice(1, 1); // count = 0; + assert.sameValue(result.length, 0, 'The value of result.length is 0'); + assert.notSameValue( + result.buffer, + sample.buffer, + 'The value of result.buffer is expected to not equal the value of `sample.buffer`' + ); + assert.sameValue(result.constructor, TA, 'The value of result.constructor is expected to equal the value of TA'); + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f2a9ad9cbd8ba6a8b1ea7f0c2a2fdb5be342409c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/detached-buffer.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.slice(obj, obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/infinity.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..0fe15fc7b32e3a9d520d29c5b3263603be89dd7d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/infinity.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Infinity values on start and end +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert( + compareArray(sample.slice(-Infinity), [40n, 41n, 42n, 43n]), + "start == -Infinity" + ); + assert( + compareArray(sample.slice(Infinity), []), + "start == Infinity" + ); + assert( + compareArray(sample.slice(0, -Infinity), []), + "end == -Infinity" + ); + assert( + compareArray(sample.slice(0, Infinity), [40n, 41n, 42n, 43n]), + "end == Infinity" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/minus-zero.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/minus-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..46349f191205a9ff9b7777610aeac4631e690764 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/minus-zero.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: -0 values on start and end +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert( + compareArray(sample.slice(-0), [40n, 41n, 42n, 43n]), + "start == -0" + ); + assert( + compareArray(sample.slice(-0, 4), [40n, 41n, 42n, 43n]), + "start == -0, end == length" + ); + assert( + compareArray(sample.slice(0, -0), []), + "start == 0, end == -0" + ); + assert( + compareArray(sample.slice(-0, -0), []), + "start == -0, end == -0" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/result-does-not-copy-ordinary-properties.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/result-does-not-copy-ordinary-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..5fe2a37c50b1f4b817f93c6eb9916b217f920a0a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/result-does-not-copy-ordinary-properties.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Result does not import own properties +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice( start , end ) +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([41n, 42n, 43n, 44n]); + sample.foo = 42; + + var result = sample.slice(); + assert.sameValue( + result.hasOwnProperty("foo"), + false, + "does not import own property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/results-with-different-length.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/results-with-different-length.js new file mode 100644 index 0000000000000000000000000000000000000000..9fbe1c25170791173609262ac5b0a28e4fc1cc38 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/results-with-different-length.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: slice may return a new instance with a smaller length +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + function testRes(result, expected, msg) { + assert(compareArray(result, expected), msg + ", result: [" + result + "]"); + } + + testRes(sample.slice(1), [41n, 42n, 43n], "begin == 1"); + testRes(sample.slice(2), [42n, 43n], "begin == 2"); + testRes(sample.slice(3), [43n], "begin == 3"); + + testRes(sample.slice(1, 4), [41n, 42n, 43n], "begin == 1, end == length"); + testRes(sample.slice(2, 4), [42n, 43n], "begin == 2, end == length"); + testRes(sample.slice(3, 4), [43n], "begin == 3, end == length"); + + testRes(sample.slice(0, 1), [40n], "begin == 0, end == 1"); + testRes(sample.slice(0, 2), [40n, 41n], "begin == 0, end == 2"); + testRes(sample.slice(0, 3), [40n, 41n, 42n], "begin == 0, end == 3"); + + testRes(sample.slice(-1), [43n], "begin == -1"); + testRes(sample.slice(-2), [42n, 43n], "begin == -2"); + testRes(sample.slice(-3), [41n, 42n, 43n], "begin == -3"); + + testRes(sample.slice(-1, 4), [43n], "begin == -1, end == length"); + testRes(sample.slice(-2, 4), [42n, 43n], "begin == -2, end == length"); + testRes(sample.slice(-3, 4), [41n, 42n, 43n], "begin == -3, end == length"); + + testRes(sample.slice(0, -1), [40n, 41n, 42n], "begin == 0, end == -1"); + testRes(sample.slice(0, -2), [40n, 41n], "begin == 0, end == -2"); + testRes(sample.slice(0, -3), [40n], "begin == 0, end == -3"); + + testRes(sample.slice(-0, -1), [40n, 41n, 42n], "begin == -0, end == -1"); + testRes(sample.slice(-0, -2), [40n, 41n], "begin == -0, end == -2"); + testRes(sample.slice(-0, -3), [40n], "begin == -0, end == -3"); + + testRes(sample.slice(-2, -1), [42n], "length == 4, begin == -2, end == -1"); + testRes(sample.slice(1, -1), [41n, 42n], "length == 4, begin == 1, end == -1"); + testRes(sample.slice(1, -2), [41n], "length == 4, begin == 1, end == -2"); + testRes(sample.slice(2, -1), [42n], "length == 4, begin == 2, end == -1"); + + testRes(sample.slice(-1, 5), [43n], "begin == -1, end > length"); + testRes(sample.slice(-2, 4), [42n, 43n], "begin == -2, end > length"); + testRes(sample.slice(-3, 4), [41n, 42n, 43n], "begin == -3, end > length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/results-with-empty-length.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/results-with-empty-length.js new file mode 100644 index 0000000000000000000000000000000000000000..82527e556b686576cfd79476b35a7226e510e7b8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/results-with-empty-length.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: slice may return a new empty instance +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + function testRes(result, msg) { + assert.sameValue(result.length, 0, msg); + assert.sameValue( + result.hasOwnProperty(0), + false, + msg + " & result.hasOwnProperty(0) === false" + ); + } + + testRes(sample.slice(4), "begin == length"); + testRes(sample.slice(5), "begin > length"); + + testRes(sample.slice(4, 4), "begin == length, end == length"); + testRes(sample.slice(5, 4), "begin > length, end == length"); + + testRes(sample.slice(4, 5), "begin == length, end > length"); + testRes(sample.slice(5, 5), "begin > length, end > length"); + + testRes(sample.slice(0, 0), "begin == 0, end == 0"); + testRes(sample.slice(-0, -0), "begin == -0, end == -0"); + testRes(sample.slice(1, 0), "begin > 0, end == 0"); + testRes(sample.slice(-1, 0), "being < 0, end == 0"); + + testRes(sample.slice(2, 1), "begin > 0, begin < length, begin > end, end > 0"); + testRes(sample.slice(2, 2), "begin > 0, begin < length, begin == end"); + + testRes(sample.slice(2, -2), "begin > 0, begin < length, end == -2"); + + testRes(sample.slice(-1, -1), "length = 4, begin == -1, end == -1"); + testRes(sample.slice(-1, -2), "length = 4, begin == -1, end == -2"); + testRes(sample.slice(-2, -2), "length = 4, begin == -2, end == -2"); + + testRes(sample.slice(0, -4), "begin == 0, end == -length"); + testRes(sample.slice(-4, -4), "begin == -length, end == -length"); + testRes(sample.slice(-5, -4), "begin < -length, end == -length"); + + testRes(sample.slice(0, -5), "begin == 0, end < -length"); + testRes(sample.slice(-4, -5), "begin == -length, end < -length"); + testRes(sample.slice(-5, -5), "begin < -length, end < -length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/results-with-same-length.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/results-with-same-length.js new file mode 100644 index 0000000000000000000000000000000000000000..d6a8999d704f845c9637c813b04a7b4dbabba66c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/results-with-same-length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: slice may return a new instance with the same length +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + function testRes(result, msg) { + assert.sameValue(result.length, 4, msg); + assert.sameValue(result[0], 40n, msg + " & result[0] === 40"); + assert.sameValue(result[1], 41n, msg + " & result[1] === 41"); + assert.sameValue(result[2], 42n, msg + " & result[2] === 42"); + assert.sameValue(result[3], 43n, msg + " & result[3] === 43"); + } + + testRes(sample.slice(0), "begin == 0"); + testRes(sample.slice(-4), "begin == -srcLength"); + testRes(sample.slice(-5), "begin < -srcLength"); + + testRes(sample.slice(0, 4), "begin == 0, end == srcLength"); + testRes(sample.slice(-4, 4), "begin == -srcLength, end == srcLength"); + testRes(sample.slice(-5, 4), "begin < -srcLength, end == srcLength"); + + testRes(sample.slice(0, 5), "begin == 0, end > srcLength"); + testRes(sample.slice(-4, 5), "begin == -srcLength, end > srcLength"); + testRes(sample.slice(-5, 5), "begin < -srcLength, end > srcLength"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end-symbol.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..7984e8fa15262f1d94d1de23e04cc6647c1eee09 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end-symbol.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt from ToInteger(end), end is symbol +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 6. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.slice(0, s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end.js new file mode 100644 index 0000000000000000000000000000000000000000..1c5a22db0ee6f4cedd15c789d66c9bb9366b8a2c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt from ToInteger(end) +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 6. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.slice(0, o1); + }); + + assert.throws(Test262Error, function() { + sample.slice(0, o2); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start-symbol.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..515112611818a84c71cd9596b3c98a2b500cceda --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start-symbol.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt from ToInteger(start), start is symbol +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.slice(s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start.js new file mode 100644 index 0000000000000000000000000000000000000000..6733e406e3c33e41940da76b7f57c8205b8a1cd7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt from ToInteger(start) +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.slice(o1); + }); + + assert.throws(Test262Error, function() { + sample.slice(o2); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..8a8a9532cdc92ecbf5f4ead192f6f3de59fcd82d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.slice, + 'function', + 'implements SendableTypedArray.prototype.slice' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.slice(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.slice(0); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the slice operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.slice(0); + throw new Test262Error('slice completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/set-values-from-different-ctor-type.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/set-values-from-different-ctor-type.js new file mode 100644 index 0000000000000000000000000000000000000000..dd6389d1e36152ec31795e71157f2ea5d21503e8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/set-values-from-different-ctor-type.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Perform regular set if target's uses a different element type +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + 10. Let srcName be the String value of O's [[TypedArrayName]] internal slot. + 11. Let srcType be the String value of the Element Type value in Table 50 for + srcName. + 12. Let targetName be the String value of A's [[TypedArrayName]] internal + slot. + 13. Let targetType be the String value of the Element Type value in Table 50 + for targetName. + 14. If SameValue(srcType, targetType) is false, then + a. Let n be 0. + b. Repeat, while k < final + i. Let Pk be ! ToString(k). + ii. Let kValue be ? Get(O, Pk). + iii. Perform ? Set(A, ! ToString(n), kValue, true). + iv. Increase k by 1. + v. Increase n by 1. + ... + 16. Return A +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +var arr = [42n, 43n, 44n]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(arr); + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + + sample.constructor = {}; + sample.constructor[Symbol.species] = other; + + var result = sample.slice(); + + assert(compareArray(result, arr), "values are set"); + assert.notSameValue(result.buffer, sample.buffer, "creates a new buffer"); + assert.sameValue(result.constructor, other, "used the custom ctor"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-destination-resizable.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-destination-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..77084761c3adf63418301cdce72384e0e7c9b418 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-destination-resizable.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws a TypeError if new typedArray's length < count +info: | + 23.2.3.27 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + const rab1 = new ArrayBuffer(8, {maxByteLength: 100}); + const ta = new TA(rab1); + const rab2 = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab2); + rab2.resize(0); + ta.constructor = { [Symbol.species]: function() { return lengthTracking; } }; + assert.throws(TypeError, function() { + ta.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-abrupt.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..563916cd33ebd31254084cbcb90d762b0526fd35 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-inherited.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000000000000000000000000000000000..7380e2346181be89f6dab26b5c0fa139089d915f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-inherited.js @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var calls = 0; + var result; + + Object.defineProperty(TA.prototype, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.slice(); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + undefined, + "used defaultCtor but still checks the inherited .constructor" + ); + + calls = 6; + result.constructor; + assert.sameValue( + calls, + 7, + "result.constructor triggers the inherited accessor property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..7702ca871fc46285aa4254356d5949cd9aab8e66 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.slice(); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.slice(); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.slice(); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.slice(); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.slice(); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.slice(); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..c23341329d0f58c97d6eda52872933800661ef80 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: get constructor on SpeciesConstructor +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var calls = 0; + var result; + + Object.defineProperty(sample, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.slice(); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + TA, + "use defaultCtor on an undefined return - .constructor check" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-abrupt.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..034356445661ff32a3673555ec8db1edafd47eaf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-abrupt.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-invocation.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000000000000000000000000000000000..605229919337d15855ead570b6513ca6d916ca29 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + result = arguments; + ctorThis = this; + return new TA(count); + }; + + sample.slice(1); + + assert.sameValue(result.length, 1, "called with 1 arguments"); + assert.sameValue(result[0], 2, "[0] is the new length count"); + + assert( + ctorThis instanceof sample.constructor[Symbol.species], + "`this` value in the @@species fn is an instance of the function itself" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..0410ef9c0a7fdb5ed986d6a2b3fbe07ee27d0566 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws a TypeError if new typedArray's length < count +info: | + 23.2.3.27 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + + +testWithBigIntTypedArrayConstructors(function(TA) { + const sample = new TA(2); + const rab = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab); + rab.resize(0); + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return lengthTracking; + }; + assert.throws(TypeError, function() { + sample.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..6c4845ef4d5851a6ae247b96418c13dd753c2612 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws a TypeError if new typedArray's length < count +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(); + }; + + assert.throws(TypeError, function() { + sample.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length.js new file mode 100644 index 0000000000000000000000000000000000000000..dc8760ed1b9fab72d46f6795f18f8f9d62ded05d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Does not throw a TypeError if new typedArray's length >= count +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var customCount, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(customCount); + }; + + customCount = 2; + result = sample.slice(); + assert.sameValue(result.length, customCount, "length == count"); + + customCount = 5; + result = sample.slice(); + assert.sameValue(result.length, customCount, "length > count"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..216b9f4f07c5289202b220a7d93b144a871f8d84 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Custom @@species constructor may return a totally different SendableTypedArray +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n]); + var other = new BigInt64Array([1n, 0n, 1n]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.slice(0, 0); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [1n, 0n, 1n]), "the returned object is preserved"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-throws.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..f3a04cd369f455362671e15c690669d912a1cdd5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var ctor = function() {}; + + sample.constructor = {}; + sample.constructor[Symbol.species] = ctor; + + assert.throws(TypeError, function() { + sample.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..ab0b9bd52f058e27badad07dc90115d641d8dc0c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Use custom @@species constructor if available +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + var calls = 0; + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + calls++; + return new TA(count); + }; + + result = sample.slice(1); + + assert.sameValue(calls, 1, "ctor called once"); + assert(compareArray(result, [41n, 42n]), "expected object"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..aac6248690302748accced052b94b084bed09075 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-returns-throws.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + sample.constructor[Symbol.species] = 0; + assert.throws(TypeError, function() { + sample.slice(); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.slice(); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.slice(); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.slice(); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.slice(); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.slice(); + }, "true"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-use-default-ctor.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..fbb037b828482fa9d4849be4c5809be997734a63 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var result; + + sample.constructor = {}; + + result = sample.slice(); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "undefined @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "undefined @@species - ctor check"); + + sample.constructor[Symbol.species] = null; + result = sample.slice(); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "null @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "null @@species - ctor check"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species.js new file mode 100644 index 0000000000000000000000000000000000000000..75e17ad6fb3acdfba121ff7554a101edfeb330a9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/speciesctor-get-species.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + get @@species from found constructor +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calls = 0; + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + calls++; + } + }); + + sample.slice(); + + assert.sameValue(calls, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/tointeger-end.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/tointeger-end.js new file mode 100644 index 0000000000000000000000000000000000000000..b9101a22ef02a9416fdc7a42579fc9018d27d7b3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/tointeger-end.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: ToInteger(end) +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice( start , end ) + + ... + 6. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert(compareArray(sample.slice(0, false), []), "false"); + assert(compareArray(sample.slice(0, true), [40n]), "true"); + + assert(compareArray(sample.slice(0, NaN), []), "NaN"); + assert(compareArray(sample.slice(0, null), []), "null"); + assert(compareArray(sample.slice(0, undefined), [40n, 41n, 42n, 43n]), "undefined"); + + assert(compareArray(sample.slice(0, 0.6), []), "0.6"); + assert(compareArray(sample.slice(0, 1.1), [40n]), "1.1"); + assert(compareArray(sample.slice(0, 1.5), [40n]), "1.5"); + assert(compareArray(sample.slice(0, -0.6), []), "-0.6"); + assert(compareArray(sample.slice(0, -1.1), [40n, 41n, 42n]), "-1.1"); + assert(compareArray(sample.slice(0, -1.5), [40n, 41n, 42n]), "-1.5"); + + assert(compareArray(sample.slice(0, "3"), [40n, 41n, 42n]), "string"); + assert( + compareArray( + sample.slice(0, obj), + [40n, 41n] + ), + "object" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/BigInt/tointeger-start.js b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/tointeger-start.js new file mode 100644 index 0000000000000000000000000000000000000000..126ec0d22604a055759259493fb40be58246c0b2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/BigInt/tointeger-start.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: ToInteger(begin) +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert(compareArray(sample.slice(false), [40n, 41n, 42n, 43n]), "false"); + assert(compareArray(sample.slice(true), [41n, 42n, 43n]), "true"); + + assert(compareArray(sample.slice(NaN), [40n, 41n, 42n, 43n]), "NaN"); + assert(compareArray(sample.slice(null), [40n, 41n, 42n, 43n]), "null"); + assert(compareArray(sample.slice(undefined), [40n, 41n, 42n, 43n]), "undefined"); + + assert(compareArray(sample.slice(1.1), [41n, 42n, 43n]), "1.1"); + assert(compareArray(sample.slice(1.5), [41n, 42n, 43n]), "1.5"); + assert(compareArray(sample.slice(0.6), [40n, 41n, 42n, 43n]), "0.6"); + + assert(compareArray(sample.slice(-1.5), [43n]), "-1.5"); + assert(compareArray(sample.slice(-1.1), [43n]), "-1.1"); + assert(compareArray(sample.slice(-0.6), [40n, 41n, 42n, 43n]), "-0.6"); + + assert(compareArray(sample.slice("3"), [43n]), "string"); + assert( + compareArray( + sample.slice(obj), + [42n, 43n] + ), + "object" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/slice/arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..22739719ca2358e02f30f9f33065504eb59196ea --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/arraylength-internal.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Use internal ArrayLength instead of getting a length property +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.slice(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 43); + assert.sameValue(result.hasOwnProperty(2), false); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/bit-precision.js b/test/sendable/builtins/TypedArray/prototype/slice/bit-precision.js new file mode 100644 index 0000000000000000000000000000000000000000..62ce3203c75d26e91e5cfe8f3d6bacfa64b2c444 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/bit-precision.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Preservation of bit-level encoding +info: | + [...] + 15. Else if count > 0, then + [...] + e. NOTE: If srcType and targetType are the same, the transfer must be + performed in a manner that preserves the bit-level encoding of the + source data. + f. Let srcByteOffet be the value of O's [[ByteOffset]] internal slot. + g. Let targetByteIndex be A's [[ByteOffset]] internal slot. + h. Let srcByteIndex be (k × elementSize) + srcByteOffet. + i. Let limit be targetByteIndex + count × elementSize. + j. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). + iii. Increase srcByteIndex by 1. + iv. Increase targetByteIndex by 1. +includes: [nans.js, compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +function body(FloatArray) { + var subject = new FloatArray(NaNs); + var sliced, subjectBytes, slicedBytes; + + sliced = subject.slice(); + + subjectBytes = new Uint8Array(subject.buffer); + slicedBytes = new Uint8Array(sliced.buffer); + + assert(compareArray(subjectBytes, slicedBytes)); +} + +testWithTypedArrayConstructors(body, floatArrayConstructors); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/coerced-start-end-grow.js b/test/sendable/builtins/TypedArray/prototype/slice/coerced-start-end-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..ae0228b3b3796a3a6005791a0fa0b2dd2b3518be --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/coerced-start-end-grow.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + SendableTypedArray.p.slice behaves correctly on SendableTypedArrays backed by resizable buffers + that is grown by argument coercion. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// The start argument grows the resizable array buffer rab. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i + 1); + } + const evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.compareArray(ToNumbers(lengthTracking.slice(evil)), [ + 1, + 2, + 3, + 4 + ]); + assert.sameValue(rab.byteLength, 6 * ctor.BYTES_PER_ELEMENT); +} + +// The end argument grows the resizable array buffer rab. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i + 1); + } + const evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return 5; + } + }; + assert.compareArray(ToNumbers(lengthTracking.slice(4,evil)), [ + ]); + assert.compareArray(ToNumbers(lengthTracking.slice(3,evil)), [ + 4, + 0 + ]); + assert.sameValue(rab.byteLength, 6 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/slice/coerced-start-end-shrink.js b/test/sendable/builtins/TypedArray/prototype/slice/coerced-start-end-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..39eb4c19617207072848798a9a0592286756aae4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/coerced-start-end-shrink.js @@ -0,0 +1,98 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + SendableTypedArray.p.slice behaves correctly on SendableTypedArrays backed by resizable buffers + that are shrunk by argument coercion. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// The start argument shrinks the resizable array buffer rab. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.throws(TypeError, () => { + fixedLength.slice(evil); + }); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i + 1); + } + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.compareArray(ToNumbers(lengthTracking.slice(evil)), [ + 1, + 2, + 0, + 0 + ]); + assert.compareArray(ToNumbers(lengthTracking.slice(evil)), [ + 1, + 2 + ]); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); +} + +// The end argument shrinks the resizable array buffer rab. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 5; + } + }; + assert.throws(TypeError, () => { + fixedLength.slice(1, evil); + }); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + for (let i = 0; i < 4; ++i) { + lengthTracking[i] = MayNeedBigInt(lengthTracking, i + 1); + } + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 5; + } + }; + assert.compareArray(ToNumbers(lengthTracking.slice(1,evil)), [ + 2, + 0, + 0 + ]); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-custom-ctor-other-targettype.js b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-custom-ctor-other-targettype.js new file mode 100644 index 0000000000000000000000000000000000000000..34cf1455d51188482faceda4da2ec6d2bc922158 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-custom-ctor-other-targettype.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached. Using other + targetType +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + If count > 0, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + var sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + var other = TA === Int8Array ? Int16Array : Int8Array; + counter++; + $DETACHBUFFER(sample.buffer); + return new other(count); + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-custom-ctor-same-targettype.js b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-custom-ctor-same-targettype.js new file mode 100644 index 0000000000000000000000000000000000000000..1016e46e08b4e2f4375ee3a5e61cb4bf668491b1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-custom-ctor-same-targettype.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached on Get custom constructor. +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + If count > 0, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + counter++; + $DETACHBUFFER(sample.buffer); + return new TA(count); + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-get-ctor.js b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-get-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..d5ebf57121d55d9edb40f07e83da160c4933fb0e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-get-ctor.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached. +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + If count > 0, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + Object.defineProperty(sample, "constructor", { + get() { + counter++; + $DETACHBUFFER(sample.buffer); + } + }); + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-speciesctor-get-species-custom-ctor-throws.js b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..89e0003791af860cd9b34b2c18383b8e6d291351 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Throws a TypeError if buffer of object created by custom constructor is detached. +info: | + %SendableTypedArray%.prototype.slice ( start, end ) + + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + + SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + SendableTypedArrayCreate ( constructor, argumentList ) + + Let newSendableTypedArray be ? Construct(constructor, argumentList). + Perform ? ValidateSendableTypedArray(newSendableTypedArray). + + ValidateSendableTypedArray ( O ) + The abstract operation ValidateSendableTypedArray takes argument O. It performs the following steps when called: + + Perform ? RequireInternalSlot(O, [[TypedArrayName]]). + Assert: O has a [[ViewedArrayBuffer]] internal slot. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + let other = new TA(count); + counter++; + $DETACHBUFFER(other.buffer); + return other; + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-other-targettype.js b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-other-targettype.js new file mode 100644 index 0000000000000000000000000000000000000000..3086326f02777ed9ad4d93381a560b388d4d42d7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-other-targettype.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Does not throw a TypeError if buffer is detached on custom constructor and + count <= 0. Using other targetType. +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + If count > 0, then + ... + Return A + +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let sample, result, Other, other; + let ctor = {}; + ctor[Symbol.species] = function(count) { + counter++; + Other = TA === Int16Array ? Int8Array : Int16Array; + $DETACHBUFFER(sample.buffer); + other = new Other(count); + return other; + }; + + sample = new TA(0); + sample.constructor = ctor; + result = sample.slice(); + assert.sameValue(result.length, 0, 'The value of result.length is 0'); + assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`'); + assert.sameValue(result.constructor, Other, 'The value of result.constructor is expected to equal the value of Other'); + assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other'); + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + + sample = new TA(4); + sample.constructor = ctor; + sample.slice(1, 1); // count = 0; + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-same-targettype.js b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-same-targettype.js new file mode 100644 index 0000000000000000000000000000000000000000..0c40fd72ed7a3e9ae23a020634da731fee4c1f99 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-same-targettype.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Does not throw a TypeError if buffer is detached on custom constructor and + count <= 0. Using other targetType. +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + If count > 0, then + ... + Return A +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let sample, result, other; + let ctor = {}; + ctor[Symbol.species] = function(count) { + counter++; + $DETACHBUFFER(sample.buffer); + other = new TA(count); + return other; + }; + + sample = new TA(0); + sample.constructor = ctor; + result = sample.slice(); + assert.sameValue(result.length, 0, 'The value of result.length is 0'); + assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`'); + assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other'); + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + + sample = new TA(4); + sample.constructor = ctor; + sample.slice(1, 1); // count = 0; + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..399e98022193960c39fb0044b63bc408bba70251 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/detached-buffer.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.slice(obj, obj); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/infinity.js b/test/sendable/builtins/TypedArray/prototype/slice/infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..65c085f657c650c9cb3655a7dc7ee59e0d355919 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/infinity.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Infinity values on start and end +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert( + compareArray(sample.slice(-Infinity), [40, 41, 42, 43]), + "start == -Infinity" + ); + assert( + compareArray(sample.slice(Infinity), []), + "start == Infinity" + ); + assert( + compareArray(sample.slice(0, -Infinity), []), + "end == -Infinity" + ); + assert( + compareArray(sample.slice(0, Infinity), [40, 41, 42, 43]), + "end == Infinity" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/slice/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..6565d471a5fa263e124ec418e08c25d9219452be --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/invoked-as-func.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.23 %SendableTypedArray%.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var slice = SendableTypedArray.prototype.slice; + +assert.sameValue(typeof slice, 'function'); + +assert.throws(TypeError, function() { + slice(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/slice/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..9650e64144ee3d5375ac40ca186f446e75704f3a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/invoked-as-method.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.23 %SendableTypedArray%.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.slice, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.slice(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/length.js b/test/sendable/builtins/TypedArray/prototype/slice/length.js new file mode 100644 index 0000000000000000000000000000000000000000..bda5cbee56935b7e24d6e9383bd7bb9bef31e569 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + %SendableTypedArray%.prototype.slice.length is 2. +info: | + %SendableTypedArray%.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.slice, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/minus-zero.js b/test/sendable/builtins/TypedArray/prototype/slice/minus-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..40f2a74416380d2fae6d69e5756b1a21d5016554 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/minus-zero.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: -0 values on start and end +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert( + compareArray(sample.slice(-0), [40, 41, 42, 43]), + "start == -0" + ); + assert( + compareArray(sample.slice(-0, 4), [40, 41, 42, 43]), + "start == -0, end == length" + ); + assert( + compareArray(sample.slice(0, -0), []), + "start == 0, end == -0" + ); + assert( + compareArray(sample.slice(-0, -0), []), + "start == -0, end == -0" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/name.js b/test/sendable/builtins/TypedArray/prototype/slice/name.js new file mode 100644 index 0000000000000000000000000000000000000000..f9712999a47028eac208a27638957689f8a9d3fc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + %SendableTypedArray%.prototype.slice.name is "slice". +info: | + %SendableTypedArray%.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.slice, "name", { + value: "slice", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/slice/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..37b7d63277aefa18b36106f62b52595e254e275b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.slice does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.slice), + false, + 'isConstructor(SendableTypedArray.prototype.slice) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.slice(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/slice/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/slice/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..9a33854bde27dea9e29203e7bed434d1b956111c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + "slice" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'slice', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/slice/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..76c02f9f91219f6c6facfb72287e1ecf34b2dd33 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/resizable-buffer.js @@ -0,0 +1,156 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + SendableTypedArray.p.slice behaves correctly on SendableTypedArrays backed by resizable + buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, i); + } + const fixedLengthSlice = fixedLength.slice(); + assert.compareArray(ToNumbers(fixedLengthSlice), [ + 0, + 1, + 2, + 3 + ]); + assert(!fixedLengthSlice.buffer.resizable); + const fixedLengthWithOffsetSlice = fixedLengthWithOffset.slice(); + assert.compareArray(ToNumbers(fixedLengthWithOffsetSlice), [ + 2, + 3 + ]); + assert(!fixedLengthWithOffsetSlice.buffer.resizable); + const lengthTrackingSlice = lengthTracking.slice(); + assert.compareArray(ToNumbers(lengthTrackingSlice), [ + 0, + 1, + 2, + 3 + ]); + assert(!lengthTrackingSlice.buffer.resizable); + const lengthTrackingWithOffsetSlice = lengthTrackingWithOffset.slice(); + assert.compareArray(ToNumbers(lengthTrackingWithOffsetSlice), [ + 2, + 3 + ]); + assert(!lengthTrackingWithOffsetSlice.buffer.resizable); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.slice(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.slice(); + }); + assert.compareArray(ToNumbers(lengthTracking.slice()), [ + 0, + 1, + 2 + ]); + assert.compareArray(ToNumbers(lengthTrackingWithOffset.slice()), [2]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.slice(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.slice(); + }); + assert.compareArray(ToNumbers(lengthTracking.slice()), [0]); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.slice(); + }); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.slice(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.slice(); + }); + assert.compareArray(ToNumbers(lengthTracking.slice()), []); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.slice(); + }); + + // Verify that the previously created slices aren't affected by the + // shrinking. + assert.compareArray(ToNumbers(fixedLengthSlice), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(ToNumbers(fixedLengthWithOffsetSlice), [ + 2, + 3 + ]); + assert.compareArray(ToNumbers(lengthTrackingSlice), [ + 0, + 1, + 2, + 3 + ]); + assert.compareArray(ToNumbers(lengthTrackingWithOffsetSlice), [ + 2, + 3 + ]); + + // Grow so that all TAs are back in-bounds. New memory is zeroed. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ToNumbers(fixedLength.slice()), [ + 0, + 0, + 0, + 0 + ]); + assert.compareArray(ToNumbers(fixedLengthWithOffset.slice()), [ + 0, + 0 + ]); + assert.compareArray(ToNumbers(lengthTracking.slice()), [ + 0, + 0, + 0, + 0, + 0, + 0 + ]); + assert.compareArray(ToNumbers(lengthTrackingWithOffset.slice()), [ + 0, + 0, + 0, + 0 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/slice/result-does-not-copy-ordinary-properties.js b/test/sendable/builtins/TypedArray/prototype/slice/result-does-not-copy-ordinary-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..4d4c1b8777298b15d1898a44133d028938fccbf3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/result-does-not-copy-ordinary-properties.js @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Result does not import own properties +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice( start , end ) +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([41, 42, 43, 44]); + sample.foo = 42; + + var result = sample.slice(); + assert.sameValue( + result.hasOwnProperty("foo"), + false, + "does not import own property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/results-with-different-length.js b/test/sendable/builtins/TypedArray/prototype/slice/results-with-different-length.js new file mode 100644 index 0000000000000000000000000000000000000000..76ef76b675ae592f20be1c8d518e9facaef3dc9b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/results-with-different-length.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: slice may return a new instance with a smaller length +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + function testRes(result, expected, msg) { + assert(compareArray(result, expected), msg + ", result: [" + result + "]"); + } + + testRes(sample.slice(1), [41, 42, 43], "begin == 1"); + testRes(sample.slice(2), [42, 43], "begin == 2"); + testRes(sample.slice(3), [43], "begin == 3"); + + testRes(sample.slice(1, 4), [41, 42, 43], "begin == 1, end == length"); + testRes(sample.slice(2, 4), [42, 43], "begin == 2, end == length"); + testRes(sample.slice(3, 4), [43], "begin == 3, end == length"); + + testRes(sample.slice(0, 1), [40], "begin == 0, end == 1"); + testRes(sample.slice(0, 2), [40, 41], "begin == 0, end == 2"); + testRes(sample.slice(0, 3), [40, 41, 42], "begin == 0, end == 3"); + + testRes(sample.slice(-1), [43], "begin == -1"); + testRes(sample.slice(-2), [42, 43], "begin == -2"); + testRes(sample.slice(-3), [41, 42, 43], "begin == -3"); + + testRes(sample.slice(-1, 4), [43], "begin == -1, end == length"); + testRes(sample.slice(-2, 4), [42, 43], "begin == -2, end == length"); + testRes(sample.slice(-3, 4), [41, 42, 43], "begin == -3, end == length"); + + testRes(sample.slice(0, -1), [40, 41, 42], "begin == 0, end == -1"); + testRes(sample.slice(0, -2), [40, 41], "begin == 0, end == -2"); + testRes(sample.slice(0, -3), [40], "begin == 0, end == -3"); + + testRes(sample.slice(-0, -1), [40, 41, 42], "begin == -0, end == -1"); + testRes(sample.slice(-0, -2), [40, 41], "begin == -0, end == -2"); + testRes(sample.slice(-0, -3), [40], "begin == -0, end == -3"); + + testRes(sample.slice(-2, -1), [42], "length == 4, begin == -2, end == -1"); + testRes(sample.slice(1, -1), [41, 42], "length == 4, begin == 1, end == -1"); + testRes(sample.slice(1, -2), [41], "length == 4, begin == 1, end == -2"); + testRes(sample.slice(2, -1), [42], "length == 4, begin == 2, end == -1"); + + testRes(sample.slice(-1, 5), [43], "begin == -1, end > length"); + testRes(sample.slice(-2, 4), [42, 43], "begin == -2, end > length"); + testRes(sample.slice(-3, 4), [41, 42, 43], "begin == -3, end > length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/results-with-empty-length.js b/test/sendable/builtins/TypedArray/prototype/slice/results-with-empty-length.js new file mode 100644 index 0000000000000000000000000000000000000000..08de1fc1fef6ad6982b88bd376695aac5f72ae09 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/results-with-empty-length.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: slice may return a new empty instance +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + function testRes(result, msg) { + assert.sameValue(result.length, 0, msg); + assert.sameValue( + result.hasOwnProperty(0), + false, + msg + " & result.hasOwnProperty(0) === false" + ); + } + + testRes(sample.slice(4), "begin == length"); + testRes(sample.slice(5), "begin > length"); + + testRes(sample.slice(4, 4), "begin == length, end == length"); + testRes(sample.slice(5, 4), "begin > length, end == length"); + + testRes(sample.slice(4, 5), "begin == length, end > length"); + testRes(sample.slice(5, 5), "begin > length, end > length"); + + testRes(sample.slice(0, 0), "begin == 0, end == 0"); + testRes(sample.slice(-0, -0), "begin == -0, end == -0"); + testRes(sample.slice(1, 0), "begin > 0, end == 0"); + testRes(sample.slice(-1, 0), "being < 0, end == 0"); + + testRes(sample.slice(2, 1), "begin > 0, begin < length, begin > end, end > 0"); + testRes(sample.slice(2, 2), "begin > 0, begin < length, begin == end"); + + testRes(sample.slice(2, -2), "begin > 0, begin < length, end == -2"); + + testRes(sample.slice(-1, -1), "length = 4, begin == -1, end == -1"); + testRes(sample.slice(-1, -2), "length = 4, begin == -1, end == -2"); + testRes(sample.slice(-2, -2), "length = 4, begin == -2, end == -2"); + + testRes(sample.slice(0, -4), "begin == 0, end == -length"); + testRes(sample.slice(-4, -4), "begin == -length, end == -length"); + testRes(sample.slice(-5, -4), "begin < -length, end == -length"); + + testRes(sample.slice(0, -5), "begin == 0, end < -length"); + testRes(sample.slice(-4, -5), "begin == -length, end < -length"); + testRes(sample.slice(-5, -5), "begin < -length, end < -length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/results-with-same-length.js b/test/sendable/builtins/TypedArray/prototype/slice/results-with-same-length.js new file mode 100644 index 0000000000000000000000000000000000000000..22cb0ceb2b585bbd680fae320db657bdf49e61aa --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/results-with-same-length.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: slice may return a new instance with the same length +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + function testRes(result, msg) { + assert.sameValue(result.length, 4, msg); + assert.sameValue(result[0], 40, msg + " & result[0] === 40"); + assert.sameValue(result[1], 41, msg + " & result[1] === 41"); + assert.sameValue(result[2], 42, msg + " & result[2] === 42"); + assert.sameValue(result[3], 43, msg + " & result[3] === 43"); + } + + testRes(sample.slice(0), "begin == 0"); + testRes(sample.slice(-4), "begin == -srcLength"); + testRes(sample.slice(-5), "begin < -srcLength"); + + testRes(sample.slice(0, 4), "begin == 0, end == srcLength"); + testRes(sample.slice(-4, 4), "begin == -srcLength, end == srcLength"); + testRes(sample.slice(-5, 4), "begin < -srcLength, end == srcLength"); + + testRes(sample.slice(0, 5), "begin == 0, end > srcLength"); + testRes(sample.slice(-4, 5), "begin == -srcLength, end > srcLength"); + testRes(sample.slice(-5, 5), "begin < -srcLength, end > srcLength"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-end-symbol.js b/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-end-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..497e9c3fca7a02583e8b6771d5038388a04fc425 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-end-symbol.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt from ToInteger(end), end is symbol +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 6. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.slice(0, s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-end.js b/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-end.js new file mode 100644 index 0000000000000000000000000000000000000000..ca6047ba2d347c35ff8c7bc9b6a41b66b847f605 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-end.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt from ToInteger(end) +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 6. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.slice(0, o1); + }); + + assert.throws(Test262Error, function() { + sample.slice(0, o2); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-start-symbol.js b/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-start-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..33def468389398caf0cdb6d8716723368b75fc55 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-start-symbol.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt from ToInteger(start), start is symbol +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.slice(s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-start.js b/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-start.js new file mode 100644 index 0000000000000000000000000000000000000000..92c53809a6e7ee859c98b375d3c519b13fa33802 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-start.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt from ToInteger(start) +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.slice(o1); + }); + + assert.throws(Test262Error, function() { + sample.slice(o2); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..e69a6538b8dea781e8420dcd83470d69a8e1ca8d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [ArrayBuffer, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.slice, + 'function', + 'implements SendableTypedArray.prototype.slice' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.slice(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.slice(0); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the slice operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.slice(0); + throw new Test262Error('slice completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/set-values-from-different-ctor-type.js b/test/sendable/builtins/TypedArray/prototype/slice/set-values-from-different-ctor-type.js new file mode 100644 index 0000000000000000000000000000000000000000..80ab0a50d52e04b470608b4f894f18c098b0b655 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/set-values-from-different-ctor-type.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Perform regular set if target's uses a different element type +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + 10. Let srcName be the String value of O's [[TypedArrayName]] internal slot. + 11. Let srcType be the String value of the Element Type value in Table 50 for + srcName. + 12. Let targetName be the String value of A's [[TypedArrayName]] internal + slot. + 13. Let targetType be the String value of the Element Type value in Table 50 + for targetName. + 14. If SameValue(srcType, targetType) is false, then + a. Let n be 0. + b. Repeat, while k < final + i. Let Pk be ! ToString(k). + ii. Let kValue be ? Get(O, Pk). + iii. Perform ? Set(A, ! ToString(n), kValue, true). + iv. Increase k by 1. + v. Increase n by 1. + ... + 16. Return A +includes: [sendableTypedArray.js, compareArray.js] +features: [Symbol.species, TypedArray] +---*/ + +var arr = [42, 43, 44]; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(arr); + var other = TA === Int8Array ? Uint8Array : Int8Array; + + sample.constructor = {}; + sample.constructor[Symbol.species] = other; + + var result = sample.slice(); + + assert(compareArray(result, arr), "values are set"); + assert.notSameValue(result.buffer, sample.buffer, "creates a new buffer"); + assert.sameValue(result.constructor, other, "used the custom ctor"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-destination-resizable.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-destination-resizable.js new file mode 100644 index 0000000000000000000000000000000000000000..d7beadceb757ef044bee27e70230cba2013564f2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-destination-resizable.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws a TypeError if new typedArray's length < count +info: | + 23.2.3.27 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + const rab1 = new ArrayBuffer(8, {maxByteLength: 100}); + const ta = new TA(rab1); + const rab2 = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab2); + rab2.resize(0); + ta.constructor = { [Symbol.species]: function() { return lengthTracking; } }; + assert.throws(TypeError, function() { + ta.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor-abrupt.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..6c321516696d295e65478420b44ee8ca22574691 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor-inherited.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000000000000000000000000000000000..77fdf51c12be31c0b304ab995389a9e6d9679b3d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor-inherited.js @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var calls = 0; + var result; + + Object.defineProperty(TA.prototype, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.slice(); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + undefined, + "used defaultCtor but still checks the inherited .constructor" + ); + + calls = 6; + result.constructor; + assert.sameValue( + calls, + 7, + "result.constructor triggers the inherited accessor property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..718fcd96b133f297da012a86da76dfbdb45e2f54 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.slice(); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.slice(); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.slice(); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.slice(); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.slice(); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.slice(); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..6841c34ad4ab9c11606c8f5cc5800674285ff783 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: get constructor on SpeciesConstructor +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var calls = 0; + var result; + + Object.defineProperty(sample, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.slice(); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + TA, + "use defaultCtor on an undefined return - .constructor check" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-abrupt.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..1ede19995b6ace5a8184cd296a6fd206deee5a0e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-abrupt.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-invocation.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000000000000000000000000000000000..725a4895023d91cccd347d71c6009fa58fe96bbe --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42]); + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + result = arguments; + ctorThis = this; + return new TA(count); + }; + + sample.slice(1); + + assert.sameValue(result.length, 1, "called with 1 arguments"); + assert.sameValue(result[0], 2, "[0] is the new length count"); + + assert( + ctorThis instanceof sample.constructor[Symbol.species], + "`this` value in the @@species fn is an instance of the function itself" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..32aa979af2e6f687f9235b96444d35a991a4705e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length-throws-resizable-arraybuffer.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws a TypeError if new typedArray's length < count +info: | + 23.2.3.27 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 23.2.4.1 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let result be ? SendableTypedArrayCreate(constructor, argumentList). + + 23.2.4.2 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, SendableTypedArray, resizable-arraybuffer] +---*/ + + +testWithTypedArrayConstructors(function(TA) { + const sample = new TA(2); + const rab = new ArrayBuffer(10, {maxByteLength: 20}); + const lengthTracking = new TA(rab); + rab.resize(0); + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return lengthTracking; + }; + assert.throws(TypeError, function() { + sample.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length-throws.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..06fd9a8f16628b055bb3eba772bd269d057d7c7a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length-throws.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws a TypeError if new typedArray's length < count +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(); + }; + + assert.throws(TypeError, function() { + sample.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length.js new file mode 100644 index 0000000000000000000000000000000000000000..bc3156cbb95c499e0687f7cf047190f817728d14 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Does not throw a TypeError if new typedArray's length >= count +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newSendableTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var customCount, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(customCount); + }; + + customCount = 2; + result = sample.slice(); + assert.sameValue(result.length, customCount, "length == count"); + + customCount = 5; + result = sample.slice(); + assert.sameValue(result.length, customCount, "length > count"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-returns-another-instance.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..4fbbdf32477415204cdf59664561f2bf21aafc98 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Custom @@species constructor may return a totally different SendableTypedArray +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js, compareArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40]); + var other = new Int8Array([1, 0, 1]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.slice(0, 0); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [1, 0, 1]), "the returned object is preserved"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-throws.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..fab5a2d451ca10705962a5eac66384fb75d58a46 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var ctor = function() {}; + + sample.constructor = {}; + sample.constructor[Symbol.species] = ctor; + + assert.throws(TypeError, function() { + sample.slice(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..c242223582c2dae70fe7a773659df25f36369ee3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Use custom @@species constructor if available +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js, compareArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42]); + var calls = 0; + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + calls++; + return new TA(count); + }; + + result = sample.slice(1); + + assert.sameValue(calls, 1, "ctor called once"); + assert(compareArray(result, [41, 42]), "expected object"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..449368a3606f304a3331d72c95bddb088ceb4d03 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-returns-throws.js @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + sample.constructor[Symbol.species] = 0; + assert.throws(TypeError, function() { + sample.slice(); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.slice(); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.slice(); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.slice(); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.slice(); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.slice(); + }, "true"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-use-default-ctor.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..95219e6358722144612fccb37679af4e855994e8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var result; + + sample.constructor = {}; + + result = sample.slice(); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "undefined @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "undefined @@species - ctor check"); + + sample.constructor[Symbol.species] = null; + result = sample.slice(); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "null @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "null @@species - ctor check"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species.js new file mode 100644 index 0000000000000000000000000000000000000000..86166a32f56ccb637200a8e09d6953c0893faed3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-get-species.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + get @@species from found constructor +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? SendableTypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calls = 0; + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + calls++; + } + }); + + sample.slice(); + + assert.sameValue(calls, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-resize.js b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..56f1dc2076067b7ec32a6979e19a51552354b8f6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/speciesctor-resize.js @@ -0,0 +1,141 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + SendableTypedArray.p.slice behaves correctly on SendableTypedArrays backed by resizable buffers + which the species constructor resizes. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// The corresponding test for Array.prototype.slice is not possible, since it +// doesn't call the species constructor if the "original array" is not an Array. + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + let resizeWhenConstructorCalled = false; + class MyArray extends ctor { + constructor(...params) { + super(...params); + if (resizeWhenConstructorCalled) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + } + } + ; + const fixedLength = new MyArray(rab, 0, 4); + resizeWhenConstructorCalled = true; + assert.throws(TypeError, () => { + fixedLength.slice(); + }); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 1); + } + let resizeWhenConstructorCalled = false; + class MyArray extends ctor { + constructor(...params) { + super(...params); + if (resizeWhenConstructorCalled) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + } + } + ; + const lengthTracking = new MyArray(rab); + resizeWhenConstructorCalled = true; + const a = lengthTracking.slice(); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); + // The length of the resulting SendableTypedArray is determined before + // SendableTypedArraySpeciesCreate is called, and it doesn't change. + assert.sameValue(a.length, 4); + assert.compareArray(ToNumbers(a), [ + 1, + 1, + 0, + 0 + ]); +} + +// Test that the (start, end) parameters are computed based on the original +// length. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 1); + } + let resizeWhenConstructorCalled = false; + class MyArray extends ctor { + constructor(...params) { + super(...params); + if (resizeWhenConstructorCalled) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + } + } + ; + const lengthTracking = new MyArray(rab); + resizeWhenConstructorCalled = true; + const a = lengthTracking.slice(-3, -1); + assert.sameValue(rab.byteLength, 2 * ctor.BYTES_PER_ELEMENT); + // The length of the resulting SendableTypedArray is determined before + // SendableTypedArraySpeciesCreate is called, and it doesn't change. + assert.sameValue(a.length, 2); + assert.compareArray(ToNumbers(a), [ + 1, + 0 + ]); +} + +// Test where the buffer gets resized "between elements". +{ + const rab = CreateResizableArrayBuffer(8, 16); + const taWrite = new Uint8Array(rab); + for (let i = 0; i < 8; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 255); + } + let resizeWhenConstructorCalled = false; + class MyArray extends Uint16Array { + constructor(...params) { + super(...params); + if (resizeWhenConstructorCalled) { + rab.resize(5); + } + } + } + ; + const lengthTracking = new MyArray(rab); + assert.compareArray(ToNumbers(lengthTracking), [ + 65535, + 65535, + 65535, + 65535 + ]); + resizeWhenConstructorCalled = true; + const a = lengthTracking.slice(); + assert.sameValue(rab.byteLength, 5); + assert.sameValue(a.length, 4); + assert.sameValue(a[0], 65535); + assert.sameValue(a[1], 65535); + assert.sameValue(a[2], 0); + assert.sameValue(a[3], 0); +} diff --git a/test/sendable/builtins/TypedArray/prototype/slice/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/slice/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..7e2b17bda6bb7ecb1513b56981f49c2ba0f1803a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/this-is-not-object.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var slice = SendableTypedArray.prototype.slice; + +assert.throws(TypeError, function() { + slice.call(undefined, 0, 0); +}, "this is undefined"); + +assert.throws(TypeError, function() { + slice.call(null, 0, 0); +}, "this is null"); + +assert.throws(TypeError, function() { + slice.call(42, 0, 0); +}, "this is 42"); + +assert.throws(TypeError, function() { + slice.call("1", 0, 0); +}, "this is a string"); + +assert.throws(TypeError, function() { + slice.call(true, 0, 0); +}, "this is true"); + +assert.throws(TypeError, function() { + slice.call(false, 0, 0); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + slice.call(s, 0, 0); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/slice/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..1bf63151c776ba5e005fe9f0f913cedaaf1f8b64 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/this-is-not-typedarray-instance.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var slice = SendableTypedArray.prototype.slice; + +assert.throws(TypeError, function() { + slice.call({}, 0, 0); +}, "this is an Object"); + +assert.throws(TypeError, function() { + slice.call([], 0, 0); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + slice.call(ab, 0, 0); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + slice.call(dv, 0, 0); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/tointeger-end.js b/test/sendable/builtins/TypedArray/prototype/slice/tointeger-end.js new file mode 100644 index 0000000000000000000000000000000000000000..b07ae6ac6fc6e5a2cb90e189c7f18dcc4fb110f9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/tointeger-end.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: ToInteger(end) +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice( start , end ) + + ... + 6. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert(compareArray(sample.slice(0, false), []), "false"); + assert(compareArray(sample.slice(0, true), [40]), "true"); + + assert(compareArray(sample.slice(0, NaN), []), "NaN"); + assert(compareArray(sample.slice(0, null), []), "null"); + assert(compareArray(sample.slice(0, undefined), [40, 41, 42, 43]), "undefined"); + + assert(compareArray(sample.slice(0, 0.6), []), "0.6"); + assert(compareArray(sample.slice(0, 1.1), [40]), "1.1"); + assert(compareArray(sample.slice(0, 1.5), [40]), "1.5"); + assert(compareArray(sample.slice(0, -0.6), []), "-0.6"); + assert(compareArray(sample.slice(0, -1.1), [40, 41, 42]), "-1.1"); + assert(compareArray(sample.slice(0, -1.5), [40, 41, 42]), "-1.5"); + + assert(compareArray(sample.slice(0, "3"), [40, 41, 42]), "string"); + assert( + compareArray( + sample.slice(0, obj), + [40, 41] + ), + "object" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/slice/tointeger-start.js b/test/sendable/builtins/TypedArray/prototype/slice/tointeger-start.js new file mode 100644 index 0000000000000000000000000000000000000000..e913a3c5abb5b7cfe92b340e30875c28f7c0c6b8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/slice/tointeger-start.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.slice +description: ToInteger(begin) +info: | + 22.2.3.24 %SendableTypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert(compareArray(sample.slice(false), [40, 41, 42, 43]), "false"); + assert(compareArray(sample.slice(true), [41, 42, 43]), "true"); + + assert(compareArray(sample.slice(NaN), [40, 41, 42, 43]), "NaN"); + assert(compareArray(sample.slice(null), [40, 41, 42, 43]), "null"); + assert(compareArray(sample.slice(undefined), [40, 41, 42, 43]), "undefined"); + + assert(compareArray(sample.slice(1.1), [41, 42, 43]), "1.1"); + assert(compareArray(sample.slice(1.5), [41, 42, 43]), "1.5"); + assert(compareArray(sample.slice(0.6), [40, 41, 42, 43]), "0.6"); + + assert(compareArray(sample.slice(-1.5), [43]), "-1.5"); + assert(compareArray(sample.slice(-1.1), [43]), "-1.1"); + assert(compareArray(sample.slice(-0.6), [40, 41, 42, 43]), "-0.6"); + + assert(compareArray(sample.slice("3"), [43]), "string"); + assert( + compareArray( + sample.slice(obj), + [42, 43] + ), + "object" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-arguments-with-thisarg.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..39e00fe9f0201222537d355c25e3fe6a317ea6b3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.some(function() { + results.push(arguments); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-arguments-without-thisarg.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..3826c67f4bd2e7398b99d9eefd8a460ae5de81cf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + callbackfn arguments +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.some(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..e0c3827a0e93b2862f40cf1278645b1e3c652394 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.some(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return false; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-no-interaction-over-non-integer.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 0000000000000000000000000000000000000000..4650a42111f9e6e42f77ef12b5148a446abf3ce0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-no-interaction-over-non-integer.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Does not interact over non-integer properties +info: | + 22.2.3.7 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.some(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - key"); + assert.sameValue(results[1][1], 1, "results[1][1] - key"); + + assert.sameValue(results[0][0], 7n, "results[0][0] - value"); + assert.sameValue(results[1][0], 8n, "results[1][0] - value"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..88d25e94a51cd48edfeea74796bdc4621ceef982 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-not-callable-throws.js @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Throws a TypeError if callbackfn is not callable +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.some(); + }, "no args"); + + assert.throws(TypeError, function() { + sample.some(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.some(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.some("abc"); + }, "string"); + + assert.throws(TypeError, function() { + sample.some(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.some(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.some(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.some(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.some({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.some(sample); + }, "same typedArray instance"); + + assert.throws(TypeError, function() { + sample.some(Symbol("1")); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..f4a68ea484b172f2e9721fdfad6d5baa26455a75 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().some(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..c2ba0c6f5076b204fc113c2930118a378761bd12 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + + sample.some(function() { + return 0; + }); + + assert.sameValue(sample[0], 40n, "[0] == 40"); + assert.sameValue(sample[1], 41n, "[1] == 41"); + assert.sameValue(sample[2], 42n, "[2] == 42"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..7b7f57bb1f518a138aaacf9cc9b2b538ca3cf399 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Returns abrupt from callbackfn +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.some(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-set-value-during-interaction.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000000000000000000000000000000000..78e7ad36e52af3af6a7c51a4da5328bb22dd3225 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-set-value-during-interaction.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.some(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1n, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7n), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + }); + + assert.sameValue(sample[0], 7n, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1n, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2n, "changed values after iteration [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..bdef2f1cf326cd18319b7466d1600a8faea5f260 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/callbackfn-this.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + callbackfn `this` value +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.some(function() { + results1.push(this); + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.some(function() { + results2.push(this); + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..092c39bb55de446c389fe6df0ced6d82dad1e89e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.some(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..92257e3ce9444b6d871161182af5666d29510f2d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.some(function() { + calls++; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..1337caa8928c101b5d10dd5a1d0ed68c8d4b5fcf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.some, + 'function', + 'implements SendableTypedArray.prototype.some' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.some(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.some(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the some operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.some(() => {}); + throw new Test262Error('some completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/returns-false-if-every-cb-returns-false.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/returns-false-if-every-cb-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..cb5068dcdb0563e6c0fb1da5513d994aeb0fb0cf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/returns-false-if-every-cb-returns-false.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Returns false if every callbackfn calls returns a coerced false. +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + + [ + false, + "", + 0, + -0, + NaN, + undefined, + null + ].forEach(function(val) { + var called = 0; + var result = sample.some(function() { + called++; + return val; + }); + assert.sameValue(called, 42, "callbackfn called for each index property"); + assert.sameValue(result, false, "result is false - " + val); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/returns-true-if-any-cb-returns-true.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/returns-true-if-any-cb-returns-true.js new file mode 100644 index 0000000000000000000000000000000000000000..86dcd64b95729fe8ca5ac95c2a892e8dd4e91d1e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/returns-true-if-any-cb-returns-true.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Returns true if any callbackfn returns a coerced true. +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + iii. If testResult is true, return true. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + [ + true, + 1, + "test262", + s, + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ].forEach(function(val) { + var called = 0; + var result = sample.some(function() { + called++; + if (called == 1) { + return false; + } + return val; + }); + assert.sameValue(called, 2, "callbackfn called for each index property"); + + var msg = "result is true - " + (val === s ? "symbol" : val); + assert.sameValue(result, true, msg); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/BigInt/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/some/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..231a27aad105e5421f94b12c4ff97be862e259e1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/BigInt/values-are-not-cached.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + sample.some(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42n; + } + + assert.sameValue( + v, 42n, "method does not cache values before callbackfn calls" + ); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/callbackfn-arguments-with-thisarg.js b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..91ea2e626d25a47e84309406fba97c7dc1c289e4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.some(function() { + results.push(arguments); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/callbackfn-arguments-without-thisarg.js b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000000000000000000000000000000000..fe8f2b16b73f0f6da0da93dd53ca66d3ed061384 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + callbackfn arguments +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + + sample.some(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/callbackfn-detachbuffer.js b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-detachbuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..cdbd9507dc876d884a98f5edcb56f7d9db8a4151 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-detachbuffer.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [detachArrayBuffer.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.some(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return false; + }); + + assert.sameValue(loops, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/callbackfn-no-interaction-over-non-integer.js b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 0000000000000000000000000000000000000000..8af52080509f3c8633d5bcf25bb58c9446e5c81b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-no-interaction-over-non-integer.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Does not interact over non-integer properties +info: | + 22.2.3.7 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7, 8]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.some(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - key"); + assert.sameValue(results[1][1], 1, "results[1][1] - key"); + + assert.sameValue(results[0][0], 7, "results[0][0] - value"); + assert.sameValue(results[1][0], 8, "results[1][0] - value"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/callbackfn-not-callable-throws.js b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-not-callable-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..bb11336321a6f81d81f4f33758551081b4781a30 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-not-callable-throws.js @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Throws a TypeError if callbackfn is not callable +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.some(); + }, "no args"); + + assert.throws(TypeError, function() { + sample.some(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.some(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.some("abc"); + }, "string"); + + assert.throws(TypeError, function() { + sample.some(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.some(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.some(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.some(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.some({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.some(sample); + }, "same typedArray instance"); + + assert.throws(TypeError, function() { + sample.some(Symbol("1")); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/callbackfn-not-called-on-empty.js b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..4849630c334beb962b3330261c6f81a0dc280698 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-not-called-on-empty.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().some(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/callbackfn-resize.js b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-resize.js new file mode 100644 index 0000000000000000000000000000000000000000..35e5029bd274a8d5f0f9090af0546a149f893da6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-resize.js @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Instance buffer can be resized during iteration +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function'); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4}); + var sample = new TA(buffer); + var finalElement, expectedElements, expectedIndices, expectedArrays; + var elements, indices, arrays, result; + + elements = []; + indices = []; + arrays = []; + result = sample.some(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(2 * BPE); + finalElement = undefined; + expectedElements = [0, 0]; + expectedIndices = [0, 1]; + expectedArrays = [sample, sample]; + } catch (_) { + finalElement = 0; + expectedElements = [0, 0, 0]; + expectedIndices = [0, 1, 2]; + expectedArrays = [sample, sample, sample]; + } + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + + assert.compareArray(elements, [0, 0, finalElement], 'elements (shrink)'); + assert.compareArray(indices, [0, 1, 2], 'indices (shrink)'); + assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)'); + assert.sameValue(result, false, 'result (shrink)'); + + elements = []; + indices = []; + arrays = []; + result = sample.some(function(element, index, array) { + if (elements.length === 0) { + try { + buffer.resize(4 * BPE); + } catch (_) {} + } + + elements.push(element); + indices.push(index); + arrays.push(array); + return false; + }); + + assert.compareArray(elements, expectedElements, 'elements (grow)'); + assert.compareArray(indices, expectedIndices, 'indices (grow)'); + assert.compareArray(arrays, expectedArrays, 'arrays (grow)'); + assert.sameValue(result, false, 'result (grow)'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/callbackfn-return-does-not-change-instance.js b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..bf28afaeda7898d97beb5929167999b709913332 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42]); + + sample.some(function() { + return 0; + }); + + assert.sameValue(sample[0], 40, "[0] == 40"); + assert.sameValue(sample[1], 41, "[1] == 41"); + assert.sameValue(sample[2], 42, "[2] == 42"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/callbackfn-returns-abrupt.js b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..510b7056f4f797ffef85d7157209b834600449c9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-returns-abrupt.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Returns abrupt from callbackfn +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.some(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/callbackfn-set-value-during-interaction.js b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000000000000000000000000000000000..b3d2b3a32dea44cf783681c03692296fb301dd98 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-set-value-during-interaction.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [Reflect.set, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + var newVal = 0; + + sample.some(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + }); + + assert.sameValue(sample[0], 7, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2, "changed values after iteration [2] == 2"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/callbackfn-this.js b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-this.js new file mode 100644 index 0000000000000000000000000000000000000000..a0b5d64951130c2fcda59e28cbca6a1680e7ccf8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/callbackfn-this.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + callbackfn `this` value +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.some(function() { + results1.push(this); + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.some(function() { + results2.push(this); + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/some/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..99fc018674e71de654eede5e4dbd599e69a63b07 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.some(callbackfn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/some/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..2b3b71ef2a3a10553e00040164c76efaef87a0c0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/get-length-uses-internal-arraylength.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.some(function() { + calls++; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/some/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..0bc2e92c1c5503150c0a9f536dc28b394a9e6ebc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/invoked-as-func.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.24 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var some = SendableTypedArray.prototype.some; + +assert.sameValue(typeof some, 'function'); + +assert.throws(TypeError, function() { + some(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/some/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..83bee2874837724e2ce0759867939625ac378b1e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/invoked-as-method.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.24 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.some, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.some(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/length.js b/test/sendable/builtins/TypedArray/prototype/some/length.js new file mode 100644 index 0000000000000000000000000000000000000000..7f01f6be4cc4db8ccc59fa5ae707b0bbff879230 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + %SendableTypedArray%.prototype.some.length is 1. +info: | + %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.some, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/name.js b/test/sendable/builtins/TypedArray/prototype/some/name.js new file mode 100644 index 0000000000000000000000000000000000000000..a043c0821b5446cae7cc23620f3db3bc0a5072a4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + %SendableTypedArray%.prototype.some.name is "some". +info: | + %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.some, "name", { + value: "some", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/some/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..c22835d314b1c4e32d3e5ee9463459fae4da4762 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.some does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.some), + false, + 'isConstructor(SendableTypedArray.prototype.some) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.some(() => {}); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/some/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/some/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..7e8fee5aa97210627ec24b928ce5b3df013125a9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + "some" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'some', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/some/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..44c82f2d3f585732390ddf99208ed04b184047a0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + SendableTypedArray.p.some behaves correctly on SendableTypedArrays backed by resizable buffers + which are grown mid-iteration. +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Below the argument array should be a view of the resizable array buffer rab. +// This array gets collected into values via reduce and CollectValuesAndResize. +// The latter performs an during which, after resizeAfter steps, rab is resized +// to length resizeTo. Note that rab, values, resizeAfter, and resizeTo may need +// to be reset before calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(!fixedLength.some(ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(!fixedLengthWithOffset.some(ResizeMidIteration)); + assert.compareArray(values, [ + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(!lengthTracking.some(ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4, + 6 + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + rab = rab; + resizeAfter = 1; + resizeTo = 5 * ctor.BYTES_PER_ELEMENT; + assert(!lengthTrackingWithOffset.some(ResizeMidIteration)); + assert.compareArray(values, [ + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/some/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/some/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..14325ef35a93160894f8c670c6a8c78f1b97bc75 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + SendableTypedArray.p.some behaves correctly on SendableTypedArrays backed by resizable buffers + which are shrunk mid-iteration. +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +let values; +let rab; +let resizeAfter; +let resizeTo; +// Below the argument array should be a view of the resizable array buffer rab. +// This array gets collected into values via reduce and CollectValuesAndResize. +// The latter performs an during which, after resizeAfter steps, rab is resized +// to length resizeTo. Note that rab, values, resizeAfter, and resizeTo may need +// to be reset before calling this. +function ResizeMidIteration(n) { + CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo); + return false; +} + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(!fixedLength.some(ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + undefined, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(!fixedLengthWithOffset.some(ResizeMidIteration)); + assert.compareArray(values, [ + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + values = []; + resizeAfter = 2; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(!lengthTracking.some(ResizeMidIteration)); + assert.compareArray(values, [ + 0, + 2, + 4, + undefined + ]); +} +for (let ctor of ctors) { + rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + values = []; + resizeAfter = 1; + resizeTo = 3 * ctor.BYTES_PER_ELEMENT; + assert(!lengthTrackingWithOffset.some(ResizeMidIteration)); + assert.compareArray(values, [ + 4, + undefined + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/some/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/some/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..46c502abcf55f09461fd9ed6d49540d8214b224e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/resizable-buffer.js @@ -0,0 +1,127 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + SendableTypedArray.p.some behaves correctly on SendableTypedArrays backed by resizable buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + function div3(n) { + return Number(n) % 3 == 0; + } + function over10(n) { + return Number(n) > 10; + } + assert(fixedLength.some(div3)); + assert(!fixedLength.some(over10)); + assert(fixedLengthWithOffset.some(div3)); + assert(!fixedLengthWithOffset.some(over10)); + assert(lengthTracking.some(div3)); + assert(!lengthTracking.some(over10)); + assert(lengthTrackingWithOffset.some(div3)); + assert(!lengthTrackingWithOffset.some(over10)); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.some(div3); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.some(div3); + }); + + assert(lengthTracking.some(div3)); + assert(!lengthTracking.some(over10)); + assert(!lengthTrackingWithOffset.some(div3)); + assert(!lengthTrackingWithOffset.some(over10)); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.some(div3); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.some(div3); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.some(div3); + }); + + assert(lengthTracking.some(div3)); + assert(!lengthTracking.some(over10)); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.some(div3); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.some(div3); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.some(div3); + }); + + assert(!lengthTracking.some(div3)); + assert(!lengthTracking.some(over10)); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert(fixedLength.some(div3)); + assert(!fixedLength.some(over10)); + assert(fixedLengthWithOffset.some(div3)); + assert(!fixedLengthWithOffset.some(over10)); + assert(lengthTracking.some(div3)); + assert(!lengthTracking.some(over10)); + assert(lengthTrackingWithOffset.some(div3)); + assert(!lengthTrackingWithOffset.some(over10)); +} diff --git a/test/sendable/builtins/TypedArray/prototype/some/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/some/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..acc41eb9c4f4bde0556adfc0b0a27ac0bcb8e9fd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [ArrayBuffer, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.some, + 'function', + 'implements SendableTypedArray.prototype.some' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.some(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.some(() => {}); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the some operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.some(() => {}); + throw new Test262Error('some completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/returns-false-if-every-cb-returns-false.js b/test/sendable/builtins/TypedArray/prototype/some/returns-false-if-every-cb-returns-false.js new file mode 100644 index 0000000000000000000000000000000000000000..dfbf139369f778e1f1c45d344c245e8cbee7a0e1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/returns-false-if-every-cb-returns-false.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Returns false if every callbackfn calls returns a coerced false. +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(42); + + [ + false, + "", + 0, + -0, + NaN, + undefined, + null + ].forEach(function(val) { + var called = 0; + var result = sample.some(function() { + called++; + return val; + }); + assert.sameValue(called, 42, "callbackfn called for each index property"); + assert.sameValue(result, false, "result is false - " + val); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/returns-true-if-any-cb-returns-true.js b/test/sendable/builtins/TypedArray/prototype/some/returns-true-if-any-cb-returns-true.js new file mode 100644 index 0000000000000000000000000000000000000000..48f88475cab9dd2e28ad0fa61df4303b39d7221a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/returns-true-if-any-cb-returns-true.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Returns true if any callbackfn returns a coerced true. +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + iii. If testResult is true, return true. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(42); + [ + true, + 1, + "test262", + s, + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ].forEach(function(val) { + var called = 0; + var result = sample.some(function() { + called++; + if (called == 1) { + return false; + } + return val; + }); + assert.sameValue(called, 2, "callbackfn called for each index property"); + + var msg = "result is true - " + (val === s ? "symbol" : val); + assert.sameValue(result, true, msg); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/some/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/some/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..aa4620e89c684c7dbb9ca603f8e0ad2bc4f3bc29 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/this-is-not-object.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var some = SendableTypedArray.prototype.some; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + some.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + some.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + some.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + some.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + some.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + some.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + some.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/some/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/some/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..1a5f84402015159f3d49221b9df34d6340033fd8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/this-is-not-typedarray-instance.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var some = SendableTypedArray.prototype.some; +var callbackfn = function () {}; + +assert.throws(TypeError, function() { + some.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + some.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + some.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + some.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/some/values-are-not-cached.js b/test/sendable/builtins/TypedArray/prototype/some/values-are-not-cached.js new file mode 100644 index 0000000000000000000000000000000000000000..2cadfd17bc302f572f8cd8adba592b1bd8ecdfdc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/some/values-are-not-cached.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.some +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.25 %SendableTypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %SendableTypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + sample.some(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42; + } + + assert.sameValue( + v, 42, "method does not cache values before callbackfn calls" + ); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/BigInt/arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..d1d76a49d026ec0ab11ce5b8e6e204a6ba222ef7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/arraylength-internal.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Use internal ArrayLength instead of getting a length property +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + ... + 3. Let len be the value of obj's [[ArrayLength]] internal slot. +includes: [sendableBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 42n, 42n]); + getCalls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.sort(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert( + compareArray(result, sample), + "result is not affected by custom length" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..b1d8db5c918e0ea0094a51fd43e57549eee710ec --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Returns abrupt from comparefn +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + When the SendableTypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... + + 22.1.3.25 Array.prototype.sort (comparefn) + + The following steps are taken: + + - If an abrupt completion is returned from any of these operations, it is + immediately returned as the value of this function. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n, 45n, 46n]); + var calls = 0; + + var comparefn = function() { + calls += 1; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + sample.sort(comparefn); + }); + + assert.sameValue(calls, 1, "immediately returned"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-calls.js b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-calls.js new file mode 100644 index 0000000000000000000000000000000000000000..e79a995d637534354350b5e231598de14b6dfa4f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-calls.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: comparefn is called if not undefined +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + When the SendableTypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expectedThis = (function() { + return this; +})(); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 42n, 42n, 42n, 42n]); + var calls = []; + + var comparefn = function() { + calls.push([this, arguments]); + }; + + sample.sort(comparefn); + + assert(calls.length > 0, "calls comparefn"); + calls.forEach(function(args) { + assert.sameValue(args[0], expectedThis, "comparefn is called no specific this"); + assert.sameValue(args[1].length, 2, "comparefn is always called with 2 args"); + assert.sameValue(args[1][0], 42n, "x is a listed value"); + assert.sameValue(args[1][0], 42n, "y is a listed value"); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-is-undefined.js b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..76d6add2bcf927dcdf7c7baa296cd43f4d3f0656 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-is-undefined.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: > + Treats explicit undefined comparefn the same as implicit undefined comparefn +info: | + %SendableTypedArray%.prototype.sort ( comparefn ) + + 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception. + ... +includes: [compareArray.js, testBigIntTypedArray.js] +features: [TypedArray, BigInt] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA([42n, 44n, 46n, 43n, 45n]); + let explicit = sample.sort(undefined); + let implicit = sample.sort(); + + assert.compareArray(explicit, [42n, 43n, 44n, 45n, 46n], 'The value of `explicit` is [42n, 43n, 44n, 45n, 46n]'); + assert.compareArray(implicit, [42n, 43n, 44n, 45n, 46n], 'The value of `implicit` is [42n, 43n, 44n, 45n, 46n]'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..41c4b9d83bced12e005a67a5377332a43124f885 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: throws on a non-undefined non-function +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + Upon entry, the following steps are performed to initialize evaluation + of the sort function. These steps are used instead of the entry steps + in 22.1.3.25: + + ... + 1. If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception. + ... + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n, 45n, 46n]); + + assert.throws(TypeError, function() { + sample.sort(null); + }); + + assert.throws(TypeError, function() { + sample.sort(true); + }); + + assert.throws(TypeError, function() { + sample.sort(false); + }); + + assert.throws(TypeError, function() { + sample.sort(''); + }); + + assert.throws(TypeError, function() { + sample.sort(/a/g); + }); + + assert.throws(TypeError, function() { + sample.sort(42); + }); + + assert.throws(TypeError, function() { + sample.sort([]); + }); + + assert.throws(TypeError, function() { + sample.sort({}); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..534d09edf5d9cfa3d7bd4c17881179a3bc3b1306 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/detached-buffer.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + 1. Let obj be the this value. + 2. Let buffer be ? ValidateSendableTypedArray(obj). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var comparefn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.sort(comparefn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..89375bdb56f774eade36ecbef4433fb0a98a2d7c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.sort, + 'function', + 'implements SendableTypedArray.prototype.sort' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.sort(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.sort(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the sort operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.sort(); + throw new Test262Error('sort completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/BigInt/return-same-instance.js b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/return-same-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..431a00c4c1701d3e518291e80fba64ac353de5e5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/return-same-instance.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Returns the same instance +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + When the SendableTypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([2n, 1n]); + var result = sample.sort(); + + assert.sameValue(sample, result, "without comparefn"); + + result = sample.sort(function() { return 0; }); + assert.sameValue(sample, result, "with comparefn"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.js b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.js new file mode 100644 index 0000000000000000000000000000000000000000..09b9a2b68591df419356c7c0d345179d30d9466a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: SendableTypedArrays sort does not cast values to String +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + When the SendableTypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var toStringCalled = false; +BigInt.prototype.toString = function() { + toStringCalled = true; +} + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([20n, 100n, 3n]); + var result = sample.sort(); + assert.sameValue(toStringCalled, false, "BigInt.prototype.toString will not be called"); + assert(compareArray(result, [3n, 20n, 100n])); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/BigInt/sorted-values.js b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/sorted-values.js new file mode 100644 index 0000000000000000000000000000000000000000..321e845c378a352d45fa1a13064fdf8c92156000 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/BigInt/sorted-values.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Sort values to numeric ascending order +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + When the SendableTypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([4n, 3n, 2n, 1n]).sort(); + assert(compareArray(sample, [1n, 2n, 3n, 4n]), "descending values"); + + sample = new TA([3n, 4n, 1n, 2n]).sort(); + assert(compareArray(sample, [1n, 2n, 3n, 4n]), "mixed numbers"); + + sample = new TA([3n, 4n, 3n, 1n, 0n, 1n, 2n]).sort(); + assert(compareArray(sample, [0n, 1n, 1n, 2n, 3n, 3n, 4n]), "repeating numbers"); +}); + +var sample = new BigInt64Array([-4n, 3n, 4n, -3n, 2n, -2n, 1n, 0n]).sort(); +assert(compareArray(sample, [-4n, -3n, -2n, 0n, 1n, 2n, 3n, 4n]), "negative values"); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/arraylength-internal.js b/test/sendable/builtins/TypedArray/prototype/sort/arraylength-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..1c4b127667ca35be34f6808f074f7f6c7430d7f3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/arraylength-internal.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Use internal ArrayLength instead of getting a length property +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + ... + 3. Let len be the value of obj's [[ArrayLength]] internal slot. +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 42, 42]); + getCalls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.sort(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert( + compareArray(result, sample), + "result is not affected by custom length" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/comparefn-call-throws.js b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-call-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..431672359c3ea0332ef2b82731063cdd27c8c82f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-call-throws.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Returns abrupt from comparefn +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + When the SendableTypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... + + 22.1.3.25 Array.prototype.sort (comparefn) + + The following steps are taken: + + - If an abrupt completion is returned from any of these operations, it is + immediately returned as the value of this function. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44, 45, 46]); + var calls = 0; + + var comparefn = function() { + calls += 1; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + sample.sort(comparefn); + }); + + assert.sameValue(calls, 1, "immediately returned"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/comparefn-calls.js b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-calls.js new file mode 100644 index 0000000000000000000000000000000000000000..4a4b030afc72aaaa0ad7d6c9c9e2286a03d32638 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-calls.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: comparefn is called if not undefined +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + When the SendableTypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var expectedThis = (function() { + return this; +})(); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 42, 42, 42, 42]); + var calls = []; + + var comparefn = function() { + calls.push([this, arguments]); + }; + + sample.sort(comparefn); + + assert(calls.length > 0, "calls comparefn"); + calls.forEach(function(args) { + assert.sameValue(args[0], expectedThis, "comparefn is called no specific this"); + assert.sameValue(args[1].length, 2, "comparefn is always called with 2 args"); + assert.sameValue(args[1][0], 42, "x is a listed value"); + assert.sameValue(args[1][0], 42, "y is a listed value"); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/comparefn-grow.js b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..a80692780b61e3cf38f8f10ae28c66406fabcee1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-grow.js @@ -0,0 +1,83 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: > + SendableTypedArray.p.sort behaves correctly on SendableTypedArrays backed by resizable buffers + which are grown by the comparison callback. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Returns a function that resizes rab to size resizeTo and then compares its +// arguments. Such a result function is to be used as an argument to .sort. +function ResizeAndCompare(rab, resizeTo) { + return (a, b) => { + rab.resize(resizeTo); + if (a < b) { + return -1; + } + if (a > b) { + return 1; + } + return 0; + } +} + +function WriteUnsortedData(taFull) { + for (let i = 0; i < taFull.length; ++i) { + taFull[i] = MayNeedBigInt(taFull, 10 - i); + } +} + +// Fixed length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 6 * ctor.BYTES_PER_ELEMENT; + const fixedLength = new ctor(rab, 0, 4); + const taFull = new ctor(rab, 0); + WriteUnsortedData(taFull); + fixedLength.sort(ResizeAndCompare(rab, resizeTo)); + // Growing doesn't affect the sorting. + assert.compareArray(ToNumbers(taFull), [ + 7, + 8, + 9, + 10, + 0, + 0 + ]); +} + +// Length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 6 * ctor.BYTES_PER_ELEMENT; + const lengthTracking = new ctor(rab, 0); + const taFull = new ctor(rab, 0); + WriteUnsortedData(taFull); + lengthTracking.sort(ResizeAndCompare(rab, resizeTo)); + // Growing doesn't affect the sorting. Only the elements that were part of + // the original TA are sorted. + assert.compareArray(ToNumbers(taFull), [ + 7, + 8, + 9, + 10, + 0, + 0 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/sort/comparefn-is-undefined.js b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-is-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..8ab8fefd39314569bed5f7df03f23cdef05e027b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-is-undefined.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: > + Treats explicit undefined comparefn the same as implicit undefined comparefn +info: | + %SendableTypedArray%.prototype.sort ( comparefn ) + + 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception. + ... +includes: [compareArray.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA([42, 44, 46, 43, 45]); + let explicit = sample.sort(undefined); + let implicit = sample.sort(); + + assert.compareArray(explicit, [42, 43, 44, 45, 46], 'The value of `explicit` is [42, 43, 44, 45, 46]'); + assert.compareArray(implicit, [42, 43, 44, 45, 46], 'The value of `implicit` is [42, 43, 44, 45, 46]'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/comparefn-nonfunction-call-throws.js b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-nonfunction-call-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..87ccec142ad67caccea3245c284eb029b8d089ca --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-nonfunction-call-throws.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: throws on a non-undefined non-function +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + Upon entry, the following steps are performed to initialize evaluation + of the sort function. These steps are used instead of the entry steps + in 22.1.3.25: + + ... + 1. If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception. + ... + +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44, 45, 46]); + + assert.throws(TypeError, function() { + sample.sort(null); + }); + + assert.throws(TypeError, function() { + sample.sort(true); + }); + + assert.throws(TypeError, function() { + sample.sort(false); + }); + + assert.throws(TypeError, function() { + sample.sort(''); + }); + + assert.throws(TypeError, function() { + sample.sort(/a/g); + }); + + assert.throws(TypeError, function() { + sample.sort(42); + }); + + assert.throws(TypeError, function() { + sample.sort([]); + }); + + assert.throws(TypeError, function() { + sample.sort({}); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/comparefn-resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..4d49dcf5519e50bd7fc08a662b72b1bdb90651d4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-resizable-buffer.js @@ -0,0 +1,218 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: > + SendableTypedArray.p.sort behaves correctly on SendableTypedArrays backed by resizable buffers + and passed a user-provided comparison callback. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const taFull = new ctor(rab, 0); + function WriteUnsortedData() { + // Write some data into the array. + for (let i = 0; i < taFull.length; ++i) { + taFull[i] = MayNeedBigInt(taFull, 10 - i); + } + } + function OddBeforeEvenComparison(a, b) { + // Sort all odd numbers before even numbers. + a = Number(a); + b = Number(b); + if (a % 2 == 1 && b % 2 == 0) { + return -1; + } + if (a % 2 == 0 && b % 2 == 1) { + return 1; + } + if (a < b) { + return -1; + } + if (a > b) { + return 1; + } + return 0; + } + // Orig. array: [10, 9, 8, 7] + // [10, 9, 8, 7] << fixedLength + // [8, 7] << fixedLengthWithOffset + // [10, 9, 8, 7, ...] << lengthTracking + // [8, 7, ...] << lengthTrackingWithOffset + + WriteUnsortedData(); + fixedLength.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 7, + 9, + 8, + 10 + ]); + WriteUnsortedData(); + fixedLengthWithOffset.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 7, + 8 + ]); + WriteUnsortedData(); + lengthTracking.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 7, + 9, + 8, + 10 + ]); + WriteUnsortedData(); + lengthTrackingWithOffset.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 7, + 8 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [10, 9, 8] + // [10, 9, 8, ...] << lengthTracking + // [8, ...] << lengthTrackingWithOffset + + WriteUnsortedData(); + assert.throws(TypeError, () => { + fixedLength.sort(OddBeforeEvenComparison); + }); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 8 + ]); + assert.throws(TypeError, () => { + fixedLengthWithOffset.sort(OddBeforeEvenComparison); + }); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 8 + ]); + WriteUnsortedData(); + lengthTracking.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 9, + 8, + 10 + ]); + WriteUnsortedData(); + lengthTrackingWithOffset.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 8 + ]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + WriteUnsortedData(); + assert.throws(TypeError, () => { + fixedLength.sort(OddBeforeEvenComparison); + }); + assert.compareArray(ToNumbers(taFull), [10]); + assert.throws(TypeError, () => { + fixedLengthWithOffset.sort(OddBeforeEvenComparison); + }); + assert.compareArray(ToNumbers(taFull), [10]); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.sort(OddBeforeEvenComparison); + }); + assert.compareArray(ToNumbers(taFull), [10]); + + WriteUnsortedData(); + lengthTracking.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [10]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.sort(OddBeforeEvenComparison); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.sort(OddBeforeEvenComparison); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.sort(OddBeforeEvenComparison); + }); + + lengthTracking.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [10, 9, 8, 7, 6, 5] + // [10, 9, 8, 7] << fixedLength + // [8, 7] << fixedLengthWithOffset + // [10, 9, 8, 7, 6, 5, ...] << lengthTracking + // [8, 7, 6, 5, ...] << lengthTrackingWithOffset + + WriteUnsortedData(); + fixedLength.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 7, + 9, + 8, + 10, + 6, + 5 + ]); + WriteUnsortedData(); + fixedLengthWithOffset.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 7, + 8, + 6, + 5 + ]); + WriteUnsortedData(); + lengthTracking.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 5, + 7, + 9, + 6, + 8, + 10 + ]); + WriteUnsortedData(); + lengthTrackingWithOffset.sort(OddBeforeEvenComparison); + assert.compareArray(ToNumbers(taFull), [ + 10, + 9, + 5, + 7, + 6, + 8 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/sort/comparefn-shrink.js b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..be19ce298d97ca3fbce77e9a1cc95d30e37b9f8d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/comparefn-shrink.js @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: > + SendableTypedArray.p.sort behaves correctly on SendableTypedArrays backed by a + resizable buffer and is shrunk by the comparison callback +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer, Array.prototype.includes] +---*/ + +// Returns a function that resizes rab to size resizeTo and then compares its +// arguments. Such a result function is to be used as an argument to .sort. +function ResizeAndCompare(rab, resizeTo) { + return (a, b) => { + rab.resize(resizeTo); + if (a < b) { + return -1; + } + if (a > b) { + return 1; + } + return 0; + } +} + +function WriteUnsortedData(taFull) { + for (let i = 0; i < taFull.length; ++i) { + taFull[i] = MayNeedBigInt(taFull, 10 - i); + } +} + +// Fixed length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 2 * ctor.BYTES_PER_ELEMENT; + const fixedLength = new ctor(rab, 0, 4); + const taFull = new ctor(rab, 0); + WriteUnsortedData(taFull); + fixedLength.sort(ResizeAndCompare(rab, resizeTo)); + // The data is unchanged. + assert.compareArray(ToNumbers(taFull), [ + 10, + 9 + ]); +} + +// Length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const resizeTo = 2 * ctor.BYTES_PER_ELEMENT; + const lengthTracking = new ctor(rab, 0); + const taFull = new ctor(rab, 0); + WriteUnsortedData(taFull); + lengthTracking.sort(ResizeAndCompare(rab, resizeTo)); + // The sort result is implementation defined, but it contains 2 elements out + // of the 4 original ones. + const newData = ToNumbers(taFull); + assert.sameValue(newData.length, 2); + assert([ + 10, + 9, + 8, + 7 + ].includes(newData[0])); + assert([ + 10, + 9, + 8, + 7 + ].includes(newData[1])); +} diff --git a/test/sendable/builtins/TypedArray/prototype/sort/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/sort/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f4d47fd40f1603eaf34f890122134cc0826d5af1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/detached-buffer.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + 1. Let obj be the this value. + 2. Let buffer be ? ValidateSendableTypedArray(obj). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var comparefn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.sort(comparefn); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/sort/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..96c9052315a9c87d4fe0d3427740826a787cd802 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/invoked-as-func.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.25 %SendableTypedArray%.prototype.sort ( comparefn ) + + ... + This function is not generic. The this value must be an object with a + [[TypedArrayName]] internal slot. + ... + + 1. Let obj be the this value as the argument. + 2. Let buffer be ValidateSendableTypedArray(obj). + 3. ReturnIfAbrupt(buffer). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var sort = SendableTypedArray.prototype.sort; + +assert.sameValue(typeof sort, 'function'); + +assert.throws(TypeError, function() { + sort(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/sort/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..38c8eaf97c93db3aac119889b990e6085180cec7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/invoked-as-method.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.25 %SendableTypedArray%.prototype.sort ( comparefn ) + + ... + This function is not generic. The this value must be an object with a + [[TypedArrayName]] internal slot. + ... + + 1. Let obj be the this value as the argument. + 2. Let buffer be ValidateSendableTypedArray(obj). + 3. ReturnIfAbrupt(buffer). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.sort, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.sort(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/length.js b/test/sendable/builtins/TypedArray/prototype/sort/length.js new file mode 100644 index 0000000000000000000000000000000000000000..3f5c8fa1b1179d3a6444739c1756fa842f67b587 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: > + %SendableTypedArray%.prototype.sort.length is 1. +info: | + %SendableTypedArray%.prototype.sort ( comparefn ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.sort, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/name.js b/test/sendable/builtins/TypedArray/prototype/sort/name.js new file mode 100644 index 0000000000000000000000000000000000000000..fa5457db1cd206cf97885dcdddabff73664030fd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: > + %SendableTypedArray%.prototype.sort.name is "sort". +info: | + %SendableTypedArray%.prototype.sort ( comparefn ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.sort, "name", { + value: "sort", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/sort/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..4d42d0162b7fd9b70962d0f8520a99f312816adf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.sort does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.sort), + false, + 'isConstructor(SendableTypedArray.prototype.sort) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.sort(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/sort/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/sort/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..908168e3e3dddd6756fcadb5635a842a61850ee6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: > + "sort" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'sort', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/resizable-buffer-default-comparator.js b/test/sendable/builtins/TypedArray/prototype/sort/resizable-buffer-default-comparator.js new file mode 100644 index 0000000000000000000000000000000000000000..bb13c5ce72336e6c2688d37965093d6c6436f470 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/resizable-buffer-default-comparator.js @@ -0,0 +1,194 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: > + SendableTypedArray.p.sort behaves correctly on SendableTypedArrays backed by resizable buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// This test cannot be reused between SendableTypedArray.protoype.sort and +// Array.prototype.sort, since the default sorting functions differ. + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const taFull = new ctor(rab, 0); + function WriteUnsortedData() { + // Write some data into the array. + for (let i = 0; i < taFull.length; ++i) { + taFull[i] = MayNeedBigInt(taFull, 10 - 2 * i); + } + } + // Orig. array: [10, 8, 6, 4] + // [10, 8, 6, 4] << fixedLength + // [6, 4] << fixedLengthWithOffset + // [10, 8, 6, 4, ...] << lengthTracking + // [6, 4, ...] << lengthTrackingWithOffset + + WriteUnsortedData(); + fixedLength.sort(); + assert.compareArray(ToNumbers(taFull), [ + 4, + 6, + 8, + 10 + ]); + WriteUnsortedData(); + fixedLengthWithOffset.sort(); + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 4, + 6 + ]); + WriteUnsortedData(); + lengthTracking.sort(); + assert.compareArray(ToNumbers(taFull), [ + 4, + 6, + 8, + 10 + ]); + WriteUnsortedData(); + lengthTrackingWithOffset.sort(); + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 4, + 6 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [10, 8, 6] + // [10, 8, 6, ...] << lengthTracking + // [6, ...] << lengthTrackingWithOffset + + WriteUnsortedData(); + assert.throws(TypeError, () => { + fixedLength.sort(); + }); + WriteUnsortedData(); + assert.throws(TypeError, () => { + fixedLengthWithOffset.sort(); + }); + WriteUnsortedData(); + lengthTracking.sort(); + assert.compareArray(ToNumbers(taFull), [ + 6, + 8, + 10 + ]); + WriteUnsortedData(); + lengthTrackingWithOffset.sort(); + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 6 + ]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + WriteUnsortedData(); + assert.throws(TypeError, () => { + fixedLength.sort(); + }); + WriteUnsortedData(); + assert.throws(TypeError, () => { + fixedLengthWithOffset.sort(); + }); + WriteUnsortedData(); + lengthTracking.sort(); + assert.compareArray(ToNumbers(taFull), [10]); + WriteUnsortedData(); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.sort(); + }); + + // Shrink to zero. + rab.resize(0); + WriteUnsortedData(); + assert.throws(TypeError, () => { + fixedLength.sort(); + }); + WriteUnsortedData(); + assert.throws(TypeError, () => { + fixedLengthWithOffset.sort(); + }); + WriteUnsortedData(); + lengthTracking.sort(); + assert.compareArray(ToNumbers(taFull), []); + WriteUnsortedData(); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.sort(); + }); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [10, 8, 6, 4, 2, 0] + // [10, 8, 6, 4] << fixedLength + // [6, 4] << fixedLengthWithOffset + // [10, 8, 6, 4, 2, 0, ...] << lengthTracking + // [6, 4, 2, 0, ...] << lengthTrackingWithOffset + + WriteUnsortedData(); + fixedLength.sort(); + assert.compareArray(ToNumbers(taFull), [ + 4, + 6, + 8, + 10, + 2, + 0 + ]); + WriteUnsortedData(); + fixedLengthWithOffset.sort(); + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 4, + 6, + 2, + 0 + ]); + WriteUnsortedData(); + lengthTracking.sort(); + assert.compareArray(ToNumbers(taFull), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + WriteUnsortedData(); + lengthTrackingWithOffset.sort(); + assert.compareArray(ToNumbers(taFull), [ + 10, + 8, + 0, + 2, + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/sort/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/sort/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..03d00bc4945690f3fb96ce9f93ecbd750d2f902b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [ArrayBuffer, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.sort, + 'function', + 'implements SendableTypedArray.prototype.sort' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.sort(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.sort(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the sort operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.sort(); + throw new Test262Error('sort completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/return-same-instance.js b/test/sendable/builtins/TypedArray/prototype/sort/return-same-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..71255421f1690ce359b1d8e8c8af0a75699b2ff9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/return-same-instance.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Returns the same instance +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + When the SendableTypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([2, 1]); + var result = sample.sort(); + + assert.sameValue(sample, result, "without comparefn"); + + result = sample.sort(function() { return 0; }); + assert.sameValue(sample, result, "with comparefn"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/sort-tonumber.js b/test/sendable/builtins/TypedArray/prototype/sort/sort-tonumber.js new file mode 100644 index 0000000000000000000000000000000000000000..24a596eac53fe05864d48ee90906ee6709a320e9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/sort-tonumber.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: The result of compareFn is immediately passed through ToNumber +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + ... + 2. If comparefn is not undefined, then + a. Let v be ? ToNumber(? Call(comparefn, undefined, « x, y »)). + b. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta = new TA(4); + var ab = ta.buffer; + + var called = false; + ta.sort(function(a, b) { + // Detaching the buffer does not cause sort to throw. + $DETACHBUFFER(ab); + return { + [Symbol.toPrimitive]() { called = true; } + }; + }); + + assert.sameValue(true, called); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/sortcompare-with-no-tostring.js b/test/sendable/builtins/TypedArray/prototype/sort/sortcompare-with-no-tostring.js new file mode 100644 index 0000000000000000000000000000000000000000..95a750f1c725f9848db7d0e14b865b49d16b2107 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/sortcompare-with-no-tostring.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: SendableTypedArrays sort does not cast values to String +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + When the SendableTypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var toStringCalled = false; +Number.prototype.toString = function() { + toStringCalled = true; +} + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([20, 100, 3]); + var result = sample.sort(); + assert.sameValue(toStringCalled, false, "Number.prototype.toString will not be called"); + assert(compareArray(result, [3, 20, 100]), "Default sorting by value"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/sorted-values-nan.js b/test/sendable/builtins/TypedArray/prototype/sort/sorted-values-nan.js new file mode 100644 index 0000000000000000000000000000000000000000..cd9cc90d24f2ae7f432ad25e0e09c7789a2443ea --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/sorted-values-nan.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Sort values to numeric ascending order +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + When the SendableTypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + + NOTE: Because NaN always compares greater than any other value, NaN property + values always sort to the end of the result when comparefn is not provided. +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([2, NaN, NaN, 0, 1]).sort(); + assert.sameValue(sample[0], 0, "#1 [0]"); + assert.sameValue(sample[1], 1, "#1 [1]"); + assert.sameValue(sample[2], 2, "#1 [2]"); + assert.sameValue(sample[3], NaN, "#1 [3]"); + assert.sameValue(sample[4], NaN, "#1 [4]"); + + sample = new TA([3, NaN, NaN, Infinity, 0, -Infinity, 2]).sort(); + assert.sameValue(sample[0], -Infinity, "#2 [0]"); + assert.sameValue(sample[1], 0, "#2 [1]"); + assert.sameValue(sample[2], 2, "#2 [2]"); + assert.sameValue(sample[3], 3, "#2 [3]"); + assert.sameValue(sample[4], Infinity, "#2 [4]"); + assert.sameValue(sample[5], NaN, "#2 [5]"); + assert.sameValue(sample[6], NaN, "#2 [6]"); +}, floatArrayConstructors); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/sorted-values.js b/test/sendable/builtins/TypedArray/prototype/sort/sorted-values.js new file mode 100644 index 0000000000000000000000000000000000000000..d838d02520127303de4ed82c4561fda62c3bb968 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/sorted-values.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Sort values to numeric ascending order +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + When the SendableTypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([4, 3, 2, 1]).sort(); + assert(compareArray(sample, [1, 2, 3, 4]), "descending values"); + + sample = new TA([3, 4, 1, 2]).sort(); + assert(compareArray(sample, [1, 2, 3, 4]), "mixed numbers"); + + sample = new TA([3, 4, 3, 1, 0, 1, 2]).sort(); + assert(compareArray(sample, [0, 1, 1, 2, 3, 3, 4]), "repeating numbers"); +}); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 0, -0, 2]).sort(); + assert(compareArray(sample, [-0, 0, 1, 2]), "0s"); +}, floatArrayConstructors); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([1, 0, -0, 2]).sort(); + assert(compareArray(sample, [0, 0, 1, 2]), "0s"); +}, intArrayConstructors); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([-4, 3, 4, -3, 2, -2, 1, 0]).sort(); + assert(compareArray(sample, [-4, -3, -2, 0, 1, 2, 3, 4]), "negative values"); +}, floatArrayConstructors.concat([Int8Array, Int16Array, Int32Array])); + +testWithTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([0.5, 0, 1.5, 1]).sort(); + assert(compareArray(sample, [0, 0.5, 1, 1.5]), "non integers"); + + sample = new TA([0.5, 0, 1.5, -0.5, -1, -1.5, 1]).sort(); + assert(compareArray(sample, [-1.5, -1, -0.5, 0, 0.5, 1, 1.5]), "non integers + negatives"); + + sample = new TA([3, 4, Infinity, -Infinity, 1, 2]).sort(); + assert(compareArray(sample, [-Infinity, 1, 2, 3, 4, Infinity]), "infinities"); + +}, floatArrayConstructors); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/stability.js b/test/sendable/builtins/TypedArray/prototype/sort/stability.js new file mode 100644 index 0000000000000000000000000000000000000000..e8e4d89482e04b745fcb71acc9996d1338db66df --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/stability.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Stability of %SendableTypedArray%.prototype.sort. +info: | + https://github.com/tc39/ecma262/pull/1433 +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +// Treat 0..3, 4..7, etc. as equal. +const compare = (a, b) => (a / 4 | 0) - (b / 4 | 0); + +testWithTypedArrayConstructors((TA) => { + // Create an array of the form `[0, 1, …, 126, 127]`. + const array = Array.from({ length: 128 }, (_, i) => i); + + const typedArray1 = new TA(array); + assert(compareArray( + typedArray1.sort(compare), + array + ), 'pre-sorted'); + + // Reverse `array` in-place so it becomes `[127, 126, …, 1, 0]`. + array.reverse(); + + const typedArray2 = new TA(array); + assert(compareArray( + typedArray2.sort(compare), + [ + 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, + 15, 14, 13, 12, 19, 18, 17, 16, 23, 22, 21, 20, + 27, 26, 25, 24, 31, 30, 29, 28, 35, 34, 33, 32, + 39, 38, 37, 36, 43, 42, 41, 40, 47, 46, 45, 44, + 51, 50, 49, 48, 55, 54, 53, 52, 59, 58, 57, 56, + 63, 62, 61, 60, 67, 66, 65, 64, 71, 70, 69, 68, + 75, 74, 73, 72, 79, 78, 77, 76, 83, 82, 81, 80, + 87, 86, 85, 84, 91, 90, 89, 88, 95, 94, 93, 92, + 99, 98, 97, 96, 103, 102, 101, 100, 107, 106, 105, 104, + 111, 110, 109, 108, 115, 114, 113, 112, 119, 118, 117, 116, + 123, 122, 121, 120, 127, 126, 125, 124, + ] + ), 'not presorted'); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/sort/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..5df32d2a1b6992fe887622655232b7b7888e7d76 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/this-is-not-object.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + 1. Let obj be the this value as the argument. + 2. Let buffer be ? ValidateSendableTypedArray(obj). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var sort = SendableTypedArray.prototype.sort; +var comparefn = function() {}; + +assert.throws(TypeError, function() { + sort.call(undefined, comparefn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + sort.call(null, comparefn); +}, "this is null"); + +assert.throws(TypeError, function() { + sort.call(42, comparefn); +}, "this is 42"); + +assert.throws(TypeError, function() { + sort.call("1", comparefn); +}, "this is a string"); + +assert.throws(TypeError, function() { + sort.call(true, comparefn); +}, "this is true"); + +assert.throws(TypeError, function() { + sort.call(false, comparefn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + sort.call(s, comparefn); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/sort/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/sort/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..cf0dab9a8579ef515ebb36e3b9d4bce9d03b7c58 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/sort/this-is-not-typedarray-instance.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.sort +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.26 %SendableTypedArray%.prototype.sort ( comparefn ) + + 1. Let obj be the this value as the argument. + 2. Let buffer be ? ValidateSendableTypedArray(obj). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var sort = SendableTypedArray.prototype.sort; +var comparefn = function() {}; + +assert.throws(TypeError, function() { + sort.call({}, comparefn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + sort.call([], comparefn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + sort.call(ab, comparefn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + sort.call(dv, comparefn); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..239413af454f12dbd4d84822e6653b8aa1fd379a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/detached-buffer.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Throws a TypeError creating a new instance with a detached buffer +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be + ? ToInteger(end). + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + ... + + 22.2.4.5 SendableTypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 11. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var begin, end; + +var o1 = { + valueOf: function() { + begin = true; + return 0; + } +}; + +var o2 = { + valueOf: function() { + end = true; + return 2; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + begin = false; + end = false; + + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.subarray(o1, o2); + }); + + assert(begin, "observable ToInteger(begin)"); + assert(end, "observable ToInteger(end)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/infinity.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..7076c1c6a256a4c7344843a37b5cf68a80267ef7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/infinity.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Infinity values on begin and end +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert( + compareArray(sample.subarray(-Infinity), [40n, 41n, 42n, 43n]), + "begin == -Infinity" + ); + assert( + compareArray(sample.subarray(Infinity), []), + "being == Infinity" + ); + assert( + compareArray(sample.subarray(0, -Infinity), []), + "end == -Infinity" + ); + assert( + compareArray(sample.subarray(0, Infinity), [40n, 41n, 42n, 43n]), + "end == Infinity" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/minus-zero.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/minus-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..69392abba8f000834fba7a9f9ef24177610c7bcf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/minus-zero.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: -0 values on begin and end +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert( + compareArray(sample.subarray(-0), [40n, 41n, 42n, 43n]), + "begin == -0" + ); + assert( + compareArray(sample.subarray(-0, 4), [40n, 41n, 42n, 43n]), + "being == -0, end == length" + ); + assert( + compareArray(sample.subarray(0, -0), []), + "being == 0, end == -0" + ); + assert( + compareArray(sample.subarray(-0, -0), []), + "being == -0, end == -0" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/result-does-not-copy-ordinary-properties.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/result-does-not-copy-ordinary-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..e685189f64ec2c41ab5b39499f62be6bf0d7e99b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/result-does-not-copy-ordinary-properties.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Subarray result does not import own property +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([41n, 42n, 43n, 44n]); + var result; + + sample.foo = 42; + + result = sample.subarray(0); + assert.sameValue( + result.hasOwnProperty("foo"), + false, + "does not import own property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-from-same-ctor.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-from-same-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..938b3900c61f941465a4d38f3a68d704f6a840d6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-from-same-ctor.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Returns a new instance from the same constructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var result = sample.subarray(1); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "prototype" + ); + assert.sameValue(result.constructor, sample.constructor, "constructor"); + assert(result instanceof TA, "instanceof"); + + assert( + compareArray(sample, [40n, 41n, 42n, 43n]), + "original sample remains the same" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-with-shared-buffer.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-with-shared-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f3685a2fe033cbb76680d96f59a7f8f96c5f229e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-with-shared-buffer.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Returns a new instance sharing the same buffer +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var buffer = sample.buffer; + var result = sample.subarray(1); + + assert.notSameValue(result, sample, "returns a new instance"); + assert.sameValue(result.buffer, sample.buffer, "shared buffer"); + assert.sameValue(sample.buffer, buffer, "original buffer is preserved"); + + sample[1] = 100n; + assert( + compareArray(result, [100n, 42n, 43n]), + "changes on the original sample values affect the new instance" + ); + + result[1] = 111n; + assert( + compareArray(sample, [40n, 100n, 111n, 43n]), + "changes on the new instance values affect the original sample" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/results-with-different-length.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/results-with-different-length.js new file mode 100644 index 0000000000000000000000000000000000000000..bbf69b82e074ef814ed5717aac149e6a3c6546c0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/results-with-different-length.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Subarray may return a new instance with a smaller length +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + function testRes(result, expected, msg) { + assert(compareArray(result, expected), msg + ", result: [" + result + "]"); + } + + testRes(sample.subarray(1), [41n, 42n, 43n], "begin == 1"); + testRes(sample.subarray(2), [42n, 43n], "begin == 2"); + testRes(sample.subarray(3), [43n], "begin == 3"); + + testRes(sample.subarray(1, 4), [41n, 42n, 43n], "begin == 1, end == length"); + testRes(sample.subarray(2, 4), [42n, 43n], "begin == 2, end == length"); + testRes(sample.subarray(3, 4), [43n], "begin == 3, end == length"); + + testRes(sample.subarray(0, 1), [40n], "begin == 0, end == 1"); + testRes(sample.subarray(0, 2), [40n, 41n], "begin == 0, end == 2"); + testRes(sample.subarray(0, 3), [40n, 41n, 42n], "begin == 0, end == 3"); + + testRes(sample.subarray(-1), [43n], "begin == -1"); + testRes(sample.subarray(-2), [42n, 43n], "begin == -2"); + testRes(sample.subarray(-3), [41n, 42n, 43n], "begin == -3"); + + testRes(sample.subarray(-1, 4), [43n], "begin == -1, end == length"); + testRes(sample.subarray(-2, 4), [42n, 43n], "begin == -2, end == length"); + testRes(sample.subarray(-3, 4), [41n, 42n, 43n], "begin == -3, end == length"); + + testRes(sample.subarray(0, -1), [40n, 41n, 42n], "begin == 0, end == -1"); + testRes(sample.subarray(0, -2), [40n, 41n], "begin == 0, end == -2"); + testRes(sample.subarray(0, -3), [40n], "begin == 0, end == -3"); + + testRes(sample.subarray(-0, -1), [40n, 41n, 42n], "begin == -0, end == -1"); + testRes(sample.subarray(-0, -2), [40n, 41n], "begin == -0, end == -2"); + testRes(sample.subarray(-0, -3), [40n], "begin == -0, end == -3"); + + testRes(sample.subarray(-2, -1), [42n], "length == 4, begin == -2, end == -1"); + testRes(sample.subarray(1, -1), [41n, 42n], "length == 4, begin == 1, end == -1"); + testRes(sample.subarray(1, -2), [41n], "length == 4, begin == 1, end == -2"); + testRes(sample.subarray(2, -1), [42n], "length == 4, begin == 2, end == -1"); + + testRes(sample.subarray(-1, 5), [43n], "begin == -1, end > length"); + testRes(sample.subarray(-2, 4), [42n, 43n], "begin == -2, end > length"); + testRes(sample.subarray(-3, 4), [41n, 42n, 43n], "begin == -3, end > length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/results-with-empty-length.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/results-with-empty-length.js new file mode 100644 index 0000000000000000000000000000000000000000..9af79be796a5adae5ddac2263753c3d2d9b340c1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/results-with-empty-length.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Subarray may return a new empty instance +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + function testRes(result, msg) { + assert.sameValue(result.length, 0, msg); + assert.sameValue( + result.hasOwnProperty(0), + false, + msg + " & result.hasOwnProperty(0) === false" + ); + } + + testRes(sample.subarray(4), "begin == length"); + testRes(sample.subarray(5), "begin > length"); + + testRes(sample.subarray(4, 4), "begin == length, end == length"); + testRes(sample.subarray(5, 4), "begin > length, end == length"); + + testRes(sample.subarray(4, 4), "begin == length, end > length"); + testRes(sample.subarray(5, 4), "begin > length, end > length"); + + testRes(sample.subarray(0, 0), "begin == 0, end == 0"); + testRes(sample.subarray(-0, -0), "begin == -0, end == -0"); + testRes(sample.subarray(1, 0), "begin > 0, end == 0"); + testRes(sample.subarray(-1, 0), "being < 0, end == 0"); + + testRes(sample.subarray(2, 1), "begin > 0, begin < length, begin > end, end > 0"); + testRes(sample.subarray(2, 2), "begin > 0, begin < length, begin == end"); + + testRes(sample.subarray(2, -2), "begin > 0, begin < length, end == -2"); + + testRes(sample.subarray(-1, -1), "length = 4, begin == -1, end == -1"); + testRes(sample.subarray(-1, -2), "length = 4, begin == -1, end == -2"); + testRes(sample.subarray(-2, -2), "length = 4, begin == -2, end == -2"); + + testRes(sample.subarray(0, -4), "begin == 0, end == -length"); + testRes(sample.subarray(-4, -4), "begin == -length, end == -length"); + testRes(sample.subarray(-5, -4), "begin < -length, end == -length"); + + testRes(sample.subarray(0, -5), "begin == 0, end < -length"); + testRes(sample.subarray(-4, -5), "begin == -length, end < -length"); + testRes(sample.subarray(-5, -5), "begin < -length, end < -length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/results-with-same-length.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/results-with-same-length.js new file mode 100644 index 0000000000000000000000000000000000000000..3ced22c914d026de675755f05f5c883d2a723879 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/results-with-same-length.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Subarray may return a new instance with the same length +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + function testRes(result, msg) { + assert.sameValue(result.length, 4, msg); + assert.sameValue(result[0], 40n, msg + " & result[0] === 40"); + assert.sameValue(result[1], 41n, msg + " & result[1] === 41"); + assert.sameValue(result[2], 42n, msg + " & result[2] === 42"); + assert.sameValue(result[3], 43n, msg + " & result[3] === 43"); + } + + testRes(sample.subarray(0), "begin == 0"); + testRes(sample.subarray(-4), "begin == -srcLength"); + testRes(sample.subarray(-5), "begin < -srcLength"); + + testRes(sample.subarray(0, 4), "begin == 0, end == srcLength"); + testRes(sample.subarray(-4, 4), "begin == -srcLength, end == srcLength"); + testRes(sample.subarray(-5, 4), "begin < -srcLength, end == srcLength"); + + testRes(sample.subarray(0, 5), "begin == 0, end > srcLength"); + testRes(sample.subarray(-4, 5), "begin == -srcLength, end > srcLength"); + testRes(sample.subarray(-5, 5), "begin < -srcLength, end > srcLength"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin-symbol.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..e22390b7c48558ec25d631117dc009e7255f72df --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin-symbol.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Return abrupt from ToInteger(begin), begin is symbol +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.subarray(s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin.js new file mode 100644 index 0000000000000000000000000000000000000000..c55130521b0433f64902c390ba4dd78d7e099b7c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Return abrupt from ToInteger(begin) +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.subarray(o1); + }); + + assert.throws(Test262Error, function() { + sample.subarray(o2); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end-symbol.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..33e6644272eba8d03f7493dd81ab177b676626fb --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end-symbol.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Return abrupt from ToInteger(end), end is symbol +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd + be ? ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.subarray(0, s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end.js new file mode 100644 index 0000000000000000000000000000000000000000..a1f19534a088d054edfa9b429c22164659b30fe6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Return abrupt from ToInteger(end) +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd + be ? ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.subarray(0, o1); + }); + + assert.throws(Test262Error, function() { + sample.subarray(0, o2); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-abrupt.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..5f4804cfc0959b2a7dd1183a12274c81520627c4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.subarray(0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-inherited.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000000000000000000000000000000000..1b1d33943922df5a2e5168a6e33f576940307ec2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-inherited.js @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var calls = 0; + var result; + + Object.defineProperty(TA.prototype, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.subarray(0); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + undefined, + "used defaultCtor but still checks the inherited .constructor" + ); + + calls = 6; + result.constructor; + assert.sameValue( + calls, + 7, + "result.constructor triggers the inherited accessor property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..618f964c0735d7bba5452c1a64a18a108dd19c60 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.subarray(0); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..d5ea86fc515c81f72cd05af78f9c87bff9f6fb54 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: get constructor on SpeciesConstructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var calls = 0; + var result; + + Object.defineProperty(sample, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.subarray(0); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + TA, + "use defaultCtor on an undefined return - .constructor check" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-abrupt.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..7a9951b117a88a02e495a63d38fdf28fb4c59da0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-abrupt.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.subarray(0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-invocation.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000000000000000000000000000000000..92ef14fc7b8434be1e7563a0e93e7dace4328445 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + var expectedOffset = TA.BYTES_PER_ELEMENT; + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(buffer, offset, length) { + result = arguments; + ctorThis = this; + return new TA(buffer, offset, length); + }; + + sample.subarray(1); + + assert.sameValue(result.length, 3, "called with 3 arguments"); + assert.sameValue(result[0], sample.buffer, "[0] is sample.buffer"); + assert.sameValue(result[1], expectedOffset, "[1] is the byte offset pos"); + assert.sameValue(result[2], 2, "[2] is expected length"); + + assert( + ctorThis instanceof sample.constructor[Symbol.species], + "`this` value in the @@species fn is an instance of the function itself" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..15de2327d61559148a50b79b3a186e6c1f90b3cf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Custom @@species constructor may return a totally different SendableTypedArray +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n]); + var other = new BigInt64Array([1n, 0n, 1n]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.subarray(0, 0); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [1n, 0n, 1n]), "the returned object is preserved"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-throws.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..19397dfb61dc067bf0c65d6dacbbf1d938b65df7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var ctor = function() {}; + + sample.constructor = {}; + sample.constructor[Symbol.species] = ctor; + + assert.throws(TypeError, function() { + sample.subarray(0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..c3d7aa34f344f3ce09cc46839d73f4b988bb732f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Use custom @@species constructor if available +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + var calls = 0; + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(buffer, offset, length) { + calls++; + return new TA(buffer, offset, length); + }; + + result = sample.subarray(1); + + assert.sameValue(calls, 1, "ctor called once"); + assert(compareArray(result, [41n, 42n]), "expected subarray"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..1cf5341f6c39be65278c5a2d79b010c47fdc687f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-returns-throws.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + sample.constructor[Symbol.species] = 0; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "true"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-use-default-ctor.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..928eb7ad7004c2a200dbee850ebf727f711a2a4b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var result; + + sample.constructor = {}; + + result = sample.subarray(0); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "undefined @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "undefined @@species - ctor check"); + + sample.constructor[Symbol.species] = null; + result = sample.subarray(0); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "null @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "null @@species - ctor check"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species.js new file mode 100644 index 0000000000000000000000000000000000000000..15d93c81928672704e7b5e9da9e80071202f5d78 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + get @@species from found constructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calls = 0; + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + calls++; + } + }); + + sample.subarray(0); + + assert.sameValue(calls, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/tointeger-begin.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/tointeger-begin.js new file mode 100644 index 0000000000000000000000000000000000000000..67045228a338cb6aeac0d002a9815d4d882431f5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/tointeger-begin.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: ToInteger(begin) +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert(compareArray(sample.subarray(false), [40n, 41n, 42n, 43n]), "false"); + assert(compareArray(sample.subarray(true), [41n, 42n, 43n]), "true"); + + assert(compareArray(sample.subarray(NaN), [40n, 41n, 42n, 43n]), "NaN"); + assert(compareArray(sample.subarray(null), [40n, 41n, 42n, 43n]), "null"); + assert(compareArray(sample.subarray(undefined), [40n, 41n, 42n, 43n]), "undefined"); + + assert(compareArray(sample.subarray(1.1), [41n, 42n, 43n]), "1.1"); + assert(compareArray(sample.subarray(1.5), [41n, 42n, 43n]), "1.5"); + assert(compareArray(sample.subarray(0.6), [40n, 41n, 42n, 43n]), "0.6"); + + assert(compareArray(sample.subarray(-1.5), [43n]), "-1.5"); + assert(compareArray(sample.subarray(-1.1), [43n]), "-1.1"); + assert(compareArray(sample.subarray(-0.6), [40n, 41n, 42n, 43n]), "-0.6"); + + assert(compareArray(sample.subarray("3"), [43n]), "string"); + assert( + compareArray( + sample.subarray(obj), + [42n, 43n] + ), + "object" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/tointeger-end.js b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/tointeger-end.js new file mode 100644 index 0000000000000000000000000000000000000000..e8213ee11b281c2bdceeab19792e6ca7abd10f9c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/BigInt/tointeger-end.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: ToInteger(end) +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be + ? ToInteger(end). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert(compareArray(sample.subarray(0, false), []), "false"); + assert(compareArray(sample.subarray(0, true), [40n]), "true"); + + assert(compareArray(sample.subarray(0, NaN), []), "NaN"); + assert(compareArray(sample.subarray(0, null), []), "null"); + assert(compareArray(sample.subarray(0, undefined), [40n, 41n, 42n, 43n]), "undefined"); + + assert(compareArray(sample.subarray(0, 0.6), []), "0.6"); + assert(compareArray(sample.subarray(0, 1.1), [40n]), "1.1"); + assert(compareArray(sample.subarray(0, 1.5), [40n]), "1.5"); + assert(compareArray(sample.subarray(0, -0.6), []), "-0.6"); + assert(compareArray(sample.subarray(0, -1.1), [40n, 41n, 42n]), "-1.1"); + assert(compareArray(sample.subarray(0, -1.5), [40n, 41n, 42n]), "-1.5"); + + assert(compareArray(sample.subarray(0, "3"), [40n, 41n, 42n]), "string"); + assert( + compareArray( + sample.subarray(0, obj), + [40n, 41n] + ), + "object" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/coerced-begin-end-grow.js b/test/sendable/builtins/TypedArray/prototype/subarray/coerced-begin-end-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..396ed930aa6016262b224be9f451f9b1603312f3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/coerced-begin-end-grow.js @@ -0,0 +1,118 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + SendableTypedArray.p.subarray behaves correctly on SendableTypedArrays backed by resizable + buffers that are grown by argument coercion. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [0, 2, 4, 6, ...] << lengthTracking + +// Growing a fixed length TA back in bounds. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + // Make `fixedLength` OOB. + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + const evil = { + valueOf: () => { + rab.resize(4 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + // The length computation is done before parameter conversion. At that + // point, the length is 0, since the TA is OOB. + assert.compareArray(ToNumbers(fixedLength.subarray(evil, 1)), []); +} + +// As above but with the second parameter conversion growing the buffer. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + // Make `fixedLength` OOB. + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + const evil = { + valueOf: () => { + rab.resize(4 * ctor.BYTES_PER_ELEMENT); + return 1; + } + }; + // The length computation is done before parameter conversion. At that + // point, the length is 0, since the TA is OOB. + assert.compareArray(ToNumbers(fixedLength.subarray(0, evil)), []); +} + + +// Growing + fixed-length TA. Growing won't affect anything. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.compareArray(ToNumbers(fixedLength.subarray(evil)), [ + 0, + 2, + 4, + 6 + ]); +} + +// As above but with the second parameter conversion growing the buffer. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return 4; + } + }; + assert.compareArray(ToNumbers(fixedLength.subarray(0, evil)), [ + 0, + 2, + 4, + 6 + ]); +} + +// Growing + length-tracking TA. The length computation is done with the +// original length. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + const evil = { + valueOf: () => { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.compareArray( + ToNumbers(lengthTracking.subarray(evil, lengthTracking.length)), [ + 0, + 2, + 4, + 6 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/coerced-begin-end-shrink.js b/test/sendable/builtins/TypedArray/prototype/subarray/coerced-begin-end-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..8629081d570e28a51c32968ff20a58aca07a5bf6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/coerced-begin-end-shrink.js @@ -0,0 +1,204 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + SendableTypedArray.p.subarray behaves correctly on SendableTypedArrays backed by resizable + buffers that are shrunk by argument coercion. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [0, 2, 4, 6, ...] << lengthTracking + + +// Fixed-length TA + first parameter conversion shrinks. The old length is +// used in the length computation, and the subarray construction fails. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.throws(RangeError, () => { + fixedLength.subarray(evil); + }); +} + +// Like the previous test, but now we construct a smaller subarray and it +// succeeds. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.compareArray(ToNumbers(fixedLength.subarray(evil, 1)), [0]); +} + +// As above but with the second parameter conversion shrinking the buffer. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 1; + } + }; + assert.compareArray(ToNumbers(fixedLength.subarray(0,evil)), [0]); +} + +// Fixed-length TA + second parameter conversion shrinks. The old length is +// used in the length computation, and the subarray construction fails. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 3; + } + }; + assert.throws(RangeError, () => { + fixedLength.subarray(0, evil); + }); +} + +// Like the previous test, but now we construct a smaller subarray and it +// succeeds. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 1; + } + }; + assert.compareArray(ToNumbers(fixedLength.subarray(0, evil)), [0]); +} + +// Shrinking + fixed-length TA, subarray construction succeeds even though the +// TA goes OOB. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.compareArray(ToNumbers(fixedLength.subarray(evil, 1)), [0]); +} + +// As above but with the second parameter conversion shrinking the buffer. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + const evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 1; + } + }; + assert.compareArray(ToNumbers(fixedLength.subarray(0,evil)), [0]); +} + +// Length-tracking TA + first parameter conversion shrinks. The old length is +// used in the length computation, and the subarray construction fails. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.throws(RangeError, () => { + lengthTracking.subarray(evil, lengthTracking.length); + }); +} + +// Like the previous test, but now we construct a smaller subarray and it +// succeeds. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.compareArray(ToNumbers(lengthTracking.subarray(evil, 1)), [0]); +} + +// As above but with the second parameter conversion shrinking the buffer. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 1; + } + }; + assert.compareArray(ToNumbers(lengthTracking.subarray(0,evil)), [0]); +} + +// Length-tracking TA + first parameter conversion shrinks. The second +// parameter is negative -> the relative index is not recomputed, and the +// subarray construction fails. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 0; + } + }; + assert.throws(RangeError, () => { + lengthTracking.subarray(evil, -1); + }); +} + +// Length-tracking TA + second parameter conversion shrinks. The second +// parameter is too large -> the subarray construction fails. +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab); + let evil = { + valueOf: () => { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + return 3; + } + }; + assert.throws(RangeError, () => { + lengthTracking.subarray(0, evil); + }); +} diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/subarray/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..beb38df4497c5a2e4090dd9e8f14a9e489cffc48 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/detached-buffer.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Throws a TypeError creating a new instance with a detached buffer +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be + ? ToInteger(end). + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + ... + + 22.2.4.5 SendableTypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 11. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var begin, end; + +var o1 = { + valueOf: function() { + begin = true; + return 0; + } +}; + +var o2 = { + valueOf: function() { + end = true; + return 2; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + begin = false; + end = false; + + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.subarray(o1, o2); + }); + + assert(begin, "observable ToInteger(begin)"); + assert(end, "observable ToInteger(end)"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/infinity.js b/test/sendable/builtins/TypedArray/prototype/subarray/infinity.js new file mode 100644 index 0000000000000000000000000000000000000000..bd8eb3b10994c101fb32144f3c5e4f8ecff14ce3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/infinity.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Infinity values on begin and end +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert( + compareArray(sample.subarray(-Infinity), [40, 41, 42, 43]), + "begin == -Infinity" + ); + assert( + compareArray(sample.subarray(Infinity), []), + "being == Infinity" + ); + assert( + compareArray(sample.subarray(0, -Infinity), []), + "end == -Infinity" + ); + assert( + compareArray(sample.subarray(0, Infinity), [40, 41, 42, 43]), + "end == Infinity" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/subarray/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..3905c3df7b7364f870e719a7a92f21379f3840fc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/invoked-as-func.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.26 %SendableTypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var subarray = SendableTypedArray.prototype.subarray; + +assert.sameValue(typeof subarray, 'function'); + +assert.throws(TypeError, function() { + subarray(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/subarray/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..34b10645f4bcb6a5251a59f89dafffee86049f8a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/invoked-as-method.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.26 %SendableTypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.subarray, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.subarray(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/length.js b/test/sendable/builtins/TypedArray/prototype/subarray/length.js new file mode 100644 index 0000000000000000000000000000000000000000..93c4b912f21f583c3360e9682b623c1b6f4ac982 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + %SendableTypedArray%.prototype.subarray.length is 2. +info: | + %SendableTypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.subarray, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/minus-zero.js b/test/sendable/builtins/TypedArray/prototype/subarray/minus-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..a9b570abf87e666be6e5bbd438564d78885c953d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/minus-zero.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: -0 values on begin and end +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert( + compareArray(sample.subarray(-0), [40, 41, 42, 43]), + "begin == -0" + ); + assert( + compareArray(sample.subarray(-0, 4), [40, 41, 42, 43]), + "being == -0, end == length" + ); + assert( + compareArray(sample.subarray(0, -0), []), + "being == 0, end == -0" + ); + assert( + compareArray(sample.subarray(-0, -0), []), + "being == -0, end == -0" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/name.js b/test/sendable/builtins/TypedArray/prototype/subarray/name.js new file mode 100644 index 0000000000000000000000000000000000000000..bf4471e6cf4a13d63f3b5dd312c8628f34e50b6e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + %SendableTypedArray%.prototype.subarray.name is "subarray". +info: | + %SendableTypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.subarray, "name", { + value: "subarray", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/subarray/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..4f6ae912a78fbd4416ede547fb24af59fd1a9e5d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.subarray does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.subarray), + false, + 'isConstructor(SendableTypedArray.prototype.subarray) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.subarray(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/subarray/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..f31825736af1dc8f4ff957899321e1fdc8442d14 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + "subarray" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'subarray', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/subarray/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..8da78b2bc43f01e5d07a617e8796b93053008635 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/resizable-buffer.js @@ -0,0 +1,184 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + SendableTypedArray.p.subarray behaves correctly on SendableTypedArrays backed by resizable + buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + const fixedLengthSubFull = fixedLength.subarray(0); + assert.compareArray(ToNumbers(fixedLengthSubFull), [ + 0, + 2, + 4, + 6 + ]); + const fixedLengthWithOffsetSubFull = fixedLengthWithOffset.subarray(0); + assert.compareArray(ToNumbers(fixedLengthWithOffsetSubFull), [ + 4, + 6 + ]); + const lengthTrackingSubFull = lengthTracking.subarray(0); + assert.compareArray(ToNumbers(lengthTrackingSubFull), [ + 0, + 2, + 4, + 6 + ]); + const lengthTrackingWithOffsetSubFull = lengthTrackingWithOffset.subarray(0); + assert.compareArray(ToNumbers(lengthTrackingWithOffsetSubFull), [ + 4, + 6 + ]); + + // Relative offsets + assert.compareArray(ToNumbers(fixedLength.subarray(-2)), [ + 4, + 6 + ]); + assert.compareArray(ToNumbers(fixedLengthWithOffset.subarray(-1)), [6]); + assert.compareArray(ToNumbers(lengthTracking.subarray(-2)), [ + 4, + 6 + ]); + assert.compareArray(ToNumbers(lengthTrackingWithOffset.subarray(-1)), [6]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + // We can create subarrays of OOB arrays (which have length 0), as long as + // the new arrays are not OOB. + assert.compareArray(ToNumbers(fixedLength.subarray(0)), []); + assert.compareArray(ToNumbers(fixedLengthWithOffset.subarray(0)), []); + assert.compareArray(ToNumbers(lengthTracking.subarray(0)), [ + 0, + 2, + 4 + ]); + assert.compareArray(ToNumbers(lengthTrackingWithOffset.subarray(0)), [4]); + + // Also the previously created subarrays are OOB. + assert.sameValue(fixedLengthSubFull.length, 0); + assert.sameValue(fixedLengthWithOffsetSubFull.length, 0); + + // Relative offsets + assert.compareArray(ToNumbers(lengthTracking.subarray(-2)), [ + 2, + 4 + ]); + assert.compareArray(ToNumbers(lengthTrackingWithOffset.subarray(-1)), [4]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.compareArray(ToNumbers(fixedLength.subarray(0)), []); + assert.compareArray(ToNumbers(lengthTracking.subarray(0)), [0]); + + // Even the 0-length subarray of fixedLengthWithOffset would be OOB -> + // this throws. + assert.throws(RangeError, () => { + fixedLengthWithOffset.subarray(0); + }); + + // Also the previously created subarrays are OOB. + assert.sameValue(fixedLengthSubFull.length, 0); + assert.sameValue(fixedLengthWithOffsetSubFull.length, 0); + assert.sameValue(lengthTrackingWithOffsetSubFull.length, 0); + + // Shrink to zero. + rab.resize(0); + assert.compareArray(ToNumbers(fixedLength.subarray(0)), []); + assert.compareArray(ToNumbers(lengthTracking.subarray(0)), []); + assert.throws(RangeError, () => { + fixedLengthWithOffset.subarray(0); + }); + assert.throws(RangeError, () => { + lengthTrackingWithOffset.subarray(0); + }); + + // Also the previously created subarrays are OOB. + assert.sameValue(fixedLengthSubFull.length, 0); + assert.sameValue(fixedLengthWithOffsetSubFull.length, 0); + assert.sameValue(lengthTrackingWithOffsetSubFull.length, 0); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.compareArray(ToNumbers(fixedLength.subarray(0)), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(ToNumbers(fixedLengthWithOffset.subarray(0)), [ + 4, + 6 + ]); + assert.compareArray(ToNumbers(lengthTracking.subarray(0)), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(ToNumbers(lengthTrackingWithOffset.subarray(0)), [ + 4, + 6, + 8, + 10 + ]); + + // Also the previously created subarrays are no longer OOB. + assert.sameValue(fixedLengthSubFull.length, 4); + assert.sameValue(fixedLengthWithOffsetSubFull.length, 2); + // Subarrays of length-tracking TAs are also length-tracking. + assert.sameValue(lengthTrackingSubFull.length, 6); + assert.sameValue(lengthTrackingWithOffsetSubFull.length, 4); +} diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/result-byteOffset-from-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/subarray/result-byteOffset-from-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..0fa3b607bbeb45a0116eb5d091edf2b3056fc327 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/result-byteOffset-from-out-of-bounds.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Result has the correct byteOffset when input is initially out-of-bounds. +info: | + %SendableTypedArray%.prototype.subarray ( start, end ) + + ... + 13. Let srcByteOffset be O.[[ByteOffset]]. + 14. Let beginByteOffset be srcByteOffset + (startIndex × elementSize). + 15. If O.[[ArrayLength]] is auto and end is undefined, then + a. Let argumentsList be « buffer, 𝔽(beginByteOffset) ». + 16. + ... + e. Let newLength be max(endIndex - startIndex, 0). + f. Let argumentsList be « buffer, 𝔽(beginByteOffset), 𝔽(newLength) ». + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(10, {maxByteLength: 10}); + +let autoLength = new Int8Array(rab, 4); +let withLength = new Int8Array(rab, 4, 2); + +let start = { + valueOf() { + // Make |autoLength| and |withLength| in-bounds again. + rab.resize(10); + return 1; + } +}; + +// Make |autoLength| out-of-bounds. +rab.resize(0); + +let resultAutoLength = autoLength.subarray(start); +assert.sameValue(resultAutoLength.byteOffset, 4); +assert.sameValue(resultAutoLength.length, 6); + +// Make |withLength| out-of-bounds. +rab.resize(0); + +let resultWithLength = withLength.subarray(start); +assert.sameValue(resultWithLength.byteOffset, 4); +assert.sameValue(resultWithLength.length, 0); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/result-does-not-copy-ordinary-properties.js b/test/sendable/builtins/TypedArray/prototype/subarray/result-does-not-copy-ordinary-properties.js new file mode 100644 index 0000000000000000000000000000000000000000..75efbfe1a9e54f781a11f6291ee33484f6d34e91 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/result-does-not-copy-ordinary-properties.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Subarray result does not import own property +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([41, 42, 43, 44]); + var result; + + sample.foo = 42; + + result = sample.subarray(0); + assert.sameValue( + result.hasOwnProperty("foo"), + false, + "does not import own property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/result-is-new-instance-from-same-ctor.js b/test/sendable/builtins/TypedArray/prototype/subarray/result-is-new-instance-from-same-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..835ed6be395cae3ed70df9c6354c6866b7f3e54e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/result-is-new-instance-from-same-ctor.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Returns a new instance from the same constructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var result = sample.subarray(1); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "prototype" + ); + assert.sameValue(result.constructor, sample.constructor, "constructor"); + assert(result instanceof TA, "instanceof"); + + assert( + compareArray(sample, [40, 41, 42, 43]), + "original sample remains the same" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/result-is-new-instance-with-shared-buffer.js b/test/sendable/builtins/TypedArray/prototype/subarray/result-is-new-instance-with-shared-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..036310ec23448c6a67c6040b9cfbed130b6c3e4c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/result-is-new-instance-with-shared-buffer.js @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Returns a new instance sharing the same buffer +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var buffer = sample.buffer; + var result = sample.subarray(1); + + assert.notSameValue(result, sample, "returns a new instance"); + assert.sameValue(result.buffer, sample.buffer, "shared buffer"); + assert.sameValue(sample.buffer, buffer, "original buffer is preserved"); + + sample[1] = 100; + assert( + compareArray(result, [100, 42, 43]), + "changes on the original sample values affect the new instance" + ); + + result[1] = 111; + assert( + compareArray(sample, [40, 100, 111, 43]), + "changes on the new instance values affect the original sample" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/results-with-different-length.js b/test/sendable/builtins/TypedArray/prototype/subarray/results-with-different-length.js new file mode 100644 index 0000000000000000000000000000000000000000..30e663896dc4e81cd75f40ee84a4c26b2a5e74dd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/results-with-different-length.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Subarray may return a new instance with a smaller length +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + function testRes(result, expected, msg) { + assert(compareArray(result, expected), msg + ", result: [" + result + "]"); + } + + testRes(sample.subarray(1), [41, 42, 43], "begin == 1"); + testRes(sample.subarray(2), [42, 43], "begin == 2"); + testRes(sample.subarray(3), [43], "begin == 3"); + + testRes(sample.subarray(1, 4), [41, 42, 43], "begin == 1, end == length"); + testRes(sample.subarray(2, 4), [42, 43], "begin == 2, end == length"); + testRes(sample.subarray(3, 4), [43], "begin == 3, end == length"); + + testRes(sample.subarray(0, 1), [40], "begin == 0, end == 1"); + testRes(sample.subarray(0, 2), [40, 41], "begin == 0, end == 2"); + testRes(sample.subarray(0, 3), [40, 41, 42], "begin == 0, end == 3"); + + testRes(sample.subarray(-1), [43], "begin == -1"); + testRes(sample.subarray(-2), [42, 43], "begin == -2"); + testRes(sample.subarray(-3), [41, 42, 43], "begin == -3"); + + testRes(sample.subarray(-1, 4), [43], "begin == -1, end == length"); + testRes(sample.subarray(-2, 4), [42, 43], "begin == -2, end == length"); + testRes(sample.subarray(-3, 4), [41, 42, 43], "begin == -3, end == length"); + + testRes(sample.subarray(0, -1), [40, 41, 42], "begin == 0, end == -1"); + testRes(sample.subarray(0, -2), [40, 41], "begin == 0, end == -2"); + testRes(sample.subarray(0, -3), [40], "begin == 0, end == -3"); + + testRes(sample.subarray(-0, -1), [40, 41, 42], "begin == -0, end == -1"); + testRes(sample.subarray(-0, -2), [40, 41], "begin == -0, end == -2"); + testRes(sample.subarray(-0, -3), [40], "begin == -0, end == -3"); + + testRes(sample.subarray(-2, -1), [42], "length == 4, begin == -2, end == -1"); + testRes(sample.subarray(1, -1), [41, 42], "length == 4, begin == 1, end == -1"); + testRes(sample.subarray(1, -2), [41], "length == 4, begin == 1, end == -2"); + testRes(sample.subarray(2, -1), [42], "length == 4, begin == 2, end == -1"); + + testRes(sample.subarray(-1, 5), [43], "begin == -1, end > length"); + testRes(sample.subarray(-2, 4), [42, 43], "begin == -2, end > length"); + testRes(sample.subarray(-3, 4), [41, 42, 43], "begin == -3, end > length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/results-with-empty-length.js b/test/sendable/builtins/TypedArray/prototype/subarray/results-with-empty-length.js new file mode 100644 index 0000000000000000000000000000000000000000..a10f59c92c29855c3e42963256693a0ed518f873 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/results-with-empty-length.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Subarray may return a new empty instance +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + function testRes(result, msg) { + assert.sameValue(result.length, 0, msg); + assert.sameValue( + result.hasOwnProperty(0), + false, + msg + " & result.hasOwnProperty(0) === false" + ); + } + + testRes(sample.subarray(4), "begin == length"); + testRes(sample.subarray(5), "begin > length"); + + testRes(sample.subarray(4, 4), "begin == length, end == length"); + testRes(sample.subarray(5, 4), "begin > length, end == length"); + + testRes(sample.subarray(4, 4), "begin == length, end > length"); + testRes(sample.subarray(5, 4), "begin > length, end > length"); + + testRes(sample.subarray(0, 0), "begin == 0, end == 0"); + testRes(sample.subarray(-0, -0), "begin == -0, end == -0"); + testRes(sample.subarray(1, 0), "begin > 0, end == 0"); + testRes(sample.subarray(-1, 0), "being < 0, end == 0"); + + testRes(sample.subarray(2, 1), "begin > 0, begin < length, begin > end, end > 0"); + testRes(sample.subarray(2, 2), "begin > 0, begin < length, begin == end"); + + testRes(sample.subarray(2, -2), "begin > 0, begin < length, end == -2"); + + testRes(sample.subarray(-1, -1), "length = 4, begin == -1, end == -1"); + testRes(sample.subarray(-1, -2), "length = 4, begin == -1, end == -2"); + testRes(sample.subarray(-2, -2), "length = 4, begin == -2, end == -2"); + + testRes(sample.subarray(0, -4), "begin == 0, end == -length"); + testRes(sample.subarray(-4, -4), "begin == -length, end == -length"); + testRes(sample.subarray(-5, -4), "begin < -length, end == -length"); + + testRes(sample.subarray(0, -5), "begin == 0, end < -length"); + testRes(sample.subarray(-4, -5), "begin == -length, end < -length"); + testRes(sample.subarray(-5, -5), "begin < -length, end < -length"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/results-with-same-length.js b/test/sendable/builtins/TypedArray/prototype/subarray/results-with-same-length.js new file mode 100644 index 0000000000000000000000000000000000000000..490ab273112113873150bc75f4aee0f571f580c2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/results-with-same-length.js @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Subarray may return a new instance with the same length +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + function testRes(result, msg) { + assert.sameValue(result.length, 4, msg); + assert.sameValue(result[0], 40, msg + " & result[0] === 40"); + assert.sameValue(result[1], 41, msg + " & result[1] === 41"); + assert.sameValue(result[2], 42, msg + " & result[2] === 42"); + assert.sameValue(result[3], 43, msg + " & result[3] === 43"); + } + + testRes(sample.subarray(0), "begin == 0"); + testRes(sample.subarray(-4), "begin == -srcLength"); + testRes(sample.subarray(-5), "begin < -srcLength"); + + testRes(sample.subarray(0, 4), "begin == 0, end == srcLength"); + testRes(sample.subarray(-4, 4), "begin == -srcLength, end == srcLength"); + testRes(sample.subarray(-5, 4), "begin < -srcLength, end == srcLength"); + + testRes(sample.subarray(0, 5), "begin == 0, end > srcLength"); + testRes(sample.subarray(-4, 5), "begin == -srcLength, end > srcLength"); + testRes(sample.subarray(-5, 5), "begin < -srcLength, end > srcLength"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-begin-symbol.js b/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-begin-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..2112e555448d7bc604468dc4dde5420d618d7052 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-begin-symbol.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Return abrupt from ToInteger(begin), begin is symbol +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.subarray(s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-begin.js b/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-begin.js new file mode 100644 index 0000000000000000000000000000000000000000..b047925c1da5b9046af15537a82a42f2c88d9951 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-begin.js @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Return abrupt from ToInteger(begin) +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.subarray(o1); + }); + + assert.throws(Test262Error, function() { + sample.subarray(o2); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-end-symbol.js b/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-end-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..a2b1d4c22e194ba72d2de2a277d1593b79f70b9e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-end-symbol.js @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Return abrupt from ToInteger(end), end is symbol +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd + be ? ToInteger(end). + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.subarray(0, s); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-end.js b/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-end.js new file mode 100644 index 0000000000000000000000000000000000000000..6b07e792e6bb194278bfe937cacf0f8490d484b5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/return-abrupt-from-end.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Return abrupt from ToInteger(end) +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd + be ? ToInteger(end). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.subarray(0, o1); + }); + + assert.throws(Test262Error, function() { + sample.subarray(0, o2); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor-abrupt.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..2386fea0311986453509e2f8b6040be82324bfe1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.subarray(0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor-inherited.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000000000000000000000000000000000..5a5a5af5262eb4c37f086964951f078998eb5948 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor-inherited.js @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var calls = 0; + var result; + + Object.defineProperty(TA.prototype, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.subarray(0); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + undefined, + "used defaultCtor but still checks the inherited .constructor" + ); + + calls = 6; + result.constructor; + assert.sameValue( + calls, + 7, + "result.constructor triggers the inherited accessor property" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..1b3c4196761d7b391ea6bd927e41ef0ca5780582 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.subarray(0); + }, "symbol"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..bb7b79be925349663ece8809e7ff533b36edd670 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-ctor.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: get constructor on SpeciesConstructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var calls = 0; + var result; + + Object.defineProperty(sample, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.subarray(0); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + TA, + "use defaultCtor on an undefined return - .constructor check" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-abrupt.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..1d7ac5b1eb4f5eb01707d5b6702d6bf8630c7551 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-abrupt.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.subarray(0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-invocation.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000000000000000000000000000000000..5076e671d12f03286c45643748b1e002bbd45144 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42]); + var expectedOffset = TA.BYTES_PER_ELEMENT; + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(buffer, offset, length) { + result = arguments; + ctorThis = this; + return new TA(buffer, offset, length); + }; + + sample.subarray(1); + + assert.sameValue(result.length, 3, "called with 3 arguments"); + assert.sameValue(result[0], sample.buffer, "[0] is sample.buffer"); + assert.sameValue(result[1], expectedOffset, "[1] is the byte offset pos"); + assert.sameValue(result[2], 2, "[2] is expected length"); + + assert( + ctorThis instanceof sample.constructor[Symbol.species], + "`this` value in the @@species fn is an instance of the function itself" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-returns-another-instance.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..fa5bb6b1dc62466fd364d15989468bf707a483e2 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Custom @@species constructor may return a totally different SendableTypedArray +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js, compareArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40]); + var other = new Int8Array([1, 0, 1]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.subarray(0, 0); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [1, 0, 1]), "the returned object is preserved"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-throws.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..bb932e7a1715792f3ffb786cd5b68e0d85acabf6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var ctor = function() {}; + + sample.constructor = {}; + sample.constructor[Symbol.species] = ctor; + + assert.throws(TypeError, function() { + sample.subarray(0); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..eb863c4faf0df0684b825e9ccd95281dede34023 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Use custom @@species constructor if available +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? SendableTypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 SendableTypedArrayCreate ( constructor, argumentList ) + + 1. Let newSendableTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateSendableTypedArray(newSendableTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newSendableTypedArray. +includes: [sendableTypedArray.js, compareArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42]); + var calls = 0; + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(buffer, offset, length) { + calls++; + return new TA(buffer, offset, length); + }; + + result = sample.subarray(1); + + assert.sameValue(calls, 1, "ctor called once"); + assert(compareArray(result, [41, 42]), "expected subarray"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-returns-throws.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..f1e24f29d3b87aff6c4e76775b922fcce11f15d3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-returns-throws.js @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + sample.constructor[Symbol.species] = 0; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "true"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-use-default-ctor.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..4b15d9bf1c15418538aad79343d20a41b1f7f8d6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var result; + + sample.constructor = {}; + + result = sample.subarray(0); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "undefined @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "undefined @@species - ctor check"); + + sample.constructor[Symbol.species] = null; + result = sample.subarray(0); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "null @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "null @@species - ctor check"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species.js b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species.js new file mode 100644 index 0000000000000000000000000000000000000000..6aa9c37897776e91d0a3c7070e3b7a4c143147fe --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/speciesctor-get-species.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + get @@species from found constructor +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? SendableTypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 SendableTypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [sendableTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calls = 0; + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + calls++; + } + }); + + sample.subarray(0); + + assert.sameValue(calls, 1); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/subarray/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..1a1552f7b4fa9cae33448122b8c5111c1840f8fa --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/this-is-not-object.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + The following steps are taken: + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var subarray = SendableTypedArray.prototype.subarray; + +assert.throws(TypeError, function() { + subarray.call(undefined, 0, 0); +}, "this is undefined"); + +assert.throws(TypeError, function() { + subarray.call(null, 0, 0); +}, "this is null"); + +assert.throws(TypeError, function() { + subarray.call(42, 0, 0); +}, "this is 42"); + +assert.throws(TypeError, function() { + subarray.call("1", 0, 0); +}, "this is a string"); + +assert.throws(TypeError, function() { + subarray.call(true, 0, 0); +}, "this is true"); + +assert.throws(TypeError, function() { + subarray.call(false, 0, 0); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + subarray.call(s, 0, 0); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/subarray/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..86088ab11edd1ffaa1a548687e47b600a1c16b26 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/this-is-not-typedarray-instance.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.9 %SendableTypedArray%.prototype.subarray( begin , end ) + + The following steps are taken: + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var subarray = SendableTypedArray.prototype.subarray; + +assert.throws(TypeError, function() { + subarray.call({}, 0, 0); +}, "this is an Object"); + +assert.throws(TypeError, function() { + subarray.call([], 0, 0); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + subarray.call(ab, 0, 0); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + subarray.call(dv, 0, 0); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/tointeger-begin.js b/test/sendable/builtins/TypedArray/prototype/subarray/tointeger-begin.js new file mode 100644 index 0000000000000000000000000000000000000000..0cebe3aab98bfe61627c8c56f484513e5914489d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/tointeger-begin.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: ToInteger(begin) +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert(compareArray(sample.subarray(false), [40, 41, 42, 43]), "false"); + assert(compareArray(sample.subarray(true), [41, 42, 43]), "true"); + + assert(compareArray(sample.subarray(NaN), [40, 41, 42, 43]), "NaN"); + assert(compareArray(sample.subarray(null), [40, 41, 42, 43]), "null"); + assert(compareArray(sample.subarray(undefined), [40, 41, 42, 43]), "undefined"); + + assert(compareArray(sample.subarray(1.1), [41, 42, 43]), "1.1"); + assert(compareArray(sample.subarray(1.5), [41, 42, 43]), "1.5"); + assert(compareArray(sample.subarray(0.6), [40, 41, 42, 43]), "0.6"); + + assert(compareArray(sample.subarray(-1.5), [43]), "-1.5"); + assert(compareArray(sample.subarray(-1.1), [43]), "-1.1"); + assert(compareArray(sample.subarray(-0.6), [40, 41, 42, 43]), "-0.6"); + + assert(compareArray(sample.subarray("3"), [43]), "string"); + assert( + compareArray( + sample.subarray(obj), + [42, 43] + ), + "object" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/subarray/tointeger-end.js b/test/sendable/builtins/TypedArray/prototype/subarray/tointeger-end.js new file mode 100644 index 0000000000000000000000000000000000000000..f95e60ed21a13778e9f8083627a2c79b3cd18d5b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/subarray/tointeger-end.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.subarray +description: ToInteger(end) +info: | + 22.2.3.27 %SendableTypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be + ? ToInteger(end). + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert(compareArray(sample.subarray(0, false), []), "false"); + assert(compareArray(sample.subarray(0, true), [40]), "true"); + + assert(compareArray(sample.subarray(0, NaN), []), "NaN"); + assert(compareArray(sample.subarray(0, null), []), "null"); + assert(compareArray(sample.subarray(0, undefined), [40, 41, 42, 43]), "undefined"); + + assert(compareArray(sample.subarray(0, 0.6), []), "0.6"); + assert(compareArray(sample.subarray(0, 1.1), [40]), "1.1"); + assert(compareArray(sample.subarray(0, 1.5), [40]), "1.5"); + assert(compareArray(sample.subarray(0, -0.6), []), "-0.6"); + assert(compareArray(sample.subarray(0, -1.1), [40, 41, 42]), "-1.1"); + assert(compareArray(sample.subarray(0, -1.5), [40, 41, 42]), "-1.5"); + + assert(compareArray(sample.subarray(0, "3"), [40, 41, 42]), "string"); + assert( + compareArray( + sample.subarray(0, obj), + [40, 41] + ), + "object" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/calls-tolocalestring-from-each-value.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/calls-tolocalestring-from-each-value.js new file mode 100644 index 0000000000000000000000000000000000000000..11a86dd13e75660553e2a120d23116c404fdac4b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/calls-tolocalestring-from-each-value.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Calls toLocaleString from each property's value +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +BigInt.prototype.toLocaleString = function() { + calls.push(this); + return "hacks" + calls.length; +}; + +var expected = ["hacks1", "hacks2"].join(separator); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = []; + assert.sameValue(sample.toLocaleString(), expected, "returns expected value"); + assert( + compareArray(new TA(calls), sample), + "toLocaleString called for each item" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/calls-tostring-from-each-value.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/calls-tostring-from-each-value.js new file mode 100644 index 0000000000000000000000000000000000000000..faea86f033d01cc8efad2165492d470ef67c922d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/calls-tostring-from-each-value.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Calls toString from each property's value return from toLocaleString +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +BigInt.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + return "hacks" + calls; + }, + valueOf: function() { + throw new Test262Error("should not call valueOf if toString is present"); + } + }; +}; + +var arr = [42n, 0n]; +var expected = ["hacks1", "hacks2"].join(separator); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(arr); + calls = 0; + assert.sameValue(sample.toLocaleString(), expected, "returns expected value"); + assert.sameValue(calls, 2, "toString called once for each item"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/calls-valueof-from-each-value.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/calls-valueof-from-each-value.js new file mode 100644 index 0000000000000000000000000000000000000000..ad50b58c9caf34d1f0f009cc790809e6a673e449 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/calls-valueof-from-each-value.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Calls valueOf from each property's value return from toLocaleString +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +BigInt.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + return "hacks" + calls; + } + }; +}; + +var expected = ["hacks1", "hacks2"].join(separator); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = 0; + assert.sameValue(sample.toLocaleString(), expected, "returns expected value"); + assert.sameValue(calls, 2, "valueOf called once for each item"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..486488ac0a82f90c3fb34d3deeb3bf64d2f320c7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/detached-buffer.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.toLocaleString(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/empty-instance-returns-empty-string.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/empty-instance-returns-empty-string.js new file mode 100644 index 0000000000000000000000000000000000000000..e185fdd35d2fa13c252b252b3999f47760af0b0e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/empty-instance-returns-empty-string.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Returns an empty string if called on an empty instance +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 4. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.toLocaleString(), ""); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..232126b8ae591dc57b31e6c703d8d9ba1ffde8da --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + 1. Let array be ? ToObject(this value). + 2.Let len be ? ToLength(? Get(array, "length")). + ... +includes: [sendableBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.toLocaleString(); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tolocalestring.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tolocalestring.js new file mode 100644 index 0000000000000000000000000000000000000000..25bfd5dbe2f4f1da0bbb29960e62daddf82e51c8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tolocalestring.js @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Returns abrupt from firstElement's toLocaleString +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 4. If len is zero, return the empty String. + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls; + +BigInt.prototype.toLocaleString = function() { + calls++; + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + calls = 0; + var sample = new TA([42n, 0n]); + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "abrupt from first element"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tostring.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tostring.js new file mode 100644 index 0000000000000000000000000000000000000000..11ad371497ab4809d142730f6e8eee54bb4124b6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tostring.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Return abrupt from firstElement's toLocaleString => toString +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + throw new Test262Error(); + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "toString called once"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-valueof.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-valueof.js new file mode 100644 index 0000000000000000000000000000000000000000..bab9f7f512a5e9dc1c0d6800d196c967dc5f5f07 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-valueof.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Return abrupt from firstElement's toLocaleString => valueOf +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + throw new Test262Error(); + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "toString called once"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tolocalestring.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tolocalestring.js new file mode 100644 index 0000000000000000000000000000000000000000..e353591a0fc8ad289a647e61432f16e394f0183d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tolocalestring.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Returns abrupt from a nextElement's toLocaleString +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + calls = 0; + var sample = new TA([42n, 0n]); + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a next element"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tostring.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tostring.js new file mode 100644 index 0000000000000000000000000000000000000000..067b7b5e3e3270be1f37e4fcefc25e81376c8254 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tostring.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Return abrupt from nextElement's toLocaleString => valueOf +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a nextElement"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-valueof.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-valueof.js new file mode 100644 index 0000000000000000000000000000000000000000..b786b0fc74311028991e2a0f02bcf9e5221064dc --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-valueof.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Return abrupt from nextElement's toLocaleString => valueOf +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a nextElement"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..d4c30d13bcaf9fb42245688176218a5997d1d750 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.toLocaleString, + 'function', + 'implements SendableTypedArray.prototype.toLocaleString' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.toLocaleString(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.toLocaleString(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the toLocaleString operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.toLocaleString(); + throw new Test262Error('toLocaleString completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-result.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-result.js new file mode 100644 index 0000000000000000000000000000000000000000..09e24b5f08d31dd2b6efae2614706ae1313ad467 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/BigInt/return-result.js @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Returns a string +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n, 43n]); + var expected = + sample[0].toLocaleString().toString() + + separator + + sample[1].toLocaleString().toString() + + separator + + sample[2].toLocaleString().toString(); + assert.sameValue(sample.toLocaleString(), expected); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/calls-tolocalestring-from-each-value.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/calls-tolocalestring-from-each-value.js new file mode 100644 index 0000000000000000000000000000000000000000..a4e8c3c061ac07602c98e2759cbe90fbd03013cf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/calls-tolocalestring-from-each-value.js @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Calls toLocaleString from each property's value +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +Number.prototype.toLocaleString = function() { + calls.push(this); + return "hacks" + calls.length; +}; + +var arr = [42, 0]; +var expected = ["hacks1", "hacks2"].join(separator); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(arr); + calls = []; + assert.sameValue(sample.toLocaleString(), expected, "returns expected value"); + assert( + compareArray(new TA(calls), sample), + "toLocaleString called for each item" + ); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/calls-tostring-from-each-value.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/calls-tostring-from-each-value.js new file mode 100644 index 0000000000000000000000000000000000000000..8ffa3757f4b83c5ea310f796eea70339a59eadaf --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/calls-tostring-from-each-value.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Calls toString from each property's value return from toLocaleString +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +Number.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + return "hacks" + calls; + }, + valueOf: function() { + throw new Test262Error("should not call valueOf if toString is present"); + } + }; +}; + +var arr = [42, 0]; +var expected = ["hacks1", "hacks2"].join(separator); + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA(arr); + calls = 0; + assert.sameValue(sample.toLocaleString(), expected, "returns expected value"); + assert.sameValue(calls, 2, "toString called once for each item"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/calls-valueof-from-each-value.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/calls-valueof-from-each-value.js new file mode 100644 index 0000000000000000000000000000000000000000..e353a7f9154597b80898948f84e6a29b7fabd518 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/calls-valueof-from-each-value.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Calls valueOf from each property's value return from toLocaleString +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +Number.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + return "hacks" + calls; + } + }; +}; + +var arr = [42, 0]; +var expected = ["hacks1", "hacks2"].join(separator); + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA(arr); + calls = 0; + assert.sameValue(sample.toLocaleString(), expected, "returns expected value"); + assert.sameValue(calls, 2, "valueOf called once for each item"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..debdcee52ea75e61ca8a29d8a4dac2d2b0658087 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/detached-buffer.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.toLocaleString(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/empty-instance-returns-empty-string.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/empty-instance-returns-empty-string.js new file mode 100644 index 0000000000000000000000000000000000000000..ed94192af6dc824c04eb81cb1a81cc864dd3a46d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/empty-instance-returns-empty-string.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Returns an empty string if called on an empty instance +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 4. If len is zero, return the empty String. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.toLocaleString(), ""); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/get-length-uses-internal-arraylength.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000000000000000000000000000000000..9daee2438b2db414ebd5da4f62df8a38d15778c6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/get-length-uses-internal-arraylength.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + 1. Let array be ? ToObject(this value). + 2.Let len be ? ToLength(? Get(array, "length")). + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(SendableTypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA([42, 43]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.toLocaleString(); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..9864acc12319f339299c31b3f8bd1fa150f69727 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/invoked-as-func.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.27 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + ... + + This function is not generic. ValidateSendableTypedArray is applied to the this + value prior to evaluating the algorithm. If its result is an abrupt + completion that exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var toLocaleString = SendableTypedArray.prototype.toLocaleString; + +assert.sameValue(typeof toLocaleString, 'function'); + +assert.throws(TypeError, function() { + toLocaleString(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..20503eb66878a28a76a8cf9e73370159d0c4b872 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/invoked-as-method.js @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.27 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + ... + + This function is not generic. ValidateSendableTypedArray is applied to the this + value prior to evaluating the algorithm. If its result is an abrupt + completion that exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.toLocaleString, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.toLocaleString(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/length.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/length.js new file mode 100644 index 0000000000000000000000000000000000000000..e7549b2a0e3a3a0f91709a34cd5d7e98bf9bd16e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + %SendableTypedArray%.prototype.toLocaleString.length is 0. +info: | + %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.toLocaleString, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/name.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/name.js new file mode 100644 index 0000000000000000000000000000000000000000..2afe20e5ffae621b8bd1c2368890a68d72599486 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + %SendableTypedArray%.prototype.toLocaleString.name is "toLocaleString". +info: | + %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.toLocaleString, "name", { + value: "toLocaleString", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..4207b72a1cd20da4594020e3ff953e30b461ef3e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.toLocaleString does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.toLocaleString), + false, + 'isConstructor(SendableTypedArray.prototype.toLocaleString) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.toLocaleString(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..ff306e9d578a62dd076375a508379c053f74e319 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + "toLocaleString" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'toLocaleString', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f206812bbbd70645ed3aa039517fa8e3c44ea7ce --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/resizable-buffer.js @@ -0,0 +1,126 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + SendableTypedArray.p.toLocaleString behaves correctly on SendableTypedArrays backed by + resizable buffers. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + const taWrite = new ctor(rab); + + // toLocaleString separator is implementation dependent. + function listToString(list) { + const comma = ['',''].toLocaleString(); + const len = list.length; + let result = ''; + if (len > 1) { + for (let i=0; i < len - 1 ; i++) { + result += list[i] + comma; + } + } + if (len > 0) { + result += list[len-1]; + } + return result; + } + + // Write some data into the array. + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + assert.sameValue(fixedLength.toLocaleString(),listToString([0,2,4,6])); + assert.sameValue(fixedLengthWithOffset.toLocaleString(),listToString([4,6])); + assert.sameValue(lengthTracking.toLocaleString(),listToString([0,2,4,6])); + assert.sameValue(lengthTrackingWithOffset.toLocaleString(),listToString([4,6])); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + assert.throws(TypeError, () => { + fixedLength.toLocaleString(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.toLocaleString(); + }); + + assert.sameValue(lengthTracking.toLocaleString(),listToString([0,2,4])); + assert.sameValue(lengthTrackingWithOffset.toLocaleString(),listToString([4])); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.toLocaleString(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.toLocaleString(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.toLocaleString(); + }); + + assert.sameValue(lengthTracking.toLocaleString(),listToString([0])); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.toLocaleString(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.toLocaleString(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.toLocaleString(); + }); + + assert.sameValue(lengthTracking.toLocaleString(),listToString([])); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.sameValue(fixedLength.toLocaleString(),listToString([0,2,4,6])); + assert.sameValue(fixedLengthWithOffset.toLocaleString(),listToString([4,6])); + assert.sameValue(lengthTracking.toLocaleString(),listToString([0,2,4,6,8,10])); + assert.sameValue(lengthTrackingWithOffset.toLocaleString(),listToString([4,6,8,10])); +} diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tolocalestring.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tolocalestring.js new file mode 100644 index 0000000000000000000000000000000000000000..9c0ab4c2b03d7bd7fdaf7a34eb0112f218526f9a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tolocalestring.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Returns abrupt from firstElement's toLocaleString +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 4. If len is zero, return the empty String. + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var calls; + +Number.prototype.toLocaleString = function() { + calls++; + throw new Test262Error(); +}; + +var arr = [42, 0]; + +testWithTypedArrayConstructors(function(TA, N) { + calls = 0; + var sample = new TA(arr); + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "abrupt from first element"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tostring.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tostring.js new file mode 100644 index 0000000000000000000000000000000000000000..332a243fa2e20fc99465c767110213626b89db16 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tostring.js @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Return abrupt from firstElement's toLocaleString => toString +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var calls = 0; + +Number.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + throw new Test262Error(); + } + }; +}; + +var arr = [42, 0]; + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA(arr); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "toString called once"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-valueof.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-valueof.js new file mode 100644 index 0000000000000000000000000000000000000000..117c817f30e9d582ba50365b7bfaa4a5bbc6b1c8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-valueof.js @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Return abrupt from firstElement's toLocaleString => valueOf +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var calls = 0; + +Number.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + throw new Test262Error(); + } + }; +}; + +var arr = [42, 0]; + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA(arr); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "toString called once"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tolocalestring.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tolocalestring.js new file mode 100644 index 0000000000000000000000000000000000000000..85a00111c0239efc41e51ea6ead3e3e0e58c5c59 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tolocalestring.js @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Returns abrupt from a nextElement's toLocaleString +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var calls = 0; + +Number.prototype.toLocaleString = function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } +}; + +var arr = [42, 0]; + +testWithTypedArrayConstructors(function(TA, N) { + calls = 0; + var sample = new TA(arr); + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a next element"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tostring.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tostring.js new file mode 100644 index 0000000000000000000000000000000000000000..3ba5caf1b2d5b991a678ab54045fa2f31ab847e1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tostring.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Return abrupt from nextElement's toLocaleString => valueOf +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var calls = 0; + +Number.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } + } + }; +}; + +var arr = [42, 0]; + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA(arr); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a nextElement"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-valueof.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-valueof.js new file mode 100644 index 0000000000000000000000000000000000000000..e874a21111430d9924deab41a94dd5e181e3b733 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-valueof.js @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Return abrupt from nextElement's toLocaleString => valueOf +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var calls = 0; + +Number.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } + } + }; +}; + +var arr = [42, 0]; + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA(arr); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a nextElement"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..b6e2b1e8d5184efefe1547c8ecab8a410bcfbb1c --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [ArrayBuffer, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.toLocaleString, + 'function', + 'implements SendableTypedArray.prototype.toLocaleString' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.toLocaleString(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.toLocaleString(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the toLocaleString operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.toLocaleString(); + throw new Test262Error('toLocaleString completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-result.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-result.js new file mode 100644 index 0000000000000000000000000000000000000000..61623291a0ca1802572622dde7179a9b7b28e625 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/return-result.js @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Returns a string +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %SendableTypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); + +var arr = [42, 0, 43]; + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA(arr); + var expected = + sample[0].toLocaleString().toString() + + separator + + sample[1].toLocaleString().toString() + + separator + + sample[2].toLocaleString().toString(); + assert.sameValue(sample.toLocaleString(), expected); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..f250c30c8241b465db1438a9b9317da9cecf01a5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/this-is-not-object.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var toLocaleString = SendableTypedArray.prototype.toLocaleString; + +assert.throws(TypeError, function() { + toLocaleString.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + toLocaleString.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + toLocaleString.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + toLocaleString.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + toLocaleString.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + toLocaleString.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + toLocaleString.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..f0d60ccb122d2684bd994109c259663741002f3d --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/this-is-not-typedarray-instance.js @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var toLocaleString = SendableTypedArray.prototype.toLocaleString; + +assert.throws(TypeError, function() { + toLocaleString.call({}); +}, "this is an Object"); + +assert.throws(TypeError, function() { + toLocaleString.call([]); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + toLocaleString.call(ab); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + toLocaleString.call(dv); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/user-provided-tolocalestring-grow.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/user-provided-tolocalestring-grow.js new file mode 100644 index 0000000000000000000000000000000000000000..1e46b21939aac755b890b2a45d1ad222e2a3f2e4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/user-provided-tolocalestring-grow.js @@ -0,0 +1,94 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + SendableTypedArray.p.toLocaleString behaves correctly when {Number,BigInt}. + prototype.toLocaleString is replaced with a user-provided function + that grows the underlying resizable buffer. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const oldNumberPrototypeToLocaleString = Number.prototype.toLocaleString; +const oldBigIntPrototypeToLocaleString = BigInt.prototype.toLocaleString; + +// toLocaleString separator is implementation dependent. +function listToString(list) { + const comma = ['',''].toLocaleString(); + const len = list.length; + let result = ''; + if (len > 1) { + for (let i=0; i < len - 1 ; i++) { + result += list[i] + comma; + } + } + if (len > 0) { + result += list[len-1]; + } + return result; +} + +// Growing + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let resizeAfter = 2; + Number.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + } + return oldNumberPrototypeToLocaleString.call(this); + }; + BigInt.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + } + return oldBigIntPrototypeToLocaleString.call(this); + }; + + // We iterate 4 elements since it was the starting length. Resizing doesn't + // affect the TA. + assert.sameValue(fixedLength.toLocaleString(), listToString([0,0,0,0])); +} + +// Growing + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let resizeAfter = 2; + Number.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + } + return oldNumberPrototypeToLocaleString.call(this); + }; + BigInt.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + } + return oldBigIntPrototypeToLocaleString.call(this); + }; + + // We iterate 4 elements since it was the starting length. + assert.sameValue(lengthTracking.toLocaleString(), listToString([0,0,0,0])); +} +Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString; +BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString; diff --git a/test/sendable/builtins/TypedArray/prototype/toLocaleString/user-provided-tolocalestring-shrink.js b/test/sendable/builtins/TypedArray/prototype/toLocaleString/user-provided-tolocalestring-shrink.js new file mode 100644 index 0000000000000000000000000000000000000000..4b71b59def94ac26cb78bb7cc7b799c9b7b6e31f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toLocaleString/user-provided-tolocalestring-shrink.js @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tolocalestring +description: > + SendableTypedArray.p.toLocaleString behaves correctly when {Number,BigInt}. + prototype.toLocaleString is replaced with a user-provided function + that shrinks the underlying resizable buffer. +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const oldNumberPrototypeToLocaleString = Number.prototype.toLocaleString; +const oldBigIntPrototypeToLocaleString = BigInt.prototype.toLocaleString; + +// toLocaleString separator is implementation dependent. +function listToString(list) { + const comma = ['',''].toLocaleString(); + const len = list.length; + let result = ''; + if (len > 1) { + for (let i=0; i < len - 1 ; i++) { + result += list[i] + comma; + } + } + if (len > 0) { + result += list[len-1]; + } + return result; +} + +// Shrinking + fixed-length TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + let resizeAfter = 2; + Number.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + return oldNumberPrototypeToLocaleString.call(this); + }; + BigInt.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + return oldBigIntPrototypeToLocaleString.call(this); + }; + + // We iterate 4 elements, since it was the starting length. The TA goes + // OOB after 2 elements. + assert.sameValue(fixedLength.toLocaleString(), listToString([0,0,'',''])); +} + +// Shrinking + length-tracking TA. +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const lengthTracking = new ctor(rab); + let resizeAfter = 2; + Number.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + return oldNumberPrototypeToLocaleString.call(this); + }; + BigInt.prototype.toLocaleString = function () { + --resizeAfter; + if (resizeAfter == 0) { + rab.resize(2 * ctor.BYTES_PER_ELEMENT); + } + return oldBigIntPrototypeToLocaleString.call(this); + }; + + // We iterate 4 elements, since it was the starting length. Elements beyond + // the new length are converted to the empty string. + assert.sameValue(lengthTracking.toLocaleString(), listToString([0,0,'',''])); +} +Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString; +BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString; diff --git a/test/sendable/builtins/TypedArray/prototype/toReversed/ignores-species.js b/test/sendable/builtins/TypedArray/prototype/toReversed/ignores-species.js new file mode 100644 index 0000000000000000000000000000000000000000..f2257da9c511a54bf6f7bba0418cd95cd01b8f9e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toReversed/ignores-species.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toReversed +description: > + %SendableTypedArray%.prototype.toReversed ignores @@species +info: | + %SendableTypedArray%.prototype.toReversed ( ) + + ... + 4. Let A be ? SendableTypedArrayCreateSameType(O, « 𝔽(length) »). + ... + + SendableTypedArrayCreateSameType ( exemplar, argumentList ) + ... + 2. Let constructor be the intrinsic object listed in column one of Table 63 for exemplar.[[TypedArrayName]]. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA(); + ta.constructor = TA === Uint8Array ? Int32Array : Uint8Array; + assert.sameValue(Object.getPrototypeOf(ta.toReversed()), TA.prototype); + + ta = new TA(); + ta.constructor = { + [Symbol.species]: TA === Uint8Array ? Int32Array : Uint8Array, + }; + assert.sameValue(Object.getPrototypeOf(ta.toReversed()), TA.prototype); + + ta = new TA(); + Object.defineProperty(ta, "constructor", { + get() { + throw new Test262Error("Should not get .constructor"); + } + }); + ta.toReversed(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toReversed/immutable.js b/test/sendable/builtins/TypedArray/prototype/toReversed/immutable.js new file mode 100644 index 0000000000000000000000000000000000000000..166c04559bbd19f9969e6b47fabc29d3859d12d8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toReversed/immutable.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toReversed +description: > + %SendableTypedArray%.prototype.toReversed does not mutate its this value +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([0, 1, 2]); + ta.toReversed(); + + assert.compareArray(ta, [0, 1, 2]); + assert.notSameValue(ta.toReversed(), ta); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toReversed/length-property-ignored.js b/test/sendable/builtins/TypedArray/prototype/toReversed/length-property-ignored.js new file mode 100644 index 0000000000000000000000000000000000000000..ab7041feb1181aa083a18fbcbb33297e9a5d8c8e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toReversed/length-property-ignored.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toReversed +description: > + %SendableTypedArray%.prototype.toReversed does not read a "length" property +info: | + %SendableTypedArray%.prototype.toReversed ( ) + + ... + 3. Let length be O.[[ArrayLength]]. + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([0, 1, 2]); + Object.defineProperty(ta, "length", { value: 2 }) + var res = ta.toReversed(); + assert.compareArray(res, [2, 1, 0]); + assert.sameValue(res.length, 3); + + ta = new TA([0, 1, 2]); + Object.defineProperty(ta, "length", { value: 5 }); + res = ta.toReversed(); + assert.compareArray(res, [2, 1, 0]); + assert.sameValue(res.length, 3); +}); + +function setLength(length) { + Object.defineProperty(SendableTypedArray.prototype, "length", { + get: () => length, + }); +} + +testWithTypedArrayConstructors(TA => { + var ta = new TA([0, 1, 2]); + + setLength(2); + var res = ta.toReversed(); + setLength(3); + assert.compareArray(res, [2, 1, 0]); + + setLength(5); + res = ta.toReversed(); + setLength(3); + assert.compareArray(res, [2, 1, 0]); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toReversed/metadata/length.js b/test/sendable/builtins/TypedArray/prototype/toReversed/metadata/length.js new file mode 100644 index 0000000000000000000000000000000000000000..b6539e5b2ca48b5a450e2342bbea68767879c084 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toReversed/metadata/length.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toReversed +description: > + The "length" property of %SendableTypedArray%.prototype.toReversed +info: | + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +verifyProperty(SendableTypedArray.prototype.toReversed, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toReversed/metadata/name.js b/test/sendable/builtins/TypedArray/prototype/toReversed/metadata/name.js new file mode 100644 index 0000000000000000000000000000000000000000..e8a00703283b3af32ce21dfd128bf9ec842a9625 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toReversed/metadata/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toReversed +description: > + %SendableTypedArray%.prototype.toReversed.name is "toReversed". +info: | + %SendableTypedArray%.prototype.toReversed ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +verifyProperty(SendableTypedArray.prototype.toReversed, "name", { + value: "toReversed", + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toReversed/metadata/property-descriptor.js b/test/sendable/builtins/TypedArray/prototype/toReversed/metadata/property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..e145426a7564991f6e3d4ccfb2357915564e9795 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toReversed/metadata/property-descriptor.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toReversed +description: > + "toReversed" property of %SendableTypedArray%.prototype +info: | + 17 ECMAScript Standard Built-in Objects + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +assert.sameValue(typeof SendableTypedArray.prototype.toReversed, "function", "typeof"); + +verifyProperty(SendableTypedArray.prototype, "toReversed", { + value: SendableTypedArray.prototype.toReversed, + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toReversed/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/toReversed/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..45cbccca5b67d03cc4dcb1e6c453d759d7581a22 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toReversed/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + %SendableTypedArray%.prototype.toReversed does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [TypedArray, change-array-by-copy, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.toReversed), + false, + 'isConstructor(SendableTypedArray.prototype.toReversed) must return false' +); + +assert.throws(TypeError, () => { + new SendableTypedArray.prototype.toReversed(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/toReversed/this-value-invalid.js b/test/sendable/builtins/TypedArray/prototype/toReversed/this-value-invalid.js new file mode 100644 index 0000000000000000000000000000000000000000..197d4e6aa43fe26978e91689f01c68c2b663a621 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toReversed/this-value-invalid.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toReversed +description: > + %SendableTypedArray%.prototype.toReversed throws if the receiver is not a valid SendableTypedArray +info: | + %SendableTypedArray%.prototype.toReversed ( ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... +includes: [detachArrayBuffer.js, sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +var invalidValues = { + 'null': null, + 'undefined': undefined, + 'true': true, + '"abc"': "abc", + '12': 12, + 'Symbol()': Symbol(), + '[1, 2, 3]': [1, 2, 3], + '{ 0: 1, 1: 2, 2: 3, length: 3 }': { 0: 1, 1: 2, 2: 3, length: 3 }, + 'Uint8Array.prototype': Uint8Array.prototype, + '1n': 1n, +}; + +Object.entries(invalidValues).forEach(value => { + assert.throws(TypeError, () => { + SendableTypedArray.prototype.toReversed.call(value[1]); + }, `${value[0]} is not a valid SendableTypedArray`); +}); + +testWithTypedArrayConstructors(function(TA) { + let buffer = new ArrayBuffer(8); + let sample = new TA(buffer, 0, 1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, () => { + sample.toReversed(); + }, `array has a detached buffer`); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toSorted/comparefn-not-a-function.js b/test/sendable/builtins/TypedArray/prototype/toSorted/comparefn-not-a-function.js new file mode 100644 index 0000000000000000000000000000000000000000..480a4f617e8cb7e0c679d4fb261fb93ea98ffb4b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toSorted/comparefn-not-a-function.js @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toSorted +description: > + %SendableTypedArray%.prototype.toSorted verifies that the comparator is callable before reading the length. +info: | + %SendableTypedArray%.prototype.toSorted ( comparefn ) + + 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception. + 2. ... + 3. Let len be ? LengthOfArrayLike(O). +includes: [sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +var invalidComparators = [null, true, false, "", /a/g, 42, 42n, [], {}, Symbol()]; + +testWithTypedArrayConstructors(TA => { + const ta = new TA([1]); + for (var i = 0; i < invalidComparators.length; i++) { + assert.throws(TypeError, function() { + ta.toSorted(invalidComparators[i]); + }, String(invalidComparators[i])); + } +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toSorted/comparefn-stop-after-error.js b/test/sendable/builtins/TypedArray/prototype/toSorted/comparefn-stop-after-error.js new file mode 100644 index 0000000000000000000000000000000000000000..a345604b435adb0d3c2333ca5d72b0ddf3f94039 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toSorted/comparefn-stop-after-error.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toSorted +description: > + %SendableTypedArray%.prototype.toSorted doesn't call copmareFn if there is an error +info: | + %SendableTypedArray%.prototype.toSorted ( compareFn ) + + ... + 9. Sort items using an implementation-defined sequence of + calls to SortCompare. If any such call returns an abrupt + completion, stop before performing any further calls to + SortCompare or steps in this algorithm and return that completion. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var calls = 0; + var ta = new TA([3, 1, 2]); + try { + ta.toSorted(() => { + ++calls; + if (calls === 1) { + throw new Test262Error(); + } + }); + } catch (e) {} + assert.sameValue(calls <= 1, true, "compareFn is not called after an error"); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toSorted/ignores-species.js b/test/sendable/builtins/TypedArray/prototype/toSorted/ignores-species.js new file mode 100644 index 0000000000000000000000000000000000000000..c47a3203ca0f86b3c949a5dd94634ec0711c240b --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toSorted/ignores-species.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toSorted +description: > + %SendableTypedArray%.prototype.toSorted ignores @@species +info: | + %SendableTypedArray%.prototype.toSorted ( comparefn ) + + ... + 6. Let A be ? SendableTypedArrayCreateSameType(O, « 𝔽(len) »). + ... + + SendableTypedArrayCreateSameType ( exemplar, argumentList ) + ... + 2. Let constructor be the intrinsic object listed in column one of Table 63 for exemplar.[[TypedArrayName]]. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA(); + ta.constructor = TA === Uint8Array ? Int32Array : Uint8Array; + assert.sameValue(Object.getPrototypeOf(ta.toSorted()), TA.prototype); + + ta = new TA(); + ta.constructor = { + [Symbol.species]: TA === Uint8Array ? Int32Array : Uint8Array, + }; + assert.sameValue(Object.getPrototypeOf(ta.toSorted()), TA.prototype); + + ta = new TA(); + Object.defineProperty(ta, "constructor", { + get() { + throw new Test262Error("Should not get .constructor"); + } + }); + ta.toSorted(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toSorted/immutable.js b/test/sendable/builtins/TypedArray/prototype/toSorted/immutable.js new file mode 100644 index 0000000000000000000000000000000000000000..503adda11dcfedbbc5db90a34a5379991ce07729 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toSorted/immutable.js @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toSorted +description: > + %SendableTypedArray%.prototype.toSorted does not mutate its this value +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([3, 1, 2]); + ta.toSorted(); + + assert.compareArray(ta, [3, 1, 2]); + assert.notSameValue(ta.toSorted(), ta); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toSorted/length-property-ignored.js b/test/sendable/builtins/TypedArray/prototype/toSorted/length-property-ignored.js new file mode 100644 index 0000000000000000000000000000000000000000..a5e8e33ba623587f4da4f50c10543e5ff97176ca --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toSorted/length-property-ignored.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toSorted +description: > + %SendableTypedArray%.prototype.toSorted does not read a "length" property +info: | + %SendableTypedArray%.prototype.toSorted ( comparefn ) + + ... + 4. Let len be O.[[ArrayLength]]. + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([3, 1, 2]); + Object.defineProperty(ta, "length", { value: 2 }) + var res = ta.toSorted() + assert.compareArray(res, [1, 2, 3]); + assert.sameValue(res.length, 3); + + ta = new TA([3, 1, 2]); + Object.defineProperty(ta, "length", { value: 5 }); + res = ta.toSorted(); + assert.compareArray(res, [1, 2, 3]); + assert.sameValue(res.length, 3); +}); + +function setLength(length) { + Object.defineProperty(SendableTypedArray.prototype, "length", { + get: () => length, + }); +} + +testWithTypedArrayConstructors(TA => { + var ta = new TA([3, 1, 2]); + + setLength(2); + var res = ta.toSorted(); + setLength(3); + assert.compareArray(res, [1, 2, 3]); + + setLength(5); + res = ta.toSorted(); + setLength(3); + + assert.compareArray(res, [1, 2, 3]); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toSorted/metadata/length.js b/test/sendable/builtins/TypedArray/prototype/toSorted/metadata/length.js new file mode 100644 index 0000000000000000000000000000000000000000..d6f880d2cf4b03015a80629c56c47f7a3dcc4497 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toSorted/metadata/length.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toSorted +description: > + The "length" property of %SendableTypedArray%.prototype.toSorted +info: | + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +verifyProperty(SendableTypedArray.prototype.toSorted, "length", { + value: 1, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toSorted/metadata/name.js b/test/sendable/builtins/TypedArray/prototype/toSorted/metadata/name.js new file mode 100644 index 0000000000000000000000000000000000000000..6d4d329a7fafd9cb483bafaff00e0502b77759fe --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toSorted/metadata/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toSorted +description: > + %SendableTypedArray%.prototype.toSorted.name is "toSorted". +info: | + %SendableTypedArray%.prototype.toSorted ( comparefn ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +verifyProperty(SendableTypedArray.prototype.toSorted, "name", { + value: "toSorted", + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toSorted/metadata/property-descriptor.js b/test/sendable/builtins/TypedArray/prototype/toSorted/metadata/property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..7c1a583719228645a7d8f8ac79444986336aefaa --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toSorted/metadata/property-descriptor.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toSorted +description: > + "toSorted" property of %SendableTypedArray%.prototype +info: | + 17 ECMAScript Standard Built-in Objects + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +assert.sameValue(typeof SendableTypedArray.prototype.toSorted, "function", "typeof"); + +verifyProperty(SendableTypedArray.prototype, "toSorted", { + value: SendableTypedArray.prototype.toSorted, + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toSorted/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/toSorted/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..258fe5aa29dcedcca1b2304b3bb01d21cea4f459 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toSorted/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + %SendableTypedArray%.prototype.toSorted does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [TypedArray, change-array-by-copy, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.toSorted), + false, + 'isConstructor(SendableTypedArray.prototype.toSorted) must return false' +); + +assert.throws(TypeError, () => { + new SendableTypedArray.prototype.toSorted(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/toSorted/this-value-invalid.js b/test/sendable/builtins/TypedArray/prototype/toSorted/this-value-invalid.js new file mode 100644 index 0000000000000000000000000000000000000000..2ff160906946de64a314b191fb6548199ae464e4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toSorted/this-value-invalid.js @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.toSorted +description: > + %SendableTypedArray%.prototype.toSorted throws if the receiver is not a valid SendableTypedArray +info: | + %SendableTypedArray%.prototype.toSorted ( comparefn ) + + 2. Let O be the this value. + 3. Perform ? ValidateSendableTypedArray(O). + ... +includes: [detachArrayBuffer.js, sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +var invalidValues = { + 'null': null, + 'undefined': undefined, + 'true': true, + '"abc"': "abc", + '12': 12, + 'Symbol()': Symbol(), + '[1, 2, 3]': [1, 2, 3], + '{ 0: 1, 1: 2, 2: 3, length: 3 }': { 0: 1, 1: 2, 2: 3, length: 3 }, + 'Uint8Array.prototype': Uint8Array.prototype, + '1n': 1n, +}; + +Object.entries(invalidValues).forEach(value => { + assert.throws(TypeError, () => { + SendableTypedArray.prototype.toSorted.call(value[1]); + }, `${value[0]} is not a valid SendableTypedArray`); +}); + +testWithTypedArrayConstructors(function(TA) { + let buffer = new ArrayBuffer(8); + let sample = new TA(buffer, 0, 1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, () => { + sample.toSorted(); + }, `array has a detached buffer`); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toString.js b/test/sendable/builtins/TypedArray/prototype/toString.js new file mode 100644 index 0000000000000000000000000000000000000000..45cd975c8daac7438c3b377c3fcb071c09573724 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toString.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tostring +description: > + "toString" property of SendableTypedArrayPrototype +info: | + 22.2.3.28 %SendableTypedArray%.prototype.toString ( ) + + The initial value of the %SendableTypedArray%.prototype.toString data property is the + same built-in function object as the Array.prototype.toString method defined + in 22.1.3.27. + + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(SendableTypedArrayPrototype.toString, Array.prototype.toString); + +verifyProperty(SendableTypedArrayPrototype, 'toString', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toString/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/toString/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..c10434310fb9444fe8675028815758e7a8e2ab20 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toString/BigInt/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tostring +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.29 %SendableTypedArray%.prototype.toString () + + ... + + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.toString(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toString/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/toString/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..70d24049e5eb8d767e155c0a489507933b455e8f --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toString/detached-buffer.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.tostring +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.29 %SendableTypedArray%.prototype.toString () + + ... + + 22.2.3.15 %SendableTypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateSendableTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.toString(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/toString/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/toString/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..c5d4d2c25e4e7fa0adf37da74052b4fd274c79e9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/toString/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.toString does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.toString), + false, + 'isConstructor(SendableTypedArray.prototype.toString) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.toString(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/values/BigInt/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/values/BigInt/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..9d2aeec6aebb6d41c89eafbb483245a96bf86c6a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/BigInt/detached-buffer.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.30 %SendableTypedArray%.prototype.values ( ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.values(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/BigInt/iter-prototype.js b/test/sendable/builtins/TypedArray/prototype/values/BigInt/iter-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..14f01efda2ae3dd55741ea982142b9d2fa0bf553 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/BigInt/iter-prototype.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + The prototype of the returned iterator is ArrayIteratorPrototype +info: | + 22.2.3.30 %SendableTypedArray%.prototype.values ( ) + + ... + 3. Return CreateArrayIterator(O, "value"). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n, 42n, 64n]); + var iter = sample.values(); + + assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/BigInt/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/values/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..621cd72e5ceb78bf199918a24580a06c6c2022ba --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.values, + 'function', + 'implements SendableTypedArray.prototype.values' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.values(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.values(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the values operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.values(); + throw new Test262Error('values completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/BigInt/return-itor.js b/test/sendable/builtins/TypedArray/prototype/values/BigInt/return-itor.js new file mode 100644 index 0000000000000000000000000000000000000000..bc049f837a6dbb8fe71497655f389f8683675b42 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/BigInt/return-itor.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: Return an iterator for the values. +info: | + 22.2.3.30 %SendableTypedArray%.prototype.values ( ) + + ... + 3. Return CreateArrayIterator(O, "value"). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA([0n, 42n, 64n]); + var itor = typedArray.values(); + + var next = itor.next(); + assert.sameValue(next.value, 0n); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, 42n); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, 64n); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, undefined); + assert.sameValue(next.done, true); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/detached-buffer.js b/test/sendable/builtins/TypedArray/prototype/values/detached-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..d7ea12767bc25f815d106e8098da54dc003588b4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/detached-buffer.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.30 %SendableTypedArray%.prototype.values ( ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [sendableTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.values(); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/invoked-as-func.js b/test/sendable/builtins/TypedArray/prototype/values/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..19cd0cf7f5670b27a9d0c0421f372af50eea8749 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/invoked-as-func.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.29 %SendableTypedArray%.prototype.values ( ) + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var values = SendableTypedArray.prototype.values; + +assert.sameValue(typeof values, 'function'); + +assert.throws(TypeError, function() { + values(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/invoked-as-method.js b/test/sendable/builtins/TypedArray/prototype/values/invoked-as-method.js new file mode 100644 index 0000000000000000000000000000000000000000..aeb582202a356d9d96b69524cf343ebe86ff70dd --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/invoked-as-method.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.29 %SendableTypedArray%.prototype.values ( ) + + 1. Let O be the this value. + 2. Let valid be ValidateSendableTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +assert.sameValue(typeof SendableTypedArrayPrototype.values, 'function'); + +assert.throws(TypeError, function() { + SendableTypedArrayPrototype.values(); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/iter-prototype.js b/test/sendable/builtins/TypedArray/prototype/values/iter-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..e244e38e0ce1dfcdd17d6bf7c9e0e4a9fb3039f9 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/iter-prototype.js @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + The prototype of the returned iterator is ArrayIteratorPrototype +info: | + 22.2.3.30 %SendableTypedArray%.prototype.values ( ) + + ... + 3. Return CreateArrayIterator(O, "value"). +includes: [sendableTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA([0, 42, 64]); + var iter = sample.values(); + + assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/length.js b/test/sendable/builtins/TypedArray/prototype/values/length.js new file mode 100644 index 0000000000000000000000000000000000000000..d7b2e90071a765b9b6cb6b973e95d28315d97390 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/length.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + %SendableTypedArray%.prototype.values.length is 0. +info: | + %SendableTypedArray%.prototype.values ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.values, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/make-in-bounds-after-exhausted.js b/test/sendable/builtins/TypedArray/prototype/values/make-in-bounds-after-exhausted.js new file mode 100644 index 0000000000000000000000000000000000000000..bea2d8aa657f493219ffa301745c76cc258fd043 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/make-in-bounds-after-exhausted.js @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + Iterator is still exhausted when typedarray is changed to in-bounds. +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(3, {maxByteLength: 5}); +let ta = new Int8Array(rab); + +// Ensure the SendableTypedArray is correctly initialised. +assert.sameValue(ta.length, 3); +assert.sameValue(ta.byteOffset, 0); + +ta[0] = 11; +ta[1] = 22; +ta[2] = 33; + +let it = ta.values(); +let r; + +// Fetch the first value. +r = it.next(); +assert.sameValue(r.done, false); +assert.sameValue(r.value, 11); + +// Resize buffer to zero. +rab.resize(0); + +// SendableTypedArray is now out-of-bounds. +assert.sameValue(ta.length, 0); +assert.sameValue(ta.byteOffset, 0); + +// Resize buffer to zero. +rab.resize(0); + +// Attempt to fetch the next value. This exhausts the iterator. +r = it.next(); +assert.sameValue(r.done, true); +assert.sameValue(r.value, undefined); + +// Resize buffer so the typed array is again in-bounds. +rab.resize(5); + +// SendableTypedArray is now in-bounds. +assert.sameValue(ta.length, 5); +assert.sameValue(ta.byteOffset, 0); + +// Attempt to fetch another value from an already exhausted iterator. +r = it.next(); +assert.sameValue(r.done, true); +assert.sameValue(r.value, undefined); diff --git a/test/sendable/builtins/TypedArray/prototype/values/make-out-of-bounds-after-exhausted.js b/test/sendable/builtins/TypedArray/prototype/values/make-out-of-bounds-after-exhausted.js new file mode 100644 index 0000000000000000000000000000000000000000..1454071132ed82ed7b9be82af659ee8f1c31d1c7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/make-out-of-bounds-after-exhausted.js @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + Calling next on an out-of-bounds typedarray throws no error when iterator exhausted. +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(3, {maxByteLength: 5}); +let ta = new Int8Array(rab, 1); + +// Ensure the SendableTypedArray is correctly initialised. +assert.sameValue(ta.length, 2); +assert.sameValue(ta.byteOffset, 1); + +ta[0] = 11; +ta[1] = 22; + +let it = ta.values(); +let r; + +// Fetch the first value. +r = it.next(); +assert.sameValue(r.done, false); +assert.sameValue(r.value, 11); + +// Fetch the second value. +r = it.next(); +assert.sameValue(r.done, false); +assert.sameValue(r.value, 22); + +// Iterator is now exhausted. +r = it.next(); +assert.sameValue(r.done, true); +assert.sameValue(r.value, undefined); + +// Resize buffer to zero. +rab.resize(0); + +// SendableTypedArray is now out-of-bounds. +assert.sameValue(ta.length, 0); +assert.sameValue(ta.byteOffset, 0); + +// Calling next doesn't throw an error. +r = it.next(); +assert.sameValue(r.done, true); +assert.sameValue(r.value, undefined); diff --git a/test/sendable/builtins/TypedArray/prototype/values/name.js b/test/sendable/builtins/TypedArray/prototype/values/name.js new file mode 100644 index 0000000000000000000000000000000000000000..dfd4a40b2fa1d791a2c7b46d4d4301c0f0d2a314 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + %SendableTypedArray%.prototype.values.name is "values". +info: | + %SendableTypedArray%.prototype.values ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +verifyProperty(SendableTypedArray.prototype.values, "name", { + value: "values", + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/values/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..6f2a8422f66fa0efeda683a6b4ce7e8b820106e8 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + SendableTypedArray.prototype.values does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.values), + false, + 'isConstructor(SendableTypedArray.prototype.values) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.values(); +}); + diff --git a/test/sendable/builtins/TypedArray/prototype/values/prop-desc.js b/test/sendable/builtins/TypedArray/prototype/values/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..4f0e78c27296201aeba256cdeb139973d1487bc1 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/prop-desc.js @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + "values" property of SendableTypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through + 26 and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, sendableTypedArray.js] +features: [TypedArray] +---*/ + +var SendableTypedArrayPrototype = SendableTypedArray.prototype; + +verifyProperty(SendableTypedArrayPrototype, 'values', { + writable: true, + enumerable: false, + configurable: true +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/resizable-buffer-grow-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/values/resizable-buffer-grow-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..8dea611e6c03289946f2c7593752a1d61bdc61ca --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/resizable-buffer-grow-mid-iteration.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + SendableTypedArray.p.values behaves correctly on SendableTypedArrays backed by resizable + buffers and resized mid-iteration. +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset + +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + // The fixed length array is not affected by resizing. + TestIterationAndResize(fixedLength.values(), [ + 0, + 2, + 4, + 6 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + // The fixed length array is not affected by resizing. + TestIterationAndResize(fixedLengthWithOffset.values(), [ + 4, + 6 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(lengthTracking.values(), [ + 0, + 2, + 4, + 6, + 0, + 0 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + TestIterationAndResize(lengthTrackingWithOffset.values(), [ + 4, + 6, + 0, + 0 + ], rab, 2, 6 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/values/resizable-buffer-shrink-mid-iteration.js b/test/sendable/builtins/TypedArray/prototype/values/resizable-buffer-shrink-mid-iteration.js new file mode 100644 index 0000000000000000000000000000000000000000..0dba590f0dbb376f056308427200996f3dbea015 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/resizable-buffer-shrink-mid-iteration.js @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + SendableTypedArray.p.values behaves correctly on SendableTypedArrays backed by resizable + buffers that are shrunk mid-iteration. +features: [resizable-arraybuffer] +includes: [compareArray.js, resizableArrayBufferUtils.js] +---*/ + +// Orig. array: [0, 2, 4, 6] +// [0, 2, 4, 6] << fixedLength +// [4, 6] << fixedLengthWithOffset +// [0, 2, 4, 6, ...] << lengthTracking +// [4, 6, ...] << lengthTrackingWithOffset +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLength = new ctor(rab, 0, 4); + + // The fixed length array goes out of bounds when the RAB is resized. + assert.throws(TypeError, () => { + TestIterationAndResize(fixedLength.values(), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + assert.throws(TypeError, () => { + TestIterationAndResize(fixedLengthWithOffset.values(), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT); + }); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTracking = new ctor(rab, 0); + TestIterationAndResize(lengthTracking.values(), [ + 0, + 2, + 4 + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} +for (let ctor of ctors) { + const rab = CreateRabForTest(ctor); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // The fixed length array goes out of bounds when the RAB is resized. + TestIterationAndResize(lengthTrackingWithOffset.values(), [ + 4, + 6 + ], rab, 2, 3 * ctor.BYTES_PER_ELEMENT); +} diff --git a/test/sendable/builtins/TypedArray/prototype/values/resizable-buffer.js b/test/sendable/builtins/TypedArray/prototype/values/resizable-buffer.js new file mode 100644 index 0000000000000000000000000000000000000000..3cda0d184b8cea8eb91730318e7d2c812eee9c5e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/resizable-buffer.js @@ -0,0 +1,161 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + SendableTypedArray.p.values behaves correctly on SendableTypedArrays backed by resizable + buffers. +includes: [compareArray.js, resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +function IteratorToNumbers(iterator) { + let result = []; + for (let value of iterator) { + result.push(Number(value)); + } + return result; +} + +for (let ctor of ctors) { + const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * ctor.BYTES_PER_ELEMENT); + const fixedLength = new ctor(rab, 0, 4); + const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2); + const lengthTracking = new ctor(rab, 0); + const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT); + + // Write some data into the array. + const taWrite = new ctor(rab); + for (let i = 0; i < 4; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, ...] << lengthTracking + // [4, 6, ...] << lengthTrackingWithOffset + + assert.compareArray(IteratorToNumbers(fixedLength.values()), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(IteratorToNumbers(fixedLengthWithOffset.values()), [ + 4, + 6 + ]); + assert.compareArray(IteratorToNumbers(lengthTracking.values()), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(IteratorToNumbers(lengthTrackingWithOffset.values()), [ + 4, + 6 + ]); + + // Shrink so that fixed length TAs go out of bounds. + rab.resize(3 * ctor.BYTES_PER_ELEMENT); + + // Orig. array: [0, 2, 4] + // [0, 2, 4, ...] << lengthTracking + // [4, ...] << lengthTrackingWithOffset + + // SendableTypedArray.prototype.{entries, keys, values} throw right away when + // called. Array.prototype.{entries, keys, values} don't throw, but when + // we try to iterate the returned ArrayIterator, that throws. + assert.throws(TypeError, () => { + fixedLength.values(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.values(); + }); + + assert.compareArray(IteratorToNumbers(lengthTracking.values()), [ + 0, + 2, + 4 + ]); + assert.compareArray(IteratorToNumbers(lengthTrackingWithOffset.values()), [4]); + + // Shrink so that the TAs with offset go out of bounds. + rab.resize(1 * ctor.BYTES_PER_ELEMENT); + assert.throws(TypeError, () => { + fixedLength.values(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.values(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.values(); + }); + + assert.compareArray(IteratorToNumbers(lengthTracking.values()), [0]); + + // Shrink to zero. + rab.resize(0); + assert.throws(TypeError, () => { + fixedLength.values(); + }); + assert.throws(TypeError, () => { + fixedLengthWithOffset.values(); + }); + assert.throws(TypeError, () => { + lengthTrackingWithOffset.values(); + }); + + assert.compareArray(IteratorToNumbers(lengthTracking.values()), []); + + // Grow so that all TAs are back in-bounds. + rab.resize(6 * ctor.BYTES_PER_ELEMENT); + for (let i = 0; i < 6; ++i) { + taWrite[i] = MayNeedBigInt(taWrite, 2 * i); + } + + // Orig. array: [0, 2, 4, 6, 8, 10] + // [0, 2, 4, 6] << fixedLength + // [4, 6] << fixedLengthWithOffset + // [0, 2, 4, 6, 8, 10, ...] << lengthTracking + // [4, 6, 8, 10, ...] << lengthTrackingWithOffset + + assert.compareArray(IteratorToNumbers(fixedLength.values()), [ + 0, + 2, + 4, + 6 + ]); + assert.compareArray(IteratorToNumbers(fixedLengthWithOffset.values()), [ + 4, + 6 + ]); + assert.compareArray(IteratorToNumbers(lengthTracking.values()), [ + 0, + 2, + 4, + 6, + 8, + 10 + ]); + assert.compareArray(IteratorToNumbers(lengthTrackingWithOffset.values()), [ + 4, + 6, + 8, + 10 + ]); +} diff --git a/test/sendable/builtins/TypedArray/prototype/values/return-abrupt-from-this-out-of-bounds.js b/test/sendable/builtins/TypedArray/prototype/values/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000000000000000000000000000000000..b17be97dc20353edeb47aaba18c0738b0a4351a5 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: Return abrupt when "this" value fails buffer boundary checks +includes: [sendableTypedArray.js] +features: [ArrayBuffer, SendableTypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof SendableTypedArray.prototype.values, + 'function', + 'implements SendableTypedArray.prototype.values' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.values(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.values(); + + var expectedError; + try { + ab.resize(BPE * 3 - 1); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateSendableTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the values operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.values(); + throw new Test262Error('values completed successfully'); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/return-itor.js b/test/sendable/builtins/TypedArray/prototype/values/return-itor.js new file mode 100644 index 0000000000000000000000000000000000000000..b7a2b106e889ead1fd985afcc7ab56c9cedad2ad --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/return-itor.js @@ -0,0 +1,49 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: Return an iterator for the values. +info: | + 22.2.3.30 %SendableTypedArray%.prototype.values ( ) + + ... + 3. Return CreateArrayIterator(O, "value"). +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var sample = [0, 42, 64]; + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(sample); + var itor = typedArray.values(); + + var next = itor.next(); + assert.sameValue(next.value, 0); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, 42); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, 64); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, undefined); + assert.sameValue(next.done, true); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/values/this-is-not-object.js b/test/sendable/builtins/TypedArray/prototype/values/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..33eb880cfde1ed384cfca756eeafc21d1c2efbab --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/this-is-not-object.js @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.30 %SendableTypedArray%.prototype.values ( ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [sendableTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var values = SendableTypedArray.prototype.values; + +assert.throws(TypeError, function() { + values.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + values.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + values.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + values.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + values.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + values.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + values.call(s); +}, "this is a Symbol"); diff --git a/test/sendable/builtins/TypedArray/prototype/values/this-is-not-typedarray-instance.js b/test/sendable/builtins/TypedArray/prototype/values/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000000000000000000000000000000000..062e84d68b1ef3b57c87ff135bfca013512ac187 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/values/this-is-not-typedarray-instance.js @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.values +description: > + Throws a TypeError exception when `this` is not a SendableTypedArray instance +info: | + 22.2.3.30 %SendableTypedArray%.prototype.values ( ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateSendableTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray] +---*/ + +var values = SendableTypedArray.prototype.values; + +assert.throws(TypeError, function() { + values.call({}); +}, "this is an Object"); + +assert.throws(TypeError, function() { + values.call([]); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + values.call(ab); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + values.call(dv); +}, "this is a DataView instance"); diff --git a/test/sendable/builtins/TypedArray/prototype/with/BigInt/early-type-coercion-bigint.js b/test/sendable/builtins/TypedArray/prototype/with/BigInt/early-type-coercion-bigint.js new file mode 100644 index 0000000000000000000000000000000000000000..44181fbbba0fd8f5a21182e9f479c38e94d3d971 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/BigInt/early-type-coercion-bigint.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + %SendableTypedArray%.prototype.with invokes ToNumber before copying +info: | + %SendableTypedArray%.prototype.with ( index, value ) + + ... + 7. If _O_.[[ContentType]] is ~BigInt~, set _value_ to ? ToBigInt(_value_). + 8. Else, set _value_ to ? ToNumber(_value_). + ... +features: [BigInt, SendableTypedArray, change-array-by-copy] +includes: [testBigIntTypedArray.js, compareArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var arr = new TA([0n, 1n, 2n]); + + var value = { + valueOf() { + arr[0] = 3n; + return 4n; + } + }; + + assert.compareArray(arr.with(1, value), [3n, 4n, 2n]); + assert.compareArray(arr, [3n, 1n, 2n]); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/early-type-coercion.js b/test/sendable/builtins/TypedArray/prototype/with/early-type-coercion.js new file mode 100644 index 0000000000000000000000000000000000000000..a03688815d85a4fa233638b1daf80b393dba4585 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/early-type-coercion.js @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + %SendableTypedArray%.prototype.with invokes ToNumber before copying +info: | + %SendableTypedArray%.prototype.with ( index, value ) + + ... + 7. If _O_.[[ContentType]] is ~BigInt~, set _value_ to ? ToBigInt(_value_). + 8. Else, set _value_ to ? ToNumber(_value_). + ... +features: [TypedArray, change-array-by-copy] +includes: [sendableTypedArray.js, compareArray.js] +---*/ + +testWithTypedArrayConstructors(TA => { + var arr = new TA([0, 1, 2]); + + var value = { + valueOf() { + arr[0] = 3; + return 4; + } + }; + + assert.compareArray(arr.with(1, value), [3, 4, 2]); + assert.compareArray(arr, [3, 1, 2]); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/ignores-species.js b/test/sendable/builtins/TypedArray/prototype/with/ignores-species.js new file mode 100644 index 0000000000000000000000000000000000000000..1761c1016acaa0f6ae9fa9eb24f1c346037465ca --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/ignores-species.js @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + %SendableTypedArray%.prototype.with ignores @@species +info: | + %SendableTypedArray%.prototype.with ( index, value ) + + ... + 10. Let A be ? SendableTypedArrayCreateSameType(O, « 𝔽(len) »). + ... + + SendableTypedArrayCreateSameType ( exemplar, argumentList ) + ... + 2. Let constructor be the intrinsic object listed in column one of Table 63 for exemplar.[[TypedArrayName]]. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([1, 2, 3]); + ta.constructor = TA === Uint8Array ? Int32Array : Uint8Array; + assert.sameValue(Object.getPrototypeOf(ta.with(0, 2)), TA.prototype); + + ta = new TA([1, 2, 3]); + ta.constructor = { + [Symbol.species]: TA === Uint8Array ? Int32Array : Uint8Array, + }; + assert.sameValue(Object.getPrototypeOf(ta.with(0, 2)), TA.prototype); + + ta = new TA([1, 2, 3]); + Object.defineProperty(ta, "constructor", { + get() { + throw new Test262Error("Should not get .constructor"); + } + }); + ta.with(0, 2); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/immutable.js b/test/sendable/builtins/TypedArray/prototype/with/immutable.js new file mode 100644 index 0000000000000000000000000000000000000000..1ff1636c0815ff77aa992e4190dfb78fc65d1c64 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/immutable.js @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + %SendableTypedArray%.prototype.with does not mutate its this value +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([3, 1, 2]); + ta.with(0, 2); + + assert.compareArray(ta, [3, 1, 2]); + assert.notSameValue(ta.with(0, 2), ta); + assert.notSameValue(ta.with(0, 3), ta); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/index-bigger-or-eq-than-length.js b/test/sendable/builtins/TypedArray/prototype/with/index-bigger-or-eq-than-length.js new file mode 100644 index 0000000000000000000000000000000000000000..8d68a9965bd086c8b42768a308c436f8b2b4fdc0 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/index-bigger-or-eq-than-length.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-typed%array%.prototype.with +description: > + %SendableTypedArray%.prototype.with throws if the index is bigger than or equal to the array length. +info: | + %SendableTypedArray%.prototype.with ( index, value ) + + ... + 3. Let len be O.[[ArrayLength]]. + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + 6. If ! IsValidIntegerIndex(O, actualIndex) is false, throw a *RangeError* exception. + ... +includes: [sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var arr = new TA([0, 1, 2]); + + assert.throws(RangeError, function() { + arr.with(3, 7); + }); + + assert.throws(RangeError, function() { + arr.with(10, 7); + }); + + assert.throws(RangeError, function() { + arr.with(2 ** 53 + 2, 7); + }); + + assert.throws(RangeError, function() { + arr.with(Infinity, 7); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/index-casted-to-number.js b/test/sendable/builtins/TypedArray/prototype/with/index-casted-to-number.js new file mode 100644 index 0000000000000000000000000000000000000000..07c4750c5080693b287d54a1ecb1d2d7d8232807 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/index-casted-to-number.js @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + %SendableTypedArray%.prototype.with casts the index to an integer. +info: | + %SendableTypedArray%.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + ... +features: [TypedArray, change-array-by-copy] +includes: [sendableTypedArray.js, compareArray.js] +---*/ + +testWithTypedArrayConstructors(TA => { + var arr = new TA([0, 4, 16]); + + assert.compareArray(arr.with(1.2, 7), [0, 7, 16]); + assert.compareArray(arr.with("1", 3), [0, 3, 16]); + assert.compareArray(arr.with("-1", 5), [0, 4, 5]); + assert.compareArray(arr.with(NaN, 2), [2, 4, 16]); + assert.compareArray(arr.with("dog", 33), [33, 4, 16]); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/index-negative.js b/test/sendable/builtins/TypedArray/prototype/with/index-negative.js new file mode 100644 index 0000000000000000000000000000000000000000..306795544a2fce984f1048f7aed4655713a590f4 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/index-negative.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + %SendableTypedArray%.prototype.with adds length to index if it's negative. +info: | + %SendableTypedArray%.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + ... +features: [TypedArray, change-array-by-copy] +includes: [sendableTypedArray.js, compareArray.js] +---*/ + +testWithTypedArrayConstructors(TA => { + var arr = new TA([0, 1, 2]); + + assert.compareArray(arr.with(-1, 4), [0, 1, 4]); + assert.compareArray(arr.with(-3, 4), [4, 1, 2]); + // -0 is not negative. + assert.compareArray(arr.with(-0, 4), [4, 1, 2]); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/index-smaller-than-minus-length.js b/test/sendable/builtins/TypedArray/prototype/with/index-smaller-than-minus-length.js new file mode 100644 index 0000000000000000000000000000000000000000..22dd26e52d68e026a61c90344a591fdbf4db5e64 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/index-smaller-than-minus-length.js @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + %SendableTypedArray%.prototype.with throws if the (negative) index is smaller than -length. +info: | + %SendableTypedArray%.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + 6. If actualIndex >= len or actualIndex < 0, throw a *RangeError* exception. + ... +features: [TypedArray, change-array-by-copy] +includes: [sendableTypedArray.js] +---*/ + +testWithTypedArrayConstructors(TA => { + var arr = new TA([0, 1, 2]); + + assert.throws(RangeError, function() { + arr.with(-4, 7); + }); + + assert.throws(RangeError, function() { + arr.with(-10, 7); + }); + + assert.throws(RangeError, function() { + arr.with(-(2 ** 53) - 2, 7); + }); + + assert.throws(RangeError, function() { + arr.with(-Infinity, 7); + }); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/index-validated-against-current-length.js b/test/sendable/builtins/TypedArray/prototype/with/index-validated-against-current-length.js new file mode 100644 index 0000000000000000000000000000000000000000..a1eb2eae1d6f1cb7c9bf41a9ca600f0640f325df --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/index-validated-against-current-length.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + The index is validated against the current length. +info: | + %SendableTypedArray%.prototype.with ( index, value ) + + 1. Let O be the this value. + 2. Let taRecord be ? ValidateSendableTypedArray(O, SEQ-CST). + 3. Let len be SendableTypedArrayLength(taRecord). + ... + 8. Else, let numericValue be ? ToNumber(value). + ... + 10. Let A be ? SendableTypedArrayCreateSameType(O, « 𝔽(len) »). + ... + 13. Return A. + +features: [TypedArray, resizable-arraybuffer] +---*/ + +let rab = new ArrayBuffer(2, {maxByteLength: 5}); +let ta = new Int8Array(rab); + +ta[0] = 11; +ta[1] = 22; + +// Ensure typed array is correctly initialised. +assert.sameValue(ta.length, 2); +assert.sameValue(ta[0], 11); +assert.sameValue(ta[1], 22); + +// Index is initially out-of-bounds. +let index = 4; + +let value = { + valueOf() { + rab.resize(5); + return 123; + } +}; + +let result = ta.with(index, value); + +// Typed array has been resized. +assert.sameValue(ta.length, 5); +assert.sameValue(ta[0], 11); +assert.sameValue(ta[1], 22); +assert.sameValue(ta[2], 0); +assert.sameValue(ta[3], 0); +assert.sameValue(ta[4], 0); + +// Result is correctly initialised. +assert.sameValue(result.length, 2); +assert.sameValue(result[0], 11); +assert.sameValue(result[1], 22); diff --git a/test/sendable/builtins/TypedArray/prototype/with/length-property-ignored.js b/test/sendable/builtins/TypedArray/prototype/with/length-property-ignored.js new file mode 100644 index 0000000000000000000000000000000000000000..58eedc2f09d60169a42cadd513a537052077dc02 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/length-property-ignored.js @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + %SendableTypedArray%.prototype.with reads the SendableTypedArray length ignoring the .length property +info: | + %SendableTypedArray%.prototype.with ( index, value ) + + ... + 3. Let len be O.[[ArrayLength]]. + ... +includes: [sendableTypedArray.js, compareArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([3, 1, 2]); + Object.defineProperty(ta, "length", { value: 2 }) + var res = ta.with(0, 0); + assert.compareArray(res, [0, 1, 2]); + assert.sameValue(res.length, 3); + + ta = new TA([3, 1, 2]); + Object.defineProperty(ta, "length", { value: 5 }); + res = ta.with(0, 0); + assert.compareArray(res, [0, 1, 2]); + assert.sameValue(res.length, 3); +}); + +function setLength(length) { + Object.defineProperty(SendableTypedArray.prototype, "length", { + get: () => length, + }); +} + +testWithTypedArrayConstructors(TA => { + var ta = new TA([3, 1, 2]); + + setLength(2); + var res = ta.with(0, 0); + setLength(3); + assert.compareArray(res, [0, 1, 2]); + + setLength(5); + res = ta.with(0, 0); + setLength(3); + assert.compareArray(res, [0, 1, 2]); +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/metadata/length.js b/test/sendable/builtins/TypedArray/prototype/with/metadata/length.js new file mode 100644 index 0000000000000000000000000000000000000000..64c0571d8723e138d670f7c33832fe4bef43d70e --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/metadata/length.js @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + The "length" property of %SendableTypedArray%.prototype.with +info: | + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [sendableTypedArray.js, propertyHelper.js] +features: [TypedArray, change-array-by-copy] +---*/ + +verifyProperty(SendableTypedArray.prototype.with, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/metadata/name.js b/test/sendable/builtins/TypedArray/prototype/with/metadata/name.js new file mode 100644 index 0000000000000000000000000000000000000000..c3740a3ec10e5abf5a7c6f06d12f39f198dcfc1a --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/metadata/name.js @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + %SendableTypedArray%.prototype.with.name is "with". +info: | + %SendableTypedArray%.prototype.with ( index, value ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [sendableTypedArray.js, propertyHelper.js] +features: [TypedArray, change-array-by-copy] +---*/ + +verifyProperty(SendableTypedArray.prototype.with, "name", { + value: "with", + writable: false, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/metadata/property-descriptor.js b/test/sendable/builtins/TypedArray/prototype/with/metadata/property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..dba7549a99645e9bb69766823d16d4bbbec6a684 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/metadata/property-descriptor.js @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + "with" property of %SendableTypedArray%.prototype +info: | + 17 ECMAScript Standard Built-in Objects + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [sendableTypedArray.js, propertyHelper.js] +features: [TypedArray, change-array-by-copy] +---*/ + +assert.sameValue(typeof SendableTypedArray.prototype.with, "function", "typeof"); + +verifyProperty(SendableTypedArray.prototype, "with", { + value: SendableTypedArray.prototype.with, + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/sendable/builtins/TypedArray/prototype/with/not-a-constructor.js b/test/sendable/builtins/TypedArray/prototype/with/not-a-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..3c28b54e187a7a54e42068d2a09b8ae75bf43df6 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/not-a-constructor.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + %SendableTypedArray%.prototype.with does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, sendableTypedArray.js] +features: [TypedArray, change-array-by-copy, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(SendableTypedArray.prototype.with), + false, + 'isConstructor(SendableTypedArray.prototype.with) must return false' +); + +assert.throws(TypeError, () => { + new SendableTypedArray.prototype.with(0, 1); +}, '`new %SendableTypedArray%.prototype.with()` throws TypeError'); + diff --git a/test/sendable/builtins/TypedArray/prototype/with/this-value-invalid.js b/test/sendable/builtins/TypedArray/prototype/with/this-value-invalid.js new file mode 100644 index 0000000000000000000000000000000000000000..6320559702f805b987d014dd10e5ecb0238a8db7 --- /dev/null +++ b/test/sendable/builtins/TypedArray/prototype/with/this-value-invalid.js @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-%sendableTypedArray%.prototype.with +description: > + %SendableTypedArray%.prototype.with throws if the receiver is null or undefined +info: | + %SendableTypedArray%.prototype.with ( index, value ) + + 1. Let O be the this value. + 2. Perform ? ValidateSendableTypedArray(O). + ... +includes: [sendableTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +var invalidValues = { + 'null': null, + 'undefined': undefined, + 'true': true, + '"abc"': "abc", + '12': 12, + 'Symbol()': Symbol(), + '[1, 2, 3]': [1, 2, 3], + '{ 0: 1, 1: 2, 2: 3, length: 3 }': { 0: 1, 1: 2, 2: 3, length: 3 }, + 'Uint8Array.prototype': Uint8Array.prototype, +}; + +Object.keys(invalidValues).forEach(desc => { + var value = invalidValues[desc]; + assert.throws(TypeError, () => { + SendableTypedArray.prototype.with.call(value, 0, 0); + }, `${desc} is not a valid SendableTypedArray`); +}); diff --git a/test/sendable/builtins/TypedArray/resizable-buffer-length-tracking-1.js b/test/sendable/builtins/TypedArray/resizable-buffer-length-tracking-1.js new file mode 100644 index 0000000000000000000000000000000000000000..1824a1030dc3fb1142ef959e8f15c023b2b00b1c --- /dev/null +++ b/test/sendable/builtins/TypedArray/resizable-buffer-length-tracking-1.js @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-arraybuffer-length +description: > + Basic functionality of length-tracking SendableTypedArrays backed by resizable + buffers +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +const rab = CreateResizableArrayBuffer(16, 40); +let tas = []; +for (let ctor of ctors) { + tas.push(new ctor(rab)); +} +for (let ta of tas) { + assert.sameValue(ta.length, 16 / ta.BYTES_PER_ELEMENT); + assert.sameValue(ta.byteLength, 16); +} +rab.resize(40); +for (let ta of tas) { + assert.sameValue(ta.length, 40 / ta.BYTES_PER_ELEMENT); + assert.sameValue(ta.byteLength, 40); +} +// Resize to a number which is not a multiple of all byte_lengths. +rab.resize(19); +for (let ta of tas) { + const expected_length = Math.floor(19 / ta.BYTES_PER_ELEMENT); + assert.sameValue(ta.length, expected_length); + assert.sameValue(ta.byteLength, expected_length * ta.BYTES_PER_ELEMENT); +} +rab.resize(1); +for (let ta of tas) { + if (ta.BYTES_PER_ELEMENT == 1) { + assert.sameValue(ta.length, 1); + assert.sameValue(ta.byteLength, 1); + } else { + assert.sameValue(ta.length, 0); + assert.sameValue(ta.byteLength, 0); + } +} +rab.resize(0); +for (let ta of tas) { + assert.sameValue(ta.length, 0); + assert.sameValue(ta.byteLength, 0); +} +rab.resize(8); +for (let ta of tas) { + assert.sameValue(ta.length, 8 / ta.BYTES_PER_ELEMENT); + assert.sameValue(ta.byteLength, 8); +} +rab.resize(40); +for (let ta of tas) { + assert.sameValue(ta.length, 40 / ta.BYTES_PER_ELEMENT); + assert.sameValue(ta.byteLength, 40); +} diff --git a/test/sendable/builtins/TypedArray/resizable-buffer-length-tracking-2.js b/test/sendable/builtins/TypedArray/resizable-buffer-length-tracking-2.js new file mode 100644 index 0000000000000000000000000000000000000000..80460496fd8d5a42ebdb9fe6ce431b233230f8d3 --- /dev/null +++ b/test/sendable/builtins/TypedArray/resizable-buffer-length-tracking-2.js @@ -0,0 +1,90 @@ +/* +* Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. +*/ + +/*--- +esid: sec-arraybuffer-length +description: > + Length-tracking SendableTypedArrays backed by resizable buffers with offsets + behave correctly +includes: [resizableArrayBufferUtils.js] +features: [resizable-arraybuffer] +---*/ + +// length-tracking-1 but with offsets. + +const rab = CreateResizableArrayBuffer(16, 40); +const offset = 8; +let tas = []; +for (let ctor of ctors) { + tas.push(new ctor(rab, offset)); +} +for (let ta of tas) { + assert.sameValue(ta.length, (16 - offset) / ta.BYTES_PER_ELEMENT); + assert.sameValue(ta.byteLength, 16 - offset); + assert.sameValue(ta.byteOffset, offset); +} +rab.resize(40); +for (let ta of tas) { + assert.sameValue(ta.length, (40 - offset) / ta.BYTES_PER_ELEMENT); + assert.sameValue(ta.byteLength, 40 - offset); + assert.sameValue(ta.byteOffset, offset); +} +// Resize to a number which is not a multiple of all byte_lengths. +rab.resize(20); +for (let ta of tas) { + const expected_length = Math.floor((20 - offset) / ta.BYTES_PER_ELEMENT); + assert.sameValue(ta.length, expected_length); + assert.sameValue(ta.byteLength, expected_length * ta.BYTES_PER_ELEMENT); + assert.sameValue(ta.byteOffset, offset); +} +// Resize so that all SendableTypedArrays go out of bounds (because of the offset). +rab.resize(7); +for (let ta of tas) { + assert.sameValue(ta.length, 0); + assert.sameValue(ta.byteLength, 0); + assert.sameValue(ta.byteOffset, 0); +} +rab.resize(0); +for (let ta of tas) { + assert.sameValue(ta.length, 0); + assert.sameValue(ta.byteLength, 0); + assert.sameValue(ta.byteOffset, 0); +} +rab.resize(8); +for (let ta of tas) { + assert.sameValue(ta.length, 0); + assert.sameValue(ta.byteLength, 0); + assert.sameValue(ta.byteOffset, offset); +} +// Resize so that the SendableTypedArrays which have element size > 1 go out of bounds +// (because less than 1 full element would fit). +rab.resize(offset + 1); +for (let ta of tas) { + if (ta.BYTES_PER_ELEMENT == 1) { + assert.sameValue(ta.length, 1); + assert.sameValue(ta.byteLength, 1); + assert.sameValue(ta.byteOffset, offset); + } else { + assert.sameValue(ta.length, 0); + assert.sameValue(ta.byteLength, 0); + assert.sameValue(ta.byteOffset, offset); + } +} +rab.resize(40); +for (let ta of tas) { + assert.sameValue(ta.length, (40 - offset) / ta.BYTES_PER_ELEMENT); + assert.sameValue(ta.byteLength, 40 - offset); + assert.sameValue(ta.byteOffset, offset); +} diff --git a/test/sendable/harness/assert-false.js b/test/sendable/harness/assert-false.js new file mode 100644 index 0000000000000000000000000000000000000000..5285c790116b2a427835d4a1722a560acbfaade8 --- /dev/null +++ b/test/sendable/harness/assert-false.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + `false` does not satisfy the assertion. +---*/ + +var threw = false; + +try { + assert(false); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-notsamevalue-nan.js b/test/sendable/harness/assert-notsamevalue-nan.js new file mode 100644 index 0000000000000000000000000000000000000000..f9e9903c1f1780e8187575ea8a1e5abf340c1be2 --- /dev/null +++ b/test/sendable/harness/assert-notsamevalue-nan.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Two references to NaN do not satisfy the assertion. +---*/ + +var threw = false; + +try { + assert.notSameValue(NaN, NaN); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-notsamevalue-notsame.js b/test/sendable/harness/assert-notsamevalue-notsame.js new file mode 100644 index 0000000000000000000000000000000000000000..a1315d588f4014ff6b7e3347a432cf70345762e7 --- /dev/null +++ b/test/sendable/harness/assert-notsamevalue-notsame.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Values that are not strictly equal satisfy the assertion. +---*/ + +assert.notSameValue(undefined, null); +assert.notSameValue(null, undefined); +assert.notSameValue(0, 1); +assert.notSameValue(1, 0); +assert.notSameValue('', 's'); +assert.notSameValue('s', ''); diff --git a/test/sendable/harness/assert-notsamevalue-objects.js b/test/sendable/harness/assert-notsamevalue-objects.js new file mode 100644 index 0000000000000000000000000000000000000000..f1fb40b351ea87e9ad85f2ef4d3cbd0801c5e041 --- /dev/null +++ b/test/sendable/harness/assert-notsamevalue-objects.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Distinct objects satisfy the assertion. +---*/ + +assert.notSameValue({}, {}); diff --git a/test/sendable/harness/assert-notsamevalue-tostring.js b/test/sendable/harness/assert-notsamevalue-tostring.js new file mode 100644 index 0000000000000000000000000000000000000000..ee583b5204513d427a6cf532e4a6739de95d1af7 --- /dev/null +++ b/test/sendable/harness/assert-notsamevalue-tostring.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + When composing a message, errors from ToString are handled. +features: [async-functions] +---*/ + +var threw = false; +var asyncFunProto = Object.getPrototypeOf(async function() {}); + +try { + assert.notSameValue(asyncFunProto, asyncFunProto); +} catch (err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error('Expected a Test262Error, but a "' + err.constructor.name + '" was thrown.'); + } +} + +if (!threw) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-notsamevalue-zeros.js b/test/sendable/harness/assert-notsamevalue-zeros.js new file mode 100644 index 0000000000000000000000000000000000000000..7b8195e2debd2bca43bd37d06e9524efb07f9d1d --- /dev/null +++ b/test/sendable/harness/assert-notsamevalue-zeros.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Positive and negative zero satisfy the assertion. +---*/ + +assert.notSameValue(0, -0); diff --git a/test/sendable/harness/assert-obj.js b/test/sendable/harness/assert-obj.js new file mode 100644 index 0000000000000000000000000000000000000000..1b54e8e3904a046b438d551a46dd03f7324cb3f0 --- /dev/null +++ b/test/sendable/harness/assert-obj.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + An object literal does not satisfy the assertion. +---*/ + +var threw = false; + +try { + assert({}); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-samevalue-nan.js b/test/sendable/harness/assert-samevalue-nan.js new file mode 100644 index 0000000000000000000000000000000000000000..5c14c5238b1ec187b1670c62cb1204c8d89534ad --- /dev/null +++ b/test/sendable/harness/assert-samevalue-nan.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Two references to NaN satisfy the assertion. +---*/ + +assert.sameValue(NaN, NaN); diff --git a/test/sendable/harness/assert-samevalue-objects.js b/test/sendable/harness/assert-samevalue-objects.js new file mode 100644 index 0000000000000000000000000000000000000000..e7296edf00eecf69aaa2b3916928b54cc3b008c2 --- /dev/null +++ b/test/sendable/harness/assert-samevalue-objects.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Distinct objects do not satisfy the assertion. +---*/ + +var threw = false; + +try { + assert.sameValue({}, {}); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-samevalue-same.js b/test/sendable/harness/assert-samevalue-same.js new file mode 100644 index 0000000000000000000000000000000000000000..29221c507ae1133ed035956f7b7120cfb5e31b13 --- /dev/null +++ b/test/sendable/harness/assert-samevalue-same.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Values that are strictly equal satisfy the assertion. +---*/ +var obj; + +assert.sameValue(undefined, undefined); +assert.sameValue(null, null); +assert.sameValue(0, 0); +assert.sameValue(1, 1); +assert.sameValue('', ''); +assert.sameValue('s', 's'); + +obj = {}; +assert.sameValue(obj, obj); diff --git a/test/sendable/harness/assert-samevalue-tostring.js b/test/sendable/harness/assert-samevalue-tostring.js new file mode 100644 index 0000000000000000000000000000000000000000..37ac77c9d99ed39f848d3e8584d99aab4ebcf1c8 --- /dev/null +++ b/test/sendable/harness/assert-samevalue-tostring.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + When composing a message, errors from ToString are handled. +features: [async-functions] +---*/ + +var threw = false; +var asyncFunProto = Object.getPrototypeOf(async function() {}); + +try { + assert.sameValue(asyncFunProto, 1); +} catch (err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error('Expected a Test262Error, but a "' + err.constructor.name + '" was thrown.'); + } +} + +if (!threw) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-samevalue-zeros.js b/test/sendable/harness/assert-samevalue-zeros.js new file mode 100644 index 0000000000000000000000000000000000000000..247f6f57885a4d8696ed3074dbe570bacfbb8f6f --- /dev/null +++ b/test/sendable/harness/assert-samevalue-zeros.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Positive and negative zero do not satisfy the assertion. +---*/ + +var threw = false; + +try { + assert.sameValue(0, -0); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } + assert.notSameValue(err.message.indexOf('-0'), -1); +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-throws-custom-typeerror.js b/test/sendable/harness/assert-throws-custom-typeerror.js new file mode 100644 index 0000000000000000000000000000000000000000..af14c168c7723b32e9f2f68704a5fa69bfbc932a --- /dev/null +++ b/test/sendable/harness/assert-throws-custom-typeerror.js @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Functions that throw instances of the specified constructor function + satisfy the assertion, without collision with error constructors of the + same name. +---*/ + +var intrinsicTypeError = TypeError; +var threw = false; + +(function() { + function TypeError() {} + + assert.throws(TypeError, function() { + throw new TypeError(); + }, 'Throws an instance of the matching custom TypeError'); + + try { + assert.throws(intrinsicTypeError, function() { + throw new TypeError(); + }); + } catch (err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error but a "' + err.constructor.name + + '" was thrown.' + ); + } + } + + if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); + } + + threw = false; + + try { + assert.throws(TypeError, function() { + throw new intrinsicTypeError(); + }); + } catch (err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error but a "' + err.constructor.name + + '" was thrown.' + ); + } + } + + if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); + } +})(); diff --git a/test/sendable/harness/assert-throws-custom.js b/test/sendable/harness/assert-throws-custom.js new file mode 100644 index 0000000000000000000000000000000000000000..52d6bdda11548818e22ef3606aae9906b2da530b --- /dev/null +++ b/test/sendable/harness/assert-throws-custom.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Functions that throw instances of the specified constructor function + satisfy the assertion. +---*/ + +function MyError() {} + +assert.throws(MyError, function() { + throw new MyError(); +}); diff --git a/test/sendable/harness/assert-throws-incorrect-ctor.js b/test/sendable/harness/assert-throws-incorrect-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..ba91820b7edfa468b95264f6d5062812c825013b --- /dev/null +++ b/test/sendable/harness/assert-throws-incorrect-ctor.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Functions that throw values whose constructor does not match the specified + constructor do not satisfy the assertion. +---*/ + +var threw = false; + +try { + assert.throws(Error, function() { + throw new TypeError(); + }); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-throws-native.js b/test/sendable/harness/assert-throws-native.js new file mode 100644 index 0000000000000000000000000000000000000000..a11c08e537dce4d3d745a1057db0c94db2ddbafe --- /dev/null +++ b/test/sendable/harness/assert-throws-native.js @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Functions that throw instances of the specified native Error constructor + satisfy the assertion. +---*/ + +assert.throws(Error, function() { + throw new Error(); +}); + +assert.throws(EvalError, function() { + throw new EvalError(); +}); + +assert.throws(RangeError, function() { + throw new RangeError(); +}); + +assert.throws(ReferenceError, function() { + throw new ReferenceError(); +}); + +assert.throws(SyntaxError, function() { + throw new SyntaxError(); +}); + +assert.throws(TypeError, function() { + throw new TypeError(); +}); + +assert.throws(URIError, function() { + throw new URIError(); +}); diff --git a/test/sendable/harness/assert-throws-no-arg.js b/test/sendable/harness/assert-throws-no-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..c12f55cefe6d2d8a8424e7b2e8f73868af08ee08 --- /dev/null +++ b/test/sendable/harness/assert-throws-no-arg.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + The assertion fails when invoked without arguments. +---*/ + +var threw = false; + +try { + assert.throws(); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-throws-no-error.js b/test/sendable/harness/assert-throws-no-error.js new file mode 100644 index 0000000000000000000000000000000000000000..4d2cf2cf09f8a25d3682479f079442c22cc85ce1 --- /dev/null +++ b/test/sendable/harness/assert-throws-no-error.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Functions that do not throw errors do not satisfy the assertion. +---*/ + +var threw = false; + +try { + assert.throws(Error, function() {}); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-throws-null-fn.js b/test/sendable/harness/assert-throws-null-fn.js new file mode 100644 index 0000000000000000000000000000000000000000..01805f5e3afb79eb277439f1532cb0bb3f1c93c7 --- /dev/null +++ b/test/sendable/harness/assert-throws-null-fn.js @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Fails if second arg is not a function +---*/ + +var threw = false; + +try { + assert.throws(TypeError, null); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} + +threw = false; + +try { + assert.throws(TypeError, {}); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} + +threw = false; + +try { + assert.throws(TypeError, ""); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-throws-null.js b/test/sendable/harness/assert-throws-null.js new file mode 100644 index 0000000000000000000000000000000000000000..5f259d41af0d7cce947440d82f91e01d5b06b8b4 --- /dev/null +++ b/test/sendable/harness/assert-throws-null.js @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Functions that throw the `null` value do not satisfy the assertion. +---*/ + +var threw = false; + +try { + assert.throws(Error, function() { + throw null; + }); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-throws-primitive.js b/test/sendable/harness/assert-throws-primitive.js new file mode 100644 index 0000000000000000000000000000000000000000..a74f5993a75241b50721ea17b395db4af995aa39 --- /dev/null +++ b/test/sendable/harness/assert-throws-primitive.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Functions that throw primitive values do not satisfy the assertion. +---*/ +var threw = false; + +try { + assert.throws(Error, function() { + throw 3; + }); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-throws-same-realm.js b/test/sendable/harness/assert-throws-same-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..319affce35ab020d6ced33bb35568bd264a73d7b --- /dev/null +++ b/test/sendable/harness/assert-throws-same-realm.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Functions that throw instances of the realm specified constructor function + do not satisfy the assertion with cross realms collisions. +---*/ + +var intrinsicTypeError = TypeError; +var threw = false; +var realmGlobal = $262.createRealm().global; + +try { + assert.throws(TypeError, function() { + throw new realmGlobal.TypeError(); + }); +} catch (err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-throws-single-arg.js b/test/sendable/harness/assert-throws-single-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..34bcd141c1cb6fba410a1e67b1aff5bdd8fb3070 --- /dev/null +++ b/test/sendable/harness/assert-throws-single-arg.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + The assertion fails when invoked with a single argument. +---*/ +var threw = false; + +try { + assert.throws(function() {}); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-tostring.js b/test/sendable/harness/assert-tostring.js new file mode 100644 index 0000000000000000000000000000000000000000..49d09c0bdb6df196d79e47047a7ab5d53d0bf577 --- /dev/null +++ b/test/sendable/harness/assert-tostring.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + When composing a message, errors from ToString are handled. +features: [async-functions] +---*/ + +var threw = false; +var asyncFunProto = Object.getPrototypeOf(async function() {}); + +try { + assert(asyncFunProto); +} catch (err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error('Expected a Test262Error, but a "' + err.constructor.name + '" was thrown.'); + } +} + +if (!threw) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/assert-true.js b/test/sendable/harness/assert-true.js new file mode 100644 index 0000000000000000000000000000000000000000..15a5d27abd5205e27db5ec93e59fbe102c1aa2fe --- /dev/null +++ b/test/sendable/harness/assert-true.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + `true` satisfies the assertion. +---*/ + +assert(true); diff --git a/test/sendable/harness/assertRelativeDateMs.js b/test/sendable/harness/assertRelativeDateMs.js new file mode 100644 index 0000000000000000000000000000000000000000..62951e101e0e677c14c43a3642b92884f4b08c9d --- /dev/null +++ b/test/sendable/harness/assertRelativeDateMs.js @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Only passes when the provided date is exactly the specified number of + milliseconds from the Unix epoch +includes: [assertRelativeDateMs.js] +---*/ + +var thrown; + +assertRelativeDateMs(new Date(1970, 0), 0); +assertRelativeDateMs(new Date(1970, 0, 1, 0, 0, 0, 0), 0); +assertRelativeDateMs(new Date(1970, 0, 1, 0, 0, 0, 1), 1); +assertRelativeDateMs(new Date(1970, 0, 1, 0, 0, 0, -1), -1); +assertRelativeDateMs(new Date(1970, 0, 1, 0, 0, 1, 0), 1000); +assertRelativeDateMs(new Date(1970, 0, 1, 0, 0, -1, 0), -1000); +assertRelativeDateMs(new Date(1970, 0, 1, 0, 2, 0, 0), 120000); +assertRelativeDateMs(new Date(1970, 0, 1, 0, -2, 0, 0), -120000); +assertRelativeDateMs(new Date(2016, 3, 12, 13, 21, 23, 24), 1460467283024); + +thrown = null; +try { + assertRelativeDateMs(new Date(1), 0); +} catch (err) { + thrown = err; +} +if (!thrown) { + throw new Error('Expected error, but no error was thrown.'); +} else if (thrown.constructor !== Test262Error) { + throw new Error('Expected error of type Test262Error.'); +} + +thrown = null; +try { + assertRelativeDateMs(new Date(-1), 0); +} catch (err) { + thrown = err; +} +if (!thrown) { + throw new Error('Expected error, but no error was thrown.'); +} else if (thrown.constructor !== Test262Error) { + throw new Error('Expected error of type Test262Error.'); +} + +thrown = null; +try { + assertRelativeDateMs(new Date(1970, 0), 1); +} catch (err) { + thrown = err; +} +if (!thrown) { + throw new Error('Expected error, but no error was thrown.'); +} else if (thrown.constructor !== Test262Error) { + throw new Error('Expected error of type Test262Error.'); +} + +thrown = null; +try { + assertRelativeDateMs(new Date(1970, 0), -1); +} catch (err) { + thrown = err; +} +if (!thrown) { + throw new Error('Expected error, but no error was thrown.'); +} else if (thrown.constructor !== Test262Error) { + throw new Error('Expected error of type Test262Error.'); +} + +thrown = null; +try { + assertRelativeDateMs(new Date('invalid'), NaN); +} catch (err) { + thrown = err; +} +if (!thrown) { + throw new Error('Expected error, but no error was thrown.'); +} else if (thrown.constructor !== Test262Error) { + throw new Error('Expected error of type Test262Error.'); +} diff --git a/test/sendable/harness/asyncHelpers-asyncTest-func-throws-sync.js b/test/sendable/harness/asyncHelpers-asyncTest-func-throws-sync.js new file mode 100644 index 0000000000000000000000000000000000000000..d6ee12c5e604fb861d845d7ab0a91550049c1507 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-asyncTest-func-throws-sync.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + The 'asyncTest' helper reports synchronous errors via $DONE. +includes: [asyncHelpers.js] +---*/ +var called = false; +var msg = "Should not be rethrown"; +function $DONE(error) { + called = true; + assert(error instanceof Test262Error); + assert.sameValue(error.message, msg, "Should report correct error"); +} +asyncTest(function () { + throw new Test262Error(msg); +}); +assert(called, "asyncTest called $DONE with a synchronously thrown error"); diff --git a/test/sendable/harness/asyncHelpers-asyncTest-rejects-non-callable.js b/test/sendable/harness/asyncHelpers-asyncTest-rejects-non-callable.js new file mode 100644 index 0000000000000000000000000000000000000000..51cd7c5ea90ad2ea58e1d3ed14ccc6dae03b85fe --- /dev/null +++ b/test/sendable/harness/asyncHelpers-asyncTest-rejects-non-callable.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + The 'asyncTest' helper rejects non-callable test functions. +includes: [asyncHelpers.js, compareArray.js] +---*/ + +const doneValues = []; +function $DONE(error) { + doneValues.push(error instanceof Test262Error); +} +asyncTest(null); +asyncTest({}); +asyncTest("string"); +asyncTest(42); +asyncTest(undefined); +asyncTest(); +assert.compareArray(doneValues, [true, true, true, true, true, true]); diff --git a/test/sendable/harness/asyncHelpers-asyncTest-return-not-thenable.js b/test/sendable/harness/asyncHelpers-asyncTest-return-not-thenable.js new file mode 100644 index 0000000000000000000000000000000000000000..f288ef082ba80e0492757b4a44992feaa0309080 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-asyncTest-return-not-thenable.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + The 'asyncTest' helper rejects test functions that do not return a thenable. +includes: [asyncHelpers.js, compareArray.js] +---*/ + +const doneValues = []; +function $DONE(error) { + // Will be a TypeError from trying to invoke .then() on non-thenable + doneValues.push(error instanceof TypeError); +} +asyncTest(function () { + return null; +}); +asyncTest(function () { + return {}; +}); +asyncTest(function () { + return "string"; +}); +asyncTest(function () { + return 42; +}); +asyncTest(function () {}); +asyncTest(function () { + return function () {}; +}); +assert.compareArray(doneValues, [true, true, true, true, true, true]); diff --git a/test/sendable/harness/asyncHelpers-asyncTest-returns-undefined.js b/test/sendable/harness/asyncHelpers-asyncTest-returns-undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..475c963474b2c9d579971353383b3543fd9b41f3 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-asyncTest-returns-undefined.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + The 'asyncTest' helper when called with async flag always returns undefined. +flags: [async] +includes: [asyncHelpers.js] +---*/ +var realDone = $DONE; +var doneCalls = 0; +globalThis.$DONE = function () { + doneCalls++; +}; + +(async function () { + assert.sameValue(undefined, asyncTest({})); + assert.sameValue( + undefined, + asyncTest(function () { + return "non-thenable"; + }) + ); + assert.sameValue( + undefined, + asyncTest(function () { + return Promise.resolve(true); + }) + ); + assert.sameValue( + undefined, + asyncTest(function () { + return Promise.reject(new Test262Error("oh no")); + }) + ); +})() + .then(() => { + assert.sameValue(doneCalls, 4, "asyncTest must call $DONE"); + }) + .then(realDone, realDone); diff --git a/test/sendable/harness/asyncHelpers-asyncTest-then-rejects.js b/test/sendable/harness/asyncHelpers-asyncTest-then-rejects.js new file mode 100644 index 0000000000000000000000000000000000000000..64b1feb3130de1fdf0bb0d353cc20387aa363204 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-asyncTest-then-rejects.js @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + The 'asyncTest' helper calls $DONE with the rejection value if the test function rejects. +flags: [async] +includes: [asyncHelpers.js, compareArray.js] +---*/ +const rejectionValues = []; +var realDone = $DONE; +globalThis.$DONE = function (mustBeDefined) { + rejectionValues.push(mustBeDefined); +}; +const someObject = {}; + +(async function () { + asyncTest(function () { + return Promise.reject(null); + }); +})() + .then(() => { + asyncTest(function () { + return Promise.reject(someObject); + }); + }) + .then(() => { + asyncTest(function () { + return Promise.reject("hi"); + }); + }) + .then(() => { + asyncTest(function () { + return Promise.reject(10); + }); + }) + .then(() => { + asyncTest(function () { + return { + then(res, rej) { + rej(true); + }, + }; + }); + }) + .then(() => { + assert.compareArray(rejectionValues, [null, someObject, "hi", 10, true]); + }) + .then(realDone, realDone); diff --git a/test/sendable/harness/asyncHelpers-asyncTest-then-resolves.js b/test/sendable/harness/asyncHelpers-asyncTest-then-resolves.js new file mode 100644 index 0000000000000000000000000000000000000000..a845bc126c03abb23276678f0557aa1a8f4edbc0 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-asyncTest-then-resolves.js @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + The 'asyncTest' helper calls $DONE with undefined, regardless of what value the promise resolves with +flags: [async] +includes: [asyncHelpers.js] +---*/ +var doneCalls = 0; +var realDone = $DONE; +globalThis.$DONE = function (noError) { + doneCalls++; + assert.sameValue( + noError, + undefined, + "asyncTest should discard promise's resolved value" + ); +}; + +(async function () { + asyncTest(function () { + return Promise.resolve(null); + }); +})() + .then(() => { + assert.sameValue(doneCalls, 1, "asyncTest called $DONE with undefined"); + asyncTest(function () { + return Promise.resolve({}); + }); + }) + .then(() => { + assert.sameValue(doneCalls, 2, "asyncTest called $DONE with undefined"); + asyncTest(function () { + return Promise.resolve("hi"); + }); + }) + .then(() => { + assert.sameValue(doneCalls, 3, "asyncTest called $DONE with undefined"); + asyncTest(function () { + return Promise.resolve(10); + }); + }) + .then(() => { + assert.sameValue(doneCalls, 4, "asyncTest called $DONE with undefined"); + asyncTest(function () { + return { + then(res, rej) { + res(true); + }, + }; + }); + }) + .then(() => { + assert.sameValue(doneCalls, 5, "asyncTest called $DONE with undefined"); + }) + .then(realDone, realDone); diff --git a/test/sendable/harness/asyncHelpers-asyncTest-without-async-flag.js b/test/sendable/harness/asyncHelpers-asyncTest-without-async-flag.js new file mode 100644 index 0000000000000000000000000000000000000000..d88c00c19ea76ce940d266d36d5e21472de8b84d --- /dev/null +++ b/test/sendable/harness/asyncHelpers-asyncTest-without-async-flag.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + The 'asyncTest' helper checks that it is called with the 'async' flag. +includes: [asyncHelpers.js] +---*/ +function makePromise() { + return { + then(res, rej) { + // Throw a different error than Test262Error to avoid confusion about what is rejecting + throw new Error("Should not be evaluated"); + }, + }; +} +assert( + !Object.hasOwn(globalThis, "$DONE"), + "Without 'async' flag, $DONE should not be defined" +); +assert.throws(Test262Error, function () { + asyncTest(makePromise); +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-custom-typeerror.js b/test/sendable/harness/asyncHelpers-throwsAsync-custom-typeerror.js new file mode 100644 index 0000000000000000000000000000000000000000..dc539f5c5f4e780d1c86451ffc00f5d6a3565813 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-custom-typeerror.js @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Thenables that reject with instances of the specified constructor function + satisfy the assertion, without collision with error constructors of the same name. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +var intrinsicTypeError = TypeError; + +asyncTest(async function () { + function TypeError() {} + var caught = false; + + var p = assert.throwsAsync( + TypeError, + async function () { + throw new TypeError(); + }, + "Throws an instance of the matching custom TypeError" + ); + assert(p instanceof Promise); + await p; + + p = assert.throwsAsync(intrinsicTypeError, async function () { + throw new TypeError(); + }); + assert(p instanceof Promise); + try { + await p; + } catch (err) { + caught = true; + assert.sameValue( + err.constructor, + Test262Error, + "Expected a Test262Error, but a '" + + err.constructor.name + + "' was thrown." + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject a collision of constructor names" + ); + } + + caught = false; + + p = assert.throwsAsync(TypeError, async function () { + throw new intrinsicTypeError(); + }); + assert(p instanceof Promise); + try { + await p; + } catch (err) { + caught = true; + assert.sameValue( + err.constructor, + Test262Error, + "Expected a Test262Error, but a '" + + err.constructor.name + + "' was thrown." + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject a collision of constructor names" + ); + } +}) diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-custom.js b/test/sendable/harness/asyncHelpers-throwsAsync-custom.js new file mode 100644 index 0000000000000000000000000000000000000000..1706ad8691b6e0ffce099ba6b01485ff8303d0fb --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-custom.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Thenables that reject with values of the specified constructor function + satisfy the assertion. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +function MyError() {} + +asyncTest(async function () { + const p = assert.throwsAsync(MyError, function () { + return Promise.reject(new MyError()); + }); + assert(p instanceof Promise); + await p; +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-func-never-settles.js b/test/sendable/harness/asyncHelpers-throwsAsync-func-never-settles.js new file mode 100644 index 0000000000000000000000000000000000000000..4b9b0c0af7ac8ef1aefdcab43d2a02d8bd24a760 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-func-never-settles.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + assert.throwsAsync returns a promise that never settles if func returns a thenable that never settles. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +var realDone = $DONE; +var doneCalls = 0 +globalThis.$DONE = function () { + doneCalls++; +} + +function delay() { + var later = Promise.resolve(); + for (var i = 0; i < 100; i++) { + later = later.then(); + } + return later; +} + +(async function () { + // Spy on the promise returned by an invocation of assert.throwsAsync + // with a function that returns a thenable which never settles. + var neverSettlingThenable = { then: function () { } }; + const p = assert.throwsAsync(TypeError, function () { return neverSettlingThenable }); + assert(p instanceof Promise, "assert.throwsAsync should return a promise"); + p.then($DONE, $DONE); +})() + // Give it a long time to try. + .then(delay, delay) + .then(function () { + assert.sameValue(doneCalls, 0, "$DONE should not have been called") + }) + .then(realDone, realDone); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-func-throws-sync.js b/test/sendable/harness/asyncHelpers-throwsAsync-func-throws-sync.js new file mode 100644 index 0000000000000000000000000000000000000000..ac2b4d5f17ff4674ff675fbb1c637634d801a081 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-func-throws-sync.js @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + assert.throwsAsync returns a promise that rejects if func or the inner thenable synchronously throws. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +async function checkRejects(func) { + var caught = false; + const p = assert.throwsAsync(Test262Error, func); + assert(p instanceof Promise, "assert.throwsAsync should return a promise"); + try { + await p; + } catch (e) { + caught = true; + assert.sameValue( + e.constructor, + Test262Error, + "throwsAsync should reject improper function with a Test262Error" + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject improper function " + func + ); + } +} + +asyncTest(async function () { + await checkRejects(function () { + throw new Error(); + }); + await checkRejects(function () { + throw new Test262Error(); + }); + await checkRejects(function () { + return { + then: function () { + throw new Error(); + }, + }; + }); + await checkRejects(function () { + return { + then: function () { + throw new Test262Error(); + }, + }; + }); +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-incorrect-ctor.js b/test/sendable/harness/asyncHelpers-throwsAsync-incorrect-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..174b8c6bedf72b307ff95f56f726f0e35b95d512 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-incorrect-ctor.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Thenables that reject with values whose constructor does not match the specified + constructor do not satisfy the assertion. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + var caught = false; + + const p = assert.throwsAsync(Error, function () { + return Promise.reject(new TypeError()); + }); + assert(p instanceof Promise); + try { + await p; + } catch (err) { + caught = true; + assert.sameValue( + err.constructor, + Test262Error, + "Expected a Test262Error, but a '" + + err.constructor.name + + "' was thrown." + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject when a value with incorrect constructor was thrown" + ); + } +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-invalid-func.js b/test/sendable/harness/asyncHelpers-throwsAsync-invalid-func.js new file mode 100644 index 0000000000000000000000000000000000000000..d8d797882dd37653fe7e8bda7d59ebaa0d533ed8 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-invalid-func.js @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + assert.throwsAsync calls $DONE with a rejecting value if func is not a function returning a thenable. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +async function checkRejects(func) { + var caught = false; + const p = assert.throwsAsync(Test262Error, func); + assert(p instanceof Promise, "assert.throwsAsync should return a promise"); + try { + await p; + } catch (e) { + caught = true; + assert.sameValue( + e.constructor, + Test262Error, + "throwsAsync should reject improper function with a Test262Error" + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject improper function " + func + ); + } +} + +asyncTest(async function () { + await checkRejects(null); + await checkRejects({}); + await checkRejects("string"); + await checkRejects(10); + await checkRejects(); + await checkRejects({ + then: function (res, rej) { + res(true); + }, + }); + await checkRejects(function () { + return null; + }); + await checkRejects(function () { + return {}; + }); + await checkRejects(function () { + return "string"; + }); + await checkRejects(function () { + return 10; + }); + await checkRejects(function () {}); + await checkRejects(function () { + return { then: null }; + }); + await checkRejects(function () { + return { then: {} }; + }); + await checkRejects(function () { + return { then: "string" }; + }); + await checkRejects(function () { + return { then: 10 }; + }); + await checkRejects(function () { + return { then: undefined }; + }); +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-native.js b/test/sendable/harness/asyncHelpers-throwsAsync-native.js new file mode 100644 index 0000000000000000000000000000000000000000..3ec3748c0c3cd866a6c97e4b2aaebf7498b00212 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-native.js @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Thenables that reject with instances of the specified native Error constructor + satisfy the assertion. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + var p = assert.throwsAsync(Error, async function () { + throw new Error(); + }); + assert(p instanceof Promise); + await p; + p = assert.throwsAsync(EvalError, async function () { + throw new EvalError(); + }); + assert(p instanceof Promise); + await p; + p = assert.throwsAsync(RangeError, async function () { + throw new RangeError(); + }); + assert(p instanceof Promise); + await p; + p = assert.throwsAsync(ReferenceError, async function () { + throw new ReferenceError(); + }); + assert(p instanceof Promise); + await p; + p = assert.throwsAsync(SyntaxError, async function () { + throw new SyntaxError(); + }); + assert(p instanceof Promise); + await p; + p = assert.throwsAsync(TypeError, async function () { + throw new TypeError(); + }); + assert(p instanceof Promise); + await p; + p = assert.throwsAsync(URIError, async function () { + throw new URIError(); + }); + assert(p instanceof Promise); + await p; +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-no-arg.js b/test/sendable/harness/asyncHelpers-throwsAsync-no-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..86febedd837d3808baf88eb63e26717964cf3454 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-no-arg.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + The assertion fails when invoked without arguments. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + var caught = false; + + const p = assert.throwsAsync(); + assert(p instanceof Promise); + try { + await p; + } catch (err) { + caught = true; + assert.sameValue( + err.constructor, + Test262Error, + "Expected a Test262Error, but a '" + + err.constructor.name + + "' was thrown." + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject when invoked without arguments" + ); + } +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-no-error.js b/test/sendable/harness/asyncHelpers-throwsAsync-no-error.js new file mode 100644 index 0000000000000000000000000000000000000000..f7e5aa22e45475b96d06fa911e6252dd6bd1a8ec --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-no-error.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Thenables that do not reject do not satisfy the assertion. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + var caught = false; + + const p = assert.throwsAsync(Error, async function () {}); + assert(p instanceof Promise); + try { + await p; + } catch (err) { + caught = true; + assert.sameValue( + err.constructor, + Test262Error, + "Expected a Test262Error, but a '" + + err.constructor.name + + "' was thrown." + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject when the thenable did not reject" + ); + } +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-null.js b/test/sendable/harness/asyncHelpers-throwsAsync-null.js new file mode 100644 index 0000000000000000000000000000000000000000..408d60e7d732ecf16cc8f985217e8ed53460db23 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-null.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Thenables that reject with the `null` value do not satisfy the assertion. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + var caught = false; + + const p = assert.throwsAsync(Error, async function () { + throw null; + }); + assert(p instanceof Promise); + try { + await p; + } catch (err) { + caught = true; + assert.sameValue( + err.constructor, + Test262Error, + "Expected a Test262Error, but a '" + + err.constructor.name + + "' was thrown." + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject when null was thrown" + ); + } +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-primitive.js b/test/sendable/harness/asyncHelpers-throwsAsync-primitive.js new file mode 100644 index 0000000000000000000000000000000000000000..f5a02da588596e7f7fab839b862687066e52586d --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-primitive.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Thenables that reject with primitive values do not satisfy the assertion. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + var caught = false; + + const p = assert.throwsAsync(Error, async function () { + throw 3; + }); + assert(p instanceof Promise); + try { + await p; + } catch (err) { + caught = true; + assert.sameValue( + err.constructor, + Test262Error, + "Expected a Test262Error, but a '" + + err.constructor.name + + "' was thrown." + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject when a primitive was thrown" + ); + } +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-resolved-error.js b/test/sendable/harness/asyncHelpers-throwsAsync-resolved-error.js new file mode 100644 index 0000000000000000000000000000000000000000..42d7ca4779ee27b3af24fba774cc66c2d5e40bf6 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-resolved-error.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Thenables that resolve with an error do not satisfy the assertion. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + var caught = false; + + const p = assert.throwsAsync( + Error, + Promise.resolve(new Error("it's-a-me, Chris Pratt")) + ); + assert(p instanceof Promise); + try { + await p; + } catch (err) { + caught = true; + assert.sameValue( + err.constructor, + Test262Error, + "Expected a Test262Error, but a '" + + err.constructor.name + + "' was thrown." + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject when the thenable resolved with an error" + ); + } +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-same-realm.js b/test/sendable/harness/asyncHelpers-throwsAsync-same-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..1e8aa80f7edad87d5a2df31eda5320236d1e2db3 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-same-realm.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + Thenables that reject with instances of the realm specified constructor function + do not satisfy the assertion with cross realms collisions. +flags: [async] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + var intrinsicTypeError = TypeError; + var caught = false; + var realmGlobal = $262.createRealm().global; + + const p = assert.throwsAsync(TypeError, async function () { + throw new realmGlobal.TypeError(); + }); + assert(p instanceof Promise); + try { + await p; + } catch (err) { + caught = true; + assert.sameValue( + err.constructor, + Test262Error, + "Expected a Test262Error, but a '" + + err.constructor.name + + "' was thrown." + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject when a different realm's error was thrown" + ); + } +}); diff --git a/test/sendable/harness/asyncHelpers-throwsAsync-single-arg.js b/test/sendable/harness/asyncHelpers-throwsAsync-single-arg.js new file mode 100644 index 0000000000000000000000000000000000000000..f5cbb1eb49dca96bd223461d591d1e38b46be9b5 --- /dev/null +++ b/test/sendable/harness/asyncHelpers-throwsAsync-single-arg.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: | + assert.throwsAsync returns a promise that rejects when invoked with a single argument +flags: [async] +includes: [asyncHelpers.js] +---*/ + +asyncTest(async function () { + var caught = false; + const p = assert.throwsAsync(function () {}); + assert(p instanceof Promise); + try { + await p; + } catch (err) { + caught = true; + assert.sameValue( + err.constructor, + Test262Error, + "Expected a Test262Error, but a '" + + err.constructor.name + + "' was thrown." + ); + } finally { + assert( + caught, + "assert.throwsAsync did not reject when invoked with a single argumemnt" + ); + } +}); diff --git a/test/sendable/harness/byteConversionValues.js b/test/sendable/harness/byteConversionValues.js new file mode 100644 index 0000000000000000000000000000000000000000..c02533947ea24db9eb3f08d2b172b8a04ff09e85 --- /dev/null +++ b/test/sendable/harness/byteConversionValues.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Ensure the original and expected values are set properly +includes: [byteConversionValues.js] +---*/ + +var values = byteConversionValues.values; +var expected = byteConversionValues.expected; + +assert(values.length > 0); +assert.sameValue(values.length, expected.Float32.length, "Float32"); +assert.sameValue(values.length, expected.Float64.length, "Float64"); +assert.sameValue(values.length, expected.Int8.length, "Int8"); +assert.sameValue(values.length, expected.Int16.length, "Int16"); +assert.sameValue(values.length, expected.Int32.length, "Int32"); +assert.sameValue(values.length, expected.Uint8.length, "Uint8"); +assert.sameValue(values.length, expected.Uint16.length, "Uint16"); +assert.sameValue(values.length, expected.Uint32.length, "Uint32"); +assert.sameValue(values.length, expected.Uint8Clamped.length, "Uint8Clamped"); diff --git a/test/sendable/harness/compare-array-arguments.js b/test/sendable/harness/compare-array-arguments.js new file mode 100644 index 0000000000000000000000000000000000000000..13c6d36edd1084e06b590d9d09489d270b5583a9 --- /dev/null +++ b/test/sendable/harness/compare-array-arguments.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Accepts spreadable arguments +includes: [compareArray.js] +---*/ + +const fixture = [0, 'a', undefined]; + +function checkFormatOfAssertionMessage(func, errorMessage) { + var caught = false; + try { + func(); + } catch (error) { + caught = true; + assert.sameValue(error.constructor, Test262Error); + assert.sameValue(error.message, errorMessage); + } + + assert(caught, `Expected ${func} to throw, but it didn't.`); +} + +function f() { + assert.compareArray(arguments, fixture); + assert.compareArray(fixture, arguments); + + checkFormatOfAssertionMessage(() => { + assert.compareArray(arguments, [], 'arguments and []'); + }, 'Actual [0, a, undefined] and expected [] should have the same contents. arguments and []'); + + checkFormatOfAssertionMessage(() => { + assert.compareArray([], arguments, '[] and arguments'); + }, 'Actual [] and expected [0, a, undefined] should have the same contents. [] and arguments'); +} + +f(...fixture); diff --git a/test/sendable/harness/compare-array-arraylike.js b/test/sendable/harness/compare-array-arraylike.js new file mode 100644 index 0000000000000000000000000000000000000000..dd7077221a10a74e62df17c0e21e6ce2d6e22b1f --- /dev/null +++ b/test/sendable/harness/compare-array-arraylike.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Accepts spreadable arguments +includes: [compareArray.js] +---*/ + +function checkFormatOfAssertionMessage(func, errorMessage) { + var caught = false; + try { + func(); + } catch (error) { + caught = true; + assert.sameValue(error.constructor, Test262Error); + assert.sameValue(error.message, errorMessage); + } + + assert(caught, `Expected ${func} to throw, but it didn't.`); +} + +const fixture = { length: 3, 0: 0, 1: 'a', 2: undefined}; + +assert.compareArray(fixture, [0, 'a', undefined]); +assert.compareArray([0, 'a', undefined], fixture); + +checkFormatOfAssertionMessage(() => { + assert.compareArray(fixture, [], 'fixture and []'); +}, 'Actual [0, a, undefined] and expected [] should have the same contents. fixture and []'); + +checkFormatOfAssertionMessage(() => { + assert.compareArray([], fixture, '[] and fixture'); +}, 'Actual [] and expected [0, a, undefined] should have the same contents. [] and fixture'); diff --git a/test/sendable/harness/compare-array-different-elements.js b/test/sendable/harness/compare-array-different-elements.js new file mode 100644 index 0000000000000000000000000000000000000000..f88c792b7305f7e04766f0c9d93f3354cd34a9ec --- /dev/null +++ b/test/sendable/harness/compare-array-different-elements.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Arrays containing different elements are not equivalent. +includes: [compareArray.js] +---*/ + +var first = [0, 'a', undefined]; +var second = [0, 'b', undefined]; + +assert.throws(Test262Error, () => { + assert.compareArray(first, second); +}, 'Arrays containing different elements are not equivalent.'); diff --git a/test/sendable/harness/compare-array-different-length.js b/test/sendable/harness/compare-array-different-length.js new file mode 100644 index 0000000000000000000000000000000000000000..adc42a7546a226dd6631c70ab2d4208446281efa --- /dev/null +++ b/test/sendable/harness/compare-array-different-length.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Arrays of differing lengths are not equivalent. +includes: [compareArray.js] +---*/ + + +assert.throws(Test262Error, () => { + assert.compareArray([], [undefined]); +}, 'Arrays of differing lengths are not equivalent.'); + +assert.throws(Test262Error, () => { + assert.compareArray([undefined], []); +}, 'Arrays of differing lengths are not equivalent.'); diff --git a/test/sendable/harness/compare-array-empty.js b/test/sendable/harness/compare-array-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..4fdc1850e230c81889aefaa6e98d309907265314 --- /dev/null +++ b/test/sendable/harness/compare-array-empty.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Empty arrays of are equivalent. +includes: [compareArray.js] +---*/ + +assert.compareArray([], [], 'Empty arrays are equivalent.'); diff --git a/test/sendable/harness/compare-array-falsy-arguments.js b/test/sendable/harness/compare-array-falsy-arguments.js new file mode 100644 index 0000000000000000000000000000000000000000..1b090010dc9549dcb63f7a988e46510d927267f1 --- /dev/null +++ b/test/sendable/harness/compare-array-falsy-arguments.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + compareArray gracefully handles nullish arguments. +includes: [compareArray.js] +---*/ + +function assertThrows(func, errorMessage) { + var caught = false; + try { + func(); + } catch (error) { + caught = true; + assert.sameValue(error.constructor, Test262Error); + assert.sameValue(error.message, errorMessage); + } + + assert(caught, `Expected ${func} to throw, but it didn't.`); +} + +assertThrows(() => assert.compareArray(), "Actual argument shouldn't be nullish. "); +assertThrows(() => assert.compareArray(null, []), "Actual argument shouldn't be nullish. "); +assertThrows(() => assert.compareArray(null, [], "foo"), "Actual argument shouldn't be nullish. foo"); + +assertThrows(() => assert.compareArray([]), "Expected argument shouldn't be nullish. "); +assertThrows(() => assert.compareArray([], undefined, "foo"), "Expected argument shouldn't be nullish. foo"); diff --git a/test/sendable/harness/compare-array-message.js b/test/sendable/harness/compare-array-message.js new file mode 100644 index 0000000000000000000000000000000000000000..2e28ee65d86268172e30443dd5259f9d948a38e0 --- /dev/null +++ b/test/sendable/harness/compare-array-message.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + compareArray can handle any value in message arg +includes: [compareArray.js] +features: [BigInt, Symbol] +---*/ + +assert.compareArray([], [], true); +assert.compareArray([], [], 1); +assert.compareArray([], [], 1n); +assert.compareArray([], [], () => {}); +assert.compareArray([], [], "test262"); +assert.compareArray([], [], Symbol("1")); +assert.compareArray([], [], {}); +assert.compareArray([], [], []); +assert.compareArray([], [], -1); +assert.compareArray([], [], Infinity); +assert.compareArray([], [], -Infinity); +assert.compareArray([], [], 0.1); +assert.compareArray([], [], -0.1); diff --git a/test/sendable/harness/compare-array-same-elements-different-order.js b/test/sendable/harness/compare-array-same-elements-different-order.js new file mode 100644 index 0000000000000000000000000000000000000000..639331a1fb285ce8a2554c1e47f5fd867ee53ef3 --- /dev/null +++ b/test/sendable/harness/compare-array-same-elements-different-order.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Arrays containg the same elements in different order are not equivalent. +includes: [compareArray.js] +---*/ + +var obj = {}; +var first = [0, 1, '', 's', null, undefined, obj]; +var second = [0, 1, '', 's', undefined, null, obj]; + +assert.throws(Test262Error, () => { + assert.compareArray(first, second); +}, 'Arrays containing the same elements in different order are not equivalent.'); diff --git a/test/sendable/harness/compare-array-same-elements-same-order.js b/test/sendable/harness/compare-array-same-elements-same-order.js new file mode 100644 index 0000000000000000000000000000000000000000..d8f17b8cef40a91fb910811d51d288480fa8bc43 --- /dev/null +++ b/test/sendable/harness/compare-array-same-elements-same-order.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Arrays containg the same elements in the same order are equivalent. +includes: [compareArray.js] +---*/ + +var obj = {}; +var first = [0, 1, '', 's', undefined, null, obj]; +var second = [0, 1, '', 's', undefined, null, obj]; + +assert.compareArray(first, second, 'Arrays containing the same elements in the same order are equivalent.'); diff --git a/test/sendable/harness/compare-array-samevalue.js b/test/sendable/harness/compare-array-samevalue.js new file mode 100644 index 0000000000000000000000000000000000000000..063309c1804a77313313d2c4b4c8fe57b032c337 --- /dev/null +++ b/test/sendable/harness/compare-array-samevalue.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + compareArray uses SameValue for value comparison. +includes: [compareArray.js] +---*/ + +assert.compareArray([NaN], [NaN]); +assert.throws(Test262Error, () => { + assert.compareArray([0], [-0]); +}); diff --git a/test/sendable/harness/compare-array-sparse.js b/test/sendable/harness/compare-array-sparse.js new file mode 100644 index 0000000000000000000000000000000000000000..e62352df68bd0919af60901035e9ca8c9293645a --- /dev/null +++ b/test/sendable/harness/compare-array-sparse.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Spares arrays are only equivalent if they have the same length. +includes: [compareArray.js] +---*/ + + +assert.compareArray([,], [,], 'Sparse arrays of the same length are equivalent.'); +assert.throws(Test262Error, () => { + assert.compareArray([,], [,,]); +}, 'Sparse arrays of differing lengths are not equivalent.'); +assert.throws(Test262Error, () => { + assert.compareArray([,,], [,]); +}, 'Sparse arrays of differing lengths are not equivalent.'); +assert.throws(Test262Error, () => { + assert.compareArray([,], []); +}, 'Sparse arrays are not equivalent to empty arrays.'); +assert.throws(Test262Error, () => { + assert.compareArray([], [,]); +}, 'Sparse arrays are not equivalent to empty arrays.'); diff --git a/test/sendable/harness/compare-array-symbol.js b/test/sendable/harness/compare-array-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..851741af51f685e85c109a73a746b40d961e4bce --- /dev/null +++ b/test/sendable/harness/compare-array-symbol.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + compareArray correctly formats Symbols in error message. +includes: [compareArray.js] +features: [Symbol] +---*/ + +var threw = false; + +try { + assert.compareArray([Symbol()], [Symbol('desc')]); +} catch (err) { + threw = true; + + assert.sameValue(err.constructor, Test262Error); + assert(err.message.indexOf('[Symbol()]') !== -1); + assert(err.message.indexOf('[Symbol(desc)]') !== -1); +} + +assert(threw); diff --git a/test/sendable/harness/dateConstants.js b/test/sendable/harness/dateConstants.js new file mode 100644 index 0000000000000000000000000000000000000000..96471ba49fb6de8af21fceed0f660cdfe979142e --- /dev/null +++ b/test/sendable/harness/dateConstants.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Including dateConstants.js will expose: + + var date_1899_end = -2208988800001; + var date_1900_start = -2208988800000; + var date_1969_end = -1; + var date_1970_start = 0; + var date_1999_end = 946684799999; + var date_2000_start = 946684800000; + var date_2099_end = 4102444799999; + var date_2100_start = 4102444800000; + +includes: [dateConstants.js] +---*/ +assert.sameValue(date_1899_end, -2208988800001); +assert.sameValue(date_1900_start, -2208988800000); +assert.sameValue(date_1969_end, -1); +assert.sameValue(date_1970_start, 0); +assert.sameValue(date_1999_end, 946684799999); +assert.sameValue(date_2000_start, 946684800000); +assert.sameValue(date_2099_end, 4102444799999); +assert.sameValue(date_2100_start, 4102444800000); diff --git a/test/sendable/harness/decimalToHexString.js b/test/sendable/harness/decimalToHexString.js new file mode 100644 index 0000000000000000000000000000000000000000..921e6746f03663d8be93bed568b0dc9d7757915c --- /dev/null +++ b/test/sendable/harness/decimalToHexString.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Including decimalToHexString.js will expose two functions: + + decimalToHexString + decimalToPercentHexString + +includes: [decimalToHexString.js] +---*/ + +assert.sameValue(decimalToHexString(-1), "FFFFFFFF"); +assert.sameValue(decimalToHexString(0.5), "0000"); +assert.sameValue(decimalToHexString(1), "0001"); +assert.sameValue(decimalToHexString(100), "0064"); +assert.sameValue(decimalToHexString(65535), "FFFF"); +assert.sameValue(decimalToHexString(65536), "10000"); + +assert.sameValue(decimalToPercentHexString(-1), "%FF"); +assert.sameValue(decimalToPercentHexString(0.5), "%00"); +assert.sameValue(decimalToPercentHexString(1), "%01"); +assert.sameValue(decimalToPercentHexString(100), "%64"); +assert.sameValue(decimalToPercentHexString(65535), "%FF"); +assert.sameValue(decimalToPercentHexString(65536), "%00"); diff --git a/test/sendable/harness/deepEqual-array.js b/test/sendable/harness/deepEqual-array.js new file mode 100644 index 0000000000000000000000000000000000000000..8c06a34ffbb45a3a6040403f04f1e273c5851925 --- /dev/null +++ b/test/sendable/harness/deepEqual-array.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + array values compare correctly. +includes: [deepEqual.js] +---*/ + +assert.deepEqual([], []); +assert.deepEqual([1, "a", true], [1, "a", true]); + +assert.throws(Test262Error, function () { assert.deepEqual([], [1]); }); +assert.throws(Test262Error, function () { assert.deepEqual([1, "a", true], [1, "a", false]); }); diff --git a/test/sendable/harness/deepEqual-circular.js b/test/sendable/harness/deepEqual-circular.js new file mode 100644 index 0000000000000000000000000000000000000000..656c35d5d74e1bb1e1a4adfbb82b2819cf539959 --- /dev/null +++ b/test/sendable/harness/deepEqual-circular.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + values compare correctly with circular references. +includes: [deepEqual.js] +---*/ + +var a = { x: 1 }; +var b = { x: 1 }; +a.a = a; +a.b = b; +b.a = b; +b.b = a; + +assert.deepEqual(a, b); diff --git a/test/sendable/harness/deepEqual-deep.js b/test/sendable/harness/deepEqual-deep.js new file mode 100644 index 0000000000000000000000000000000000000000..bd8b4eb8e2526e68974b0f9aca745b2c8eed7731 --- /dev/null +++ b/test/sendable/harness/deepEqual-deep.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + values compare correctly. +includes: [deepEqual.js] +---*/ + +assert.deepEqual({ a: { x: 1 }, b: [true] }, { a: { x: 1 }, b: [true] }); + +assert.throws(Test262Error, function () { assert.deepEqual({}, { a: { x: 1 }, b: [true] }); }); +assert.throws(Test262Error, function () { assert.deepEqual({ a: { x: 1 }, b: [true] }, { a: { x: 1 }, b: [false] }); }); diff --git a/test/sendable/harness/deepEqual-mapset.js b/test/sendable/harness/deepEqual-mapset.js new file mode 100644 index 0000000000000000000000000000000000000000..cbf2dcdcca43eb8e26da4947ba8c37a4e27063c1 --- /dev/null +++ b/test/sendable/harness/deepEqual-mapset.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + map/set values compare correctly. +includes: [deepEqual.js] +---*/ + +assert.deepEqual(new Set(), new Set()); +assert.deepEqual(new Set([1, "a", true]), new Set([1, "a", true])); +assert.deepEqual(new Map(), new Map()); +assert.deepEqual(new Map([[1, "a"], ["b", true]]), new Map([[1, "a"], ["b", true]])); + +assert.throws(Test262Error, function () { assert.deepEqual(new Set([]), new Set([1])); }); +assert.throws(Test262Error, function () { assert.deepEqual(new Set([1, "a", true]), new Set([1, "a", false])); }); +assert.throws(Test262Error, function () { assert.deepEqual(new Map([]), new Map([[1, "a"], ["b", true]])); }); +assert.throws(Test262Error, function () { assert.deepEqual(new Map([[1, "a"], ["b", true]]), new Map([[1, "a"], ["b", false]])); }); +assert.throws(Test262Error, function () { assert.deepEqual(new Map([[1, "a"], ["b", true]]), new Set([[1, "a"], ["b", false]])); }); diff --git a/test/sendable/harness/deepEqual-object.js b/test/sendable/harness/deepEqual-object.js new file mode 100644 index 0000000000000000000000000000000000000000..e087864c38962e4caf1979b30e4c8ff5dfac0df4 --- /dev/null +++ b/test/sendable/harness/deepEqual-object.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + object values compare correctly. +includes: [deepEqual.js] +---*/ + + +assert.deepEqual({}, {}); +assert.deepEqual({ a: 1, b: true }, { a: 1, b: true }); + +assert.throws(Test262Error, function () { assert.deepEqual({}, { a: 1, b: true }); }); +assert.throws(Test262Error, function () { assert.deepEqual({ a: 1, b: true }, { a: 1, b: false }); }); diff --git a/test/sendable/harness/deepEqual-primitives-bigint.js b/test/sendable/harness/deepEqual-primitives-bigint.js new file mode 100644 index 0000000000000000000000000000000000000000..db511f8b3658a0fd84a0ffa88671d378050166f0 --- /dev/null +++ b/test/sendable/harness/deepEqual-primitives-bigint.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + primitive BigInt values compare correctly. +features: [BigInt] +includes: [deepEqual.js] +---*/ + +assert.deepEqual(1n, 1n); +assert.deepEqual(Object(1n), 1n); + +assert.throws(Test262Error, function () { assert.deepEqual(1n, 1); }); +assert.throws(Test262Error, function () { assert.deepEqual(1n, 2n); }); diff --git a/test/sendable/harness/deepEqual-primitives.js b/test/sendable/harness/deepEqual-primitives.js new file mode 100644 index 0000000000000000000000000000000000000000..236791ba19774336871a2ac9377cd289b5fd0131 --- /dev/null +++ b/test/sendable/harness/deepEqual-primitives.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + primitive values compare correctly. +includes: [deepEqual.js] +---*/ + + +var s1 = Symbol(); +var s2 = Symbol(); +assert.deepEqual(null, null); +assert.deepEqual(undefined, undefined); +assert.deepEqual("a", "a"); +assert.deepEqual(1, 1); +assert.deepEqual(true, true); +assert.deepEqual(s1, s1); +assert.deepEqual(Object("a"), "a"); +assert.deepEqual(Object(1), 1); +assert.deepEqual(Object(true), true); +assert.deepEqual(Object(s1), s1); + +assert.throws(Test262Error, function () { assert.deepEqual(null, 0); }); +assert.throws(Test262Error, function () { assert.deepEqual(undefined, 0); }); +assert.throws(Test262Error, function () { assert.deepEqual("", 0); }); +assert.throws(Test262Error, function () { assert.deepEqual("1", 1); }); +assert.throws(Test262Error, function () { assert.deepEqual("1", "2"); }); +assert.throws(Test262Error, function () { assert.deepEqual(true, 1); }); +assert.throws(Test262Error, function () { assert.deepEqual(true, false); }); +assert.throws(Test262Error, function () { assert.deepEqual(s1, "Symbol()"); }); +assert.throws(Test262Error, function () { assert.deepEqual(s1, s2); }); diff --git a/test/sendable/harness/detachArrayBuffer-host-detachArrayBuffer.js b/test/sendable/harness/detachArrayBuffer-host-detachArrayBuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..a41eca6eee42ae8fd8350225f12964c27955381a --- /dev/null +++ b/test/sendable/harness/detachArrayBuffer-host-detachArrayBuffer.js @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Including detachArrayBuffer.js will expose a function: + + $DETACHBUFFER + + $DETACHBUFFER relies on the presence of a host definition for $262.detachArrayBuffer + +includes: [detachArrayBuffer.js] +---*/ + +var $262 = { + detachArrayBuffer() { + throw new Test262Error('$262.detachArrayBuffer called.'); + }, + destroy() {} +}; + +var ab = new ArrayBuffer(1); +var threw = false; + +try { + $DETACHBUFFER(ab); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } + if (err.message !== '$262.detachArrayBuffer called.') { + throw new Error(`Expected error message: ${err.message}`); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} + + diff --git a/test/sendable/harness/detachArrayBuffer.js b/test/sendable/harness/detachArrayBuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..d8a6bb28d70f445ea3a61508f8040e216e57032e --- /dev/null +++ b/test/sendable/harness/detachArrayBuffer.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Including detachArrayBuffer.js will expose a function: + + $DETACHBUFFER + + $DETACHBUFFER relies on the presence of a definition for $262.detachArrayBuffer. + + Without a definition, calling $DETACHBUFFER will result in a ReferenceError +---*/ + +var ab = new ArrayBuffer(1); +var threw = false; + +try { + $DETACHBUFFER(ab); +} catch(err) { + threw = true; + if (err.constructor !== ReferenceError) { + throw new Error( + 'Expected a ReferenceError, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a ReferenceError, but no error was thrown.'); +} + + diff --git a/test/sendable/harness/fnGlobalObject.js b/test/sendable/harness/fnGlobalObject.js new file mode 100644 index 0000000000000000000000000000000000000000..79612ca56c4e6dc61c8f07fe258dcec7e8b80cd6 --- /dev/null +++ b/test/sendable/harness/fnGlobalObject.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Including fnGlobalObject.js will expose a function: + + fnGlobalObject + + fnGlobalObject returns a reference to the global object. + +includes: [fnGlobalObject.js] +---*/ + +var gO = fnGlobalObject(); + +assert(typeof gO === "object"); +assert.sameValue(gO, this); diff --git a/test/sendable/harness/isConstructor.js b/test/sendable/harness/isConstructor.js new file mode 100644 index 0000000000000000000000000000000000000000..7c93bf57e35812421011877e91d1cb280c7ccb32 --- /dev/null +++ b/test/sendable/harness/isConstructor.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Including isConstructor.js will expose one function: + + isConstructor + +includes: [isConstructor.js] +features: [generators, Reflect.construct] +---*/ + +assert.sameValue(typeof isConstructor, "function"); + +assert.throws(Test262Error, () => isConstructor(), "no argument"); +assert.throws(Test262Error, () => isConstructor(undefined), "undefined"); +assert.throws(Test262Error, () => isConstructor(null), "null"); +assert.throws(Test262Error, () => isConstructor(123), "number"); +assert.throws(Test262Error, () => isConstructor(true), "boolean - true"); +assert.throws(Test262Error, () => isConstructor(false), "boolean - false"); +assert.throws(Test262Error, () => isConstructor("string"), "string"); + +assert.throws(Test262Error, () => isConstructor({}), "Object instance"); +assert.throws(Test262Error, () => isConstructor([]), "Array instance"); + +assert.sameValue(isConstructor(function(){}), true); +assert.sameValue(isConstructor(function*(){}), false); +assert.sameValue(isConstructor(() => {}), false); + +assert.sameValue(isConstructor(Array), true); +assert.sameValue(isConstructor(Array.prototype.map), false); diff --git a/test/sendable/harness/nans.js b/test/sendable/harness/nans.js new file mode 100644 index 0000000000000000000000000000000000000000..1e88c35b2f43ffabfb551f115720bf0bdd560236 --- /dev/null +++ b/test/sendable/harness/nans.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Including nans.js will expose: + + var NaNs = [ + NaN, + Number.NaN, + NaN * 0, + 0/0, + Infinity/Infinity, + -(0/0), + Math.pow(-1, 0.5), + -Math.pow(-1, 0.5), + Number("Not-a-Number"), + ]; + +includes: [nans.js] +---*/ + +for (var i = 0; i < NaNs.length; i++) { + assert.sameValue(Number.isNaN(NaNs[i]), true, "index: " + i); +} diff --git a/test/sendable/harness/nativeFunctionMatcher.js b/test/sendable/harness/nativeFunctionMatcher.js new file mode 100644 index 0000000000000000000000000000000000000000..eb5837e8afabd5423017650bc1f2037b46500640 --- /dev/null +++ b/test/sendable/harness/nativeFunctionMatcher.js @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Ensure that the regular expression generally distinguishes between valid + and invalid forms of the NativeFunction grammar production. +includes: [nativeFunctionMatcher.js] +---*/ + +[ + 'function(){[native code]}', + 'function(){ [native code] }', + 'function ( ) { [ native code ] }', + 'function a(){ [native code] }', + 'function a(){ /* } */ [native code] }', + `function a() { + // test + [native code] + /* test */ + }`, + 'function(a, b = function() { []; }) { [native code] }', + 'function [Symbol.xyz]() { [native code] }', + 'function [x[y][z[d]()]]() { [native code] }', + 'function ["]"] () { [native code] }', + 'function [\']\'] () { [native code] }', + '/* test */ function() { [native code] }', + 'function() { [native code] } /* test */', + 'function() { [native code] } // test', +].forEach((s) => { + try { + validateNativeFunctionSource(s); + } catch (unused) { + throw new Error(`${JSON.stringify(s)} should pass`); + } +}); + +[ + 'native code', + 'function() {}', + 'function(){ "native code" }', + 'function(){ [] native code }', + 'function()) { [native code] }', + 'function(() { [native code] }', + 'function []] () { [native code] }', + 'function [[] () { [native code] }', + 'function ["]] () { [native code] }', + 'function [\']] () { [native code] }', + 'function() { [native code] /* }', + '// function() { [native code] }', +].forEach((s) => { + let fail = false; + try { + validateNativeFunctionSource(s); + fail = true; + } catch (unused) {} + if (fail) { + throw new Error(`${JSON.stringify(s)} should fail`); + } +}); diff --git a/test/sendable/harness/promiseHelper.js b/test/sendable/harness/promiseHelper.js new file mode 100644 index 0000000000000000000000000000000000000000..3b9a3fb4022d18afec0fa3c743dc65df7f786e56 --- /dev/null +++ b/test/sendable/harness/promiseHelper.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Including promiseHelper.js will expose a function: + + checkSequence + + To ensure execution order of some async chain, checkSequence accepts an array + of numbers, each added during some operation, and verifies that they + are in numeric order. + +includes: [promiseHelper.js] +---*/ + +assert(checkSequence([1, 2, 3, 4, 5])); + +var threw = false; + +try { + checkSequence([2, 1, 3, 4, 5]); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} + diff --git a/test/sendable/harness/propertyhelper-verifyconfigurable-configurable-object.js b/test/sendable/harness/propertyhelper-verifyconfigurable-configurable-object.js new file mode 100644 index 0000000000000000000000000000000000000000..86d2eee70827dcf467f7001a53a6b0dda4d2d433 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifyconfigurable-configurable-object.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified property is configurable satisfy the assertion. +includes: [propertyHelper.js] +---*/ + +Object.defineProperty(this, 'Object', { + configurable: true, + value: Object +}); + +verifyConfigurable(this, 'Object'); diff --git a/test/sendable/harness/propertyhelper-verifyconfigurable-configurable.js b/test/sendable/harness/propertyhelper-verifyconfigurable-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..dbe3cfb927f8628436e581ad6aacb7880632de8b --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifyconfigurable-configurable.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified property is configurable satisfy the assertion. +includes: [propertyHelper.js] +---*/ + +var obj = {}; +Object.defineProperty(obj, 'a', { + configurable: true +}); + +verifyConfigurable(obj, 'a'); diff --git a/test/sendable/harness/propertyhelper-verifyconfigurable-not-configurable.js b/test/sendable/harness/propertyhelper-verifyconfigurable-not-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..ce4e580a5833debfb3b2bb4152d6e94b6a0f5e00 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifyconfigurable-not-configurable.js @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified property is not configurable do not satisfy the + assertion. +includes: [propertyHelper.js] +---*/ + +var threw = false; +var obj = {}; +Object.defineProperty(obj, 'a', { + configurable: false +}); + +try { + verifyConfigurable(obj, 'a'); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/propertyhelper-verifyenumerable-enumerable-symbol.js b/test/sendable/harness/propertyhelper-verifyenumerable-enumerable-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..392158459d2f87b16fa0946b5631b28d9e28ba96 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifyenumerable-enumerable-symbol.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified symbol property is enumerable satisfy the assertion. +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var obj = {}; +var s = Symbol('1'); +Object.defineProperty(obj, s, { + enumerable: true +}); + +verifyEnumerable(obj, s); diff --git a/test/sendable/harness/propertyhelper-verifyenumerable-enumerable.js b/test/sendable/harness/propertyhelper-verifyenumerable-enumerable.js new file mode 100644 index 0000000000000000000000000000000000000000..e065b0487d1f9b2bd4b792472c139260f74c1b9c --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifyenumerable-enumerable.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified string property is enumerable satisfy the assertion. +includes: [propertyHelper.js] +---*/ + +var obj = {}; +Object.defineProperty(obj, 'a', { + enumerable: true +}); + +verifyEnumerable(obj, 'a'); diff --git a/test/sendable/harness/propertyhelper-verifyenumerable-not-enumerable-symbol.js b/test/sendable/harness/propertyhelper-verifyenumerable-not-enumerable-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..834e38035650d81f54d4d068f2cda4a223a28ac0 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifyenumerable-not-enumerable-symbol.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified symbol property is not enumerable do not satisfy the + assertion. +includes: [propertyHelper.js] +features: [Symbol] +---*/ +var threw = false; +var obj = {}; +var s = Symbol('1'); +Object.defineProperty(obj, s, { + enumerable: false +}); + +try { + verifyEnumerable(obj, s); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Test262Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/propertyhelper-verifyenumerable-not-enumerable.js b/test/sendable/harness/propertyhelper-verifyenumerable-not-enumerable.js new file mode 100644 index 0000000000000000000000000000000000000000..b89b60bd1a120fc750eb348935f1ae681009b0b3 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifyenumerable-not-enumerable.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified string property is not enumerable do not satisfy the + assertion. +includes: [propertyHelper.js] +---*/ +var threw = false; +var obj = {}; +Object.defineProperty(obj, 'a', { + enumerable: false +}); + +try { + verifyEnumerable(obj, 'a'); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Test262Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/propertyhelper-verifynotconfigurable-configurable.js b/test/sendable/harness/propertyhelper-verifynotconfigurable-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..c8588def2a17b4ac12fec565b2fdf8df069e2974 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifynotconfigurable-configurable.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified property is configurable do not satisfy the + assertion. +includes: [propertyHelper.js] +---*/ +var threw = false; +var obj = {}; +Object.defineProperty(obj, 'a', { + configurable: true +}); + +try { + verifyNotConfigurable(obj, 'a'); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/propertyhelper-verifynotconfigurable-not-configurable.js b/test/sendable/harness/propertyhelper-verifynotconfigurable-not-configurable.js new file mode 100644 index 0000000000000000000000000000000000000000..44441eefe9f964f62c12f1078d0edc40ab74685f --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifynotconfigurable-not-configurable.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified property is not configurable satisfy the assertion. +includes: [propertyHelper.js] +---*/ + +var obj = {}; +Object.defineProperty(obj, 'a', { + configurable: false +}); + +verifyNotConfigurable(obj, 'a'); diff --git a/test/sendable/harness/propertyhelper-verifynotenumerable-enumerable-symbol.js b/test/sendable/harness/propertyhelper-verifynotenumerable-enumerable-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..aabe520fb344f0440ef4c670ff581013b124d02a --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifynotenumerable-enumerable-symbol.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified symbol property is enumerable do not satisfy the + assertion. +includes: [propertyHelper.js] +features: [Symbol] +---*/ +var threw = false; +var obj = {}; +var s = Symbol('1'); +Object.defineProperty(obj, s, { + enumerable: true +}); + +try { + verifyNotEnumerable(obj, s); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Test262Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Test262Error( + 'Expected a Test262Error, but no error was thrown for symbol key.' + ); +} diff --git a/test/sendable/harness/propertyhelper-verifynotenumerable-enumerable.js b/test/sendable/harness/propertyhelper-verifynotenumerable-enumerable.js new file mode 100644 index 0000000000000000000000000000000000000000..6199175ef49d8e3d7219c4fae2dec98397bb1030 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifynotenumerable-enumerable.js @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified string property is enumerable do not satisfy the + assertion. +includes: [propertyHelper.js] +---*/ +var threw = false; +var obj = {}; +Object.defineProperty(obj, 'a', { + enumerable: true +}); + +try { + verifyNotEnumerable(obj, 'a'); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Test262Error( + 'Expected a Test262Error, but no error was thrown for string key.' + ); +} diff --git a/test/sendable/harness/propertyhelper-verifynotenumerable-not-enumerable-symbol.js b/test/sendable/harness/propertyhelper-verifynotenumerable-not-enumerable-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..0b9ab739f30572183e3c84be9372f3f21ad9b171 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifynotenumerable-not-enumerable-symbol.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified symbol property is not enumerable satisfy the + assertion. +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var obj = {}; +var s = Symbol('1'); +Object.defineProperty(obj, s, { + enumerable: false +}); + +verifyNotEnumerable(obj, s); diff --git a/test/sendable/harness/propertyhelper-verifynotenumerable-not-enumerable.js b/test/sendable/harness/propertyhelper-verifynotenumerable-not-enumerable.js new file mode 100644 index 0000000000000000000000000000000000000000..49df7e7b52df304b12bcff5b50581e6e3dd7dec3 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifynotenumerable-not-enumerable.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified string property is not enumerable satisfy the + assertion. +includes: [propertyHelper.js] +---*/ + +var obj = {}; +Object.defineProperty(obj, 'a', { + enumerable: false +}); + +verifyNotEnumerable(obj, 'a'); diff --git a/test/sendable/harness/propertyhelper-verifynotwritable-not-writable-strict.js b/test/sendable/harness/propertyhelper-verifynotwritable-not-writable-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..169234db9063de21801bd01c117d76856818d8b6 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifynotwritable-not-writable-strict.js @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified property is not writable satisfy the assertion. +includes: [propertyHelper.js] +---*/ + +var obj = {}; + +Object.defineProperty(obj, 'a', { + writable: false, + value: 123 +}); + +verifyNotWritable(obj, 'a'); + +if (obj.a !== 123) { + throw new Error('`verifyNotWritable` should be non-destructive.'); +} diff --git a/test/sendable/harness/propertyhelper-verifynotwritable-writable.js b/test/sendable/harness/propertyhelper-verifynotwritable-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..5671e3cff8a70389f5e684041cdbf78b31aaed09 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifynotwritable-writable.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified property is writable do not satisfy the assertion. +includes: [propertyHelper.js] +---*/ +var threw = false; +var obj = {}; +Object.defineProperty(obj, 'a', { + writable: true, + value: 1 +}); + +try { + verifyNotWritable(obj, 'a'); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/propertyhelper-verifywritable-array-length.js b/test/sendable/harness/propertyhelper-verifywritable-array-length.js new file mode 100644 index 0000000000000000000000000000000000000000..d0ee0a61c2cc4fc7c780da6455935eb13c68d005 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifywritable-array-length.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + "length" property of Arrays is tested with valid value. +includes: [propertyHelper.js] +---*/ + +var array = [1, 2, 3]; + +verifyWritable(array, "length"); + +assert.sameValue(array.length, 3, '`verifyWritable` should be non-destructive.'); diff --git a/test/sendable/harness/propertyhelper-verifywritable-not-writable.js b/test/sendable/harness/propertyhelper-verifywritable-not-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..558160d1d477586c05069644ff31880b4d6072e5 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifywritable-not-writable.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified property is not writable do not satisfy the + assertion. +includes: [propertyHelper.js] +---*/ +var threw = false; +var obj = {}; +Object.defineProperty(obj, 'a', { + writable: false +}); + +try { + verifyWritable(obj, 'a'); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/propertyhelper-verifywritable-writable.js b/test/sendable/harness/propertyhelper-verifywritable-writable.js new file mode 100644 index 0000000000000000000000000000000000000000..fddeafd838b0d84a009575566fadfaeba6b0d009 --- /dev/null +++ b/test/sendable/harness/propertyhelper-verifywritable-writable.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified property is writable satisfy the assertion. +includes: [propertyHelper.js] +---*/ +var obj = {}; + +Object.defineProperty(obj, 'a', { + writable: true, + value: 123 +}); + +verifyWritable(obj, 'a'); + +if (obj.a !== 123) { + throw new Error('`verifyWritable` should be non-destructive.'); +} diff --git a/test/sendable/harness/proxytrapshelper-default.js b/test/sendable/harness/proxytrapshelper-default.js new file mode 100644 index 0000000000000000000000000000000000000000..3a686c37f30495a0a739be8e7ffc894daa45906b --- /dev/null +++ b/test/sendable/harness/proxytrapshelper-default.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: allowProxyTraps helper should default throw on all the proxy trap named methods being invoked +esid: pending +author: Jordan Harband +includes: [proxyTrapsHelper.js] +---*/ + +var traps = allowProxyTraps(); + +function assertTrapThrows(trap) { + if (typeof traps[trap] !== 'function') { + throw new Test262Error('trap ' + trap + ' is not a function'); + } + var failedToThrow = false; + try { + traps[trap](); + failedToThrow = true; + } catch (e) {} + if (failedToThrow) { + throw new Test262Error('trap ' + trap + ' did not throw an error'); + } +} + +assertTrapThrows('getPrototypeOf'); +assertTrapThrows('setPrototypeOf'); +assertTrapThrows('isExtensible'); +assertTrapThrows('preventExtensions'); +assertTrapThrows('getOwnPropertyDescriptor'); +assertTrapThrows('has'); +assertTrapThrows('get'); +assertTrapThrows('set'); +assertTrapThrows('deleteProperty'); +assertTrapThrows('defineProperty'); +assertTrapThrows('enumerate'); +assertTrapThrows('ownKeys'); +assertTrapThrows('apply'); +assertTrapThrows('construct'); diff --git a/test/sendable/harness/proxytrapshelper-overrides.js b/test/sendable/harness/proxytrapshelper-overrides.js new file mode 100644 index 0000000000000000000000000000000000000000..14f2c7ac5d6abdd1cbfb989753098274ebf8a8c7 --- /dev/null +++ b/test/sendable/harness/proxytrapshelper-overrides.js @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: allowProxyTraps helper should default throw on all the proxy trap named methods being invoked +esid: pending +author: Jordan Harband +includes: [proxyTrapsHelper.js] +---*/ +var overrides = { + getPrototypeOf: function () {}, + setPrototypeOf: function () {}, + isExtensible: function () {}, + preventExtensions: function () {}, + getOwnPropertyDescriptor: function () {}, + has: function () {}, + get: function () {}, + set: function () {}, + deleteProperty: function () {}, + defineProperty: function () {}, + enumerate: function () {}, + ownKeys: function () {}, + apply: function () {}, + construct: function () {}, +}; +var traps = allowProxyTraps(overrides); + +function assertTrapSucceeds(trap) { + if (typeof traps[trap] !== 'function') { + throw new Test262Error('trap ' + trap + ' is not a function'); + } + if (traps[trap] !== overrides[trap]) { + throw new Test262Error('trap ' + trap + ' was not overriden in allowProxyTraps'); + } + var threw = false; + try { + traps[trap](); + } catch (e) { + threw = true; + } + if (threw) { + throw new Test262Error('trap ' + trap + ' threw an error'); + } +} + +function assertTrapThrows(trap) { + if (typeof traps[trap] !== 'function') { + throw new Test262Error('trap ' + trap + ' is not a function'); + } + var failedToThrow = false; + try { + traps[trap](); + failedToThrow = true; + } catch (e) {} + if (failedToThrow) { + throw new Test262Error('trap ' + trap + ' did not throw an error'); + } +} + +assertTrapSucceeds('getPrototypeOf'); +assertTrapSucceeds('setPrototypeOf'); +assertTrapSucceeds('isExtensible'); +assertTrapSucceeds('preventExtensions'); +assertTrapSucceeds('getOwnPropertyDescriptor'); +assertTrapSucceeds('has'); +assertTrapSucceeds('get'); +assertTrapSucceeds('set'); +assertTrapSucceeds('deleteProperty'); +assertTrapSucceeds('defineProperty'); +assertTrapSucceeds('ownKeys'); +assertTrapSucceeds('apply'); +assertTrapSucceeds('construct'); + +// enumerate should always throw because the trap has been removed +assertTrapThrows('enumerate'); diff --git a/test/sendable/harness/sta.js b/test/sendable/harness/sta.js new file mode 100644 index 0000000000000000000000000000000000000000..1c6e7c9a29dbfca470194112dceff87721514a9f --- /dev/null +++ b/test/sendable/harness/sta.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Including sta.js will expose three functions: + + Test262Error + Test262Error.thrower + $DONOTEVALUATE +---*/ + +assert(typeof Test262Error === "function"); +assert(typeof Test262Error.prototype.toString === "function"); +assert(typeof Test262Error.thrower === "function"); +assert(typeof $DONOTEVALUATE === "function"); diff --git a/test/sendable/harness/tcoHelper.js b/test/sendable/harness/tcoHelper.js new file mode 100644 index 0000000000000000000000000000000000000000..f6666bb06eb91bfdc664d741b88d4becc8e019b8 --- /dev/null +++ b/test/sendable/harness/tcoHelper.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Including tcoHelper.js will expose: + + var $MAX_ITERATIONS = 100000; + + This defines the number of consecutive recursive function calls that must be + made in order to prove that stack frames are properly destroyed according to + ES2015 tail call optimization semantics. + +includes: [tcoHelper.js] +---*/ + + +assert.sameValue($MAX_ITERATIONS, 100000); diff --git a/test/sendable/harness/testTypedArray-conversions-call-error.js b/test/sendable/harness/testTypedArray-conversions-call-error.js new file mode 100644 index 0000000000000000000000000000000000000000..8902d448ac4bdb67eea441b21be9fb085c7c11a8 --- /dev/null +++ b/test/sendable/harness/testTypedArray-conversions-call-error.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Including testTypedArray.js will expose: + + testTypedArrayConversions() + +includes: [testTypedArray.js] +features: [TypedArray] +---*/ +var threw = false; + +try { + testTypedArrayConversions({}, () => {}); +} catch(err) { + threw = true; + if (err.constructor !== TypeError) { + throw new Error( + 'Expected a TypeError, but a "' + err.constructor.name + + '" was thrown.' + ); + } +} + +if (threw === false) { + throw new Error('Expected a TypeError, but no error was thrown.'); +} + + diff --git a/test/sendable/harness/testTypedArray-conversions.js b/test/sendable/harness/testTypedArray-conversions.js new file mode 100644 index 0000000000000000000000000000000000000000..295563def6f0489bb471db9bf6120a44d46dbf37 --- /dev/null +++ b/test/sendable/harness/testTypedArray-conversions.js @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Including testTypedArray.js will expose: + + testTypedArrayConversions() + +includes: [testTypedArray.js] +features: [TypedArray] +---*/ +var callCount = 0; +var bcv = { + values: [ + 127, + ], + expected: { + Int8: [ + 127, + ], + Uint8: [ + 127, + ], + Uint8Clamped: [ + 127, + ], + Int16: [ + 127, + ], + Uint16: [ + 127, + ], + Int32: [ + 127, + ], + Uint32: [ + 127, + ], + Float16: [ + 127, + ], + Float32: [ + 127, + ], + Float64: [ + 127, + ] + } +}; + +testTypedArrayConversions(bcv, function(TA, value, expected, initial) { + var sample = new TA([initial]); + sample.fill(value); + assert.sameValue(initial, 0); + assert.sameValue(sample[0], expected); + callCount++; +}); + diff --git a/test/sendable/harness/testTypedArray.js b/test/sendable/harness/testTypedArray.js new file mode 100644 index 0000000000000000000000000000000000000000..a90830bce48a5b0405d208a797edccebdd0400c9 --- /dev/null +++ b/test/sendable/harness/testTypedArray.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Including testTypedArray.js will expose: + + var typedArrayConstructors = [ array of TypedArray constructors ] + var TypedArray + + testWithTypedArrayConstructors() + testTypedArrayConversions() + +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert(typeof TypedArray === "function"); +assert.sameValue(TypedArray, Object.getPrototypeOf(Uint8Array)); + +var hasFloat16Array = typeof Float16Array !== 'undefined'; + +var callCount = 0; +testWithTypedArrayConstructors(() => callCount++); +assert.sameValue(callCount, 9 + hasFloat16Array); + +var index = 0; + +assert.sameValue(typedArrayConstructors[index++], Float64Array); +assert.sameValue(typedArrayConstructors[index++], Float32Array); +if (hasFloat16Array) { + assert.sameValue(typedArrayConstructors[index++], Float16Array); +} +assert.sameValue(typedArrayConstructors[index++], Int32Array); +assert.sameValue(typedArrayConstructors[index++], Int16Array); +assert.sameValue(typedArrayConstructors[index++], Int8Array); +assert.sameValue(typedArrayConstructors[index++], Uint32Array); +assert.sameValue(typedArrayConstructors[index++], Uint16Array); +assert.sameValue(typedArrayConstructors[index++], Uint8Array); +assert.sameValue(typedArrayConstructors[index++], Uint8ClampedArray); diff --git a/test/sendable/harness/verifyProperty-arguments.js b/test/sendable/harness/verifyProperty-arguments.js new file mode 100644 index 0000000000000000000000000000000000000000..5cc2efce7b19d64812a95b61ee57d378db6ee539 --- /dev/null +++ b/test/sendable/harness/verifyProperty-arguments.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + verifyProperty should receive at least 3 arguments: obj, name, and descriptor +includes: [propertyHelper.js] +---*/ +assert.throws(Test262Error, () => { + verifyProperty(); +}, "0 arguments"); + +assert.throws(Test262Error, () => { + verifyProperty(Object); +}, "1 argument"); + +assert.throws(Test262Error, () => { + verifyProperty(Object, 'foo'); +}, "2 arguments"); diff --git a/test/sendable/harness/verifyProperty-configurable-object.js b/test/sendable/harness/verifyProperty-configurable-object.js new file mode 100644 index 0000000000000000000000000000000000000000..2376ba9f810b7420d0dc43ef4b1ba75858705705 --- /dev/null +++ b/test/sendable/harness/verifyProperty-configurable-object.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Objects whose specified property is configurable satisfy the assertion. +includes: [propertyHelper.js] +---*/ + +Object.defineProperty(this, 'Object', { + configurable: true, + value: Object +}); + +verifyProperty(this, 'Object', { + configurable: true +}); diff --git a/test/sendable/harness/verifyProperty-desc-is-not-object.js b/test/sendable/harness/verifyProperty-desc-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..415e13079e04da16e8e6f71fe9cd310fd85d5d8e --- /dev/null +++ b/test/sendable/harness/verifyProperty-desc-is-not-object.js @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + The desc argument should be an object or undefined +includes: [propertyHelper.js] +features: [Symbol] +---*/ +var sample = { foo: 42 }; + +assert.throws(Test262Error, () => { + verifyProperty(sample, "foo", 'configurable'); +}, "string"); + +assert.throws(Test262Error, () => { + verifyProperty(sample, 'foo', true); +}, "boolean"); + +assert.throws(Test262Error, () => { + verifyProperty(sample, 'foo', 42); +}, "number"); + +assert.throws(Test262Error, () => { + verifyProperty(sample, 'foo', null); +}, "null"); + +assert.throws(Test262Error, () => { + verifyProperty(sample, 'foo', Symbol(1)); +}, "symbol"); diff --git a/test/sendable/harness/verifyProperty-noproperty.js b/test/sendable/harness/verifyProperty-noproperty.js new file mode 100644 index 0000000000000000000000000000000000000000..674d64090c516cc2c12dc4d79162bbf034e44644 --- /dev/null +++ b/test/sendable/harness/verifyProperty-noproperty.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + The first argument should have an own property +includes: [propertyHelper.js] +---*/ +assert.throws(Test262Error, () => { + verifyProperty(Object, 'JeanPaulSartre', {}); +}, "inexisting property"); + +assert.throws(Test262Error, () => { + verifyProperty({}, 'hasOwnProperty', {}); +}, "inexisting own property"); diff --git a/test/sendable/harness/verifyProperty-restore-accessor-symbol.js b/test/sendable/harness/verifyProperty-restore-accessor-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..12e5464f15b5ab1abdb33c07c132dee7b651fcd4 --- /dev/null +++ b/test/sendable/harness/verifyProperty-restore-accessor-symbol.js @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + verifyProperty allows restoring the original accessor descriptor +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var obj; +var prop = Symbol(1); +var desc = { enumerable: true, configurable: true, get() { return 42; }, set() {} }; + +obj = {}; +Object.defineProperty(obj, prop, desc); + +verifyProperty(obj, prop, desc); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(obj, prop), + false +); + +obj = {}; +Object.defineProperty(obj, prop, desc); + +verifyProperty(obj, prop, desc, { restore: true }); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(obj, prop), + true +); +assert.sameValue(obj[prop], 42); +assert.sameValue( + Object.getOwnPropertyDescriptor(obj, prop).get, + desc.get +); + +assert.sameValue( + Object.getOwnPropertyDescriptor(obj, prop).set, + desc.set +); diff --git a/test/sendable/harness/verifyProperty-restore-accessor.js b/test/sendable/harness/verifyProperty-restore-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..c1c437a816952a79d519bd5c46c431e8ae90e1fb --- /dev/null +++ b/test/sendable/harness/verifyProperty-restore-accessor.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + verifyProperty allows restoring the original accessor descriptor +includes: [propertyHelper.js] +---*/ + +var obj; +var prop = "prop"; +var desc = { enumerable: true, configurable: true, get() { return 42; }, set() {} }; + +obj = {}; +Object.defineProperty(obj, prop, desc); + +verifyProperty(obj, prop, desc); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(obj, prop), + false +); + +obj = {}; +Object.defineProperty(obj, prop, desc); + +verifyProperty(obj, prop, desc, { restore: true }); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(obj, prop), + true +); +assert.sameValue(obj[prop], 42); +assert.sameValue( + Object.getOwnPropertyDescriptor(obj, prop).get, + desc.get +); + +assert.sameValue( + Object.getOwnPropertyDescriptor(obj, prop).set, + desc.set +); diff --git a/test/sendable/harness/verifyProperty-restore-symbol.js b/test/sendable/harness/verifyProperty-restore-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..fcd4a80202bfb4221e3cfafaeace33fe2b9e34a1 --- /dev/null +++ b/test/sendable/harness/verifyProperty-restore-symbol.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + verifyProperty allows restoring the original descriptor +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var obj; +var prop = Symbol(1); +var desc = { enumerable: true, configurable: true, writable: true, value: 42 }; + +obj = {}; +Object.defineProperty(obj, prop, desc); + +verifyProperty(obj, prop, desc); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(obj, prop), + false +); + +obj = {}; +Object.defineProperty(obj, prop, desc); + +verifyProperty(obj, prop, desc, { restore: true }); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(obj, prop), + true +); +assert.sameValue(obj[prop], 42); diff --git a/test/sendable/harness/verifyProperty-restore.js b/test/sendable/harness/verifyProperty-restore.js new file mode 100644 index 0000000000000000000000000000000000000000..64a5da3960c577310b5d9e834721ee44b1594294 --- /dev/null +++ b/test/sendable/harness/verifyProperty-restore.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + verifyProperty allows restoring the original descriptor +includes: [propertyHelper.js] +---*/ + +var obj; +var prop = 'prop'; +var desc = { enumerable: true, configurable: true, writable: true, value: 42 }; + +obj = {}; +Object.defineProperty(obj, prop, desc); + +verifyProperty(obj, prop, desc); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(obj, prop), + false +); + +obj = {}; +Object.defineProperty(obj, prop, desc); + +verifyProperty(obj, prop, desc, { restore: true }); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(obj, prop), + true +); +assert.sameValue(obj[prop], 42); diff --git a/test/sendable/harness/verifyProperty-same-value.js b/test/sendable/harness/verifyProperty-same-value.js new file mode 100644 index 0000000000000000000000000000000000000000..644aeff7d186abefa34646e049d0e0568927eb23 --- /dev/null +++ b/test/sendable/harness/verifyProperty-same-value.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + verifyProperty uses SameValue for value comparison. +includes: [propertyHelper.js] +---*/ + +var obj = { + a: NaN, + b: -0, +}; + +assert(verifyProperty(obj, 'a', { value: NaN })); +assert(verifyProperty(obj, 'b', { value: -0 })); + +assert.throws(Test262Error, function() { + verifyProperty(obj, 'b', { value: 0 }); +}); diff --git a/test/sendable/harness/verifyProperty-string-prop.js b/test/sendable/harness/verifyProperty-string-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..b717d7efec5b40f4f6c34eb995fba60ebecb1629 --- /dev/null +++ b/test/sendable/harness/verifyProperty-string-prop.js @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Verify property descriptor +includes: [propertyHelper.js] +---*/ + +var obj; +var prop = 'prop'; + +function reset(desc) { + obj = {}; + Object.defineProperty(obj, prop, desc); +} + +function checkDesc(desc) { + reset(desc); + assert(verifyProperty(obj, prop, desc)); + + reset(desc); + assert(verifyProperty(obj, prop, { enumerable: desc.enumerable })); + + reset(desc); + assert(verifyProperty(obj, prop, { writable: desc.writable })); + + reset(desc); + assert(verifyProperty(obj, prop, { configurable: desc.configurable })); + + reset(desc); + assert(verifyProperty(obj, prop, { configurable: desc.configurable, enumerable: desc.enumerable })); + + reset(desc); + assert(verifyProperty(obj, prop, { configurable: desc.configurable, writable: desc.writable })); + + reset(desc); + assert(verifyProperty(obj, prop, { writable: desc.writable, enumerable: desc.enumerable })); + + reset(desc); + assert(verifyProperty(obj, prop, { enumerable: desc.enumerable, configurable: desc.configurable })); +} + +checkDesc({ enumerable: true, configurable: true, writable: true }); +checkDesc({ enumerable: false, writable: false, configurable: false }); +checkDesc({ enumerable: true, writable: false, configurable: false }); +checkDesc({ enumerable: false, writable: true, configurable: false }); +checkDesc({ enumerable: false, writable: false, configurable: true }); +checkDesc({ enumerable: true, writable: false, configurable: true }); +checkDesc({ enumerable: true, writable: true, configurable: false }); +checkDesc({ enumerable: false, writable: true, configurable: true }); diff --git a/test/sendable/harness/verifyProperty-symbol-prop.js b/test/sendable/harness/verifyProperty-symbol-prop.js new file mode 100644 index 0000000000000000000000000000000000000000..a8a40a6c3e2a563dea7cd874bd1f972aadf2b1af --- /dev/null +++ b/test/sendable/harness/verifyProperty-symbol-prop.js @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Verify symbol named property descriptor +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var obj; +var prop = Symbol(1); + +function reset(desc) { + obj = {}; + Object.defineProperty(obj, prop, desc); +} + +function checkDesc(desc) { + reset(desc); + assert(verifyProperty(obj, prop, desc)); + + reset(desc); + assert(verifyProperty(obj, prop, { enumerable: desc.enumerable })); + + reset(desc); + assert(verifyProperty(obj, prop, { writable: desc.writable })); + + reset(desc); + assert(verifyProperty(obj, prop, { configurable: desc.configurable })); + + reset(desc); + assert(verifyProperty(obj, prop, { configurable: desc.configurable, enumerable: desc.enumerable })); + + reset(desc); + assert(verifyProperty(obj, prop, { configurable: desc.configurable, writable: desc.writable })); + + reset(desc); + assert(verifyProperty(obj, prop, { writable: desc.writable, enumerable: desc.enumerable })); + + reset(desc); + assert(verifyProperty(obj, prop, { enumerable: desc.enumerable, configurable: desc.configurable })); +} + +checkDesc({ enumerable: true, configurable: true, writable: true }); +checkDesc({ enumerable: false, writable: false, configurable: false }); +checkDesc({ enumerable: true, writable: false, configurable: false }); +checkDesc({ enumerable: false, writable: true, configurable: false }); +checkDesc({ enumerable: false, writable: false, configurable: true }); +checkDesc({ enumerable: true, writable: false, configurable: true }); +checkDesc({ enumerable: true, writable: true, configurable: false }); +checkDesc({ enumerable: false, writable: true, configurable: true }); diff --git a/test/sendable/harness/verifyProperty-undefined-desc.js b/test/sendable/harness/verifyProperty-undefined-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..1c910b727dd624cc36d2d96eb51ee384a8f8905c --- /dev/null +++ b/test/sendable/harness/verifyProperty-undefined-desc.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ +/*--- +description: > + Verify an undefined descriptor +includes: [propertyHelper.js] +---*/ +var sample = { + bar: undefined, + get baz() {} +}; + +assert.sameValue( + verifyProperty(sample, "foo", undefined), + true, + "returns true if desc and property descriptor are both undefined" +); + +assert.throws(Test262Error, () => { + verifyProperty(sample, 'bar', undefined); +}, "dataDescriptor value is undefined"); + +assert.throws(Test262Error, () => { + verifyProperty(sample, 'baz', undefined); +}, "accessor returns undefined"); diff --git a/test/sendable/harness/verifyProperty-value-error.js b/test/sendable/harness/verifyProperty-value-error.js new file mode 100644 index 0000000000000000000000000000000000000000..9b44e6ee10f15c837ac1c74109c105be1875ef24 --- /dev/null +++ b/test/sendable/harness/verifyProperty-value-error.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Including propertyHelper.js will expose: + + verifyProperty() + ... + +includes: [propertyHelper.js] +---*/ + +var threw = false; +var object = Object.defineProperty({}, "prop", { + value: 1 +}); + +try { + verifyProperty(object, "prop", { + value: 2 + }); +} catch(err) { + threw = true; + if (err.constructor !== Test262Error) { + throw new Error( + 'Expected a Test262Error, but a "' + err.constructor.name + + '" was thrown.' + ); + } + + if (err.message !== 'descriptor value should be 2; object value should be 2') { + throw new Error('The error thrown did not define the specified message'); + } +} + +if (threw === false) { + throw new Error('Expected a Test262Error, but no error was thrown.'); +} diff --git a/test/sendable/harness/verifyProperty-value.js b/test/sendable/harness/verifyProperty-value.js new file mode 100644 index 0000000000000000000000000000000000000000..fbdf2862543bb179daaa3aef559cff7d8f1b82d6 --- /dev/null +++ b/test/sendable/harness/verifyProperty-value.js @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 SwanLink (Jiangsu) Technology 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. + */ + +/*--- +description: > + Verify property descriptor +includes: [propertyHelper.js] +---*/ + +var obj; +var prop = 'prop'; + +function reset(desc) { + desc.value = prop; + obj = Object.defineProperty({}, prop, desc); +} + +function checkDesc(desc) { + reset(desc); + assert(verifyProperty(obj, prop, desc)); + + reset(desc); + assert(verifyProperty(obj, prop, { value: 'prop', enumerable: desc.enumerable })); + + reset(desc); + assert(verifyProperty(obj, prop, { value: 'prop', writable: desc.writable })); + + reset(desc); + assert(verifyProperty(obj, prop, { value: 'prop', configurable: desc.configurable })); + + reset(desc); + assert(verifyProperty(obj, prop, { value: 'prop', configurable: desc.configurable, enumerable: desc.enumerable })); + + reset(desc); + assert(verifyProperty(obj, prop, { value: 'prop', configurable: desc.configurable, writable: desc.writable })); + + reset(desc); + assert(verifyProperty(obj, prop, { value: 'prop', writable: desc.writable, enumerable: desc.enumerable })); + + reset(desc); + assert(verifyProperty(obj, prop, { value: 'prop', enumerable: desc.enumerable, configurable: desc.configurable })); +} + +checkDesc({ enumerable: true, configurable: true, writable: true }); +checkDesc({ enumerable: false, writable: false, configurable: false }); +checkDesc({ enumerable: true, writable: false, configurable: false }); +checkDesc({ enumerable: false, writable: true, configurable: false }); +checkDesc({ enumerable: false, writable: false, configurable: true }); +checkDesc({ enumerable: true, writable: false, configurable: true }); +checkDesc({ enumerable: true, writable: true, configurable: false }); +checkDesc({ enumerable: false, writable: true, configurable: true }); diff --git a/test262/data/package.json b/test262/data/package.json new file mode 100644 index 0000000000000000000000000000000000000000..faa769dd7c7ff09631b9dbf525b1888832728a79 --- /dev/null +++ b/test262/data/package.json @@ -0,0 +1,31 @@ +{ + "name": "test262", + "version": "5.0.0", + "description": "Test262 tests conformance to the continually maintained draft future ECMAScript standard found at http://tc39.github.io/ecma262/ , together with any Stage 3 or later TC39 proposals.", + "repository": { + "type": "git", + "url": "git+https://github.com/tc39/test262.git" + }, + "license": "BSD", + "bugs": { + "url": "https://github.com/tc39/test262/issues" + }, + "private": true, + "homepage": "https://github.com/tc39/test262#readme", + "devDependencies": { + "esvu": "^1.2.11", + "test262-harness": "^8.0.0" + }, + "scripts": { + "ci": "./tools/scripts/ci_test.sh", + "test": "test262-harness", + "diff": "git diff --diff-filter ACMR --name-only main.. -- test/ && git ls-files --exclude-standard --others -- test/", + "test:diff": "npm run test:diff:v8 && npm run test:diff:spidermonkey && npm run test:diff:chakra && npm run test:diff:javascriptcore", + "test:diff:v8": "test262-harness -t 8 --hostType=d8 --hostPath=v8 $(npm run --silent diff)", + "test:diff:spidermonkey": "test262-harness -t 8 --hostType=jsshell --hostPath=spidermonkey $(npm run --silent diff)", + "test:diff:chakra": "test262-harness -t 8 --hostType=ch --hostPath=chakra $(npm run --silent diff)", + "test:diff:javascriptcore": "test262-harness -t 8 --hostType=jsc --hostPath=javascriptcore $(npm run --silent diff)", + "test:diff:xs": "test262-harness -t 8 --hostType=xs --hostPath=xs $(npm run --silent diff)" + } +} +